Commit Graph
6832 Commits
Author SHA1 Message Date
Yu Watanabe 1479799c4d proc-cmdline: use proc_cmdline_key_string() when we search for key 2023-03-24 15:20:05 +09:00
Yu Watanabe b3e9a267ce proc-cmdline: rename variable 2023-03-24 15:20:05 +09:00
Yu Watanabe a175b98171 proc-cmdline: insert an empty line between variable declaration and assertion 2023-03-24 15:20:05 +09:00
Daan De Meyer ba54d73055 chase-symlinks: Use xopenat() instead of open_mkdir_at()
We don't rely on any of the extra functionality of open_mkdir_at()
so let's just use xopenat() directly.
2023-03-23 23:25:33 +00:00
Luca Boccassi d024c4d0e1 Merge pull request #26949 from DaanDeMeyer/xopenat-reopen
loop-util: Add loop_device_make_by_path_at()
2023-03-23 23:08:21 +00:00
Lennart Poettering b839101aac fileio: add new helper fdopen_independent()
This is a combination of fdopen() and fd_reopen(). i.e. it first reopens
the fd, and then converts that into a FILE*.

We do this at various places already manually. let's move this into a
helper call of its own.
2023-03-23 22:48:00 +00:00
Daan De Meyer 06ca2db39d fs-util: Allow xopenat() to reopen existing file descriptors 2023-03-23 17:31:55 +01:00
Daan De Meyer 1d5240cfaa Merge pull request #26936 from DaanDeMeyer/xopenat-lock
fs-util: Add xopenat_lock()
2023-03-23 07:49:12 +01:00
Daan De Meyer a7253c7fec Merge pull request #26916 from DaanDeMeyer/log-context-ref
log: Avoid pushing the same fields more than once on the log context
2023-03-22 22:07:45 +01:00
Daan De Meyer 2646b86dd6 fs-util: Add xopenat_lock()
open/create a file/directory and lock it using the given lock type.
2023-03-22 21:54:20 +01:00
Daan De Meyer a3b00f91bb core: Settle log target if we're going to be closing all fds
Whenever we're going to close all file descriptors, we tend to close
the log and set it into open when needed mode. When this is done with
the logging target set to LOG_TARGET_AUTO, we run into issues because
for every logging call, we'll check if stderr is connected to the
journal to determine where to send the logging message. This check
obviously stops working when we close stderr, so we settle the log
target before we do that so that we keep using the same logging
target even after stderr is closed.
2023-03-22 13:20:08 +01:00
Daan De Meyer bd7a79528c stat-util: Add verify_regular_at() 2023-03-22 12:17:14 +01:00
Daan De Meyer f3e03bd04e Merge pull request #26828 from DaanDeMeyer/tmpfile-at
tmpfile-util: Add open_tmpfile_linkable_at() and link_tmpfile_at()
2023-03-21 20:52:17 +01:00
Lennart Poettering 42db4a8db7 fd-util: make sure fd_reopen() works with AT_FDCWD systematically
Prompted by:

https://github.com/systemd/systemd/pull/26827#pullrequestreview-1341171981
2023-03-21 20:51:55 +01:00
Daan De Meyer 12ef261794 chase-symlinks: Add more chase_symlinks_at() helpers
Copies of the corresponding chase_symlinks() helpers.
2023-03-21 16:08:35 +01:00
Daan De Meyer 88f2ee8601 chase-symlinks: Return zero from access() and stat() helpers
We never check if r > 0 when using these helpers, so let's just
return zero like we usually do.
2023-03-21 16:08:35 +01:00
Daan De Meyer 63bfd52f48 chase-symlinks: Add CHASE_EXTRACT_FILENAME flag
Useful in combination with CHASE_PARENT to get a directory file
descriptor to the parent directory of the resolved path and the
filename of the resolved path in the parent directory (which might
not be the same as the filename of the input path because of symlinks).
2023-03-21 16:08:29 +01:00
Daan De Meyer d294857ea6 tmpfile-util: Add open_tmpfile_linkable_at() and link_tmpfile_at() 2023-03-21 15:20:01 +01:00
Daan De Meyer 14460a8a2b fs-util: Add open_parent_at() 2023-03-21 15:20:01 +01:00
Daan De Meyer aea3ca3613 lock-util: Add make_lock_file_at() 2023-03-21 15:19:33 +01:00
Daan De Meyer 81b3565efd log: Add key/value support to the log context
Now that we have reference counting, it's useful to be able to push
single key values onto the log context separately, so that we don't
have to allocate new storage to join the separate string together into
a single field which means we won't be able to reuse a context containing
the same field.
2023-03-21 14:54:04 +01:00
Daan De Meyer 883354532c log: Avoid pushing the same fields more than once on the log context
Let's try to optimize against pushing the same fields multiple times
onto the log context. To achieve this we make the log context reference
counted and return an existing context object if it's using the same
fields.

A consequence of this is that we have to make sure attaching/detaching
is coupled to the lifetime of the context object, so we make the attach
and detach functions private for now. If we need independent attach/detach
in the future, we can make that work with some extra complexity but since
we don't need it yet, let's not support it for now.
2023-03-21 14:25:10 +01:00
Yu Watanabe 00546c18fd strv: introduce strv_print_full() 2023-03-20 09:32:09 +01:00
Yu Watanabe 9edf5752e5 Merge pull request #26879 from mrc0mmand/cocci
tree-wide: simplify x ? x : y to x ?: y where applicable
2023-03-19 02:48:39 +09:00
Frantisek Sumsal 1da3cb8141 tree-wide: simplify x ? x : y to x ?: y where applicable 2023-03-18 14:23:11 +01:00
Yu Watanabe 58f5f60f1a os-util: add missing headers
For 'bool' and 'usec_t'.
2023-03-17 20:40:34 +09:00
Daan De Meyer 197dd3a9a4 terminal-util: Don't assume terminal is dumb if connected to /dev/null
If we're connected to /dev/null, we're likely going to be writing
colors to something that's not stdout/stderr, so let's fall back to
checking TERM if that's the case.
2023-03-16 11:21:28 +01:00
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