Commit Graph

89299 Commits

Author SHA1 Message Date
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
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
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
b256396e2a Update NEWS 2026-05-21 21:59:17 +01: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
818397761e Update NEWS 2026-05-21 21:49:22 +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
0761c9f493 update TODO 2026-05-21 21:44:06 +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
Lennart Poettering
c3d8c2d25c docs: document the new smbios measurements 2026-05-21 21:44:06 +01:00
Luca Boccassi
2b8ba0e05a Update NEWS 2026-05-21 21:13:10 +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
Luca Boccassi
c7655af547 ci: ignore failures to chown journal in GHA jobs
Otherwise when the build fails, this fails, and the GUI jumps to the
chown failure instead of the actual failure

Follow-up for 35bf1c8264
2026-05-21 20:43:56 +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
Yu Watanabe
dae51cc08e dhcp-server-send: rework sending DHCP reply message
This should mostly not change anything, except for some corner cases.
Just refactoring.
2026-05-22 04:30:34 +09:00
Yu Watanabe
29b662184b sd-dhcp-server: make IP service type (TOS) configurable 2026-05-22 04:30:34 +09:00
Yu Watanabe
0bb26684d0 sd-dhcp-server: refactoring for socket fd handling
This makes
- UDP socket fd is owned by IO event source,
- open RAW socket fd just before sending first packet,
- set TOS and socket priority,
- use AF_UNIX soxket pair in the unit test and fuzzer, so the unit test
  can now run by unprivileged user.
2026-05-22 04:30:34 +09:00
Yu Watanabe
27d99475b6 dhcp-serve-request: move message size check to dhcp_server_handle_message() 2026-05-22 04:30:34 +09:00
Yu Watanabe
45a3a3b92c dhcp-server-request: modernize server_receive_message() 2026-05-22 04:30:34 +09:00
Yu Watanabe
3f8d0004e9 sd-dhcp-server: split into small pieaces
No functional change, just several functions are moved/split/renamed.
2026-05-22 04:30:34 +09:00
Yu Watanabe
0e07870f59 test-dhcp-server: several cleanups
No effective change, just rafactoring.
2026-05-22 04:30:34 +09:00
Daan De Meyer
1d102a663e meson: Add libucontext to libshared_deps
Fixes #42236
2026-05-21 19:41:37 +01:00
Clayton Craft
301b4193a0 bootctl: remove fallback EFI Boot#### variable on uninstall
This cleans up the fallback Boot#### entry that was registered on
install. The logic cleaning up variables was moved from verb_remove into
a new remove_variables function, which mirrors the install side.
2026-05-21 11:30:46 -07:00
Clayton Craft
6e0ebe437b bootctl: register fallback EFI Boot#### entry on install
This adds a second install_boot_option call to register a Boot#### entry
pointing at systemd-boot-fallback{arch}.efi, and place it immediately
after the primary entry in BootOrder.

The fallback file does not exist on the ESP on first install and is
only created on first update when the existing primary binary is
rotated to the fallback path. We register the variable anyway, so
that the entry exists in the BootOrder once the fallback file shows up.
Until then, firmware that reaches the fallback entry will fail to
load it and fall through to the next entry in BootOrder, which is
fine. install_boot_option gains a require_existing parameter so the
existing early return on a missing ESP path can be skipped for the
fallback, where a missing path is expected.

This also does a bit of refactoring by splitting the bottom part of
run_install() into a new install_variables() function that handles
registering both the primary and fallback entries.
2026-05-21 11:30:45 -07:00
Clayton Craft
037b9a0680 bootctl: back up sd-boot binary to fallback path on update
When a primary sd-boot binary already exists on the ESP and is being
updated, it is copied to systemd-boot-fallback{arch}.efi before installing
the new version. This gives firmware a fallback Boot#### entry pointing
to the previous binary in case the new one fails to load.

The fallback is preserved (not overwritten) when its product and version
match the currently booted bootloader (read from the LoaderInfo EFI
variable), since that means it already holds the known good binary that
booted this session. In all other cases it is overwritten with the current
primary, when no fallback exists yet, when LoaderInfo is unavailable, or
when the fallback's product or version differs from what booted.

This also moves the version_check() call up so its result determines
both the rotation decision and the main copy, and avoids a duplicate
check (and duplicate "Skipping..." log) when the binary is already
current.
2026-05-21 11:30:45 -07:00
Clayton Craft
6c356b6a8b bootctl: add after_slot parameter to insert_into_order()
This adds an after_slot parameter that, when not set to UINT16_MAX,
requests that the new slot be placed immediately after the given slot in
BootOrder. When after_slot is set and the new slot already exists in
BootOrder, it will leave its position alone. This is so that if a user
reorders it, we don't stomp on their changes.
2026-05-21 11:26:59 -07:00
Clayton Craft
bb520fd6a5 bootctl: add description and ret_slot parameters to install_boot_option()
This moves creation of the EFI boot option description out of
install_boot_option and into the caller, and adds a ret_slot output
parameter for capturing the assigned BootOrder slot. This allows reusing
the function for installing variables with different descriptions.
2026-05-21 11:26:59 -07:00
Clayton Craft
1027cbd8ae bootctl: rename install_variables/remove_variables to install/remove_boot_option
These functions install or remove a single EFI Boot#### entry, not
"all variables," so this renames them to better reflect what they do.
2026-05-21 11:26:59 -07:00
Clayton Craft
a2ba538ead bootctl: fix removing variables on uninstall
remove_variables looks up the EFI boot entry by matching both the path
and the partition UUID and it wasn't actually removing any entries
because verb_remove was passing SD_ID128_NULL, so the lookup never
matched and Boot#### entries were left behind on uninstall.

Fixes 38433a6
2026-05-21 11:26:59 -07:00
Rocker Zhang
a52e0f87f5 systemctl: also attempt kexec image extraction on EINVAL
load_kexec_kernel() retries kexec_file_load() with an extracted kernel
(decompressed Image / ZBOOT PE / UKI) when the kernel rejects the image,
but it only does so when kexec_file_load() failed with ENOEXEC. On arm64
that retry never happens: arm64's image_probe()
(arch/arm64/kernel/kexec_image.c) returns -EINVAL on an ARM64_IMAGE_MAGIC
mismatch, whereas x86's bzImage64_probe() and the generic
kexec_image_probe_default() return -ENOEXEC. So `systemctl kexec` of a
UKI on arm64 skips the extraction path and falls back to the
/usr/sbin/kexec binary, which is no longer a dependency since e107c7ead0
("systemctl: replace kexec-tools dependency with direct kexec_file_load()
syscall") -- leaving kexec broken.

Accept EINVAL in addition to ENOEXEC. This is safe: the extraction in
kexec_maybe_decompress_kernel() re-gates on the actual file magic (MZ /
compression headers) and is a no-op returning 0 for anything else, so an
EINVAL that is not a format mismatch just falls through to the existing
fallback as before.

Fixing this in systemd (rather than only in the kernel) is appropriate:
systemd must keep working with already-shipped arm64 kernels whose
kexec_file_load() returns EINVAL for an unrecognized image magic.

Relates to: https://github.com/systemd/systemd/issues/28538

Co-developed-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-21 19:00:58 +01:00
Lennart Poettering
29c6d1c125 boot: measure select SMBIOS objects explicitly 2026-05-21 18:34:01 +02:00
Lennart Poettering
9990c03295 update TODO 2026-05-21 18:30:16 +02:00
Lennart Poettering
9a28e54b54 ci: add test for new machine-tags concept 2026-05-21 18:30:16 +02:00
Lennart Poettering
b6d9a987f7 firstboot: allow configuring machine tags via firstboot 2026-05-21 18:30:16 +02:00
Lennart Poettering
461ec6facc condition: add a condition that matches against the machine tags 2026-05-21 18:30:16 +02:00