Commit Graph

5155 Commits

Author SHA1 Message Date
Daan De Meyer
f5abe8f957 Merge pull request #26784 from DaanDeMeyer/chase-fix
Allow creating files and directories with chase_symlinks_open() and further improvements
2023-03-15 15:51:47 +01:00
Daan De Meyer
39eb3ffaaa fs-util: Drop unlink_noerrno() 2023-03-15 13:27:20 +01:00
Daan De Meyer
a45332500d Merge pull request #26820 from DaanDeMeyer/dir-fd-is-root
fd-util: Add dir_fd_is_root()
2023-03-15 12:48:14 +01:00
Daan De Meyer
ea8282b6fc chase-symlinks: Add more assertions
Let's turn some runtime errors into assertions and add a few new
assertions.
2023-03-15 12:38:14 +01:00
Daan De Meyer
47f0e1b5e0 chase-symlinks: Rework open() functions and some chase flags
Currently, when CHASE_PARENT is specified, we chase the parent directory
of the symlink itself. Let's change this and chase the parent directory
of the symlink target so that trying to open the actual file later with
O_NOFOLLOW doesn't fail with ELOOP.

To get the current behavior, callers can add CHASE_NOFOLLOW to chase
the parent directory of the symlink itself.

Currently, when CHASE_MKDIR_0755 is specified, we create all components
of the path as directories. Instead, let's change the flag to only create
parent directories and leave the final component of the PATH untouched.
Also, allow CHASE_NONEXISTENT with CHASE_MKDIR_0755 now that it doesn't
create all components anymore.

Finally, rework chase_symlinks_and_open() and chase_symlinkat_at_and_open()
to always chase the parent directory and use xopenat() to open the final
component of the path. This allows us to pass O_CREAT to create the file or
directory (O_DIRECTORY) if it is missing. If CHASE_PARENT is configured, we
just reopen the parent directory that we chased.
2023-03-15 12:38:11 +01:00
Daan De Meyer
af423b4ba9 fd-util: Add dir_fd_is_root() 2023-03-15 11:51:08 +01:00
Daan De Meyer
9bf8441503 mountpoint-util: Add path_get_mnt_id_at() 2023-03-15 11:51:06 +01:00
Lennart Poettering
32e7970304 Merge pull request #26800 from t-8ch/memfd_create
memfd: add support for exec flags
2023-03-15 09:28:09 +01:00
Lennart Poettering
264c267686 Merge pull request #26794 from bluca/log_extra_fields
core: append LogExtraFields= values to log_unit* messages
2023-03-15 09:27:47 +01:00
Thomas Weißschuh
c29715a8f7 treewide: memfd_create: use exec flags
Use the flags MEMFD_EXEC or MEMFD_NOEXEC_SEAL as applicable.

These warnings instruct the kernel wether the memfd is executable or
not.

Without specifying those flags the kernel will emit the following
warning since version 6.3,
commit 105ff5339f49 ("mm/memfd: add MFD_NOEXEC_SEAL and MFD_EXEC"):

    kernel: memfd_create() without MFD_EXEC nor MFD_NOEXEC_SEAL, pid=1 'systemd'
2023-03-15 01:18:59 +00:00
Thomas Weißschuh
ad62530ebb memfd-util: add wrapper for memfd_create
The wrapper removes the flags MFD_EXEC and MFD_NOEXEC_SEAL when running
on kernels not understanding those flags.
2023-03-15 01:18:59 +00:00
Thomas Weißschuh
8cb0a001d8 missing: add memfd exec flags 2023-03-15 01:18:59 +00:00
Luca Boccassi
2461943b84 log: add iov helpers for log_context 2023-03-14 16:37:03 +00:00
Daan De Meyer
06344330a1 chase-symlinks: Remove unused ret_fd arguments 2023-03-14 13:46:58 +01:00
Daan De Meyer
0a9b887878 chase-symlinks: Fix memory leak 2023-03-14 09:56:59 +01:00
Daan De Meyer
7486f9c342 fs-util: Add xopenat()
xopenat() will create directories if O_DIRECTORY and O_CREAT are
specified. Note that this is not an atomic operation.
2023-03-14 09:55:04 +01:00
Lennart Poettering
b6904196a6 namespace-util: set mounts back to MS_SHARED in detach_mount_namespace()
For nspawn and services we first turn off two-way propagation of mounts
from host to sandbox via MS_SLAVE, and then set MS_SHARED again, so that
we create a new mount prop peer group again, and that we provide
behaviour similar to what we provide on the host further down the tree.

Let's do the same in detach_mount_namespace(), which we use for the
temporary mounts in the implementation of --image= in various tools.

This doesn't fix any immediate issue, but ensures we expose somewhat
systematic behaviour: whenever we detach mount namespaces we always set
things back to MS_SLAVE in the child.
2023-03-14 13:02:51 +09:00
Topi Miettinen
7a114ed4b3 execute: use prctl(PR_SET_MDWE) for MemoryDenyWriteExecute=yes
On some ARM platforms, the dynamic linker could use PROT_BTI memory protection
flag with `mprotect(..., PROT_BTI | PROT_EXEC)` to enable additional memory
protection for executable pages. But `MemoryDenyWriteExecute=yes` blocks this
with seccomp filter denying all `mprotect(..., x | PROT_EXEC)`.

Newly preferred method is to use prctl(PR_SET_MDWE) on supported kernels. Then
in-kernel implementation can allow PROT_BTI as necessary, without weakening
MDWE. In-kernel version may also be extended to more sophisticated protections
in the future.
2023-03-13 18:44:36 +00:00
Yu Watanabe
cbcdc582f3 Merge pull request #26749 from DaanDeMeyer/more-cleanups
execute: Some modernizations
2023-03-14 03:34:37 +09:00
Franck Bui
07e0ffc823 conf: replace config_parse_many_nulstr() with config_parse_config_file()
All daemons use a similar scheme to read their main config files and theirs
drop-ins. The main config files are always stored in /etc/systemd directory and
it's easy enough to construct the name of the drop-in directories based on the
name of the main config file.

Hence the new helper does that internally, which allows to reduce and simplify
the args passed previously to config_parse_many_nulstr().

Besides the overall code simplification it results:

  16 files changed, 87 insertions(+), 159 deletions(-)

it allows to identify clearly the locations in the code where configuration
files are parsed.
2023-03-14 03:31:21 +09:00
Daan De Meyer
846c9c12e7 lock-util: Add posix_lock()
POSIX locks with the same interface as flock().
2023-03-13 13:04:08 +01:00
Yu Watanabe
37c6a3dc1a time-util: add note about on DST change 2023-03-13 04:43:51 +09:00
Yu Watanabe
bd5770da76 time-util: make USEC_TIMESTAMP_FORMATTABLE_MAX for 32bit system off by one day
As the same reason why we take one day off for 64bit case.

This also makes both upper bounds always defined for testing.
2023-03-13 04:43:19 +09:00
Yu Watanabe
c9501b03cd Merge pull request #26641 from medhefgo/boot-elf2efi
boot: Drop gnu-efi / Add elf2efi.py
2023-03-11 17:15:01 +09:00
Daan De Meyer
aa41079175 Merge pull request #26726 from DaanDeMeyer/cleanups
Various small cleanups
2023-03-10 14:22:53 +01:00