Commit Graph
7528 Commits
Author SHA1 Message Date
Mike Yuan 085f92730a tree-wide: use ALPHANUMERICAL where appropriate
Prompted by 43116c5662
2026-03-04 07:36:10 +09:00
Yu Watanabe 43116c5662 tree-wide: use DIGITS and friends 2026-03-03 22:18:26 +01:00
Lennart Poettering d2b27a7a8c xstatx_full(): add flag to acquire STATX_MNT_ID_UNIQUE if we can, with fallback. 2026-03-03 08:49:23 +01:00
Lennart Poettering 2e9208199f stat-util: teach statx_mount_same() STATX_MNT_ID_UNIQUE
So far statx_mount_same() assumed STATX_MNT_ID_UNIQUE didn't exist.
However it does exist, hence do something useful if we see it set. Note
that this creates a certain ambiguity: if we compare one statx struct
with STATX_MNT_ID_UNIQUE and one without it (but with the regular mnt
id), then we cnanot really come to a clear conclusion, hence need to
introduce a third, unknown state.

Note that we don't request STATX_MNT_ID_UNIQUE yet wherever we call
statx_mount_same(). THis will be added in a later commit.
2026-03-03 08:48:01 +01:00
Lennart Poettering e4206858ad fd-util: minor shortcut 2026-03-03 08:48:01 +01:00
Lennart Poettering 4023840ffa fd-util: rename fds_are_same_mount() fds_inode_and_mount_same()
The old name suggested this would only check if the two inodes are on
the same mount, but it actually checks if they are the same inodes too.

Let's rename it to make this clearer, in particular as we have
both statx_inode_same() and statx_mount_same() already, and they are
even used here, and hence very confusing.

This also drops two checks from the test case, which are simply wrong.
Given they apparently weren't load bearing (since no CI tripped up),
let's just drop them.
2026-03-03 08:48:01 +01:00
Lennart Poettering 0384875582 chase: drop wrong optimization
The same optimization is already applied in the very similar
dir_fd_is_root() check a few lines up – with the exception that it
doesn't accept AT_FCWD there. And frankly turning off
CHASE_AT_RESOLVE_IN_ROOT if we operate on AT_FCWD is simply wrong. Hence
remove this code.
2026-03-03 08:48:01 +01:00
Lennart Poettering 3538b77f9d chase: tighten checks on ".." once we hit the root of an CHASE_AT_RESOLVE_IN_ROOT root tree
Let's harden things in case concurrent access is allowed to a root tree
passed via CHASE_AT_RESOLVE_IN_ROOT: let's not just validate via the
path if we hit the root of the tree, but also by comparing inodes +
mount ids.

Hardening opportunity reported by Sebastian Wick.
2026-03-03 08:48:01 +01:00
Lennart Poettering c8031ff37e chase: port to statx()
In one of the next commits we want to acquire .stx_mnt_id from statx()
for each inode we traverse (plain fstat() doesn't provide that field).
Hence let's port chase() over to statx() as preparation for that.

No change in behaviour.
2026-03-03 08:48:01 +01:00
Lennart Poettering 004e60e0fc chase: put limit on overall chase cycles
Let's add some protections in case we deal with inodes owned by an
untrusted person, with concurrent access: let's put a limit on how long
we traverse, and fail eventually so that live changes cannot send us in
circles indefinitely.

This reworks the current CHASE_MAX logic so that it not only applies to
symlinks transitions, but to any transitions.

This also bumps CHASE_MAX a bit, given that it's now bumped on every
single iteration of the loop.
2026-03-03 08:48:01 +01:00
Lennart Poettering 97fe03e12f stat-util: add statx() flavours of stat_verify_regular() + stat_verify_socket() 2026-03-03 08:48:01 +01:00
Lennart Poettering 36d7e177ad fd-util: make use of XAT_FDROOT in path_is_root_at() 2026-03-03 08:48:01 +01:00
Mike Yuan a12a4bdc9a pidref: do not tamper with pidref_acquire_pidfd_id() retval
If a pidfd id is passed to us, it must have originated from
somewhere, i.e. pidfs should be supported on the system.
Hence let's be honest about -EOPNOTSUPP, which might indicate
some bigger problems under the hood, rather than allowing
it to be turned into mild -ESRCH.
2026-03-02 15:25:53 +09:00
Yu Watanabe 5ae3bb09c6 mountpoint-util: add overlay check to fstype_is_blockdev_backed() and simplify fstype_is_api_vfs() (#40866) 2026-03-02 13:15:14 +09:00
Mike Yuan abffc0ef43 process-util: leave actual log fd closing to close_all_fds() if the latter will be done anyways 2026-03-01 13:18:19 +01:00
Lennart Poettering d423ec258c nss-systemd,strv: use a common definition of a non-NULL but empty strv
Follow-up for: 239903d44c
2026-03-01 08:51:14 +01:00
Pontus Lundkvist 352bb934fe mountpoint-util: remove duplicate check in fstype_is_api_vfs()
devtmpfs is part of the @basic-api filesystem-set
2026-02-27 14:10:27 +01:00
Pontus Lundkvist d4acc09d9d mountpoint-util: add exempt for overlay in fstype_is_blockdev_backed()
This allows `systemd-mount` to be used with --type overlay
2026-02-27 14:06:09 +01:00
Zbigniew Jędrzejewski-Szmek 04897fbbee bootctl: override is_efi_boot() check by --variables= option (#40413)
Fixes #40392.
2026-02-25 15:42:53 +01:00
Daan De Meyer 838528104b nsresourced: Optionally map foreign UID range
Whenever delegating UID ranges to a user namespace, it can also be
useful to map the foreign UID range, so that the container running in
the user namespace with delegated UID ranges can download container
images and unpack them to the foreign UID range.

Let's add an option mapForeign to make this possible. Note that this option
gives unprivileged users full access to the any foreign UID range owned directory
that they can access. Hence it is recommended (and already was recommended) to
store foreign UID range owned directories in a 0700 directory owned by the
owner of the tree to avoid access and modifications by other users.

This is already the case for the main users of the foreign UID range,
namely /var/lib/machines, /var/lib/portables and /home/<user> which all
use 0700 as their mode.

Users will also be able to create foreign UID range owned inodes in any
directories their own user can write to (on most systems this means /tmp,
/var/tmp and /home/<user>).
2026-02-24 18:29:37 +01:00
Daan De Meyer 95d05079bf nsresourced: Add support for self mappings with delegations
mkosi does all of its environment setup in an unprivileged user
namespace with an identity mapping. When it invokes nspawn and nspawn
tries to get a transient userns from nsresourced, this fails as no
transient ranges are mapped into mkosi's unprivileged userns (as doing
so would require privileges).

To fix this problem, let's allow allocating unprivileged self user
namespaces in nsresourced, similar to what the kernel allows, except that
we also support delegations for these. This means that mkosi can get its
unprivileged userns as before from nsresourced, but it can also request a
delegated 64K range inside that userns as well, which nsresourced can then
allocate to nspawn later when it asks for one.

Similar to the kernel, we disallow setgroups for self mappings. However,
instead of doing this via /proc/self/setgroups, which applies to the current
user namespace and all its child user namespaces, we use the BPF LSM to deny
setgroups instead, so that it can still be allowed for child user namespaces.
We need this because as soon as a container launches in a child user namespace
using one of the delegated mappings, it has to be able to do setgroups() to be
able to function properly.

To allow mapping the root user, we need to add the CAP_SETFCAP capability to
nsresourced.
2026-02-24 18:29:37 +01:00
Daan De Meyer 025439faaa nsresourced: Add support for delegated ranges
We want to support the scenario where we bind mount the nsresourced
varlink socket into a container to allow nested containers where the
outer container runs in its own transient range from nsresourced but
can still allocate transient ranges for its own nested containers.

To support this use case let's add support for delegation. Delegated
ranges are allocated when allocating the primary range and are propagated
1:1 to the user namespace. We track delegated ranges in ".delegate" files
in the userns registry so that they can't be used for other range allocations.

We make one exception for delegated ranges though, if we get a request from
a user namespace that is a child of the user namespace that owns the delegated
ranges, we allow allocating from the delegated range. The parent userns already
has full ownership over the child userns, so it doesn't matter that the parent
userns and the child userns share the same range. This allows making use of
delegated ranges without having to run another copy of nsresourced inside the
parent userns to hand out from the delegated range.

To support recursive delegations, we keep track of the previous owners of the
delegated range and restore ownership to the last previous owner when the current
owner is freed.
2026-02-24 18:29:37 +01:00
Daan De Meyer 6c2d437585 nsresourced: Allow operations outside transient UID/GID ranges
The purpose of the userns-restrict BPF-LSM program is to prevent the
transient ranges leaking to disk, so let's allow operations outside the
transient UID ranges, even if the mount is not allowlisted.

This is preparation for the next commits where we'll add support for mapping
the current user and the foreign UID range into the user namespaces provisioned
by nsresourced. Operations creating files/directories as these UIDs/GIDs should
not need the corresponding mount to be allowlisted with nsresourced.
2026-02-24 18:29:37 +01:00
Yu Watanabe c418543a65 include: update kernel headers from v7.0-rc1
In v7.0-rc1, the kernel introduces typelimits.h to define __KERNEL_INT_MIN/_MAX.
Also, NULL_FS_MAGIC has been introduced for immutable rootfs..
2026-02-24 23:08:52 +09:00
Yu Watanabe 3cfb169988 errno-list: filter out EFSBADCRC and EFSCORRUPTED
These are introduced in kernel v7.0.
2026-02-24 12:58:09 +00:00
Zbigniew Jędrzejewski-Szmek 04d2a86e66 manager: add needs-stop/needs-start (#40709)
Intend to use these in the deb packaging scriptlets

Fixes: #19755
2026-02-24 00:36:06 +01:00
Luca Boccassi f3a34fcc3a manager: add 'needs-stop/needs-start' markers
Useful for packaging scripts, when units are removed.
When multiple markers are assigned without +/-, the last one wins.
When using +/-, the job merging logic is followed to the extent possible.
2026-02-23 13:05:23 +00:00
Mike Yuan d8302c2fd9 journalctl-vl-server: allow querying units for specific uid in system scope
This also moves journal_add_unit_matches() back to
journalctl-filter.[ch], as I see more appropriate.
2026-02-23 10:43:00 +01:00
Daan De Meyer 0dbdbed03f uid-range: Handle same userns in uid_range_load_userns_by_fd()
If we're asked to look up our own user namespace mapping, don't go
via fd as trying to setns() to our own user namespace in
userns_enter_and_pin() would fail with EPERM as the kernel doesn't
allow switching to your own userns.
2026-02-19 21:33:11 +01:00
Daan De Meyer e6be5fb720 ssh-proxy: Support ssh machine/xxx for nspawn containers 2026-02-19 21:32:29 +01:00
Lennart Poettering cab2caa170 mountpoint-util: fix typo in comment 2026-02-19 15:08:20 +01:00
Lennart Poettering dbf13060e1 uid-range: add uid_range_base() that returns the lowest entry 2026-02-19 15:05:14 +01:00
Lennart Poettering 4c701125df basic: define Architecture typedef in basic-forward.h 2026-02-19 15:05:14 +01:00
Yu Watanabe 3aaa9d9882 Revert "meson: fix compatibility with Python 3.7"
This reverts commit 2793d6acf0.

Now we require Python 3.9 or newer.
2026-02-18 18:47:15 +09:00
Daan De Meyer e38fac0cc5 sd-bus: Make sure we can connect to user machines as well (#40698)
Don't unconditionally look into /run/systemd/machines. If we're a
connected to a session bus, look at the machines for the current user
instead.
2026-02-17 19:13:40 +01:00
Daan De Meyer 6119252f5a sd-bus: Don't fork unnecessarily to connect to container
Let's check if we're already in the right namespaces and call connect()
directly if that's the case. This can easily happen when the machine is
specified as .host or so.
2026-02-17 17:52:20 +01:00
Daan De Meyer a12c5bf4f5 sd-bus: Make sure we can connect to user machines as well
Don't unconditionally look into /run/systemd/machines. If we're a
connected to a session bus, look at the machines for the current user
instead.
2026-02-17 17:52:20 +01:00
Daan De Meyer 8d11835397 namespace-util: Do is_our_namespace() checks first in namespace_enter()
These checks may rely on /proc on older kernels which we could lose access
to by joining namespaces so let's do all the checks first and then join
namespaces.
2026-02-17 17:52:17 +01:00
Yu Watanabe 1f8fefd7de memstream-util: fix doubled %m
Follow-up for abe72100cf.
2026-02-18 00:47:25 +09:00
Daan De Meyer 3791710f44 namespace-util: Add extra debug logging 2026-02-17 16:44:37 +01:00
Mike Yuan fad273450a socket-util: remove unused {send,receive}_many_fds*()
These were introduced as part of the effort of sd-executor
worker pool (#29566), which never landed due to unsignificant
performance improvement. Let's just remove the unused
helpers. If that work ever gets resurrected they can be
restored from this commit pretty easily.
2026-02-17 14:56:00 +09:00
Yu Watanabe ed6a2eaa31 ask-password-api: several modernizations for ask_password_agent(); use CLEANUP_TMPFILE_AT more (#40631) 2026-02-16 20:07:32 +09:00
Daan De Meyer 4e40c2a515 namespace-util: Merge namespace_enter_delegated() into namespace_enter() (#40669)
There's no need to pass in a boolean to decide whether we use
namespace_enter_delegated() or not. Instead, we can just check if we
have CAP_SYS_ADMIN in our own user namespace. If we don't, then we have
to insist on a child user namespace being passed in and we have to enter
it first to get CAP_SYS_ADMIN as without CAP_SYS_ADMIN we wouldn't be
able
to call setns() in the first place. If we do have CAP_SYS_ADMIN, we can
always enter the other namespaces first before entering the user
namespace.

Additionally, we don't fail anymore if we can't reset the UID/GID since
a
root user might not always be available in every user namespace we might
enter.
2026-02-16 11:26:41 +01:00
Daan De Meyer 211c3c9d41 namespace-util: Merge namespace_enter_delegated() into namespace_enter()
There's no need to pass in a boolean to decide whether we use
namespace_enter_delegated() or not. Instead, we can just check if we
have CAP_SYS_ADMIN in our own user namespace. If we don't, then we have
to insist on a child user namespace being passed in and we have to enter
it first to get CAP_SYS_ADMIN as without CAP_SYS_ADMIN we wouldn't be able
to call setns() in the first place. If we do have CAP_SYS_ADMIN, we can
always enter the other namespaces first before entering the user namespace.

Additionally, we don't fail anymore if we can't reset the UID/GID since a
root user might not always be available in every user namespace we might
enter.
2026-02-16 10:27:02 +01:00
Mike Yuan 3ac675dff3 process-util: drop unused TAKE_PID
Follow-up for fbd276cb86

We now track helper processes via PidRef throughout the codebase.
2026-02-16 09:44:53 +01:00
Mike Yuan 36f82366d0 process-util: group oom_score_adjust_is_valid() with getter/setter 2026-02-16 09:44:53 +01:00
Mike Yuan 763f615c3a log-context: drop redundant forward decl
We consolidated all these into forward.h.
2026-02-16 09:44:52 +01:00
Daan De Meyer e2c1f3ca2a user-util: Don't setgroups() if /proc/self/gid_map is empty
If /proc/self/gid_map is empty, the kernel will refuse setgroups(),
so don't attempt it if that's the case on top of the /proc/self/setgroups
check we already have.
2026-02-16 09:37:32 +01:00
Daan De Meyer 051d228b1c tree-wide: Add some extra debug logging 2026-02-16 09:37:32 +01:00
andre4ik3 4afa6cf07a locale-util: allow overriding locale directory via environment 2026-02-16 08:09:33 +09:00