Commit Graph
55793 Commits
Author SHA1 Message Date
Luca Boccassi 7ebbe57ece Kill several SysV compat functionalities (v258) (#38178) 2025-07-15 01:21:13 +01:00
Luca Boccassi 9ae2dbf7f4 Two fixlets for coverage test (#38183) 2025-07-14 21:16:36 +01:00
Luca Boccassi 6eab4cd44c boot: add LoaderTpm2ActivePcrBanks runtime variable
It turns out checking sysfs is not 100% reliable to figure out whether
the firmware had TPM2 support enabled or not. For example with EDK2 arm64, the
default upstream build config bundles TPM2 support with SecureBoot support,
so if the latter is disabled, TPM2 is also unavailable. But still, the ACPI
TPM2 table is created just as if it was enabled. So /sys/firmware/acpi/tables/TPM2
exists and looks correct, but there are no measurements, neither the firmware
nor the loader/stub can do them, and /sys/kernel/security/tpm0/binary_bios_measurements
does not exist.

The loader can use the apposite UEFI protocol to check, which is a more
definitive answer. Given userspace can also make use of this information, export
the bitmask with the list of active banks as-is. If it's not 0, then we can be
sure a working TPM2 was available in EFI mode.

Partially fixes https://github.com/systemd/systemd/issues/38071
2025-07-14 20:56:22 +01:00
Daan De Meyer 9120022587 vmspawn: Run auxiliary daemons inside scope instead of separate service (#38047)
Currently, vmspawn is in this really weird state where vmspawn itself
and qemu will inherit the caller's execution environment but the
auxiliary
daemons it spawn will run in a fully pristine environment in the service
manager. In practice, this causes issues as checks for whether auxiliary
daemons are installed happen in the caller's execution environment but
they
might not exist in the spawned service's execution environment.

A good example of where this causes issues is trying to use
systemd-vmspawn
in our CI. We use mkosi in CI to run systemd-vmspawn in a custom
userspace
with all the necessary tools available, but systemd-vmspawn then tries
to
spawn services that run these tools using the host userspace, where the
tools are not available or too old and hence systemd-vmspawn fails to
start.

Let's make things more consistent and allow using systemd-vmspawn in CI
at
the same time by having systemd-vmspawn spawn auxiliary daemons itself
instead of having the service manager spawn them. We use
systemd-socket-activate to still have socket activation for these
services,
even though we now spawn them ourselves. To make sure we wait for
systemd-socket-activate to bind to its socket before continuing, we use
the
new general fork_notify() helper.

Why not support both "online" and "offline" operation? systemd-vmspawn
is not
well tested as is and supporting two completely separate modes for
spawning
auxiliary daemons will drastically increase the surface area for bugs.
Given
there doesn't seem to be a major benefit to running daemons in services,
it
seems better to only support offline operation and not both. Should we
want
separate resource control for the auxiliary daemons in the future, we
can run
move them into separate scopes if needed.
2025-07-14 16:51:18 +02:00
DaanDeMeyer 852de7ed70 nspawn: Prepare --bind-user= logic for reuse in systemd-vmspawn
Aside from the usual boilerplate of moving the shared logic to shared/,
we also rework the implementation of --bind-user= to be similar to what
we'll do in systemd-vmspawn. Instead of messing with the nspawn container
user namespace, we use idmapped mounts to map the user's home directory on
the host to the mapped uid in the container.

Ideally we'd also use the "userdb.transient" credentials to provision the
user records, but this would only work for booted containers, whereas the
current logic works for non-booted containers as well.

Aside from being similar to how we'll implement --bind-user= in vmspawn,
using idmapped mounts also allows supporting --bind-user= without having to
use --private-users=.
2025-07-14 16:25:22 +02:00
DaanDeMeyer c81fa16ddf vmspawn: Run auxiliary daemons inside scope instead of separate service
Currently, vmspawn is in this really weird state where vmspawn itself
and qemu will inherit the caller's execution environment but the auxiliary
daemons it spawn will run in a fully pristine environment in the service
manager. In practice, this causes issues as checks for whether auxiliary
daemons are installed happen in the caller's execution environment but they
might not exist in the spawned service's execution environment.

A good example of where this causes issues is trying to use systemd-vmspawn
in our CI. We use mkosi in CI to run systemd-vmspawn in a custom userspace
with all the necessary tools available, but systemd-vmspawn then tries to
spawn services that run these tools using the host userspace, where the
tools are not available or too old and hence systemd-vmspawn fails to start.

Let's make things more consistent and allow using systemd-vmspawn in CI at
the same time by having systemd-vmspawn spawn auxiliary daemons itself
instead of having the service manager spawn them. We use
systemd-socket-activate to still have socket activation for these services,
even though we now spawn them ourselves. To make sure we wait for
systemd-socket-activate to bind to its socket before continuing, we use the
new general fork_notify() helper.

Why not support both "online" and "offline" operation? systemd-vmspawn is not
well tested as is and supporting two completely separate modes for spawning
auxiliary daemons will drastically increase the surface area for bugs. Given
there doesn't seem to be a major benefit to running daemons in services, it
seems better to only support offline operation and not both. Should we want
separate resource control for the auxiliary daemons in the future, we can run
move them into separate scopes if needed.

As a bonus, this approach allows us to get rid of the extra complexity of
having to fork off the qemu process first so we can allocate a scope for it
that the other services bind to. This means large parts of
0fc45c8d20 are reverted by this commit.
2025-07-14 15:07:48 +02:00
DaanDeMeyer e4691ebb49 fork-journal: Generalize to fork-notify
Most of the logic isn't journalctl specific, let's generalize a bit
so we can reuse this for other commands as well.
2025-07-14 15:07:48 +02:00
DaanDeMeyer be3f7aaf44 fork-journal: Don't log if process is already gone in journal_terminate() 2025-07-14 15:07:48 +02:00
Daan De Meyer 43d0d111d2 core/cgroup: always submit unit to realize queue if all controllers are being invalidated (#38194) 2025-07-14 15:07:16 +02:00
DaanDeMeyer a79e94aa58 vmspawn: Pass credentials via files
Credentials data can get potentially very large. Passing it all via
the command line is rather messy. Let's pass all the credential data
via files instead to both make the final command line less verbose
and reduce the chance of us running into command line size limits if
many or large credentials are used.
2025-07-14 14:54:19 +02:00
DaanDeMeyer 1408505318 meson: Fix missing test dependencies
These test would fail when executed directly with meson test before
doing a build because the required dependencies are not declared, let's
fix that.
2025-07-14 13:07:29 +01:00
DaanDeMeyer b955051244 nspawn: Don't clear idmapping if we're not doing an idmapped mount
We only need to clear the existing idmapping if we're going to be
replacing it with another idmapping. Otherwise we should keep the
existing idmapping in place.
2025-07-14 11:54:56 +01:00
Daan De Meyer 6488fa5634 Replace underscores in filenames with hyphens (#38203) 2025-07-14 10:37:23 +02:00
DaanDeMeyer f4df5902d8 bpf: Use hyphens in directory names instead of underscores 2025-07-13 12:45:37 +02:00
DaanDeMeyer d962bfeb03 boot: Use hypen in efi-config.h instead of underscore 2025-07-13 12:41:57 +02:00
DaanDeMeyer 47f761fda6 basic: Use hyphens in missing header names instead of underscores 2025-07-13 12:41:14 +02:00
Yu Watanabe dc1505555b utmp: drop setting runlevel entry in utmp
This removes systemd-update-utmp-runlevel.service and related command.
2025-07-13 05:49:00 +09:00
Yu Watanabe 8ba48d4bf8 core,initctl,systemctl: kill /dev/initctl support
This also kills support for controlling system state through
/sbin/init, initctl, and telinit.
2025-07-13 05:38:14 +09:00
Yu Watanabe af925f7eb3 systemctl: kill SysV compat 'runlevel' command 2025-07-13 05:38:13 +09:00
Yu Watanabe 5572fb18c0 systemctl/halt: drop support for calling in SysV init script
Traditionally, halt is called at the end of the init script on
reboot/shutdown. To support such usecase, previously we read the current
runlevel from utmp and set force flag on reboot/shutdown.

This drops the support for such the usecase.
Note, neither supported nor tested, but hopefully still the command can
be used in the end of the sysv init script by specifying -ff.
2025-07-13 05:38:13 +09:00
Yu Watanabe c17516a84a systemctl: move functions in systemctl-sysv-compat.[ch]
- parse_shutdown_time_spec() is used only by systemctl-compat-shutdown.c,
- talk_initctl() and action_to_runlevel() are used only by systemctl-compat-telinit.c,
- the exit code enum is widely used in systemctl, hence moved to systemctl-util.h.

No functional change, preparation for later changes.
2025-07-13 05:38:13 +09:00
Mike Yuan 391ad5d8aa io.systemd.Unit.List fix context/runtime split (#38172)
This PR rearranges fields in io.systemd.Unit.List according to
@poettering guidance:

> if a property can be set in a unit file, ever, then it belongs in
context. Otherwise, it belongs to runtime.

https://github.com/systemd/systemd/issues/38124
2025-07-12 18:01:41 +02:00
Mike Yuan e0d3213e09 core/cgroup: always submit unit to realize queue if all controllers are being invalidated
Alternative to #38190
Fixes #38112
2025-07-12 17:41:52 +02:00
Mike Yuan 77af13ffdb core/cgroup: remove deserialization for "cpuacct-usage-base"
This has been superseded by "cpu-usage-base" ever since
the introduction of cgroup v2. With upgrading and thus
deserialzing from cgroup v1 systems becoming impossible
it is eligible for removal.
2025-07-12 17:41:04 +02:00
Mike Yuan db54d1a6b7 core/exec-invoke: pass "/" instead of "" for cgroup root 2025-07-12 17:32:32 +02:00
Yu Watanabe 5921c48fcf meson: fix coverage build
This moves coverage.h to src/coverage/, and specifies path to coverage.h
with files() directive, to make it can be included even when located
outside of the include directories. Otherwise, libc-wrapper cannot be
built when -Db_coverage=true option is enabled.

Follow-up for 543a48b653.
2025-07-12 21:19:01 +09:00
Yu Watanabe b1eb6cc28b pidref: propagate critical errors in pidref_acquire_pidfd_id()
Follow-up for 571867ffa7.

Fixes CID#1612242.
2025-07-12 19:51:01 +09:00
DaanDeMeyer b98d6bff23 core: Fix scope SIGTERM logging
KILL_TERMINATE_AND_LOG doesn't do anything at the moment, let's fix
that.
2025-07-12 19:50:47 +09:00
Lennart Poettering d38dd7d17a core/scope: drop effectively unused unit_watch_pidref() calls (#38186) 2025-07-12 07:27:56 +02:00
DaanDeMeyer bd427d005c journal: Fix socket max level initialization
Follow up for df5b3426f6
2025-07-12 07:18:45 +02:00
Mike Yuan 66867d5308 core/scope: serialize_item() is NOP on NULL 2025-07-11 22:20:25 +02:00
Mike Yuan 4db4641a65 core/scope: drop effectively unused unit_watch_pidref() calls
Follow-up for 495e75ed5c

The mentioned commit switched scope unit's "pids" deserialization
to call unit_watch_pid() already, meaning all later invocations
in scope_coldplug() are no-op. Remove the cruft altogether.
2025-07-11 21:58:51 +02:00
Lennart Poettering b2f23bd2b1 Support global sysext/confext in systemd-stub/systemd-sysext (#38113)
Systemd-stub supports loading addons, credentials, system and
configuration
extensions from ESP and while addons and credentials can be both global
and
per-UKI, sysext/confext are only per-UKI. 

Add support for global sysext/confext to systemd-stub/systemd-sysext.

Fixes #37993
2025-07-11 21:10:51 +02:00
Lennart Poettering aac7e892e4 machined: make registration of unpriv user's VMs/containers work (#37855)
This adds missing glue to reasonably allow unpriv users VMs/containers
to register with the system machined.

This primarily adds two things:

1. machined can now properly track VMs/containers residing in subcgroups
of units, because that's effectively what happens for per-user
VMs/containers: they are placed below the system unit `user@….service`
in some user unit.

2. machines registered with machined now have an owning UID: users can
operate on their own machines withour re-authentication, but not on
others.

Note that this is only a first step regarding machined's hookup of
nspawn/vmspawn in the long run for unpriv operation.

I think eventually we should make it so that there's both a per-user and
a per-system machined instance (so far, and even with this PR there's
still one per-system instance), and per-user containers/VMs would
registering with *both*. Having two instances makes sense I think,
because it would mean we can make machined reasonably manage the
per-user image discovery, and also do the per-system network/hostname
handling.
2025-07-11 21:10:08 +02:00
Lennart Poettering 12d1f44681 vmspawn: do not set vt220
We do not let qemu do terminal stuff, hence no point in setting any
TERM.
2025-07-11 18:17:04 +02:00
Lennart Poettering f820b27565 vmspawn: introduce --notify-ready= switch
This mimics the switch of the same name from nspawn: it controls whether
we expect a READY=1 message from the payload or not. Previously we'd
always expect that. This makes it configurable, just like it is in
nspawn.

There's one fundamental difference in behaviour though: in nspawn it
defaults to off, in vmspawn it defaults to on. (for historical reasons,
ideally we'd default to on in both cases, but changing is quite a compat
break both directly and indirectly: since timeouts might get triggered).
2025-07-11 18:17:04 +02:00
Lennart Poettering 0fc45c8d20 vmspawn: substantially beef up cgroup logic, to match more closely what nspawn does
This beefs up the cgroup logic, adding --slice=, --property= to vmspawn
the same way it already exists in nspawn.

There are a bunch of differences though: we don't delegate the cgroup
access in the allocated unit (since qemu wouldn't need that), and we do
registration via varlink not dbus. Hence, while this follows a similar
logic now, it differs in a lot of details.

This makes in particular one change: when invoked on the command line
we'll only add the qemu instance to the allocated scope, not the vmspawn
process itself (this follows more closely how nspawn does this where
only the container payload has its scope, not nspawn itself). This is
quite tricky to implement: unlike in nspawn we have auxiliary services
to start, with depencies to the scope. This means we need to start the
scope early, so that we know the scope's name. But the command line to
invoke is only assembled from the data we learn about the auxiliary
services, hence much later. To addres we'll now fork off the child that
eventually will become early, then move it to a scope, prepare the
cmdline and then very late send the cmdline (and the fds we want to
pass) to the prepared child, which then execs it.
2025-07-11 18:17:04 +02:00
Lennart Poettering 3cfa7826d2 vmspawn: spawn polkit during registration phase
Just like in nspawn, there's a chance we need to PK authenticate the
registration, hence let's spawn off the agent for that during that
phase, and terminate it once we don't need it anymore.
2025-07-11 18:17:04 +02:00
Lennart Poettering 6dc6e6459b vmspawn: use VM leader PID not vmspawn PID to register machine
Let's make vmspawn machine registration more like nspawn machine
registration, and register the payload, not vmspawn/nspawn itself.
2025-07-11 18:17:04 +02:00
Lennart Poettering 6ef1fc6d02 nspawn: properly order include of constants.h 2025-07-11 18:16:48 +02:00
Lennart Poettering 0c250b3919 nspawn: tweak logging/notifications when processing exit requests 2025-07-11 18:15:12 +02:00
Lennart Poettering f63ca4fc14 nspawn: slightly beef up READY= logic in nspawn
Let's also send out a STATUS= message when we get READY=1 if it didn't
come with a STATUS= message itself.

Also, let's initially say the container is "started", and only once the
READY=1 is seen claim it was "running".
2025-07-11 18:15:12 +02:00
Lennart Poettering f2f26f1527 nspawn: reorganize scope allocation/registration logic
This cleans up allocation of a scope unit for the container: when
invoked in user context we'll now allocate a scope through the per-user
service manager instead of the per-system manager. This makes a ton more
sense, since it's the user that invokes things after all. And given that
machined now can register containers in the user manager there's nothing
stopping us to clean this up.

Note that this means we'll connect to two busses if run unpriv: once to
the per-user bus to allocate the scope unit, and once to the per-system
bus to register it with machined.
2025-07-11 18:15:12 +02:00
Lennart Poettering ca1daebdd6 machinectl: output supervisor info in status output 2025-07-11 18:15:12 +02:00
Lennart Poettering 596c596d09 machined: add a bit more debug logging 2025-07-11 18:15:12 +02:00
Lennart Poettering 74546a7e29 machined: explicitly watch machine cgroup for getting empty 2025-07-11 18:15:12 +02:00
Lennart Poettering 97754cd14d machined: also track 'supervisor' process of a machine
So far, machined strictly tracked the "leader" process of a machine,
i.e. the topmost process that is actually the payload of the machine.
Its runtime also defines the runtime of the machine, and we can directly
interact with it if we need to, for example for containers to join the
namespaces, or kill it.

Let's optionally also track the "supervisor" process of a machine, i.e.
the host process that manages the payload if there is one. This is
generally useful info, but in particular is useful because we might need
to communicate with it to shutdown a machine without cooperation of the
payload. Traditionally we did this by simply stopping the unit of the
machine, but this is not doable now that the host machined can be used
to track per-user machines.

In the long run we probably want a more bespoke protocol between
machined and supervisors (so that we can execute other commands too,
such as request cooperative reboots/shutdowns), but that's for later.

Some environments call the concept "monitor" rather than "supervisor" or
use some other term. I stuck to "supervisor" because nspawn uses this,
and ultimately one name is as good as another.

And of course, in other implementations of VM managers of containers
there might not be a single process tracking each VM/container. Because
of this, the concept of a supervisor is optional.
2025-07-11 18:15:12 +02:00
Lennart Poettering adaff8eb35 machined: use different polkit actions for registering and creating a machine
The difference between these two operations are large: one is relatively
superficial: for "registration" all resources remain associated with the
invoking user, only the cgroup is reported to machined which then keeps
track of the machine, too. OTOH "creation" a scope is allocated in
system context, hence the invoked code will be owned by the system, and
its resource usage charged against the system.

Hence, use two distinct polkit actions for this, so that we can relax
access to registration, but keep access to creation tough.
2025-07-11 18:15:12 +02:00
Lennart Poettering 276d200186 machined: track UID owner of machines
Now that unpriv clients can register machines, let's register their UID
too. This allows us to do two things:

1. make sure the scope delegation is assigned to the right UID (so that
   the unpriv user can actually create cgroups below the delegated
   scope)

2. permit certain types of access (i.e. killing, or pty access) to the
   client without auth if it owns the machine.
2025-07-11 18:15:12 +02:00
Lennart Poettering d5feeb373c machined: optionally track machines in cgroup subgroups 2025-07-11 18:15:12 +02:00