Commit Graph

90912 Commits

Author SHA1 Message Date
Chris Down
41c12e32ce TEST-80-NOTIFYACCESS: Add notify-reload signal handler validation test
Add a new integration test to verify the signal handler validation for
Type=notify-reload services, as introduced in the previous commit.

The test adds a shell harness and four service files to cover all scenarios:

1. `notify-reload-no-handler.service`: Verifies that the service fails to
   start with Result=protocol when the handler is missing at the first
   READY=1.

2. `notify-reload-sigstop.service`: Verifies that SIGSTOP is exempt from
   handler validation because it cannot be caught or blocked.

3. `notify-reload-toggle-handler.service`: Verifies that removing the
   handler at runtime results in a warning on reload, but the signal is still
   sent, causing the service to terminate from unhandled SIGHUP.

4. `notify-reload-well-behaved.service`: Verifies the happy path where a
   service with a handler starts and reloads successfully.

Use bounded FIFO operations and journal cursors so failures are prompt and log
assertions cannot race a relative time window.
2026-08-05 17:31:03 -07:00
Chris Down
d361e5ba34 core/service: Prevent accidental service termination during reload
We currently blindly send the configured reload signal (e.g. SIGHUP or
SIGUSR1) to the main service PID for Type=notify-reload units, even if
the service hasn't installed a userspace handler. This can lead to
invoking unintended default behavior (typically process termination) in
daemons which later deprecate and remove their reload handler.

This is a real problem we have seen in production on multiple occasions.
In one particularly egregious instance, a production distributed storage
service had a large percentage of its nodes all terminate at once when
sent a reload signal. In this case a signal handler had been removed, but
another place still sending the signal was missed.

To mitigate this, introduce signal handler validation for
Type=notify-reload services. We check both SigCgt (traditional handlers
via sigaction) and SigBlk (blocked signals for signalfd) to detect valid
handler configurations:

1. On first READY=1: When the service first sends READY=1 during initial
   startup, we check for the handler. If it's missing, the service
   startup is aborted with Result=protocol.

2. On reload: Immediately before sending the reload signal, we check
   again. If the handler is missing, we log a warning but still send
   the signal.

The rationale is that a missing handler at first startup represents a
definite misconfiguration that should be caught early. A missing handler
at reload time is warned about, but we defer to the operator's judgement
since the service already started successfully.

These checks are a best-effort, pragmatic safety net. They are naturally
racy, but in practice they prevent the common class of bugs from static
misconfiguration or software updates.
2026-08-04 16:51:37 -07:00
Chris Down
b64b996119 process-util: Add helpers to check for signal handler presence
Add new pidref_has_sigcgt() and pidref_has_sigblk() helpers. These read
the SigCgt and SigBlk bitmasks from /proc/<pid>/status to detect either
traditional signal handlers installed via sigaction(2), or blocked signals
that are typically handled via signalfd(2), such as through
sd_event_add_signal().

Both mechanisms represent valid ways to handle a signal without invoking
the default action. Share the parsing and pidref verification between the
two public helpers.
2026-08-04 16:51:37 -07:00
Christian Glombek
91d2131e20 test: TEST-89: remove temporary files when browse helpers return
The RETURN traps in the browse helpers only stopped the transient
varlinkctl unit; the mktemp'd output/error/scratch files were never
removed and leaked on every invocation. Remove them from the same trap,
after the unit has been stopped so that nothing is still writing to
them, and make that stop best-effort like in
testcase_browse_ifindex_zero_no_flap: if varlinkctl exited on its own,
the transient unit is already gone, and a failing stop would otherwise
abort the testcase under errexit and skip the removal.

testcase_browse_ifindex_zero_no_flap cleans up its output file from the
trap it already arms for the dummy link, which is an EXIT trap since
run_testcases runs each testcase in its own subshell.

While at it, tidy up the helpers' variable scoping: error_file was
accidentally a global, and i/svc were declared in the wrong functions
(they are used by check_both/check_first, via dynamic scoping).
2026-08-01 03:54:58 +09:00
Yu Watanabe
dda5008019 tmpfiles: fix log message about BSD lock 2026-08-01 03:17:00 +09:00
Yu Watanabe
994289a030 test: stage volatile deb packages for upgrade test, and retry failed units (#43209) 2026-08-01 01:48:48 +09:00
Yu Watanabe
d2685c303b tmpfiles: reject extra argument fields and make 'r'/'R' support age field (#43195)
This updates systemd-tmpfiles in two small areas:

- Reject non-empty argument fields for tmpfiles.d line types that do not
consume the argument field, instead of warning and silently ignoring
them.
- Let `r` and `R` tmpfiles.d entries honor the `Age` field when
`systemd-tmpfiles --clean` is used. The existing `--remove` behavior
remains unconditional.

The completed TODO entries are removed, and NEWS/man page documentation
is updated for the visible behavior changes.
2026-08-01 01:34:08 +09:00
Adam Dinwoodie
7b761dba0f core/timer: fix next trigger with RandomizedOffsetSec + Persistent (#42826)
When a calendar timer with RandomizedOffsetSec and Persistent=true fires a
catch-up activation, last_trigger is set to the current wall-clock time.
This inherently already includes any randomized offset, because the
trigger was that the activation time including the offset had passed.

When computing the next elapse, calendar_spec_next_usec() finds the next
calendar boundary after the base time, and then random_offset is added to the
result. If the base time already includes the offset, the next calendar
boundary is one period too far in the future, causing a scheduled activation
to be skipped.

Fix this by always subtracting random_offset from the base time before passing
it to calendar_spec_next_usec(), matching what the fallback branches (using
inactive_exit_timestamp or current time) already do. This puts the base into
"pre-offset calendar space" so that the next calendar match and subsequent
offset addition yield the correct next activation time.

Fixes #42337.
2026-08-01 00:53:33 +09:00
Armaan Sandhu
2bb179632f string-util: don't miss ANSI sequence at the very end in previous_ansi_sequence()
The backwards scan started at offset length-3, so the last position at which a
sequence can begin, length-2, was never examined. CSI sequences are at least
three bytes long and were thus unaffected, but two byte Fe sequences (ESC
followed by 0x40…0x5F) terminating the examined slice were missed.

ellipsize_mem() calls this to figure out whether a sequence ends exactly at the
current position, so that it can be skipped over, which is precisely the case
that was broken: such a sequence was instead counted as two visible cells and
copied through as text, and the string was ellipsized more aggressively than
requested. For example ellipsize("🐱🐱\x1bM🐱🐱\x1bM", 5, 0) returned a three
cell wide string rather than the five cells asked for.
2026-08-01 00:12:40 +09:00
Sinity
3e04f8f450 core/dbus: do not flush a user manager's bus that is not RUNNING
destroy_bus() flushes unwritten data for unprivileged managers so that
queued messages are not lost when a connection is torn down. However,
sd_bus_flush() first drives the connection to completion via
bus_ensure_running(): for a connection still in OPENING or
AUTHENTICATING this blocks the manager synchronously - a single-fd
ppoll, the event loop is not running - until the peer answers or
BUS_AUTH_TIMEOUT (= DEFAULT_TIMEOUT_USEC, 90 s by default) expires; a
connection in HELLO blocks the same way on the Hello call's own
method timeout. destroy_bus() is reached from four places: the
disconnect handler, manager_recheck_dbus(), the failed-setup path in
api_bus_instance_id_reply(), and bus_done() during normal shutdown or
reexec (via manager_free()).

Such a peer legitimately never answers: during session teardown,
dbus.socket can be (or re-enter) listening while the D-Bus service
behind it is hung or already gone, so connect() succeeds against the
socket backlog and the authentication request is never read. The user
manager then freezes mid-shutdown - or mid-reexec - for 90 s, with
every remaining unit stop (or the reexec itself) gated behind it.

This is the block traced in #16471 (2020, v245): the reporter's
strace shows the manager hanging in a single-fd ppoll with an ~89 s
timeout right after SIGTERM - bus_ensure_running() driving an
AUTHENTICATING reconnection - and their summary attributes it to the
flush. Their tested sd-bus-level patch (breaking the wait via a
SIGTERM-set flag) was met with "a work-around once things are already
bad, but we shouldn't even get in that state"; the same reply stated
the expectation this commit implements - the manager "should normally
protect itself ... and not issue dbus messages when the dbus service
isn't fully up". bus_foreach_bus() already applies that principle in
the other direction, skipping enqueue for connections that "haven't
started yet" via the same sd_bus_is_ready() check. 1166f4472d
("core/dbus: do not block the manager on GetId during bus
(re-)connection") removed the connect-time instance of the same class
of block, in code added in 2025. The flush here is twelve years
older: it dates back to the libsystemd-bus conversion (718db96199,
2013).

Only flush when the connection is currently RUNNING. This does not
change what gets delivered in the failure case this fixes: whatever a
non-RUNNING connection's write queue holds (auth/Hello traffic, and
any subscriber signal a per-unit or per-job bus_track attached without
a readiness check) was never actually sent by the old code either -
sd_bus_flush() calls bus_ensure_running() before it ever looks at the
write queue, so a connection that times out without reaching RUNNING
had its queued data silently discarded on close exactly as before,
just after blocking for up to 90 s first rather than immediately. The
one narrowing is a connection that would have completed authentication
within the timeout window: previously such traffic could still reach
the peer after the block; now it will not. Every destroy_bus() call
site is reached only once the manager has already decided the
connection is being torn down (disconnected, recognized as down, or
the process itself exiting/reexecuting), so this narrowing does not
trade a working delivery for a broken one.

Fixes #16471
2026-07-31 23:57:09 +09:00
Yu Watanabe
63e35ca3f9 selinux: relax error handling in permissive mode (#36929)
Error returned from security_compute_create_raw() means that kernel
couldn't compute target context. Very likely because file context is not
known to the policy, i.e. security.selinux xattr contains some garbage
value and we are running in permissive mode, otherwise returned context
would be "unlabeled_t" instead of getting an error.

mac_selinux_get_create_label_from_exe() is used to figure out create
label for socket units and we fail to start the socket if we can't
figure out that label.

However, it may be necessary to start some sockets in order to get to
the point when we launch the service that relabels (in permissive mode)
the entire filesystem and reboots.
2026-07-31 12:49:14 +09:00
Yu Watanabe
3abe380d04 core/service: append the original error cause in the debugging logs 2026-07-31 11:30:32 +09:00
Michal Sekletar
a3fee62707 core/service: ignore SELinux label errors in permissive mode
Return -ENODATA instead of the raw error when SELinux is permissive, so
the caller falls back to the default label. This is needed to allow
relabeling service to start on systems where file contexts maybe
invalid.
2026-07-31 11:30:32 +09:00
Luca Boccassi
fb3581af65 test: find out tpm device rather than hardcoding it in TEST-92-TPM2-SWTPM
Looks like the device might change depending on the boot sequence, so
discover it in the test rather than hardcoding it to /dev/tpmrm0.

Fixes https://github.com/systemd/systemd/issues/43210

Follow-up for 1b1900a6f3
2026-07-31 11:06:30 +09:00
Yu Watanabe
71a2af43f9 core: quote each exec directory entry when serializing
Quote each serialized exec directory entry, and use extract flags
compatible with config_parse_exec_directories() when deserializing.
This allows paths containing spaces and escaped characters to round-trip
correctly.

Fixes #41853.
Replaces #42686.
2026-07-31 10:46:50 +09:00
Frantisek Sumsal
6d7a2ec6ba ci: fix /etc and /usr ownership
Recent Ubuntu 24.04 GHA images have /etc and /usr owned by runner
instead of root, which breaks some of our tests. This has been filed to
GH as https://github.com/actions/runner-images/issues/14477, so let's
work around this in our jobs until it's fixed.
2026-07-30 15:25:30 +01:00
Luca Boccassi
cdc3fd019b test: retry units failed during package replacement in TEST-88-UPGRADE
Retry units that still exist and clear stale state for units removed by
a downgrade, as packages might be old and not have new units that were
added in the latest version.
2026-07-30 09:13:35 +01:00
Luca Boccassi
f029c336e9 mkosi: stage volatile deb packages for upgrade test
Prepare scripts run before volatile packages are installed, so parse
the list from the config to ensure they are all included to avoid
failures due to some packages missing from the list.

Follow-up for 28e1f84d6a
2026-07-30 09:13:35 +01:00
dongshengyuan
249421e75e tmpfiles: honor age for r/R cleanup
Let r and R lines participate in --clean when they specify an age. The
target itself is removed only after its selected file or directory
timestamps have aged enough; --remove remains unconditional.

Follow-up for: beca6b6e6b
2026-07-30 13:45:52 +08:00
Baurzhan Muftakhidinov
c00fea9db1 po: Translated using Weblate (Kazakh)
Currently translated at 100.0% (286 of 286 strings)

Co-authored-by: Baurzhan Muftakhidinov <baurthefirst@gmail.com>
Translate-URL: https://translate.fedoraproject.org/projects/systemd/main/kk/
Translation: systemd/main
2026-07-30 13:55:48 +09:00
Daniel28972897
b2cd050073 libudev: cache the errno for a failed parent lookup
udev_device_get_parent() caches the result of device_new_from_parent()
in udev_device->parent on first call. device_new_from_parent() sets
errno correctly via return_with_errno() when it fails, so a caller
gets the right errno on the first invocation. But on any subsequent
call for the same object, the cached NULL is returned directly without
recomputing anything, so errno reflects whatever happened in between
rather than the original failure reason.

Cache the errno alongside the parent pointer (new parent_errno field,
zero-initialized like the rest of the struct via udev_device_new()'s
compound literal) and restore it whenever the cached parent is NULL.
2026-07-30 07:24:17 +09:00
Frantisek Sumsal
9d4019b9b7 ci: build the release clang build with _FORTIFY_SOURCE=3
Since this combination is known to cause interesting issues in our
allocation machinery.
2026-07-30 01:18:58 +09:00
Frantisek Sumsal
a56d7db48f alloc-util: make malloc_sizeof_safe() compatible with clang's _FORTIFY_SOURCE=3
Turns out that clang's interprocedural analysis is quite smart and can
look through our expand_to_usable() trick, which then causes crashes
with _FORTIFY_SOURCE=3.

clang's interprocedural analysis can see that expand_to_usable() simply
returns its first argument, so it replaces all uses of the return value
with that argument (the original realloc() result). This effectively
bypasses expand_to_usable()'s alloc_size attribute, causing the fortify
check to use the (smaller) size from realloc() instead, which eventually
leads to a false-positive buffer overflow:

$ build/test-varlink-idl
/* test_parse_format */
...
*** buffer overflow detected ***: terminated
Aborted                    (core dumped) build/test-varlink-idl

This is not an issue with gcc (at least not yet), since gcc sees
expand_to_usable() as an opaque user-defined allocation-like function
and simply trusts the alloc_size attribute that comes with it.

To fix this, let's add a simple no-op barrier to malloc_sizeof_safe()
that clobbers the input pointer, which causes
__builtin_dynamic_object_size() to return (size_t)-1 - this is
interpreted as an "unknown" size by the following fortify check which is
then skipped instead of triggering the assertion.

Similarly, test-alloc-util now doesn't call malloc_usable_size()
directly but instead goes through malloc_sizeof_safe(), so it's also
guarded by the barrier.

This follows the already established pile of similar workaround for the
same class of issues we encountered with gcc, namely [0], which prompted
[1], that was later reverted in [2], and then followed by another couple
of fixes in [3] and [4].

Resolves: #43178

[0] https://github.com/systemd/systemd/issues/22801
[1] 0bd292567a
[2] 2cfb790391
[3] 7929e180aa
[4] 4f79f545b3
2026-07-30 01:18:58 +09:00
Eric Curtin
21ab2fe6ec shared/switch-root: sync only file systems becoming unreachable, not everything
switch_root() calls a blanket sync() before detaching the old root
file system, in order to make sure it is in a good state before it
becomes unreachable via MNT_DETACH/pivot_root().

A global sync() however flushes out *every* mounted file system on
the system, not just the ones we are actually about to detach. On
real-world systems that commonly have several additional mounted file
systems (separate /home, /var, additional data partitions, network
shares, removable media, ...) this needlessly delays switch_root() with
completely unrelated I/O. This matters in particular for
initrd-switch-root.service, which runs this code on the critical path
of pretty much every single boot with an initrd, and for soft-reboot.

Replace the global sync() with a new sync_departing_file_systems()
helper that walks /proc/self/mountinfo and calls syncfs() on every
file system except:

  - 'new_root' and anything mounted below it: these remain mounted
    and reachable after the transition and keep being synced normally
    as part of their regular life cycle, so they don't need to be
    force-flushed here.

  - API/pseudo file systems (proc, sysfs, cgroupfs, autofs, ...),
    network file systems, and overlayfs (which has no backing store
    of its own), as determined by the new fstype_is_worth_syncing()
    predicate. There is nothing meaningful to flush on any of these,
    and more importantly, opening an untriggered autofs mount point
    would needlessly trigger it, and opening a stale network mount
    could block for a long time - exactly what we are trying to avoid
    on this code path.

  - Any flavour of FUSE (plain 'fuse', 'fuseblk', or a
    'fuse.<subtype>', e.g. sshfs, rclone, gvfs, ntfs-3g, exfat-fuse,
    ...), classified via the new fstype_is_fuse() predicate in
    src/basic/mountpoint-util.c, plus a few other, non-FUSE guest/host
    file sharing file systems with the same "backed by a companion
    daemon/hypervisor that could be wedged" risk profile (virtiofs,
    vboxsf, vmhgfs). All I/O against any of these, including the
    syncfs() we'd otherwise issue, is routed through an arbitrary
    userspace daemon (or, for virtiofs/vboxsf/vmhgfs, the host/
    hypervisor side), which could hang indefinitely if wedged, dead,
    or otherwise unresponsive - there's no timeout on this code path.
    'fuseblk' might sound exempt given the name, and does wrap an
    actual block device, but that doesn't bound its syncfs() latency
    by the kernel block layer alone the way a native block device
    file system's is: the request is still serviced by the same FUSE
    daemon as any other FUSE variant, and can hang exactly the same
    way, so it is excluded here too, trading its comparatively minor
    data-safety benefit for avoiding that unbounded hang risk.

    '9p' (which can be used with a writeback cache and hence carry
    real dirty data, e.g. common in QEMU/KVM guests) and the
    shared-storage cluster file systems 'gfs', 'gfs2' and 'ocfs2'
    (which fstype_is_network() also happens to classify as "network"
    file systems, since they additionally rely on a networked
    distributed lock manager for coordination) are deliberately *not*
    excluded: unlike FUSE/virtiofs/etc., these are serviced by a
    mature, in-kernel client (talking directly to the hypervisor over
    a bounded virtio transport, or to real - if shared - block
    storage), not an arbitrary, potentially wedged userspace daemon,
    so they carry the same bounded, local sync latency any other
    block device backed file system already does here. Skipping them
    would needlessly sacrifice the data-safety guarantee the original
    blanket sync() gave them, without meaningfully improving safety.

  - Mount table entries that we can positively confirm are currently
    shadowed by another mount stacked on top of them at the same
    path: since we can only reach a file system by (re-)opening its
    target path, and that always resolves to whatever is currently on
    top, syncing by path alone could end up flushing the wrong
    superblock. Detect this via the new shared
    libmount_fs_id_matches_path() helper (factored out of, and now
    also used by, the pre-existing get_sub_mounts(), which needed the
    exact same check for the same reason). This same check is also
    applied to a mountinfo entry whose target is 'new_root' itself
    (not just anything strictly below it): comparing its mount ID
    against new_root's own, freshly determined mount ID tells apart
    the file system that is actually still reachable there (which we
    continue to skip) from a stale entry that merely shares the exact
    same path (e.g. if new_root wasn't already its own mount point
    and got bind-mounted onto itself earlier in switch_root()), which
    is departing just the same and must not be skipped just because
    of that coincidence.

Every failure mode that means we can no longer be sure we've covered
every departing file system correctly - libmount being unavailable,
/proc/self/mountinfo (or a specific entry in it) failing to parse,
being unable to tell whether a specific entry is currently shadowed,
or syncfs_path() itself failing for an otherwise-eligible entry - is
handled the exact same way: propagate the error up and let the sole
caller, switch_root(), fall back to one plain, global sync() to cover
everything, rather than deciding on and performing that fallback (or,
worse, silently skipping the affected file system without any
fallback at all) at each of these different spots individually. This
should be rare in practice, so it doesn't meaningfully undercut the
benefit of the targeted sync in the common case.

Everything else that's actually about to become unreachable (the old
root itself, but also any other, unrelated real file system that
happens to be mounted underneath it and gets detached along with it)
is still synced, so this keeps the same safety guarantee the original
blanket sync() gave for file systems that actually do go away here.
Uses the existing syncfs_path() helper for the actual open+syncfs.

sync_departing_file_systems() itself returns -EOPNOTSUPP if libmount
support isn't compiled in, handled the same way by switch_root() as
any of its other error returns.

Note we intentionally don't use O_PATH file descriptors here: syncfs()
requires a 'real' file descriptor and fails with EBADF on O_PATH ones.

Also note there remains an inherent, narrow TOCTOU race between the
mount-ID check described above and the open() syncfs_path() performs
right after it: if something else mounts something new on top of a
given 'path' in between, that open() could still end up triggering an
automount, or hanging on a stale mount, since there is no open()/
openat() equivalent of statx()'s AT_NO_AUTOMOUNT to prevent this for a
"real" (non-O_PATH) file descriptor. Unlike the other failure modes
handled here, a hanging open() can't be recovered from by falling back
to sync() afterwards, since control never returns to do so. Closing
this fully would require disproportionate effort (e.g. performing the
open() in a separate, killable/timeout-bounded process) for a window
that is already narrow, since this code only runs with most other
activity on the system already quiesced during the switch_root()
transition itself, so it is accepted as-is (see the comment at the
call site for details).

This mirrors the same reasoning already applied to the shutdown path
in src/shutdown/shutdown.c, which deliberately avoids a 'dumb' sync()
there for identical reasons.
2026-07-30 01:15:03 +09:00
Yu Watanabe
08ca33fdde core: postpone dbus queue dispatch while API bus setup is pending (#43200)
Since 1166f4472d the API bus setup
and the subscriber coldplug happen only once the asynchronous GetId
reply is processed by the event loop. After a daemon-reexec,
manager_dispatch_dbus_queue() runs before subscribers were registered
and consumed send_reloading_done, so the one-shot Reloading(false)
signal was never sent.

Clients that wait for this signal to detect that a reexec finished time out.

Track the pending setup and hold the flag until the reply handler has
re-added the subscriptions.

Also affects v261.2 via backport 26f3717e27.
2026-07-29 20:38:21 +09:00
r-vdp
2e254eba03 test: add case for the Reloading bus signal
Check that the manager broadcasts Reloading(true/false) on the API bus
for daemon-reload, and the one-shot Reloading(false) after a
daemon-reexec, which requires the subscribers of the previous instance
to be coldplugged before the D-Bus queue is dispatched.
2026-07-29 11:17:14 +02:00
r-vdp
266b3e5021 core: postpone D-Bus queue dispatch until the API bus is set up
Since 1166f4472d ("core/dbus: do not block the manager on GetId during
bus (re-)connection") the API bus setup and the subscriber coldplug
happen only once the asynchronous GetId reply is processed by the
event loop. After a daemon-reexec, manager_dispatch_dbus_queue() runs
before subscribers were re-added, so bus_foreach_bus() skipped the
API bus and queued messages were lost for subscribers. In particular
the one-shot Reloading(false) signal was never sent, and clients that
wait for it to detect that a reexec finished timed out.

Track whether bus_setup_api() has run for the current API bus
connection, and postpone dispatching the queue until then.
2026-07-29 09:52:57 +02:00
dongshengyuan
e347f63b0f tmpfiles: reject unused argument fields
Line types which do not use the argument field used to warn and ignore
a non-empty field. Treat that as invalid configuration instead, so typos
are not silently accepted.

Follow-up for: 614cc34f3a
2026-07-29 15:29:54 +08:00
Paul Meyer
57f8a85a21 cryptsetup: measure volume key and keyslot via the pcrextend Varlink service (#43109)
Motivated by
https://github.com/systemd/systemd/pull/43041#discussion_r3595022610.

Switch systemd-cryptsetup's volume-key and keyslot measurements from
driving the TPM directly (tpm2-util) to the io.systemd.PCRExtend Varlink
service, aligning it with how the verity and imds measurements already
work.

Some notes on decisions taken:
- The volume key is sent over the wire. systemd-pcrextend will do the
hmac. The socket is root only. Otherwise we would need to do bank
negotiation via varlink and pollute the interface with it.
- `tpm2-measure-bank=` deprecated/dropped. Same reason as above.
- `tpm2-device=` now only affects unlocking. The device for measurements
is selected by pcrextend.
- Measuring requires the presence of `systemd-pcrextend.socket` in the
initrd, should be already given as systemd-veritysetup relies on it,
too.
- Logs are done on the pcrextend side.
2026-07-29 07:21:08 +02:00
Eric Curtin
d47b07d05f test-bpf-restrict-fs: skip if manager startup fails due to lack of privileges (#43202)
test-bpf-restrict-fs.c creates a Manager with RUNTIME_SCOPE_SYSTEM, which
tries to set up the real system runtime directory hierarchy (e.g. create
/run/systemd/), and that requires privileges the test process may not
have (e.g. unprivileged sandboxed builders such as OBS).

Previously this was masked because bpf_restrict_fs_supported() did a
trial open/load/attach of the BPF program itself, which also requires
elevated privileges and so failed first, causing the test to skip
before ever reaching manager_new()/manager_startup(). Since
bpf_restrict_fs_supported() no longer does that trial load, the test
now reaches manager_new()/manager_startup() in these unprivileged
environments and hard-fails instead of skipping, e.g.:

  Assertion failed: Expected "manager_startup(m, NULL, NULL, NULL, NULL)"
  to succeed, but got error: -13/EACCES

Use the same manager_errno_skip_test() pattern already used by other
tests (test-engine.c, test-execute.c, test-path.c, ...) to skip
gracefully when manager_new() or manager_startup() fail due to missing
privileges, instead of asserting.

Follow-up for c99678eeda.
2026-07-29 11:46:05 +09:00
Markus Boehme
b8968c4921 update-utmp: shorten comm on boot/shutdown
audit_log_user_comm_message from libaudit 4.2 rejects comm arguments
that exceed the kernel's comm limit of 15 characters with EINVAL. The
hard-coded "systemd-update-utmp" exceeds this by 4 characters. Shorten
it to "update-utmp" instead.
2026-07-29 11:41:17 +09:00
Emilio Sepulveda
89de9a9ccb po: Translated using Weblate (Interlingua)
Currently translated at 4.1% (12 of 286 strings)

Co-authored-by: Emilio Sepulveda <emism.translations@gmail.com>
Translate-URL: https://translate.fedoraproject.org/projects/systemd/main/ia/
Translation: systemd/main
2026-07-29 10:20:17 +09:00
dongshengyuan
f5ffb38606 tools: add -n shortcut for --dry-run
Accept -n as a short option for --dry-run in bootctl,
systemd-oomd, systemd-sysusers, and systemd-tmpfiles.

For systemd-repart, make -n equivalent to --dry-run=yes,
while keeping --dry-run=BOOL available.

Follow-up for: 2479f0bb09
2026-07-29 03:47:58 +09:00
Antonio Alvarez Feijoo
efc207d7ab rules: do not install 60-tpm2-id.rules without TPM2 support
This change also allows to import `tpm2_id` as a built-in instead of as a
program.
2026-07-29 01:23:14 +09:00
dongshengyuan
385623fee3 test: cover DeviceAllow parsing
Add unit coverage for config_parse_device_allow().

Verify valid device paths and subsystem patterns, invalid
specifiers and rights, default permissions, and reset handling.

Follow-up for: 20d52ab60e
2026-07-29 01:22:05 +09:00
Paul Meyer
1bdf2db6f7 cryptsetup: measure via the pcrextend varlink service
Measure the volume key and unlock keyslot through io.systemd.PCRExtend
instead of driving the TPM directly via tpm2-util, matching how the
verity and imds measurements already work.

Bank selection and the TPM context now live entirely in
systemd-pcrextend. As a result the tpm2-measure-bank= crypttab option
can no longer be honored per volume and is now a deprecated no-op.

Signed-off-by: Paul Meyer <katexochen0@gmail.com>
2026-07-28 14:59:02 +02:00
lzwind
9b76949a47 network: document that Domains= may be specified more than once (#43194)
The `Domains=` option in the `[Network]` section did not document its
behaviour when specified repeatedly. In practice the option is additive
(each occurrence accumulates search/routing domains) and assigning an
empty string resets the list, matching the closely related `DNS=`
option. This is implemented by `config_parse_domains()` in
`src/network/networkd-dns.c`, which frees both the search and route
domain sets on an empty `rvalue` and otherwise inserts each
whitespace-separated entry into the corresponding set.

Document this explicitly, using the same wording already used for
`DNS=` in the same man page, so users know repeated assignments are
combined and that an empty value clears them.

Fixes #38740.
2026-07-28 21:35:25 +09:00
Eric Curtin
c99678eeda core/bpf-restrict-fs: avoid loading the LSM BPF program twice at boot
bpf_restrict_fs_setup() is always called right after a successful
bpf_restrict_fs_supported(true) probe (see manager_setup() in
manager.c). Previously the probe independently opened, sized and
kernel-verifier-loaded the BPF object via prepare_restrict_fs_bpf(),
then did a trial LSM attach/detach via bpf_can_link_lsm_program() to
confirm the program *could* attach, and threw the whole object away
-- only for bpf_restrict_fs_setup() to build and verifier-load an
identical one from scratch again for the real, permanent attach.

The trial attach in the probe is redundant: if BPF_LSM_MAC attach
isn't actually usable (e.g. no BPF trampoline support on the running
architecture/kernel), bpf_restrict_fs_setup()'s own
sym_bpf_program__attach_lsm() call will simply fail, and that failure
is already logged and handled gracefully by its caller in manager.c
(logged as a warning, systemd continues without RestrictFileSystems=
enforcement). So bpf_restrict_fs_supported() only needs to check
whether the BPF LSM hook is enabled in the kernel at all
(lsm_supported("bpf")); it doesn't need to open/load/attach the BPF
program itself. Drop that from the probe, so the program is opened,
sized and verified by the kernel exactly once per boot instead of
twice.

Since the probe no longer verifies that the LSM BPF program can
actually attach, test-bpf-restrict-fs.c can no longer rely on
bpf_restrict_fs_supported(true) alone to skip on kernels/architectures
where the hook is listed but the real attach fails (e.g. missing BPF
trampoline support). Have the test also check m->restrict_fs after
manager_startup() and skip if the program never got attached, instead
of proceeding to hard-fail the enforcement assertions.
2026-07-28 21:33:38 +09:00
Yu Watanabe
4f32e0e853 sysupdate: Change feature/component enablement and disablement (#43191)
- sysupdate: In the auto-enable service, don't enable all features
    
    The auto-enable service should activate suggested components and
features but enabled all features which includes the default components
    unsuggested features and any unsuggested features of the suggested
components. This is unexpected behavior and we rather want this service
    to be limited to suggested features.
Switch the service flag to suggested and make the wording more explicit
    in the man page. Also fix the wrong statement that it operates on
    enabled components, it operates on all components, also explicitly
    disabled ones.

- sysupdate: Change disabling with
--component-suggested/--feature-suggested
    
    The disabling of features or components with the flag
--component-suggested/--feature-suggested didn't disable the suggested
ones but instead disabled all other ones. This is rather unintuitive due
    to how the flags are named and also not really needed because the
intended reconciliation outcome can instead be done by first disabling
everything and then enabling the suggested ones again which is easier to
    reason about. For components the tricky part is that they default to
enabled and thus it's better to have the disable/enable commands with
--component-suggested operate only on suggested ones instead of touching
others like "legacy" components that don't explicity say whether they
    are enabled and suggested or not.
    
    Make running disablement of components/features with
    --component-suggested/--feature-suggested undo a previous enablement
with the same flags. Document how one can align the system to only use
suggested components/features and not anything else by doing it in two
steps, first disabling everything and then enabling suggested ones. This
also makes it clearer now that all components that are not explicitly
    enabled nor suggested will be disabled then.
2026-07-28 21:24:45 +09:00
Nick Rosbrook
f195b1c1a8 meson: add build option for /var/log mode
In Ubuntu, rsyslog is (a) part of the minimal image and (b) does not run
as root. To facilitate this, the rsyslog package configures /var/log
to be writeable by the syslog group.

There are currently conflicts in the Ubuntu packaging due to the way
tmpfiles are handled in package scripts: when systemd-tmpfiles is
invoked with both configurations (or for all configurations), things
work fine. But if invoked with only var.conf, which is the default case
for package upgrades, rsyslog is broken.

One suggestion to approach this was to make rsyslog's tmpfile
configuration use ACLs instead of trying to change the owning group and
directory mode. This can work, but since the ACL mask is stored in the
group permission bits, the effective mask for rsyslog becomes r-x again
when var.conf is invoked, because it sees that 0775 != 0755, and chmods
the directory.

Hence, for /var/log write permisssions to be extendable with ACLs,
the mode must be at least 0775. Rather than change the default,
add a build option to configure the /var/log mode.
2026-07-28 21:23:18 +09:00
Yu Watanabe
f2718dee52 locale: update Context only on success
Do not clear Context.vc, Context.x11_from_vc, and Context.x11_from_xorg
on errors like ENOMEM or so.

This does not change behavior on success.
2026-07-28 20:19:30 +09:00
dongshengyuan
d73f3879f0 repart: drop legacy FactoryReset EFI variable
Follow-up for 9e050b0458.
2026-07-28 19:51:45 +09:00
Axel
9e60701fb1 Fix typo in 'website' in README.md 2026-07-28 19:46:34 +09:00
Kai Lüke
3cf8ab36a8 sysupdate: Change disabling with --component-suggested/--feature-suggested
The disabling of features or components with the flag
--component-suggested/--feature-suggested didn't disable the suggested
ones but instead disabled all other ones. This is rather unintuitive due
to how the flags are named and also not really needed because the
intended reconciliation outcome can instead be done by first disabling
everything and then enabling the suggested ones again which is easier to
reason about. For components the tricky part is that they default to
enabled and thus it's better to have the disable/enable commands with
--component-suggested operate only on suggested ones instead of touching
others like "legacy" components that don't explicity say whether they
are enabled and suggested or not.

Make running disablement of components/features with
--component-suggested/--feature-suggested undo a previous enablement
with the same flags. Document how one can align the system to only use
suggested components/features and not anything else by doing it in two
steps, first disabling everything and then enabling suggested ones. This
also makes it clearer now that all components that are not explicitly
enabled nor suggested will be disabled then.
2026-07-28 16:24:29 +09:00
Paul Meyer
1812d8792f pcrextend: extract varlink call boilerplate into shared helpers
pcrextend_verity_now() and pcrextend_imds_userdata_now() carried
near-identical copies of the connect + io.systemd.PCRExtend.Extend call.
Factor that into pcrextend_pcr_now() and pcrextend_nvpcr_now() and
reimplement both on top of them. No functional change.

Signed-off-by: Paul Meyer <katexochen0@gmail.com>
2026-07-28 08:58:28 +02:00
Paul Meyer
16c75b8d3b pcrextend: add secret parameter to varlink interface
Add an optional 'secret' input to io.systemd.PCRExtend.Extend. When set,
the HMAC of the measured data keyed by the secret is extended instead of
a plain hash, matching the existing tpm2_{pcr,nvpcr}_extend_bytes()
secret parameter. This lets callers measure a secret (e.g. a volume key)
without leaking a hash of it.

Signed-off-by: Paul Meyer <katexochen0@gmail.com>
2026-07-28 08:58:25 +02:00
Paul Meyer
1472ccebe7 pcrextend: pass iovecs through the extend helpers
extend_pcr_now(), extend_nvpcr_now() and escape_and_truncate_data() took
a (void *data, size_t) pair, even though both the dispatch layer and
tpm2_{pcr,nvpcr}_extend_bytes() already speak struct iovec. Drop the
pointless deconstruct/reassemble and pass the iovec through directly.

Signed-off-by: Paul Meyer <katexochen0@gmail.com>
2026-07-28 08:38:22 +02:00
Chris Coulson
f0f3687700 tpm2: Improve how NvPCR protection works.
NV indexes created in the storage hierarchy can be undefined and
redefined with TPM owner auth. Because of this, NvPCRs need some way
to prevent them from being redfined in a way that allows spoof
measurements to be replayed.

The current approach requires knowledge of a secret ("anchor secret")
in order to derive the initial NvPCR measurement and to derive a
measurement to an existing PCR (9). The credential is protected by the
TPM with a PCR policy. Without access to the credential, it's not
possible to replay measurements to a newly defined NvPCR without
breaking the binding with the measurement in PCR 9. However, this
approach has a couple of issues:

- The credential is currently only protected by PCR11. As it's not
  protected by the rest of the boot chain, it's possible to boot other
  operating systems in order to replay the PCR11 measurements and
  recover the secret. Note that as the NvPCR anchoring happens in early
  boot, the credential is stored in the ESP.
- Someone with privileged access to a system can just create a new
  credential containing a known secret and store this in /var/lib and
  the ESP. The NvPCRs are anchored with this known secret on subsequent
  boots, and therefore the measurements can no longer be trusted.
  Imagine the scenario where privileged access is theoretically possible
  as a result of some vulnerability. After upgrading the system to fix
  this vulnerability, the system should be able to attest that it is
  now in a good state. However, if an adversary were able to use their
  priviliges to replace the credential, they are able to obtain
  persistence and the NvPCR measurements are no longer trustworthy.

This PR changes things to take a different approach. Instead of
requiring knowledge of a secret, the NvPCRs are now created in a way
that requires a policy to be satisfied for writing. The write policy has
2 branches:
- TPM2_PolicyNvWritten(true), which can be satisified without any
  further authorization if the NvPCR has already been extended.
- TPM2_PolicyAuthorize(pcrPubKey, SHA256("nvpcr-init")) which can be
  satisfied with a signed PCR policy, and must be used to perform the
  initial extend to a NvPCR.

The intention here is that the signed PCR policy that can be used to
authorize the initial extend to the NvPCR can only be satisfied during
early boot. During later boot phases, this signed PCR policy must not be
valid. This means that if a NvPCR is undefined and redefined, it won't
be possible to satisfy its write policy in order to able to perform the
initial extend.

In order to anchor the NvPCRs and prevent them from being undefined and
then redefined with a different policy that does allow them to be
extended, the names of the NvPCRs are measured to PCR9. Verifiers must
check that the names of attested NvPCRs match the measurements in PCR9.

This uses the PCR signing key from the currently booted UKI to create
the NvPCRs. If this changes between boots, then tpm2-setup automatically
recreates new NvPCRs with an updated write policy to reflect this. I've
tried to be careful to not undefine arbitrary NV indexes in this case,
so it checks that the existing NV index looks like a NvPCR (ie, it has
the expected attributes) before undefining it.

I did originally try to preserve the old behaviour for existing systems,
but it makes things a lot more complicated. As the new implementation
already creates new NvPCRs when the PCR signing key changes, I ended up
just automatically upgrading the old NvPCRs as well. Again, I check here
that any existing NV index looks like an old style NvPCR (ie, it has the
expected attributes) before undefining it.

I did notice that the initial NvPCR measurement isn't going into the
log. I don't know if that was an intentional choice, but I've preserved
that behaviour in this PR.

This also adds a new option to ukify (--sign-initrd-pcrs) which creates
signed policies (one per PCR bank) that can only be satisfied from the
initrd. These policies are used for initializing the NvPCRs, but can also
be used for protecting TPM2 keyslots enrolled with systemd-cryptenroll
(by using the --tpm2-public-key-policyref=initrd option).

There is one outstanding issue. The NvPCR definitions support different
algorithms, but the use of PolicyAuthorize means that they can only support
SHA-256 for now. This is because the signed policy algorithm must match
the name algorithm, and some additional work is required to support
signed PCR policies for algorithms other than SHA256. I've left a note in
tpm2_nvpcr_initialize that details what's required, and I'll take a look
at that in a subsequent PR.
2026-07-28 08:35:39 +02:00
Kai Lüke
9913d9ac97 sysupdate: In the auto-enable service, don't enable all features
The auto-enable service should activate suggested components and
features but enabled all features which includes the default components
unsuggested features and any unsuggested features of the suggested
components. This is unexpected behavior and we rather want this service
to be limited to suggested features.
Switch the service flag to suggested and make the wording more explicit
in the man page. Also fix the wrong statement that it operates on
enabled components, it operates on all components, also explicitly
disabled ones.
2026-07-28 15:20:09 +09:00
Liu Zheng
0d92898e85 localed: normalize empty X11 option values to NULL after parsing
x11_read_data() parses an 'Option "XkbVariant" ""' line in
00-keyboard.conf with strv_split_full(..., EXTRACT_UNQUOTE), which turns
the empty quoted value into a non-NULL empty string rather than NULL.
Since 812aa57d2c ("string-util: beef up string_is_safe()") an empty
string is rejected by string_is_safe() unless STRING_ALLOW_EMPTY is
passed, so x11_context_is_safe() now refuses such a context and
x11_context_verify() discards the whole thing. As a result "localectl
status" reports "X11 Layout: (unset)" even though the file names a valid
layout, and compositors reading org.freedesktop.locale1 (e.g. the SDDM
greeter) fall back to the us layout.

Introduce x11_context_normalize(), suggested by @lionheartyu, which
converts empty strings to NULL while freeing the heap allocation —
unlike x11_context_empty_to_null() which only NULLs the pointer without
freeing. Call it at the end of x11_read_data(), before
x11_context_verify(), so empty option values are treated as unset. This
also keeps x11_context_equal() comparisons consistent with the setter
path (method_set_x11_keyboard) and vconsole_read_data(), which both
store NULL for empty values.

Fixes #43007
2026-07-28 11:53:11 +09:00