Commit Graph
90287 Commits
Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek 8985fc5e57 manager: try to reexecute as /proc/self/exe too
If we try to reexecute, and the binary was started from a non-standard
path, this would fail:
  src/core/main.c:2396: Reexecuting.
  src/core/main.c:2240: Failed to execute our own binary /usr/lib/systemd/systemd: No such file or directory
Let's make things more robust by trying /proc/self/exe too.
2026-07-02 17:19:18 +02:00
Zbigniew Jędrzejewski-Szmek 7bff0f09fe core: let manager_load_startable_unit_or_warn take a log level
Add a log_level parameter so callers can control the severity of load
failures. During boot, when no unit was explicitly requested on the
kernel command line (arg_default_unit is unset), failing to load the
default unit is not fatal since we fall back to other targets, so log
those attempts at LOG_INFO instead of LOG_ERR. All other callers pass
LOG_ERR to keep their existing behaviour.
2026-07-02 17:19:18 +02:00
Zbigniew Jędrzejewski-Szmek a0146fe807 core: embed essential units as built-in fallbacks
Compile the contents of a few essential target unit files
(graphical.target, multi-user.target, rescue.target, etc.) into the
manager binary, with comments stripped, and fall back to those built-in
copies when no fragment is found on disk. This lets the manager reach a
usable state even on a system that ships none of these unit files, e.g.
in minimal environments or one-off chroots.

On-disk files always take precedence (masks included), as the fallback is
only consulted when nothing is found in the lookup paths. The unit file
list is defined in units/meson.build and embedded via a small generator
script; 'units' is now processed before 'src/core' so the list is
available there.

The set of units and services is selected that should allow for a normal
operation of starting/stopping/restarting, of the machine. The services
all use SuccessAction=…, so they don't require any binaries to be
installed.

sigpwr.target is included, even though it doesn't do anything useful.
The same is true in normal installations. We might want to change it
do something useful there too.
2026-07-02 17:19:18 +02:00
Zbigniew Jędrzejewski-Szmek a809b6e565 core: add fallback-default-target build option
Add a 'fallback-default-target' meson option that configures which unit
to activate when default.target is not installed. This makes things more
resilient in general and is also useful for minimal/statically-linked
installations that may not ship a default.target symlink.

'graphical.target' is used as the default value of the setting, because
that's what we symlink as default.target in units/meson.build.

In the initrd, we had a fallback to start default.target if initrd.target
cannot be started. This fallback is changed to only do that if it is
not found, not on other errors. This seems more correct (and makes
the two fallbacks symmetrical.)
2026-07-02 17:19:18 +02:00
Zbigniew Jędrzejewski-Szmek fff9c9ba46 meson: allow manager to be linked statically
After stripping, in an unoptimized build with glibc, we get a 8.7 MB binary:
$ file build-static/systemd
build-static/systemd: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, BuildID[sha1]=1ec004bf61b775d284d909a818a3c4f63f83f055, for GNU/Linux 3.2.0, stripped
$ ls -lh build-static/systemd
-rwxr-xr-x 1 zbyszek zbyszek 8.7M Jun 30 14:07 build-static/systemd
2026-07-02 17:19:18 +02:00
Zbigniew Jędrzejewski-Szmek b0dfec9fa4 core: convert exec-invoke to use the new static-friendly functions
The libc API is rather ugly: it requires the caller to pass an
array of the maximum possible size (or to repeatedly query the group
list to discover the actual size). With our "static-friendly" helpers,
we reallocate the array on the fly.
2026-07-02 17:19:18 +02:00
Zbigniew Jędrzejewski-Szmek 50b4f1e3bf shared/creds-util: use getpwuid_malloc()
Static linking, i.e. without dlopen, sometimes fails when getpwuid
is used. I doesn't fail in all cases (glibc version?), so I didn't
do this initially.
2026-07-02 17:19:18 +02:00
Zbigniew Jędrzejewski-Szmek 5c2bd19f40 user-util: add getgrouplist_malloc and initgroups_wrapper 2026-07-02 17:19:18 +02:00
Zbigniew Jędrzejewski-Szmek bbeef4b948 various: add -Dbuild-static and alternatives to libc functions
When we try to build with -static, the linker refuses dlopen and
various functions related to nss. This commit adds the basic support
to compile with -static and allow the link to pass.
2026-07-02 17:19:18 +02:00
Zbigniew Jędrzejewski-Szmek b3749de21c user-util: add lookup_groups_in_files 2026-07-02 17:19:18 +02:00
Zbigniew Jędrzejewski-Szmek 2c01b4895e user-util: sysconf_ngroups_max
This hides the iffy interface of sysconf(_SC_NGROUPS_MAX) to simplify
the calllers.
2026-07-02 17:19:18 +02:00
Zbigniew Jędrzejewski-Szmek aac88fd8ab user-util: add lookup_pwent_in_files and lookup_grent_in_files
Those functions will be used later. This commits adds the
implementations and tests for them.

glibc functions require ability to open nss modules, which requires
dlopen. Linking will fail if any of the nss-using functions are used.
So the following few commits will provide replacements for all of
them.
2026-07-02 17:19:18 +02:00
Zbigniew Jędrzejewski-Szmek fcb2c6c259 meson: replace -Dbuild-executor-shared=single with -Dsystemd-multicall-binary=true
This effectively reverts the meson config changes introduced in
0c6186695a. I wasn't happy with that form
back when it was commited, and in hindsight, I like it even less. Let's
just add a new option that hopefully is easier to understand and will
work better when new functionality is added in the future.

Now there are two options:
link-executor-shared (boolean, defaults to true)
  — "link (separate) systemd-executor to libsystemd-shared.so and libsystemd-core.so"
systemd-multicall-binary (also boolean, defaults to false)
  — "link systemd+systemd-executor as a single binary"

Build directories will need to be recreated again, sorry!
2026-07-02 16:35:36 +02:00
Daan De Meyer d08882653d meson: fix fs.exists() check for fuzz corpus samples
Commit 8355eb6e11 ("meson: Check if files returned by git ls-files
actually exist") checks the paths printed by git ls-files, which are
relative to the project root, with fs.exists(), which resolves them
relative to the test/fuzz subdirectory. As a result, every corpus
sample was silently skipped, and only the generated directives tests
were registered. Resolve the paths against the project source root
instead.
2026-07-02 15:33:28 +01:00
Daan De Meyer 62c5c888f4 compress: handle ZSTD_CONTENTSIZE_UNKNOWN when decompressing blobs
The zstd blob decompression code assumed ZSTD_getFrameContentSize() always
returns the decompressed size, which holds for the journal and coredump blobs
systemd compresses itself with the one-shot ZSTD_compress(). Frames produced by
the streaming API, however, don't record the decompressed size in their header,
so ZSTD_getFrameContentSize() returns ZSTD_CONTENTSIZE_UNKNOWN. Per the zstd
documentation this is not an error, but decompress_blob_zstd() and
decompress_startswith_zstd() bailed out with -EBADMSG regardless.

This broke kexec of kernel images compressed with 'zstd' (e.g. zstd -22), whose
ZBOOT payload is decompressed via decompress_blob().

Treat only ZSTD_CONTENTSIZE_ERROR as fatal and, when the size is unknown, grow
the output buffer as we stream the frame out instead of relying on the recorded
size. Add a regression test that feeds a streaming-compressed (hence
unknown-size) zstd frame through decompress_blob() and decompress_startswith().
2026-07-02 16:09:26 +02:00
Philip Withnall 075f74a19c docs: Update memory pressure docs for latest GLib support for it
As of GLib 2.90.0 (not yet released), GLib will fully support the spec,
including the `MEMORY_PRESSURE_WATCH` and `MEMORY_PRESSURE_WRITE`
environment variables, which it did not support previously.

See https://gitlab.gnome.org/GNOME/glib/-/merge_requests/5046
2026-07-02 15:05:14 +01:00
Frantisek Sumsal 60d982d3fc test: suppress fails on the Africa/Tripoli (Libya) timezone
As it switched between CET and EET multiple times in the past, causing
random fails with certain historical timestamps:

834/1524 test - systemd:test-time-util     FAIL    0.96s   killed by signal 6 SIGABRT
 ...
TZ=Africa/Tripoli, tzname[0]=EET, tzname[1]=CEST
@378687574661411 → Thu 1981-12-31 23:59:34 CET → @378683974000000 → Thu 1981-12-31 23:59:34 EET
src/test/test-time-util.c:450: Assertion failed: Expected "ignore" to be true
/builddir/build/BUILD/systemd-261.1-build/systemd-261.1/tools/test-crash-trace.sh: line 18: 87088 Aborted                    (core dumped) "$@"
2026-07-02 13:17:06 +01:00
Paul Meyer 1ef7c15bd8 ukify: show all sections and profiles in inspect JSON output
The JSON output keyed every section by name, so a UKI with repeated
sections only showed the last one: in a multi-profile UKI all but one
.profile/.cmdline/.pcrsig were dropped, as were extra .dtbauto/.efifw.

Report the shared base sections by name at the top level (so .cmdline
etc. stay where they were), each profile as its own by-name object under
a new "_profiles" array, and the alternative-set sections (.dtbauto,
.efifw) as arrays.

Co-developed-by: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Paul Meyer <katexochen0@gmail.com>
2026-07-02 13:26:33 +02:00
Paul Meyer 6603180b38 boot: measure SMBIOS via non-TPM runtime measurements
In commit 29c6d1c125 ("boot: measure select SMBIOS objects
explicitly") we added an explicit SMBIOS measurement in systemd-boot
and systemd-stub, covering cases where firmware doesn't measure SMBIOS
itself. measure_smbios() bailed unless a TPM was present, so it skipped
the measurement on confidential guests that only expose a CC
measurement protocol (e.g. Intel TDX RTMRs).

We can have much higher expectations of the virtual firmware used for
confidential computing, and the firmware is attested, so we can expect
it to always measure SMBIOS in this case. We still do our own
measurement to get a measurement structure similar to that of
non-confidential guests, and as another line of defense.

Signed-off-by: Paul Meyer <katexochen0@gmail.com>
2026-07-02 11:43:13 +01:00
Paul Meyer 34f0384c53 shell-completion: add tdx to systemd-vmspawn --coco values
Missed in a78afc1616 ("vmspawn: add Intel TDX confidential VM
support")

Signed-off-by: Paul Meyer <katexochen0@gmail.com>
2026-07-02 10:55:39 +01:00
Luca Boccassi dbcf482492 terminal-util: tweaks for show_menu() (#42822) 2026-07-02 10:02:53 +01:00
Michael Vogt 896fd702ba firstboot: add new systemd.firstboot=headless mode
This adds a new systemd.firstboot=headless mode. It differs from the
existing systemd.firstboot=no mode in that it still performs the
non-interactive auto-configuration that requires no user input (such
as selecting the only installed locale, or applying settings provided
via credentials), and only skips the prompts that would otherwise
block waiting for user input. In contrast, =no disables that
auto-configuration along with the prompts.

The option is also honoured by homectls firstboot logic and
systemd-cryptenroll, where headless behaves the same as no
(because the is no auto-configuration).
2026-07-02 09:52:21 +01:00
Lennart Poettering bd13921c78 test: add test case for show_menu() 2026-07-02 08:20:59 +02:00
Lennart Poettering 00af6e918b terminal-util: drop assert() on 'x'
We happily take a NULL strv as argument, equivalent to an empty one,
like most of our strv handling funcs.
2026-07-02 08:20:59 +02:00
Lennart Poettering a0b6644796 terminal-util: make sure we never go below 10 characters line width 2026-07-02 08:20:59 +02:00
Lennart Poettering 6e9a1c4cd6 terminal-util: use LESS_BY() where appropriate 2026-07-02 08:18:36 +02:00
Lennart Poettering 72c6ac77e3 terminal-util: calculate array index only once 2026-07-02 08:18:36 +02:00
Luca Boccassi 03b498d8a8 core: assorted hardening fixes flagged by kres (#42840) 2026-07-02 00:57:06 +01:00
Luca Boccassi f738dcb3b7 bpf-restrict-fs: use a 32-bit magic key on big-endian too
The inner map is created with a uint32_t key, but the update passed
&magic[i] where magic is a (possibly 64-bit) statfs_f_type_t. On
little-endian the low 32 bits happen to be read; on big-endian 64-bit
(s390x, ppc64 BE) the zero high word is read instead, so every
filesystem collides on key 0 (the allow/deny selector) and
RestrictFileSystems= is silently broken. Pass a truncated copy.

Follow-up for 184b4f78cf
2026-07-01 22:46:45 +01:00
Luca Boccassi 62c182f0d5 core/scope: don't assert when start is retried during cgroup chown
While a delegated scope waits for the async cgroup chown helper it sits
in SCOPE_START_CHOWN (UNIT_ACTIVATING). unit_start() forwards to
->start() while activating, so scope_start() could be re-entered in
that state and trip assert(s->state == SCOPE_DEAD), aborting PID 1.
Treat SCOPE_START_CHOWN as already-starting instead.

Follow-up for 03860190fe
2026-07-01 22:46:45 +01:00
Luca Boccassi b64a44707d core: donate the fdset to do_reexecute() to avoid a double free
do_reexecute() freed the FDSet on the switch-root/soft-reboot fallback
but the caller's copy stayed live, so main() freed it again if every
fallback exec then failed. Donate the fdset instead: pass it with
TAKE_PTR() and take ownership via a _cleanup_ local, freeing it exactly
once on every exit path.

Follow-up for 3c7878f94b
2026-07-01 22:46:45 +01:00
Shihao Ren 48dc1bbd09 run: refuse --no-block when combined with --scope
In the systemd-run --scope mode, --no-block has no actual effect and will
be silently ignored. Therefore, this combination is explicitly rejected to
reduce confusion for users when using it.

Fixes: #42806
2026-07-01 23:37:44 +02:00
Lennart Poettering afcc11d938 crypto-util, ssl-util: set log level to debug in dlopen_many_sym_or_warn() (#42811)
Otherwise in systems with OpenSSL 3 the journal contains multiple error
entries because the preferred library libcrypto.so.4 is not present.

Follow-up for ccdd42351f
2026-07-01 22:15:51 +02:00
Lennart Poettering 62db9abc38 vmspawn: add Intel TDX confidential VM support (#42835) 2026-07-01 22:14:09 +02:00
Lennart Poettering 66f7a14c6d mkfs-util: fixes for mtools invocation (#42839) 2026-07-01 22:10:49 +02:00
Luca Boccassi a96c0075d4 tree-wide: trivial sysconf() invocations tweaks (#42837) 2026-07-01 19:42:52 +01:00
Luca Boccassi 0a869d3882 shared/install: give the borrowed name back before bailing on error
In the unmask path, when install_changes_add() fails the borrowed
*name was not handed back via TAKE_PTR() before returning, so
install_info_clear() freed the caller's strv entry, leaving a dangling
pointer that is double-freed at the caller's strv_free().

Follow-up for f31f10a620
2026-07-01 18:18:00 +01:00
Luca Boccassi 61196f5817 quotacheck: don't apply an invalid quotacheck.mode= value
quota_check_mode_from_string() returns -EINVAL on a bad value, storing
it in the global arg_mode. Only change arg_mode on success.

Follow-up for d73691c64e
Follow-up for dba4fe9a60
2026-07-01 18:18:00 +01:00
Luca Boccassi 7ddb3ead85 core: avoid using uninitialized buffer on bad systemd.random_seed=
unbase64mem() leaves p/sz uninitialized on failure, and the
deserialization doesn't bail out in that case, unlike other cases.

Follow-up for d247f232a8
2026-07-01 18:18:00 +01:00
Chris Coulson 5a80137aa4 tpm2-setup: Create and persist an endorsement key
This updates systemd-tpm2-setup to create and persist an endorsement
key if there isn't one already. For each supported EK template profile,
it will read the EK certificate from its NV index if there is one.
When there is an EK certificate present, a primary key is created using
the corresponding template. If the resulting EKpub matches the public
key in the certificate, the created EK is persisted and the process is
complete.

The low-range templates and the high-range RSA 2048/3072 and ECC NIST
P256/P384 storage templates are supported, as detailed in section
5.3 of the "TCG EK Credential Profile For TPM Family 2.0" spec v2.7.
High-range templates are preferred because these permit EK usage without
requiring knowledge of the authorization value for the endorsement
hierarchy, meaning that, like with the SRK, it is possible to restrict
the usage of the endorsement hierarchy whilst still permitting use of
the persistent EK.

The EK is always persisted at handle 0x81010001. This handle is
reserved in Table 2 of the "TCG TPM v2.0 Provisioning Guidance" spec
v1.0r1.0, although this is only a recommendation. This
handle is within the block of handles reserved for endorsement
primary keys in the "Registry of Reserved TPM 2.0 Handles and
Localities" spec v1.2r1.00. Section 2.3.2 of this specification also
makes a suggestion that there should be a relationship between the EK
certificate NV index and a corresponding persistent EK handle by
using handles at the same offsets within their respective ranges.
However, this contradicts the provisioning guidance spec which reserves
0x81010001 when there isn't a certificate at 0x01c00001. For simplicity,
I've chosen to use a single handle for the EK regardless of which profile
it is created with.

The "TCG EK Credential Profile For TPM Family 2.0" spec also provides a
way for endorsement keys to be certified with non-standard templates by
storing the template in a NV index. This is also supported.

The EK creation is not executed with tpm2-setup --early, as there's no
need for it to be created so early, unlike with the SRK. I also haven't
stored EKpub in /var/lib/systemd like with the SRKpub, as I'm not sure
there will be a use case for this yet.

A follow-up PR may be needed to add some internal helpers to make use
of the persisted EK, as use of low-range EKs requires a policy session.
High-range EKs can be used with a HMAC session because they have the
userWithAuth attribute set and we are creating them with an empty
authorization value.

https://trustedcomputinggroup.org/resource/http-trustedcomputinggroup-org-wp-content-uploads-tcg-ek-credential-profile/
https://trustedcomputinggroup.org/resource/tcg-tpm-v2-0-provisioning-guidance/
https://trustedcomputinggroup.org/resource/registry/
2026-07-01 17:36:50 +02:00
Michael Vogt ab344eb750 core: add absolute-path properties to varlink StartTransient
Similar to PR#42360 this commit adds missing properties for
absolute path handling in io.systemd.Unit.StartTransient for
the `Exec` context and a macro helper to share the common code.

The properties added are:
IPCNamespacePath, NetworkNamespacePath, RootDirectory, RootHashPath,
RootHashSignaturePath, RootImage, RootVerity, UserNamespacePath,
RootMStack.

Note that RootHashPath, RootHashSignaturePath need custom apply
functions because the varlink name "RootHashPath" differs from the
name that needs to be written into the unit file ("RootHash=")
and the iovec must be cleared.
2026-07-01 16:14:37 +02:00
Lennart Poettering 7f9b1da527 tree-wide: fix return type of sysconf() 2026-07-01 16:14:20 +02:00
Lennart Poettering 818b3b31e6 time-util: use sysconf_clock_ticks_cached() at all places we query _SC_CLK_TCK 2026-07-01 16:14:19 +02:00
Lennart Poettering 60bac209eb memory-util: don't use 'r' for non-int returns 2026-07-01 16:14:19 +02:00
Lennart Poettering d769892ad0 env-util: use our own sc_arg_max() helper at more places 2026-07-01 16:14:19 +02:00
Lennart Poettering d789af7280 mkfs-util: deal with mmd name clashes gracefully
In various cases we'll touch the same directories multiple times with
mtools: for example the /loader/ dir itself. Unfortunately mtools' mmd
does not implement a graceful "-p" switch like mkdir, but will do some
interactive name clash thing instead. We can turn this off via "-Ds
-DS", so let's do that. But that's not enough since the tool will still
fail with a non-explanatory exit status of 1. This hence ignores that
failure and proceeds anyway, under the assumption that failures to
create a directory will sooner or later be detected anyway once the
directory is to be populated and turns out not be existing because the
creation failed.

This makes some integration test/mkosi invocations work
non-interactively again.

Follow-up for f191ca982c
2026-07-01 16:10:39 +02:00
Lennart Poettering b4502c72c8 mkfs-util: let's debug log about all fork off cmdlines 2026-07-01 16:10:39 +02:00
Paul Meyer 4dd73ad924 core: trust SMBIOS credentials under Intel TDX
SMBIOS OEM strings are host-controlled and normally distrusted by PID1
in confidential VMs. Under TDX, however, the SMBIOS table (including
Type 11) is measured into RTMR0 by the firmware (TDVF), so a remote
verifier can detect host tampering with credentials delivered this
way. Accept them there, while keeping fw_cfg distrusted as those
items are not measured even on TDX.

This lets systemd-vmspawn deliver credentials to TDX guests via the
normal SMBIOS path, unlike SNP which requires the initrd cpio channel.

Signed-off-by: Paul Meyer <katexochen0@gmail.com>
2026-07-01 16:09:27 +02:00
Luca Boccassi ef7b9f679b pcrlock: add vl methods for fw and sb
Add varlink method wrappers for locking/unlocking firmware code and config,
and secure boot policy and authority.
2026-07-01 14:56:53 +01:00
Luca Boccassi 04f8927173 Add more shutdown timestamps and preserve via LUO (#42671)
Add more shutdown timestamps, export them via D-Bus/Varlink, use them in
`systemd-analyze time`, and preserve them across kexec via LUO. This is
useful to measure reboot performance with added measurement points and
more granular intervals.
2026-07-01 14:12:21 +01:00