Commit Graph
6800 Commits
Author SHA1 Message Date
Yu Watanabe 4da43aeb0c locale-util: coding style cleanups 2025-04-13 04:59:26 +09:00
Yu Watanabe a4a5ee4cd1 locale-util: filter out non-UTF-8 locales even when failed to parse $SYSTEMD_LIST_NON_UTF8_LOCALES 2025-04-13 04:59:26 +09:00
Yu Watanabe 90abb64fd5 locale-util: fix argument for munmap() 2025-04-13 04:59:26 +09:00
Busayo Dada a51804a5ff Use secure_getenv() instead of getenv() where appropriate 2025-04-12 11:48:22 +01:00
Michal Sekletar 8b5e3be88e basic/namespace-util: obtain uid and gid before unsharing user namespace
Getting user and group after unsharing user namespace is too late
because without any mapping, i.e. just after unshare(), we are mapped to
nobody.
2025-04-09 03:06:05 +09:00
Yu Watanabe 8bf8e51bf5 fs-util: fix typo
Follow-up for 053e0626db.
2025-04-07 16:53:15 +09:00
Yu Watanabe 77c796d46f terminal-util: fix typo
Follow-up for 3390be38d1.
2025-04-07 16:35:18 +09:00
Yu Watanabe 79ef03740d terminal-util: fix typo
Follow-up for b27f791691.
2025-04-07 16:34:07 +09:00
Daan De Meyer 6aa69f702b core: Resolve /dev/console if it's connected to stdin (#36666) 2025-04-06 14:14:35 +02:00
Mike Yuan c0ebcb818e build-path: teach pin_callout_binary() to search $PATH too
Prompted by 2caa462504
2025-04-06 02:39:06 +02:00
Mike Yuan 28b6bfd370 build-path: port to open_and_check_executable(), do not return resolved path
Follow-up for b58c240312

We need to be extremely careful with using the path associated with fd,
since it contains the resolved path if a symlink was opened. In particular,
it's really not desirable to return the resolved executable path in
pin_callout_binary(), which would end up as argv[0] in udev_event_spawn(),
potentially changing the behavior of spawned process.
2025-04-06 02:39:05 +02:00
Mike Yuan 326d60a9d0 path-util: generalize open_and_check_executable() 2025-04-06 02:32:47 +02:00
Yu Watanabe e4e40936f3 nspawn: drop cgv1 handling; core: drop cgroup agent (#36764) 2025-04-05 17:57:18 +09:00
Yu Watanabe 99d704c6e8 stat-util: drop unnecessary call of xopenat() in xstatfsat() 2025-04-05 00:13:01 +09:00
Daan De Meyer c7f7d87db5 terminal-util: Make sure resolve_dev_console() always returns a full path
Currently it returns a full path in some cases and a partial path in others.
Let's make sure it always returns a full path.
2025-04-04 17:12:58 +02:00
Mike Yuan 40d54c2da0 procfs-util: modernize convert_meminfo_value_to_uint64_bytes() 2025-04-04 15:34:51 +02:00
Mike Yuan 110d0ff1fa procfs-util: use xsprintf() where appropriate 2025-04-04 15:34:51 +02:00
Mike Yuan 77a0d2e3ec core/cgroup: remove legacy hierarchy setup
This also makes pin_cgroupfs_fd actually pin the fs root,
so that we can port all cg_* helpers to operate under
the fd later on.
2025-04-04 15:34:51 +02:00
Mike Yuan 2a010ef8fd cgroup-util: remove now unused cg_kernel_controllers() 2025-04-04 14:36:14 +02:00
Yu Watanabe b58c240312 build-path: make pin_callout_binary() optionally provides the path to the found executable 2025-04-04 21:02:18 +09:00
Yu Watanabe 2c31eda469 build-path: check if found path is executable binary
Otherwise, the path may point to a non-executable, e.g. a directory.
2025-04-04 20:56:11 +09:00
Lennart Poettering 2caa462504 build-path: make invoke_callout_binary() honour $PATH as last resort
If we cannot find the callout we need in the build dir let's look for it
in $PATH as last resort.

This makes invoke_callout_binary() usable for all binaries we install
into $PATH (as opposed to /usr/lib/systemd), but has no effect
on callout binaries specified with full path.

This is useful, since we soon want to invoke journalctl as a callout.
2025-04-03 19:40:30 +09:00
Yu Watanabe 9ec7d7ae90 tree-wide: replace unsigned int -> unsigned, long int -> long 2025-04-03 06:01:31 +09:00
Yu Watanabe dba777cf26 memfd-util: make memfd_add/get_seals() static 2025-04-03 06:01:31 +09:00
Yu Watanabe 8f9737bf7e prioq: minor tweaks (#36963) 2025-04-03 04:10:10 +09:00
Lennart Poettering 39ce0324f9 prioq: add some minor overflow checking assert()s 2025-04-02 17:27:15 +02:00
Lennart Poettering bbcfac20a6 prioq: invalidate index pointers on removal 2025-04-02 17:27:15 +02:00
Yu Watanabe 147f1d7b26 process-util: make wait_for_terminate() as trivial wrapper of its PidRef version 2025-04-03 00:11:27 +09:00
Lennart Poettering 4ecc87bf1c process-util: add pidref-based version of wait_for_terminate_and_check() 2025-04-03 00:11:27 +09:00
Yu Watanabe 451277707d validatefs: several follow-ups (#36910) 2025-04-01 05:35:21 +09:00
Yu Watanabe 9441880d83 socket-util: introduce socket_autobind() helper (#36893)
Prompted by https://github.com/systemd/systemd/pull/36858#discussion_r2017719305
and #36833.
2025-04-01 02:55:04 +09:00
Mike Yuan 05587cece5 xattr-util: add missing assertions
Follow-up for ed024abac6
and 9fbe26cfa8

Also, let's not get too tangled up in the style of defining variables
in between. The functions are short enough, and vars involved are still
effectively at the beginning... Put differently, the separation from
'int r' is too deliberate and brings no actual value in my eyes.
2025-03-31 19:23:49 +02:00
Yu Watanabe 30252c0ca4 introduce systemd-validatefs@.service that ensures file systems can only be used in the way they were intended (#36714)
If we have multiple trusted fs (i.e. luks or dm-verity) we generate via
repart at boot, we must make sure they cannot be "misappropriated", i.e.
used for a different mount they were intended for.

Hence, let's introduce "mount constraint" data (encoded in xattrs on the
root inode of the fs) that tells us where a file system has to be
mounted, and what the gpt partition metadata has to be for the fs to be
valid.

Inspired by this thread:
https://lists.freedesktop.org/archives/systemd-devel/2025-March/051244.html
2025-04-01 01:14:33 +09:00
Mike Yuan 1eeb4f9f47 socket-util: introduce socket_autobind() helper
Prompted by https://github.com/systemd/systemd/pull/36858#discussion_r2017719305
and #36833
2025-03-31 18:11:37 +02:00
Mike Yuan ddbbc98bd5 socket-util: drop SO_BINDTODEVICE fallback in socket_bind_to_ifindex()
Our baseline is v5.4 now.
2025-03-31 18:00:09 +02:00
Yu Watanabe 4216018807 missing_socket: drop unnecessary definitions and update comments
- SO_PEERGROUPS is since kernel v4.13
  (28b5ba2aa0f55d80adb2624564ed2b170c19519e),
- SO_BINDTOIFINDEX is since kernel v5.1
  (f5dd3d0c9638a9d9a02b5964c4ad636f06cf7e2c).
2025-03-31 23:22:12 +09:00
Lennart Poettering f872373a26 generators: hook in validatefs on gpt-auto and fstab generator mounts
Let's turn on validatefs automatically for all auto-discovered
partitions.

Let's add an x-systemd.validatefs option to optionally turn this on for
fstab listed file systems.
2025-03-31 15:14:28 +02:00
Lennart Poettering 9fbe26cfa8 xattr-util: add trivial xsetxattr_strv() wrapper 2025-03-31 15:13:55 +02:00
Lennart Poettering ed024abac6 xattr-util: add trivial getxattr_at_strv() helper 2025-03-31 15:13:28 +02:00
Zbigniew Jędrzejewski-Szmek 55a8d118d6 basic/strv: return NULL from strv_skip
strv_skip was written to carefully return the original array, but this turns
out to be an unnecessary complication. After the previous patch, no caller
cares about the distinction between NULL and { NULL }, but various callers need
to wrap the process the returned value with strv_isempty(), sometimes more than
once. Let's always return NULL for an empty result to allow callers to be
simplified.
2025-03-27 12:04:23 +01:00
Luca Boccassi 5aee5bda1a tree-wide: introduce LOG_ITEM() macro for verifying format string (#36780)
This introduce `LOG_ITEM()` macro that checks format strings in
log_struct() and friends.

Hopefully, this silences false-positive warnings by Coverity.
2025-03-24 12:58:14 +00:00
Mike Yuan b062cf19f4 memory-util: make mempcpy_typesafe nestable 2025-03-20 17:31:54 +01:00
Yu Watanabe db4b4e0cd3 core: Make DelegateNamespaces= work for user managers with CAP_SYS_ADMIN (#36771)
Currently DelegateNamespaces= only works for services spawned by the
system manager. User managers will always unshare the user namespace
first even if they're running with CAP_SYS_ADMIN.

Let's add support for DelegateNamespaces= for user managers if they're
running with CAP_SYS_ADMIN. By default, we'll still delegate all
namespaces
for user managers, but this can now be overridden by explicitly passing
DelegateNamespaces=.

If a user manager is running without CAP_SYS_ADMIN, the user manager is
still always unshared first just like before.
2025-03-20 06:28:18 +09:00
Daan De Meyer f49b7404b2 capability-util: Ignore unknown capabilities instead of aborting
capability_ambient_set_apply() can be called with capability sets
containing unknown capabilities. Let's not crash when this is the
case but instead ignore the unknown capabilities.

This fixes a crash when running the following command:

"systemd-run -p "AmbientCapabilities=~" --wait --pipe id"

Fixes d5e12dc75e
2025-03-19 10:01:19 +01:00
Yu Watanabe 4b4181f4ac io-util: add one more assertion for Coverity
Fixes CID#1548067.
2025-03-19 11:41:25 +09:00
Yu Watanabe c995855266 bitfield: check if specified index is non-negative
Hopefully silences false-positive warnings by Coverity e.g. CID#1590746.
2025-03-19 09:56:04 +09:00
Yu Watanabe 3cf6a3a3d4 tree-wide: check more log message format in log_struct() and friends
This introduce LOG_ITEM() macro that checks arbitrary formats in
log_struct().
Then, drop _printf_ attribute from log_struct_internal(), as it does not
help so much, and compiler checked only the first format string.

Hopefully, this silences false-positive warnings by Coverity.
2025-03-19 01:56:48 +09:00
Lennart Poettering 2d47f43b43 cgroup-util: remove cg_get_xattr(), it's apparently unused 2025-03-18 07:17:10 +01:00
Lennart Poettering 33cbda04eb xattr-util: rework getxattr_at_malloc()
Let's return the size in a return parameter instead of the return value.
And if NULL is specified this tells us the caller doesn't care about the
size and expects a NUL terminated string. In that case look for an
embedded NUL byte, and refuse in that case.

This should lock things down a bit, as we'll systematically refuse
embedded NUL strings now when we expect strings.
2025-03-18 07:17:10 +01:00
Lennart Poettering 783b40bd73 namespace-util: introduce userns_acquire_self_root()
This is a simple helper for creating a userns that just maps the
callers user to UID 0 in the namespace. This can be acquired unpriv,
which makes it useful for various purposes, for example for the logic in
is_idmapping_supported(), hence port it over.

(is_idmapping_supported() used a different mapping before, with the
nobody users, but there's no real reason for that, and we'll use
userns_acquire_self_root() elsewhere soon, where the root mapping is
important).
2025-03-17 16:03:18 +01:00