Commit Graph

217 Commits

Author SHA1 Message Date
Daan De Meyer
10eaca4159 sysupdate: Use partition types for pending/partial partitions
Fixes #40658
2026-02-18 11:15:04 +09:00
Daan De Meyer
7b9600a6b2 sysupdate: Compute temporary paths before vacuuming
We don't want to vacuum anything if we're just going to fail just
afterwards because a GPT partition label exceeds the maximum size
so let's compute the temporary paths for all transfers before we do
any vacuuming or acquiring.
2026-02-13 15:46:52 +09:00
Philip Withnall
e6e8efcffb sysupdate: Add some more debug output
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2026-02-09 12:05:15 +00:00
Philip Withnall
3bc9208435 sysupdate: Add acquire and install verbs
These expose the two parts of ‘update’, so that update sets can be
acquired (downloaded) and installed (applied) in separate actions at
different times. For example, this could allow a load of update sets to
be acquired when online, and later applied when offline.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Helps: https://github.com/systemd/systemd/issues/34814
2026-02-09 12:05:10 +00:00
Philip Withnall
cf7cccf2f7 sysupdate: Split the update verb into two parts internally
An ‘acquire’ (download) part, and an ‘install’ (apply) part.

Following commits will expose these as separate verbs and D-Bus methods,
but this commit is the one which rearranges the internals.

If doing an ‘install’, a mirror version of the ‘acquire’ has to happen
first to make sure the transfer’s internal state is correct.

‘Acquire’ can require an internet connection, but ‘install’ will always
work with `--offline` specified.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Helps: https://github.com/systemd/systemd/issues/34814
2026-02-09 12:05:05 +00:00
Philip Withnall
594d0345fa sysupdate: Add partial/pending flags to UpdateSet
This commit adds the flags and some basic formatting/printing of them.
Following commits will integrate them into the update/acquire/install
logic.

`UPDATE_PARTIAL` is set if any of the instances in the `UpdateSet` are
partial, i.e. have been partially downloaded.

`UPDATE_PENDING` is set if any of the instances in the `UpdateSet` are
pending, i.e. have been acquired (downloaded) but not yet installed.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Helps: https://github.com/systemd/systemd/issues/34814
2026-02-09 12:05:01 +00:00
Philip Withnall
ba9687adef sysupdate: Factor out temporary path computation for transfers
This helper function will be reused in a following commit.

This introduces no functional changes.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Helps: https://github.com/systemd/systemd/issues/34814
2026-02-09 12:04:52 +00:00
Philip Withnall
adcc03a0c0 sysupdate: Vacuum partial/pending instances first
Modify the vacuum implementation to preferentially vacuum partial or
pending transfers first (unless protected) as they are meant to be
fairly transitory, and ones which are hanging around have probably been
forgotten about and/or are out of date.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Helps: https://github.com/systemd/systemd/issues/34814
2026-02-09 12:03:59 +00:00
Philip Withnall
48fff6a27a sysupdate: Implement acquire and install steps for transfers
Instead of using a random temporary path for file transfers, use a
predictable one which indicates whether the transfer is partially
complete or pending installation. Similarly for partitions.

This is another step towards being able to split the ‘update’ step into
‘acquire’ and ‘install’.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Helps: https://github.com/systemd/systemd/issues/34814
2026-02-09 12:03:47 +00:00
Philip Withnall
edf7679faf sysupdate: Factor out a vacuum helper function
This will be reused in an upcoming commit.

This commit introduces no functional changes.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Helps: https://github.com/systemd/systemd/issues/34814
2026-02-09 11:54:45 +00:00
Philip Withnall
fdc661116d sysupdate: Allow instances to be partial or pending
If we allow target instances to be partial or pending, we can build on
top of this to allow updates to be split into two phases: ‘acquire’ (which
takes an available source instance and copies it (temporarily partial) to
a pending target instance; and ‘install’ (which takes a pending target
instance and installs it as an installed target instance).

This commit introduces a file/directory and partition prefix naming
scheme to identify partial and pending instances.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Helps: https://github.com/systemd/systemd/issues/34814
2026-02-09 11:54:40 +00:00
Philip Withnall
ec10efa1a1 sysupdate: Split context_apply() into acquire and install steps
This introduces no functional changes at the moment, but will be used in
upcoming commits.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Helps: https://github.com/systemd/systemd/issues/34814
2026-02-09 11:54:25 +00:00
Yu Watanabe
1d60b723a3 Fix bug in DM iteration and standardise how to iterate through DM layers (#40426)
get_block_device_harder_fd() currently only traverses one level of
device mapper stacking when looking for the underlying block device.
This causes issues with nested DM setups like dm-crypt on top of
dm-integrity, where we don't traverse enough to get the actual physical
device.

Fix this by iterating through all DM layers until we reach a device with
no underlying device. And while we're at it also make cgroups use the
same logic.

Fixes: #40419
2026-01-30 15:36:03 +09:00
Lennart Poettering
8a4f856977 conf-files: rename .name field to .filename to make clearer what precisely it is the name of 2026-01-25 20:51:50 +01:00
Lennart Poettering
6ecfa12af0 conf-files: add support for root_fd based operation
Let's make sure we can safely load configuration files based on a root
fd, including XAT_FDROOT.

(While we are at it, always pass path to root fs before fd to root fs,
following our recently updated CODING_STYLE)
2026-01-25 20:51:50 +01:00
Chris Down
7b8c4d01e6 blockdev-util: Add recursive lookup flag
Originating device lookups currently use separate entry points and
callers must decide between the single-step helper and manual looping.

Add a recursive flag to block_device_get_originating() and
block_get_originating(), and update callers to pass an explicit value.
2026-01-23 13:26:08 +08:00
Mike Yuan
382382a6eb sysupdate-resource: on hash mismatch the best before marker is not ignored
Hence use a less ambiguous wording.

Follow-up for d0badc0a61
Addresses https://github.com/systemd/systemd/pull/40393#discussion_r2709953179
2026-01-21 15:48:14 +01:00
Lennart Poettering
d0badc0a61 sysupdate: add simple "freshness" validation to systemd-sysupdate
In order to make "freeze" attacks against the update logic harder let's
add the ability to encode a "Best Before" date into SHA256SUMS directory
listings: if the current time is already beyond that time, we'll ignore
the SHA256SUMS as "stale" and fail the upgrade. Or in other words: the
freeze attack will now result in a client-side error eventually, instead
of success state.

The best before data is encoded in an optional pseudo-file listed in SHA256SUMS:
any file named BEST-BEFORE-YYYY-MM-DD.
2026-01-20 21:22:35 +01:00
Yu Watanabe
2aa496312e conf-files: introduce CONF_FILES_WARN flag and set it at various places
Closes #40285.
2026-01-16 23:05:33 +09:00
Mike Yuan
ca6b65991c udev,sysupdated: fix pidfd leak
Follow-up for 179dcf924f

After the mentioned commit, event_add_child_pidref() duplicates
the pidfd internally, hence the original pidfd would be leaked
with TAKE_PIDREF.
2026-01-02 07:59:15 +09:00
Daan De Meyer
aec52c1e6e string-table: Introduce DECLARE_STRING_TABLE_LOOKUP() and friends
Let's introduce these for the following two reasons:
- Using them makes sure the parameter names match between declaration
  and definition (if both use the corresponding macros).
- They make sure developers can't forget the _const_ and _pure_
  attributes for the declarations.

This commit also includes some include sorting fixes
2026-01-02 04:05:45 +09:00
Daan De Meyer
daff8ea8bb tree-wide: Introduce DECLARE_TRIVIAL_REF_UNREF_FUNC() and friends 2026-01-02 04:04:19 +09:00
Daan De Meyer
29d1df4b03 tree-wide: Remove unnecessary SIGCHLD blocking
Now that sd-event doesn't insist on blocking
SIGCHLD anymore when watching for process exit,
let's stop blocking SIGCHLD tree-wide where not
required anymore.
2025-12-20 15:50:47 +01:00
Daan De Meyer
fbd276cb86 tree-wide: Use pidref_wait_for_terminate_and_check()
Let's use the pidref variants for waiting and
checking a process everywhere and get rid of the
non pidref variants.
2025-12-20 15:50:47 +01:00
Yu Watanabe
93378148d4 tree-wide: normalize comment style 2025-12-15 08:50:13 +09:00
Luca Boccassi
eb98ddd8b8 sysupdate: also mention patterns to match in error log on failure
The gpt uuid is not the only thing that needs to match, the pattern
does as well, so mention it in the error log if present
2025-12-05 10:09:38 +00:00
Daan De Meyer
9a6a8f35eb tree-wide: Small fixes for various clang-tidy warnings 2025-11-26 16:22:00 +09:00
Yu Watanabe
f866ff3df8 tree-wide: replace tab with space, adjust missing or duplicated space 2025-11-24 12:45:06 +01:00
Zbigniew Jędrzejewski-Szmek
5220bb8c3f meson: automatically add 'extract' to 'sources'
In all cases, everything that we list in 'extract', we also list in
'sources'. We can simplify things by automatically appending the first
list to the second.

In the listings, move 'extract' key right below 'sources', since now
they are both "sources", just with slightly different meanings.
2025-11-20 10:03:48 +09:00
Yu Watanabe
5963cdf498 tree-wide: add missing '#pragma once' 2025-11-05 05:16:34 +09:00
Mike Yuan
d98c783516 sysupdated: port to sd_json_parse_file_at() 2025-11-04 10:46:01 +01:00
Daan De Meyer
b8ee7c2206 tree-wide: Various forward header cleanups
- Make sure forward headers have the iwyu pragma to always keep them
- Make sure we always include the daemon specific forward header
  instead of shared-forward.h
- Remove shared-forward.h include where the daemon specific forward
  header is already included
2025-10-17 21:11:23 +09:00
Daan De Meyer
f102bc3e5f tree-wide: Introduce sd-forward.h and shared-forward.h headers
Let's not leak details from src/shared and src/libsystemd into
src/basic, even though you can't actually do anything useful with
just forward declarations from src/shared.

The sd-forward.h header is put in src/libsystemd/sd-common as we
don't have a directory for shared internal headers for libsystemd
yet.

Let's also rename forward.h to basic-forward.h to keep things
self-explanatory.
2025-10-16 17:00:29 +02:00
Lennart Poettering
b7c07f6ab4 json: add generic dispatchers for version strings 2025-10-07 18:57:01 +02:00
Lennart Poettering
b7f6bdbbd3 service-util: add generic parser for runtime scope 2025-09-25 22:43:59 +02:00
Lennart Poettering
d71f2899bd meson: drop libblkid dep from components not using it directly 2025-09-24 18:11:12 +02:00
Daan De Meyer
9adb4685df tree-wide: Remove unused includes 2025-09-19 14:46:55 +02:00
Yu Watanabe
ee120e5caa sysupdate: use conf_files_list_strv_full() to enumerate definitions
No functional change, just refactoring.
2025-09-17 22:04:06 +09:00
Yu Watanabe
11a1f68217 sysupdate: use conf_files_list_strv_full() to enumerate features
No functional change, just refactoring.
2025-09-17 22:04:06 +09:00
Yu Watanabe
5035e4a4f8 sysupdate: use conf_files_list_strv_full() to enumerate components
With this change, root directory is correctly supported, and symlinked
components are also correctly enumerated.
2025-09-17 22:04:06 +09:00
Yu Watanabe
4279336618 chase: trigger automount only when explicitly requested
Since c5de7b14ae
file searching implies a new mount api syscall by default,
to trigger automounts.

But, this is not necessary in most cases, e.g. when chasing
syspath in sd-device (actually this causes regression in umockdev,
see https://github.com/martinpitt/umockdev/issues/271).
Another example is reading unit files, especially .network files,
as automount may trigger mounting network filesystems...

Also, when this is used in NSS plugins, programs that load the
plugins may fail because of spuriously configured seccomp. See #38565.

Let's not trigger automount by default, and do only when explicitly
requested.

This introduces CHASE_TRIGGER_AUTOFS, and use it in
- service manager,
- bootctl and finding ESP/xbootldr,
- sysupdate,
- mountfsd,
- systemd-mount.

There may be several more places we should trigger automount, but let's
do that later.

Follow-up for c5de7b14ae.
Fixes #38565.
Replaces #38569.

Co-authored-by: Luca Boccassi <luca.boccassi@gmail.com>
2025-08-20 02:32:02 +09:00
Yu Watanabe
2e7d7e929e Revert "chase: invert CHASE_NO_AUTOFS and only set it where needed"
This reverts commit 490aa05ca1.

As commented https://github.com/systemd/systemd/pull/38569#discussion_r2284978273,
the commit makes autofs check bypassed. Before the commit, when
CHASE_NO_AUTOFS is set, we did not shortcut chasing paths, and refused
any autofs mount points in the path. However, with the commit, the flag
was swapped but even when CHASE_AUTOFS is unset, the autofs check may be
skipped.

To fix the issue, rather than swapping the flag, we should introduce
another flag, say CHASE_TRIGGER_AUTOFS. This revert the commit, and in a
later commit, the new flag will be introduced.
2025-08-20 02:15:36 +09:00
Luca Boccassi
490aa05ca1 chase: invert CHASE_NO_AUTOFS and only set it where needed
Since c5de7b14ae
file searching implies a new mount api syscall by default,
to trigger automounts.

This is problematic in NSS plugins, as they are dlopen'ed inside
processes by glibc, for two reasons.

First of all, potentially searching on a networked filesystem
automount could lead to nasty surprises, such as the process
responsible for setting up the network filesystem trying to
search on that same filesystem.

More importantly, the new mount api syscall was never part of
the filesystem seccomp filter that we provide by default, and
given mounting/remounting/bind mounting is one of the possible
ways to bypass sandboxing it is very likely not allowed when
custom filters are used in sandboxed processes, if they don't
need to do these operations otherwise.
The filesystem seccomp mask we provide has been updated, however
this only takes effect on the next restart of a service. When
systemd is upgraded via a package upgrade, the new nss plugin is
installed and will be immediately dlopen'ed by glibc when needed,
without waiting for the process to restart, which means the existing
seccomp filter applies, causing the filter to trigger.
Given it's not really possible for any arbitrary program to
predict which NSS modules glibc will load, given programs do not
configure that and instead nsswitch is set up by the sysadmin,
it's impossible to handle at each process level. It's also not
possible to know when it will be triggered, given the plugin
is not linked in each binary tools like need-restart cannot
even pre-emptively restart services that may be affected.

This means in practice, upgrading from systemd << v258 to >= v258
requires a reboot to avoid either subtle or catastrophic system
failures.

By avoiding to trigger automounts in nss-systemd we can avoid
both issues.

userdb drop-ins are searched for in:

/etc/userdb/
/run/userdb/
/run/host/userdb/
/usr/local/lib/userdb/
/usr/lib/userdb/

none of which are supported as automounts anyway.

Note that this happens only when the userdbd service is not running,
as otherwise nss-systemd will go through the varlink IPC, rather than
doing the searches in-process.

So invert CHASE_NO_AUTOFS to CHASE_AUTOFS and set it in the places where
we do want to trigger automounts, like looking for the ESP.

Follow-up for c5de7b14ae
Fixes https://github.com/systemd/systemd/issues/38565
2025-08-19 16:48:13 +02:00
Yu Watanabe
00085ba6c2 import,sysupdate: make notify event processed before SIGCHLD of worker processes
This fixes the following warning:
```
[    5.628796] TEST-13-NSPAWN.sh[299]: + importctl import-raw --class=confext /var/tmp/importtest
(snip)
[    5.638894] systemd-importd[302]: (transfer1) Operation completed successfully.
[    5.640760] TEST-13-NSPAWN.sh[318]: ^MTotal:   0%^MTotal:  40%
[    5.638902] systemd-importd[302]: (transfer1) Exiting.
[    5.638931] systemd-importd[302]: Got percentage from client: 40%
[    5.638956] systemd-importd[302]: Transfer process succeeded.
[    5.638988] systemd-importd[302]: Got notification datagram from unexpected peer, ignoring.
```
2025-08-13 23:44:58 +09:00
Abderrahim Kitouni
83c1e8ff5f updatectl: allow interactive authorization 2025-08-05 17:03:20 +01:00
Nick Labich
85e9805903 sysupdate: Prevent unnecessary failure when a transfer Path is not present
Fixes https://github.com/systemd/systemd/issues/38007
2025-07-25 10:53:48 +01:00
Yu Watanabe
5918ba9c69 tree-wide: fix log messages: "Failed VERB" -> "Failed to VERB" 2025-07-22 03:05:33 +09:00
Yu Watanabe
3fc2a44043 include: move trivial kernel header wrappers to src/include/override/ 2025-07-11 13:05:46 +09:00
Yu Watanabe
4f18ff2e29 tree-wide: include unistd.h where necessary
We use symbols provided by unistd.h without including it. E.g.
open(), close(), read(), write(), access(), symlink(), unlink(), rmdir(),
fsync(), syncfs(), lseek(), ftruncate(), fchown(), dup2(), pipe2(),
getuid(), getgid(), gettid(), getppid(), pipe2(), execv(), _exit(),
environ, STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO, F_OK, and their
friends and variants, so on.

Currently, unistd.h is indirectly included mainly in the following two paths:
- through missing_syscall.h, which is planned to covert to .c file.
- through signal.h -> bits/sigstksz.h, which is new since glibc-2.34.
  Note, signal.h is included by sd-eevent.h. So, many source files
  indirectly include unistd.h if newer glibc is used.

Currently, our baseline on glibc is 2.31. We need to support glibc older
than 2.34, but unfortunately, we do not have any CI environments with
such old glibc. CIFuzz uses glibc-2.31, but it builds only fuzzers, and
many files are even not compiled.
2025-06-30 09:19:15 +02:00
Lennart Poettering
51cc3825d1 tree-wide: use sd_bus_message_send() instead of sd_bus_send() wherever possible
Also, add a coccinelle script that patches this automatically.
2025-06-24 23:23:40 +09:00