Commit Graph
87464 Commits
Author SHA1 Message Date
Michael Vogt bf2d68433d coccinelle: generalize pidref_is_set() to =~ _is_set()
Our coccinelle/check-pointer-deref.cocci checker has a special
case for `assert(pidref_is_set(param))`. It turns out we can
generalize this and catch the following:
- iovec_is_set
- sd_dhcp_duid_is_set
- sd_dhcp_client_id_is_set
2026-03-27 11:14:49 +01:00
Mike Yuan be176c0c91 Make imds networking unlocked by default (#41359) 2026-03-26 20:08:17 +01:00
Zbigniew Jędrzejewski-Szmek 2d2dc38f00 basic/proc-cmdline: extend comments
Inspired by the discussion in #41161.

Also change the order of flags to be more logical. First the option
to specify at what fields we look, then the option to specify how we
return their name, the the value, and finally what to do if the value
is missing.
2026-03-26 18:53:40 +01:00
Mike Yuan de68e23ff1 creds: minor cleanups for --newline= handling (#41329)
Prompted by #41325

Fixes #41348
2026-03-26 18:36:51 +01:00
Mike Yuan e153cf36b0 core: address review feedback from Mike (#41354)
This commit addresses the review feedback from @YHNdnzj (many thanks)

Closes: https://github.com/systemd/systemd/issues/41324
2026-03-26 18:18:01 +01:00
Michael Vogt 777d9c10ad coccinelle: add checks for pointer access without NULL check
The fix in 8f1751a111 made me wonder if we could automatically detect
when pointers are accessed but when this might not be safe. Systemd
is already using a lot of `assert(dst)` and this change now forces
us to use them.

So this commit (ab)uses coccinelle to flag any pointer parameter
dereference not preceded by assert(param), ASSERT_PTR(param), or an
explicit NULL check. It adds integration into meson as a new "coccinelle"
test suite (just like clang-tidy) and is run in CI. The check is not
perfect but seems a reasonable heuristic.

For this RFC commit it is scoped to a subset, it excludes 25 dirs right
now and includes around 100. About 300 warnings left. Busywork that I am
happy to do if there is agreement that it is worth it.

With this in place we would have caught the bug from 8f1751a111 in CI:
```
FAIL: check-pointer-deref.cocci found issues in systemd/src/boot:
diff -u -p systemd/src/boot/measure.c /tmp/nothing/measure.c
--- systemd/src/boot/measure.c
+++ /tmp/nothing/measure.c
@@ -312,7 +312,6 @@ EFI_STATUS tpm_log_tagged_event(
         if (err != EFI_SUCCESS)
                 return err;

-        *ret_measured = true;
         return EFI_SUCCESS;
 }
```

This also adds a new POINTER_MAY_BE_NULL() for the cases when the
called function will do the NULL check (like `iovec_is_set()`).
2026-03-26 18:13:17 +01:00
Zbigniew Jędrzejewski-Szmek 6240d420d6 meson: unlock imds network by default
Enabling locking by default would constitute a major footgun and
compatibility break on upgrades. This functionality is useful, but it
requires the rest of the system to be "ported" to use systemd-imds
first. The user or distro should opt in to "locked" mode only after
doing the integration work.
2026-03-26 17:32:43 +01:00
Zbigniew Jędrzejewski-Szmek c3e4e8a527 meson: simplify setting of ImdsNetworkMode default
This follows the pattern used for dnssec default mode right above.
2026-03-26 17:28:21 +01:00
Luca Boccassi ace4f53b67 labeler: update to latest commit and limit file-based label to 5 (#41358)
When doing large refactors or large changes the bot spams
labels left and right, making the PR unreadable. Use the
new option to limit the bot to a max of 5 file-based
labels. If more than 5 would be set, all file-based labels
are skipped.
2026-03-26 15:36:43 +00:00
Lennart Poettering 4cb283f931 imds: some minor review fixes
Addresses these issues:

https://github.com/systemd/systemd/pull/40980#pullrequestreview-4013313066
2026-03-26 16:13:11 +01:00
Lennart Poettering 720848d368 optionally run a software TPM at boot as fallback for TPM less machines (#41016)
In various scenarios it's useful to be able to run a software TPM as
fallback on a machine if it doesn't natively have a hardware for it, in
order to provide somewhat systematic interfacing for legacy machines.
This adds the infrastructure for it.

Relevant parts:

1. On EFI systems sd-stub will now generate a random secret on first
boot and store it in a persistent NV variable, which is marked
inaccessible to the OS. It then derives a per-OS secret from that which
is passed to the OS via the initrd logic. This is generally useful, but
in particular is intended to secure the software TPM at least a bit: it
provides better security than nothing (i.e. the only protection in place
is that the firmwrae protections work, but this is also what shim relies
on, hence maybe not too bad), and allows swtpm to encrypt its storage
with something.

2. systemd-tpm2-generator is extended to optionally start an swtpm if no
tpm hw is detected. Because this is of course a major downgrade in
security, this has to be requested explicitly at boot via a kernel
cmdline switch.

3. This optionally mounts the ESP from the initrd. This is general
infrastructure, and has been requested before, but is particularly
interesting in the context of software TPMs: the state needs to be
stored somewhere, and that before the rootfs can be unlocked.

4. This introduces a special new separator measurement for PCRs 0-7 that
isolates all measurements from pre-os/uefi world from those done by the
OS. I added this for three reasons:
- in the swtpm case we'll not have any pre-os/uefi measurements, and we
need to be able to determine cleanly that this is the case. this hence
is supposed to play a similar role as the usual firmware separator
measurement, that however cleanly fixates to the PCRs even the case
where the firmware measurements don't exist at all
   - this is a very comprehensive fix for #40567
- not all firmwares generate the firmware separator at all, but it is
essential to seal off firmware variables from OS generated ones. This
can fill the void to some degree.
6. This introduces a new kernel cmdline switch
systemd.tpm2-measured-os=1, which allows force enabling all our
measurement logic, even if UKI TPM measurements are not done. This is
supposed to be used for the swtpm case so that one gets all the
measurements even without having the early boot verified boot chain in
place.

Benefits of all this: systems that care about TPMs have a (lower
security) compat glue in place that allows supporting legacy hw the same
way as modern hw in many ways, so that remote attestation and other uses
can reasonably work with the same codepaths.

Also see: https://github.com/lxc/incus-os/pull/667 regarding prior
similar work.

Fixes: #40567
2026-03-26 16:12:46 +01:00
Lennart Poettering 1e254ad1bd update TODO 2026-03-26 16:11:34 +01:00
Lennart Poettering eaeeae6598 units: make use of nvpcrs only after the NV anchor completion measurement is done
This makes sure we don't use the "hardware" or "verity" nvpcrs before
the NV anchor measurement is done.

This is mostly to avoid confusing output, and to indirectly ensure the
nvpcr allocation in tpm2-setup is the load bearing one, but it should
not be load bearing for security afaics.
2026-03-26 16:11:34 +01:00
Lennart Poettering 7c27f9f594 pcrextend: measure another separator at boot
This has been requested previously for PCR 7 (#40567), but let's do that
for all firmware owned PCRs, since some firmwares forget to measure
their own separator. Let's hence measure our own guranteed one.

Fixes: #40567
2026-03-26 16:11:34 +01:00
Lennart Poettering 3b20cc4526 creds-util: only lock against public key PCR stuff if we are booted with UEFI supporting TPMs
The UKI public key PCR stuff only works if we get PCR measurements from
the pre-boot environment, hence automatically disable the logic by
default if we don't have that.
2026-03-26 16:11:34 +01:00
Lennart Poettering 96bb950ffa pcrlock: deal with firmwares which understand TPM but where no TPM is available
This is a potentially common case in VMs: firmwares might know the
concept of TPMs, but the hardware is not enabled in the specific VM.
Let's handle this case nicely.
2026-03-26 16:11:34 +01:00
Lennart Poettering 1494cb04ea pcrlock: don't fail if firmware measurements aren't available
With swtpm in place we now commonly have systems where TPM is available
during runtime, but not in the firmware. Handle that nicely.
2026-03-26 16:11:34 +01:00
Lennart Poettering cd911bec6e core: introduce ConditionSecurity=measured-os
So far we always conditioned our TPM magic on the UKI having detected
TPM support in the firmware. This is a bit limiting when we want to
support a software TPM that is not visible to the firmware. Hence let's
split this up, and add a separate control that can be set via the kernel
command line.  However, as before, let's by default inherit the firmare
TPM discovery state into it, to retain the current behaviour unless
overriden.

With this in place, boot with "systemd.tpm2_measured_os=1
systemd.tpm2_software_fallback=1" on the kernel cmdline to get the swtpm
fallback and then a measured OS based on it.
2026-03-26 16:11:34 +01:00
Lennart Poettering ca03d178a0 tree-wide: relax TPM available checks for many cases
In many cases it's essential to know if the firmware supports a TPM, but
in others we should accept it if the firmware doesn't have TPM support,
in particular if we want to run the OS with a software TPM.

Hence, add tpm2_is_mostly_supported() as function similar to
tpm2_is_fully_supported(), with the only difference that the former
doesn't insist on a firmware supported TPM. Then, change a number of
users over to this (but not all).
2026-03-26 16:11:34 +01:00
Lennart Poettering 750795d103 tpm2-generator: if requested run things with an swtpm
We want to start the software TPM fallback only if no real hw is
evailable and if the user opts-in to this behaviour. Add a generator
that drives all this, based on kernel command line configuration.
2026-03-26 16:11:34 +01:00
Lennart Poettering 056c21aaeb tpm2: add "systemd-tpm2-swtpm" wrapper for "swtpm"
For TPM-less systems it's sometimes valuable to have a fill-in software
TPM running from early boot on, so that TPM-based functionality can
"just work" and rely on TPM semantics, even if it's at a substantially
weaker security level.

This adds a wrapper around swtpm. It's a binary that chainloads swtpm
but does a few preparatory steps and integrates into systemd's logic
otherwise.

All this is then exposed as systemd-tpm2-swtpm.service.

The service is not hooked into much yet, that is added in later commits.
2026-03-26 16:11:34 +01:00
Luca Boccassi c30656f35a labeler: limit file-based label to 5
When doing large refactors or large changes the bot spams
labels left and right, making the PR unreadable. Use the
new option to limit the bot to a max of 5 file-based
labels. If more than 5 would be set, all file-based labels
are skipped.
2026-03-26 15:07:56 +00:00
Luca Boccassi a42fbad472 labeler: update to latest commit
Adds 'changed-files-labels-limit' and 'max-files-changed' configs
2026-03-26 15:06:16 +00:00
Mike Yuan 734af2908a creds: minor tweak for fputc() error handling
Let's do not assume errno is set for return values other than
EOF, following what we do in fileio.c.
2026-03-26 16:01:35 +01:00
Mike Yuan 64d1c102ad creds: if newline is explicitly requested, skip tty check
Before this commit, the > 0 state of arg_newline tristate is
simply ignored.

Yes, this is a minor compat break, but I'd argue the previous
behavior was not useful as "yes" is treated the same as "auto".
An issue also reported that it was quite surprising.

Fixes #41348
2026-03-26 16:00:42 +01:00
Mike Yuan 1060f82611 creds: use parse_tristate_argument_with_auto() where appropriate 2026-03-26 15:55:50 +01:00
Mike Yuan 82bfcc37e2 cleanup-util: include assert-fundamental.h instead of -util
The split was initially done to reduce transitive includes,
and for assert() only the former is needed.
2026-03-26 15:55:50 +01:00
Michael Vogt 31b9f451d7 core: always call manager_log_caller() even without pidref
Its fine if `manager_log_caller()` with an empty pidref,
it will log an unknown caller.

Thanks to @YHNdnzj for suggesting this.
2026-03-26 15:27:50 +01:00
Michael Vogt 1e9f0d76fb core: drop incorrect comment about SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)
The comment about `SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)` is
incorrect. To quote @YHNdnzj:
```
nah, the capability-based permission model is a legacy from kdbus. We cannot do it race-freely without it. Please simply drop the comment.
```

Thanks to @YHNdnzj for suggesting this.
2026-03-26 15:21:10 +01:00
Michael Vogt 21b25d8470 core: add assert(selinux_permission) to manager_do_set_objective
Thanks to @YHNdnzj for suggesting this.
2026-03-26 15:21:10 +01:00
Michael Vogt 34eec125d6 core: simplify manager_do_set_objective root path handling
The manager_do_set_objective() was doing a bunch of work to
check the `root` path that can already be done via
`json_dispatch_path` so instead of duplicating use the helper.

Thanks to @YHNdnzj for suggesting this.
2026-03-26 15:21:10 +01:00
Michael Vogt 1bdb3625c7 core: drop _manager() from new vl_method to shutdown
Drop the _manager suffix for vl_method_{poweroff,{soft,}reboot,
halt,kexec}_manager.

They're unambiguous enough and the power mgmt operations are
not manager-wide but system-wide.

Thanks to @YHNdnzj for suggesting this.
2026-03-26 15:21:10 +01:00
Lennart Poettering 6718ba1769 gpt-auto-generator: generate an initrd ESP mount if it makes sense
We need to store state persistently for the software TPM (i.e. the root
key). But given that TPMs are generally used to unlock the rootfs, this
storage cannot be on the rootfs. Hence let's use the ESP instead, as the
next best thing, that is guaranteed to exist during early boot, given we
just were booted from it.

This defines automatic logic for this, but does not cause the ESP mount
job to be enqueued (since typically we don't actually want that
mounted), this is left for the actual services that needs to be done.

Note that the mount here is set up quite differently from the one from
the host: since initrds are short-lived anyway, it seemed pointless to
use autofs. Moreover this uses a fixed place to mount the ESP, inspired
by the /sysroot/ + /sysusr/ mount naming. All that to simplify things a
bit for the consumers (which is mostly swtpm)
2026-03-26 14:34:56 +01:00
Lennart Poettering 23b4c833a4 fileio: add WRITE_DATA_FILE_MODE_0400 mode 2026-03-26 14:34:56 +01:00
Cynthia 0c2747e789 kernel-install(uki): filter comments from cmdline
This change aligns the behaviour of UKI generation with the behaviour
of BLS. The latter filters out lines starting with a #, allowing users
to add comments and/or temporarily remove some flags from the kernel
command line.

The kernel-install test have been adjusted to use a multiline cmdline
with a comment in it. Without this patch, the test fails.
2026-03-26 14:28:22 +01:00
Zbigniew Jędrzejewski-Szmek 1cf9e4e25e Basic IMDS support (#40980)
This adds a new cloud IMDS client, that can cover AWS, Azure, GCP,
Hetzner imds to varying degrees. Each cloud has this and it's very basic
functionality, hence I think it makes sense to add this to systemd.

Since the clouds are all different this tries hard to do the abstract
common logic in code, but encode the endpoint details, and well-known
keys in hwdb, attached to the DMI id device.

Why all this?

* Efficiency: we can schedule this in the initrd, at the earliest points
possible, without unnecessary delays
* Robustness: imds is typically slow and/or heavily rate-limited:
systemd-imdsd as single entrypoint can deal with that, and provide a
reliable, cached interface
* Security: the idea is that systemd-imdsd is the only service behing
able to access the IMDS HTTP, and the host carries a blackhole route for
it otherwise. That way sensitive info can be kept away from clients, and
requires polkit auth for access
* Simplicity: extraction of systemd's system credentials from IMDS
userdata happens with systemd's own infra, and for many usecases that
should already be enough.
* Measurements: before accepting the IDMS userdata, it can be measured
into a PCR, as any other configuration input for the system

Fixes: #40763
2026-03-26 14:12:31 +01:00
Daan De Meyer 437278abd5 ci: Support multi-line review comments in claude-review
Pass side, start_line, and start_side through to createReviewComment()
when present, enabling multi-line review comments. Update the prompt to
document all positioning fields using JSON Schema and make line required.
2026-03-26 13:46:08 +01:00
Daan De Meyer f9363bc5da Revert "ci: Add subject_type to createReviewComment()"
This reverts commit 211cd6e9a3.

They document it here:
https://octokit.github.io/rest.js/v22/#pulls-create-review-comment
but apparently that's out of date and this doesn't work anymore.
2026-03-26 13:46:08 +01:00
Luca Boccassi 186032e1ed boot: add checks for invalid splash images in UKI
A malformed bmp with 8bits depth but smaller color
map would cause out of bounds reads. This is not a real
problem as the image is signed, but better to be safe.

Reported on yeswehack.com as:
YWH-PGM9780-135

Follow-up for 0fa2cac4f0
2026-03-26 11:52:23 +01:00
Luca Boccassi 82d96837db boot: fix typo in function name
Follow-up for dde03dd2a8
2026-03-26 11:52:23 +01:00
Daan De Meyer c78ba976e1 mkosi: Install clang-tidy package instead of clang-tools
clang-tools surprisingly enough doesn't provide clang-tidy
2026-03-26 10:14:09 +00:00
Lennart Poettering 29f45d1342 update TODO 2026-03-26 10:54:15 +01:00
Lennart Poettering 41dc0dc7b6 test: add simple integration test for systemd-imdsd 2026-03-26 10:54:15 +01:00
Lennart Poettering 168a7f7770 imds: add generator that hooks in IMDS logic on cloud guests
The infrastructure added in the previous commits added support for IMDS
client functionality, but didn't really to enable the logic by default
on suitable hosts.

This commit adds a generator that automatically hooks the IMDS
functionality into the boot process if it detects that the system is
running on a compliant cloud system. it enables both the imds daemon and
the client.
2026-03-26 10:54:15 +01:00
Lennart Poettering 19a783f4dd imds: add TPM measurements to imds tool
This automatically measures the IMDS 'userdata' into PCR 12, i.e. where
we measure the other owner-supplied configuration, such as confexts and
credentials and similar.

(Why 12? It's really about who owns the data and what it is for.
PCRs/NvPCRs are scarce hence there's a strong incentive to not go
overboard with new allocations, and IMDS userdata in purpose and owner
is very very similar to confexts and credentials, hence let's reuse the
PCR for this purpose.)
2026-03-26 10:54:15 +01:00
Lennart Poettering 1228660400 imds: add "systemd-imds" tool that is a simple client to "systemd-imdsd"
This is a client tool to the systemd-imdsd@.service added in the
previous commit. It's mostly just a 1:1 IPC client via Varlink. It can
be used to query any IMDS key, but it's primary usecase is to acquire
the "userdata" from IMDS. Moreover, if invoked with the --import switch
it will check if the userdata contains a list of system credentials. If
so, it will import them into the local credstore. If the userdata does
not look like a list of system credentials no operation is executed,
under the assumption the data is intended for cloud-init instead.

It also imports a couple of other fields, if available and recogniuzed,
such as SSH keys and the hostname.
2026-03-26 10:54:15 +01:00
Lennart Poettering eb6e5b07f1 imds: add new systemd-imdsd.service that makes IMDS data accessible locally
This service's job is to talk to a VM associated IMDS service provided
by the local Cloud. It tries to abstract the protocol differences
various IMDS implementations implement, but does *not* really try to
abstract more than a few basic fields of the actual IMDS metadata.

IMDS access is wrapped in a Varlink API that local clients can talk to.

If possible this makes use of the IMDS endpoint information that has
been added to hwdb in the preceeding commit. However, endpoint info can
also be provided via kernel command line and credentials. For debugging
purposes we also accept them via environment variables and command line
arguments.

This adds a concept of early-boot networking, just enough to be able to
talk to the IMDS service. It is minimally configurable via a kernel
cmdline option (and a build-time option): the user may choose between
"locked" and "unlocked" mode. In the former mode direct access to IMDS via
HTTPS is blocked via a prohibit route (and thus all IMDS communication
has to be done via systemd-imdsd@.service). In the latter case no such
lockdown takes place, and IMDS may be acquired both via this new service
and directly. The latter is typically a good idea for compatibility with
current systems, the former is preferable for secure installations.

Access to IMDS fields is controlled via PK.
2026-03-26 10:54:15 +01:00
Lennart Poettering f3eac272e6 hwdb: add database for basic IMDS properties
This adds a hardware database that contains information about IDMS
functionality of various clouds, keyed off the SMBIOS identification of
each. Currently this contains information about 6 major clouds, but the
idea is that this grows to include more and more major clouds.

Nothing uses this data yet, that's added in a later commit.
2026-03-26 10:54:15 +01:00
Daan De Meyer 211cd6e9a3 ci: Add subject_type to createReviewComment()
Apparently this is required by the createReviewComment() API.
2026-03-26 10:18:13 +01:00
Daan De Meyer db3ace5da5 ci: Use path instead of file in claude-review prompt as JSON key
In https://github.com/systemd/systemd/pull/40980 claude hallucinated
and used "path" instead of "file" as the JSON key. Since "path" is
arguably more correct than "file" anyway, let's switch to that.
2026-03-26 10:18:13 +01:00