Commit Graph
60278 Commits
Author SHA1 Message Date
Chris Mason fa0cd9b79f dissect-image: fix wrong errno on pread failure
In acquire_sig_for_roothash() the pread() failure branch returns
-ENOMEM, which is copy-pasted from the malloc() check immediately
above it:

    _cleanup_free_ char *buf = new(char, partition_size+1);
    if (!buf)
            return -ENOMEM;

    ssize_t n = pread(fd, buf, partition_size, partition_offset);
    if (n < 0)
            return -ENOMEM;

pread() sets errno to the actual I/O failure (EIO, EINTR, EBADF,
...). Aliasing those to -ENOMEM misleads dissect_log_error() and
any caller that branches on the returned code; verity signature
lookup failures get reported as out-of-memory.

Fix by returning -errno from the pread() failure branch. The
malloc() branch above is correct and unchanged.

Fixes: 98ca65c36a ("dissect: check that roothash in signature matches before selecting partition")
Assisted-by: kres (claude-opus-4-7)
Signed-off-by: Chris Mason <clm@meta.com>
2026-05-22 22:14:48 +02:00
Chris Mason f134bca68b dissect-image: fix swallowed open() error in mountfsd_make_directory
mountfsd_make_directory() opens the parent directory after a
successful path_extract_filename() call, but reports failure using
the stale path_extract_filename() return value:

    r = path_extract_filename(path, &dirname);
    if (r < 0)
            return log_debug_errno(r, ...);
    ...
    _cleanup_close_ int fd = open(parent, O_DIRECTORY|O_CLOEXEC);
    if (fd < 0)
            return log_debug_errno(r, "Failed to open '%s': %m", parent);

At the open() check site r holds the non-negative return of
path_extract_filename(). log_debug_errno() with a non-negative
first argument returns 0, so the function reports success even
though open() failed. Callers that pass a non-NULL ret_directory_fd
then consume an uninitialized fd value, and the diagnostic message
is suppressed because log_debug_errno(0, ...) emits nothing.

Fix by passing errno instead of r, matching the convention used in
mountfsd_mount_image() and mountfsd_mount_directory() in the same
file. The real open() failure (ENOENT, EACCES, ENOTDIR, EMFILE, ...)
now propagates to the caller and the log message is preserved.

Fixes: 1be8caa6be ("importd: support unpacking tarballs to foreign UID range")
Assisted-by: kres (claude-opus-4-7)
Signed-off-by: Chris Mason <clm@meta.com>
2026-05-22 22:14:41 +02:00
Luca Boccassi b261762c82 meson: fix build with -Dmachine=false
Fixes https://github.com/systemd/systemd/issues/42257

Follow-up for 5d0ac2c23c
2026-05-22 16:03:47 +01:00
Yu Watanabe e75c406448 sd-dhcp-server-lease: always update all information in bound lease
We manage bound leases by their client ID. Hence, potentially, other
fields may be changed. Let's always update all information.
2026-05-22 22:11:45 +09:00
Luca Boccassi 3fb520f010 pkcs11: switch to RSA-OAEP SHA-256/SHA-1
RSA PKCS#1 v1.5 is vulnerable to Bleichenbacher-style padding oracle
attacks, albeit very difficult and unlikely to actually happen in the
real world. Still for hardedning, switch new enrollments to RSA-OAEP,
with SHA-256 preferred and SHA-1 as fallback (probed at enrollment time,
since e.g. SoftHSM only accepts SHA-1, and older token might as well).

The actual padding scheme used to wrap a given key is recorded as a new
optional 'pkcs11-padding' / 'padding' field in the LUKS2 token JSON and
the homed user record. Decryption defaults to PKCS#1 v1.5 when absent so
existing enrollments keep working.
2026-05-22 14:09:16 +01:00
Luca Boccassi 86b389090d sysupdate: List default component only if transfer definition exists (#42179)
`sysupdate --json=short components` lists the components known to
sysupdate; these are the components which something like `updatectl`
will try to update.

The `default` component represents the host, and is meant to be listed
if transfer definitions exist in (for example) `/etc/sysupdate.d`
corresponding to the host OS. This then corresponds to `TARGET_HOST` in
`updatectl` and causes it to try updating that target.

The logic for working out whether the `default` component was present
essentially boiled down to “does `{/run,/etc,/usr/lib}/sysupdate.d`
exist”, and it didn’t check whether a `.transfer` or `.conf` file
actually existed in the config directory.

This is quite the corner case, but becomes more evident on systems where
sysupdate is being used to update a portable service but not the main
OS. At that point, if `/etc/sysupdate.d` exists empty (for some reason),
`updatectl` falls over because it starts trying to update the host OS
without any configuration to do so.

So, modify `sysupdate` to more fully load the available configuration
when listing components, and query it a bit more deeply to check whether
a default component exists.

If `sysupdate` is called with various command line arguments to affect
how its configuration is loaded, do *not* say that a default component
exists, as these arguments essentially anull the possibility of a
default being used in that process.

Add an integration test based on the reproducer provided by the issue
reporter. This test has been tested to fail if the changes to
`sysupdate.c` aren’t applied — if so, the second call to `sysupdate
components` would return
`{"default":true,"components":["some-component"]}`.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Fixes: https://github.com/systemd/systemd/issues/41501
2026-05-22 14:07:06 +01:00
Luca Boccassi 561f4cd866 bootctl: refactor get_file_version() (#42246) 2026-05-22 13:50:36 +01:00
Daan De Meyer deb75e296d nsresourced: Verify user namespace identity on registry lookup (#42224) 2026-05-22 14:31:03 +02:00
Luca Boccassi 4bfc5ac457 report-basic: add a bunch more essential metrics (#42248) 2026-05-22 13:29:08 +01:00
Luca Boccassi d40f7a40c1 tpm2: measure user records on first login (#42228)
This is useful so that we can "blow a fuse" in TPM policies once a user
logged in.
2026-05-22 13:28:33 +01:00
Yu Watanabe c130068ebd sd-dhcp-server: update conditions when we should send DHCPNAK (#42252) 2026-05-22 20:02:17 +09:00
Rocker Zhang 851ee29a54 test: cover LUO serialize-side anti-hijack guard in TEST-91
manager_luo_serialize_fd_stores() refuses to serialize a unit fd store
entry that holds a child LUO session named like PID 1's own ("systemd"),
to stop a service from hijacking PID 1's reserved session namespace
across kexec. That guard had no test coverage.

Add a test-luo store-hijack/check-hijack subcommand pair: on the first
boot a system service preserves a child LUO session named "systemd" in
its fd store; after kexec the test asserts the entry was not restored --
the unit's NFileDescriptorStore is 0, and check-hijack, run as the unit's
own second-boot ExecStart, confirms the hijack fd is absent from its
restored LISTEN_FDNAMES -- proving PID 1 skipped it during serialization.

The restore-side guards (corrupt mapping, reserved token 0, invalid unit
name, missing child session) are intentionally not covered: they only run
against PID 1's own "systemd" session built by luo_preserve_fd_stores(),
which a cooperating userspace helper cannot corrupt without racing or
displacing PID 1 (it single-owns /dev/liveupdate at shutdown). Triggering
them reliably would need kernel fault injection.

Co-developed-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-22 12:00:05 +01:00
Yu Watanabe d69d919379 dhcp-server-request: drop unused value in DHCPRequest 2026-05-22 19:47:48 +09:00
Philip Withnall 8de5a7b94d sysupdate: List default component only if transfer definition exists
`sysupdate --json=short components` lists the components known to
sysupdate; these are the components which something like `updatectl`
will try to update.

The `default` component represents the host, and is meant to be listed
if transfer definitions exist in (for example) `/etc/sysupdate.d`
corresponding to the host OS. This then corresponds to `TARGET_HOST` in
`updatectl` and causes it to try updating that target.

The logic for working out whether the `default` component was present
essentially boiled down to “does `{/run,/etc,/usr/lib}/sysupdate.d`
exist”, and it didn’t check whether a `.transfer` or `.conf` file
actually existed in the config directory.

This is quite the corner case, but becomes more evident on systems where
sysupdate is being used to update a portable service but not the main
OS. At that point, if `/etc/sysupdate.d` exists empty (for some reason),
`updatectl` falls over because it starts trying to update the host OS
without any configuration to do so.

So, modify `sysupdate` to more fully load the available configuration
when listing components, and query it a bit more deeply to check whether
a default component exists.

If `sysupdate` is called with various command line arguments to affect
how its configuration is loaded, do *not* say that a default component
exists, as these arguments essentially anull the possibility of a
default being used in that process.

Add an integration test based on the reproducer provided by the issue
reporter. This test has been tested to fail if the changes to
`sysupdate.c` aren’t applied — if so, the second call to `sysupdate
components` would return
`{"default":true,"components":["some-component"]}`.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Fixes: https://github.com/systemd/systemd/issues/41501
2026-05-22 11:46:32 +01:00
Philip Withnall a7a1bc8678 sysupdate: Add a flag to control error behaviour in internal function
Optionally prevent `context_read_definitions()` erroring out if zero
transfer definitions were found.

This commit makes no functional changes (the flag is always passed to
calls to `context_make_offline()` for the moment), but the new flag will be
used in the following commit.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Helps: https://github.com/systemd/systemd/issues/41501
2026-05-22 11:46:24 +01:00
Philip Withnall f4a3acb6ed sysupdate: Convert an internal bool argument to flags
This commit makes no functional changes, but the new flags will be
used and extended in the following commit. We need a flags variable to
avoid having two bool arguments, which would be confusing.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Helps: https://github.com/systemd/systemd/issues/41501
2026-05-22 11:45:07 +01:00
Lennart Poettering e3e897cf8f bootctl: refactor get_file_version() to use proper PE parsing
This irked me for a while. Let's not scan for strings stupidly, but
properly parse PE files to find the magic marker.

It's easy with our own PE APIs, hence we should do it.

This moves logging to the callers (previously, this was all mixed up).
2026-05-22 12:26:25 +02:00
Lennart Poettering 7c17b25fa4 pe-binary: tweak pe_read_section_data() error codes
Let's return -EBADMSG if the PE headers reference stuff missing in the
file, regardless if that's because the offsets are larger than SSIZE_MAX
or just larger than the file size. We generally use EBADMSG for all
cases we deem the file to not be a conformant PE file, and these two
cases are the same. Hence, let's be systematic here.
2026-05-22 12:26:25 +02:00
Lennart Poettering e997c01580 report-basic: report TPM2 vendor strings too
This is highly relevant to debug/analyze TPM related behaviour, hence
let's report this as part of the metrics.
2026-05-22 12:24:29 +02:00
Lennart Poettering ef9cc58dfa report-basic: also report confidential computing tech 2026-05-22 12:24:29 +02:00
Lennart Poettering 80b5207d01 report-basic: report various SMBIOS fields as metrics, too
This are pretty fundamental hw fields, let's make them available.
2026-05-22 12:24:29 +02:00
Lennart Poettering ef9eddd202 report-basic: also report /etc/machine-info fields, just like os-release fields
The TAGS= field is really nice to have in reports, hence make this a
thing.
2026-05-22 12:17:09 +02:00
Lennart Poettering 6f6ca5a224 logind: automatically pull in systemd-pcrlogin@.service on first login 2026-05-22 12:15:14 +02:00
Lennart Poettering e32209c69c pcrextend: add support for measuring a user record, to be executed on first login of the user
This is supposed to be useful to mark an interactive user login as a
"break glass" event in the measurement logs, i.e. as in many typically
headless scenerios this indicates debug access or similar.
2026-05-22 12:15:12 +02:00
Lennart Poettering 0bd861ff76 pcrextend: port to help-util.[ch] APIs 2026-05-22 10:37:38 +02:00
Lennart Poettering 469de233a3 sysupdate: Add separate polkit actions for cancellation (#42209)
This allows us to have a separate, more permissive, policy for
cancelling ongoing sysupdate jobs. The new default policy for
cancellation actions is to allow them for the active user, without admin
authentication, because typically the user can just pull the plug on the
computer to cancel a job anyway.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Fixes: https://github.com/systemd/systemd/issues/38568
2026-05-22 10:35:49 +02:00
Daan De Meyer 24319a9c2c efi-api: fix unaligned access in efi_guid_to_id128()
EFI_GUID requires 4-byte alignment due to its uint32_t Data1 field, but
callers may pass pointers at arbitrary offsets into serialized EFI
variable buffers (e.g. bootctl walking BootXXXX entries). UBSan flagged
the misaligned member access; the old comment claiming the struct was
packed was wrong. Copy the bytes into an aligned local first.

Co-developed-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-22 10:25:50 +02:00
Luca Boccassi b45a897edc hwdb: reject out-of-bounds fnmatch prefixes
Ensure that fnmatch traversal doesn't go off the hwdb.bin in case of
a corrupted file

Originally reported on yeswehack.com as #YWH-PGM9780-70

For the unit test:
Co-developed-by: GitHub Copilot <github-copilot[bot]@users.noreply.github.com>
2026-05-22 09:17:24 +01:00
Yu Watanabe b4f7e30d0b dhcp-server-request: rename dhcp_server_handle_message() -> dhcp_server_process_message()
Then, make it take struct iovec.
No functional change, just refactoring.
2026-05-22 15:57:06 +09:00
Yu Watanabe e294a8eada dhcp-server-request: rework when we should reply DHCPNAK
Previously, DHCPNAK was sent only when the client is in INIT-REBOOT
state. But, on selecting or renewing, the request is directed to a
specific server, so we can safely reply with DHCPNAK.

Also, verify existing bound lease even when there is no static lease for
the client.
2026-05-22 15:57:06 +09:00
Yu Watanabe 94b39d22dd dhcp-server-request: logs more when received invalid messages 2026-05-22 15:57:06 +09:00
Yu Watanabe c73478d49f dhcp-server-request: also save IP_PKTINFO of received message
It will be used later.

This also drops redundant ifindex check, as the socket is already
initialized with socket_bind_to_ifindex().
2026-05-22 15:57:06 +09:00
Yu Watanabe dced69aba5 sd-dhcp-server: use sd_dhcp_message to parse/build DHCP messages (#42240) 2026-05-22 15:28:52 +09:00
Yu Watanabe 30200eee52 sd-dhcp-server: drop unused enum
Follow-up for 2e5580a8c1.
2026-05-22 06:58:45 +02:00
Yu Watanabe 15103b697d sd-dhcp-server: use sd_dhcp_message object on sending reply
This also makes the conditions in dhcp_server_send_message() uses
the message that will be sent, rather than we received.

This does not change basic functionality, but changes/fixes several
minor behaviors, e.g.
- fix when the broadcast flag assignment,
- set server identifier in DHCPFORCERENEW.
2026-05-22 09:38:29 +09:00
Yu Watanabe 5e08ff899e sd-dhcp-server: use sd_dhcp_message to parse received messages
This is mostly refactoring. This does not change basic behavior, but
changes/fixes some minor/corner cases, e.g.

- extend the minimum default lease time from 1 second to 30 seconds, as
  1 second is too short and causes the network unstable (though 30
  seconds is stll too short, but hopefully that does not make the
  network unstable).
- error code on broken/malicious message received may be changed.
2026-05-22 09:33:15 +09:00
Yu Watanabe 8c09b8f128 dhcp-server-request: drop invalid short-cut logic
Even if no pool is allocated, the server may have a static lease
matching with the DHCPDISCOVER message.
2026-05-22 08:34:42 +09:00
Yu Watanabe 05c295d269 dhcp: move definition of enum DHCPState to dhcp-protocol.[ch]
It will be also used in DHCP server, later.
2026-05-22 08:34:22 +09:00
Yu Watanabe 3115496c8c sd-dhcp-relay: use forward declarations 2026-05-22 08:33:48 +09:00
Yu Watanabe 0ae07c1e00 sd-dhcp-server: several trivial cleanups (#42235)
This should mostly not change behavior, except for some corner cases.
Just refactoring and preparation for later changes.
2026-05-22 06:44:07 +09:00
Luca Boccassi 918c592272 bootctl: add A/B fallback for sd-boot updates (#41650)
On `bootctl install`, two EFI boot entries are registered: one for the
primary sd-boot binary and one for a fallback. On `bootctl update`, the
existing primary binary is rotated to the fallback path before the new
version is installed, so the fallback entry always points to the
previous known-good binary.

```
$ sudo bootctl install
...
Created EFI boot entry "Linux Boot Manager".
Created EFI boot entry "Fallback Linux Boot Manager".
$ sudo bootctl update
Copied "/boot/EFI/systemd/systemd-bootaa64.efi" to "/boot/EFI/systemd/systemd-boot-fallbackaa64.efi".
Copied "/usr/lib/systemd/boot/efi/systemd-bootaa64.efi" to "/boot/EFI/systemd/systemd-bootaa64.efi".
$ efibootmgr
...
Boot0004* Linux Boot Manager        HD(...)/\EFI\systemd\systemd-bootaa64.efi
Boot0005* Fallback Linux Boot Manager     HD(...)/\EFI\systemd\systemd-boot-fallbackaa64.efi
```

Fixes: #23805
2026-05-21 21:56:05 +01:00
Luca Boccassi 2f2203c231 boot,stub: explicitly measure select SMBIOS objects (#42233)
This is supposed to protect our SMBIOS type 11 importing for
credentials. Note that firmwares are supposed to measure SMBIOS anyway
to PCR 1. Alas firmware doesn't really do that in various cases. Hence
let's do so again, for select objects.

This closes a gap where some of the input for OS (i.e. system
credentials places in smbios11) isn't measured properly.

(I really want this to get into v261, because this will fuck up the PCRs
a bit more, and we already have the new separator measurement in v261,
hence there's value in getting this merged at the same time, so that we
don't break the measurements a 2nd time)
2026-05-21 21:44:42 +01:00
Lennart Poettering 14a05bd208 pcrlock: port --help to help-util.[ch] apis 2026-05-21 21:44:06 +01:00
Lennart Poettering 8cc5dbe9cd pcrlock: decode new smbios events 2026-05-21 21:44:06 +01:00
Lennart Poettering e4f0935f19 bootctl: show SMBIOS feature flags 2026-05-21 21:44:06 +01:00
Yu Watanabe 580bd17d90 Use malloc'ed strings instead of static libc buffers for user and group lookup (#42184)
Preparation for other work.
2026-05-22 05:09:56 +09:00
Luca Boccassi ecec206cb4 hostnamed,pid1,firstboot: introduce "machine tags" concept (#42223)
Fixes: #38591
2026-05-21 20:57:34 +01:00
Yu Watanabe d40d021ca5 dhcp-server-request: check server address in DHCPDECLINE and DHCPRELEASE
Otherwise, we may do something wrong by messages for another DHCP server.
Let's silently ignore messages with unmatching server identifier.

Also, logs something when we receive DHCPRELEASE but found lease does
not match the reported address.
2026-05-22 04:30:34 +09:00
Yu Watanabe e359c6df65 sd-dhcp-server: store more information in DHCPRequest
This makes DHCPRequest stores
- the message type of the received message,
- acquired address,
- found static DHCP lease,

This also moves call of dhcp_request_get_lifetime_timestamp() from
dhcp_server_ack() to dhcp_server_set_lease(), and rename
DHCPRequest.server_id -> .server_address.

No functional change, just refactoring.
2026-05-22 04:30:34 +09:00
Yu Watanabe 252f3855fe sd-dhcp-server: use struct hw_addr_data to manage client hardware address parsed from DHCP message
Then, this drops garbage in DHCP server lease in DBus and Varlink message.

This also drops fallback to use client ID as hardware address when chaddr
field is not set. In that case, we should broadcast reply.
2026-05-22 04:30:34 +09:00