Commit Graph
58864 Commits
Author SHA1 Message Date
Michael Vogt 3e9eaf45f0 network: make check-pointer-deref clean
Add the needed assert changes to make the code clean
for the new check-pointer-deref script.
2026-03-30 13:36:00 +02:00
Michael Vogt 1626130254 journal: make check-pointer-deref clean
Add the needed assert changes to make the code clean
for the new check-pointer-deref script.
2026-03-30 13:36:00 +02:00
Michael Vogt f3c49a597f nspawn: make check-pointer-deref clean
Add the needed assert changes to make the code clean
for the new check-pointer-deref script.
2026-03-30 13:36:00 +02:00
Michael Vogt 69d54d5213 cleanup: address review feedback from claude
Trivial ordering/modernizing change that got highlighted by
claude and refined by keszybz to move to the modern systemd
style.

Thanks to keszybz for suggesting this.
2026-03-30 13:34:58 +02:00
Daan De Meyer be2ac4beb5 repart: allow --el-torito= with any --empty= value
The restriction requiring --empty= to be require, force, or create
when using --el-torito= is unnecessary.
context_verify_eltorito_overlap() already validates that the ISO 9660
blocks don't collide with GPT partition entries or the first usable
LBA, which is sufficient to guarantee safety regardless of the empty
mode.

This is needed for two-stage image builds where the first stage creates
the usr and verity partitions, and the second stage adds --el-torito=
to produce a bootable ISO with a UKI containing usrhash= derived from
the verity hash of the first stage. In the second stage, repart runs
with --empty=allow since the image already exists.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-29 23:58:07 +02:00
Valentin David 365361f490 repart: Optionally write minimal an El Torito boot catalog for EFI
This only points the firmware to the ESP. The ISO9660 is empty.
The initramfs should create a loop device to change block size
and enable GPT partitions.

This was tested using OVMF on qemu, with:
`-drive if=pflash,file=OVMF_CODE.fd,readonly=on,format=raw -drive if=pflash,file=OVMF_VARS.fd,format=raw -drive if=none,id=live-disk,file=dick.iso,media=cdrom,format=raw,readonly=on -device virtio-scsi-pci,id=scsi -device scsi-cd,drive=live-disk`

And a simple definition:
```
[Partition]
Type=esp
Format=vfat
CopyFiles=/usr/lib/systemd/boot/efi/systemd-bootx64.efi:/EFI/BOOT/BOOTX64.EFI
```
2026-03-29 22:46:54 +02:00
Daan De Meyer ea79ac6f36 Assorted coverity fixes (#41406) 2026-03-29 21:02:55 +02:00
Zbigniew Jędrzejewski-Szmek ab3a2f375f sd-varlink: export sd_varlink_set_sentinel
I tried to implement a varlink service using sd-varlink, and
not being able to use the approach with sentinel is exteremely
painful. This is useful internally and likewise externally.
2026-03-29 20:32:15 +02:00
Valentin David 421bdc489f repart: Make it possible to set persistent allow-discards activation flag
AllowDiscards= will set allow-discards in the persistent flags which will make
activating the device automatically activate with that option. This is
useful for devices discovered through gpt-auto-generator without
needing to use some kernel command line to set the option.
2026-03-28 23:46:37 +01:00
Luca Boccassi 4b25c74c20 recurse-dir: add assert_cc for DIRENT_SIZE_MAX allocation
Coverity flags offsetof(DirectoryEntries, buffer) + DIRENT_SIZE_MAX * 8
as a potential overflow. All operands are compile-time constants, so add
an assert_cc() to prove this at build time.

CID#1548020

Follow-up for 6393b847f4
2026-03-28 20:24:22 +00:00
Luca Boccassi 3e38052f1d exec-util: use unsigned shift for ExecCommandFlags
Using signed int literal '1' in left shift operations can
theoretically lead to undefined behavior. Use 1U to be explicit
about unsigned arithmetic.

CID#1548018

Follow-up for b3d593673c
2026-03-28 20:13:40 +00:00
Luca Boccassi cda2962daf compress: add assert for space doubling overflow safety
Coverity flags 2 * space as a potential overflow. The space value
is bounded by prior allocation success, but add an explicit assert
to document this for static analyzers.

CID#1548056

Follow-up for 5e592c66bd
2026-03-28 20:13:03 +00:00
Luca Boccassi 2bd6930efe importd: add assert for log_message_size accumulation bounds
Coverity flags log_message_size += l as a potential overflow, but l
is bounded by the read() count parameter which is
sizeof(log_message) - log_message_size. Add an assert to make this
invariant explicit.

CID#1548062

Follow-up for 3d7415f43f
2026-03-28 20:10:14 +00:00
Luca Boccassi c34169e9d3 sd-bus: add asserts for rbuffer_size accumulation bounds
Coverity flags rbuffer_size += k as a potential overflow, but k is
always bounded by the iov size (which is the difference between the
allocated buffer and current rbuffer_size). Add asserts to make this
invariant explicit.

CID#1548044
CID#1548071

Follow-up for a7e3212d89
2026-03-28 20:09:40 +00:00
Luca Boccassi 1b7d2fa978 uid-range: add asserts to document overflow safety in coalesce
Coverity flags the x->start + x->nr and y->start + y->nr additions
as potential overflows. These are safe because uid_range_add_internal()
validates start + nr <= UINT32_MAX before inserting entries. Add asserts
to document this invariant for static analyzers.

CID#1548015

Follow-up for 8530dc4467
2026-03-28 19:56:31 +00:00
Luca Boccassi c8b53fcfd3 sd-event: add assert to help static analysis trace signal bounds
Coverity flags the signal_sources array access as a potential
out-of-bounds read because it cannot trace through the SIGNAL_VALID()
macro to know that ssi_signo < _NSIG. Add an explicit assert after
the runtime check to make the constraint visible to static analyzers.

CID#1548033

Follow-up for 7a64c5f23e
2026-03-28 19:56:31 +00:00
Luca Boccassi be85048e28 cpu-set-util: add asserts to guide static analysis after realloc
Coverity flags CPU_SET_S() calls as potential out-of-bounds writes
because it cannot trace that cpu_set_realloc() guarantees the
allocated buffer is large enough for the given index. Add asserts
to make the size invariant explicit.

CID#1611787
CID#1611788

Follow-up for 0985c7c4e2
2026-03-28 19:56:31 +00:00
Luca Boccassi 1929226e7e debug-generator: use unsigned bit shift for breakpoint flags
Using signed int literal '1' in left shift can lead to undefined
behavior if the shift amount causes overflow of a signed int. Use
UINT32_C(1) since the result is stored in a uint32_t variable.

CID#1568482

Follow-up for e9f781a5a4
2026-03-28 19:56:31 +00:00
Luca Boccassi 86fd0337c6 scsi_id: use strscpy instead of strncpy for wwn fields
strncpy does not null-terminate the destination buffer if the source
string is longer than the count parameter. Since wwn and
wwn_vendor_extension are char[17] and we copy up to 16 bytes, there's
a risk of missing null termination. Use strscpy which always
null-terminates.

CID#1469706

Follow-up for 4e9fdfccbd
2026-03-28 19:56:31 +00:00
Luca Boccassi 3e889473c9 resolved: fix TOCTOU in hook discovery
Coverity complains that the directory is not pinned by FD
so it might changed between the stat and the open

CID#1643236

Follow-up for 8209f4adcd
2026-03-28 19:56:31 +00:00
Luca Boccassi bf37ed0a65 stat-util: add assert to silence coverity
Coverity thinks _mntidb can be used uninitialized, but this
is not the case when r == 0. Add a bool variable to make it
clearer instead of reusing 'r' later, and an assert to guide
static analyzers.

CID#1644850

Follow-up for 5817c73391
2026-03-28 19:56:31 +00:00
Luca Boccassi 8fe512a02e stat-util: fix return type of mode_verify_socket()
It returns an error code, not a mode

Follow-up for 97fe03e12f
2026-03-28 19:56:31 +00:00
Luca Boccassi 74a9ed911d pe-binary: add explicit cast to silence coverity
Otherwise it gets confused about underflows (which are already checked)

CID#1645068

Follow-up for a434270139
2026-03-28 19:56:31 +00:00
Luca Boccassi 1a0fe20bc2 pe-binary: fix error reporting
This is a local calculation, errno is not set

Follow-up for a434270139
2026-03-28 19:56:31 +00:00
Luca Boccassi 85b20f5fa7 boot: add overflow check in GPT parser
ALIGN_TO() can overflow and return SIZE_MAX

CID#1644887

Follow-up for ccbd324a3a
2026-03-28 19:56:31 +00:00
Luca Boccassi 9bdc8c8138 imdsd: voidify unchecked call
CID#1646046

Follow-up for eb6e5b07f1
2026-03-28 19:56:30 +00:00
Luca Boccassi 7ff1bfdb68 dissect: add asserts to appease coverity
CID#1645844
CID#1645845

Follow-up for 91578e5293
2026-03-28 15:37:58 +00:00
Luca Boccassi b3c3a40b35 sysupdate: add more input validation
Ensure bogus inputs are cleanly rejected. These are privileged
interfaces so in practice it's not a problem.

Reported on yeswehack.com as YWH-PGM9780-168

Follow-up for bf2c741fd7
2026-03-28 09:15:33 +01:00
Duncan Overbruck 7208a74a2b boot-entry: add 'auto' keyword to parse_boot_entry_token_type
Add the auto keyword as documented in the help message and man pages of
`kernel-install`, `bootctl` and `systemd-pcrlock`.
2026-03-27 23:16:54 +01:00
Luca Boccassi 1224e5d195 shutdown: remove kexec-tools dependency
'kexec -e' is just a small wrapper that does the xen hypercall
on xen, or otherwise just calls reboot(). Drop the dependency,
and reuse the existing xen hypercall helper.
2026-03-27 23:03:01 +01:00
Zbigniew Jędrzejewski-Szmek 5f2258affc many: more checks for pointer access without NULL check (#41370)
This is a followup for https://github.com/systemd/systemd/pull/41096
that makes more subsystems pass the new `check-pointer-deref` coccinelle
checks. See the individual commits.

My plan is to do a few more of these PRs until we have it all covered. I
could also do it in a single very big PR but I'm worried about a)
conflicts b) that its just too big/annoying to review. Only 7 dirs left
but some (like src/basic) are quite big (~50k loc) so those PRs will be
a bit bigger.
2026-03-27 14:58:27 +01:00
Daan De Meyer bb5c7328cf vmspawn: improve firmware selection to match mkosi's implementation
Align find_ovmf_config() with mkosi's find_ovmf_firmware() by adding
checks that were previously missing:

- Filter on interface-types, only selecting UEFI firmware definitions.
  Previously non-UEFI (e.g. BIOS-only) firmware could be selected.

- Check machine type compatibility using substring matching against the
  target machine patterns in firmware descriptions (e.g. "q35" matches
  "pc-q35-*"), following the same approach as mkosi.

- Make nvram-template optional in the firmware JSON mapping. Firmware
  definitions without an nvram-template are now parsed successfully
  (with vars remaining NULL) rather than failing entirely.

Also rework the firmware target parsing to store both architecture and
machine arrays per target (instead of just a flat architecture list),
and extract the machine matching into firmware_data_matches_machine().

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-27 14:22:29 +01:00
Daan De Meyer d6e5fbca73 vmspawn: Add --firmware=describe
It's useful to be able to check what firmware description vmspawn
will select. In particular, this will allow me to figure out the
nvram template file that will be picked up so I can pick it up in
mkosi and operate on it to pass a modified version of it to vmspawn
with --efi-nvram-template=.
2026-03-27 14:22:29 +01:00
Daan De Meyer 5a7d70e807 vmspawn: add --efi-nvram-template= and --firmware-features= options
Add --efi-nvram-template=PATH to specify a custom firmware variables
file to copy and use as the initial EFI NVRAM state instead of the
default template from the firmware definition.

Add --firmware-features=FEATURE[,FEATURE...] to require or exclude
specific firmware features during automatic firmware discovery.
Features prefixed with "!" are excluded. If a feature appears in both
the included and excluded lists, inclusion takes priority. Firmware
with the "enrolled-keys" feature is excluded by default.

Refactor --secure-boot= to operate on the firmware features sets
instead of maintaining a separate tristate. --secure-boot=yes adds
"secure-boot" to the include set, --secure-boot=no adds it to the
exclude set, and --secure-boot=auto removes it from both.

Generalize find_ovmf_config() to accept include/exclude feature sets
instead of a secure boot tristate, removing the special-cased
enrolled-keys and secure-boot filtering logic.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-27 14:22:29 +01:00
Lennart Poettering b34ff170d1 tmpfile-util: don't log about lack of O_TMPFILE support
It's a very common case (vfat...), and it's just too much noise. After
all the whole function exists primarily to deal with O_TMPFILE not being
availeble everywhere...
2026-03-27 11:55:32 +00:00
Luca Boccassi 79f8447f5f sd-boot: 4 smaller fixes (#41367) 2026-03-27 11:47:33 +00:00
Mike Yuan 771800a403 machine: never ever allow non-root-owned host machine
We really should lock this down _hard_, as evidenced by recent
security fallouts.
2026-03-27 11:47:42 +01:00
Mike Yuan 90cc5b0159 machine: introduce MACHINE_CLASS_CAN_REGISTER
Follow-up for 6df5f80bd3

Similar to SESSION_CAN_* macros in logind-session.h
2026-03-27 11:47:42 +01:00
Michael Vogt 44b2d1e155 import: make check-pointer-deref clean
Add the needed assert changes to make the code clean
for the new check-pointer-deref script.
2026-03-27 11:30:32 +01:00
Luca Boccassi 78ab70a46f boot: avoid division by zero in splash image handling
A malformed image can cause a division by zero, check that
the parameters are not zero.

Reported on yeswehackl.com as YWH-PGM9780-173

Follow-up for 0fa2cac4f0
2026-03-27 10:28:20 +00:00
Michael Vogt f124464b45 nss-systemd: make check-pointer-deref clean
Add the needed assert changes to make the code clean
for the new check-pointer-deref script.
2026-03-27 11:24:49 +01:00
Michael Vogt 39ef41e388 resolved: make check-pointer-deref clean
Add the needed assert changes to make the code clean
for the new check-pointer-deref script.
2026-03-27 11:24:38 +01:00
Michael Vogt 5d82ecc0e3 libsystemd-network: make check-pointer-deref clean
Add the needed assert changes to make the code clean
for the new check-pointer-deref script.
2026-03-27 11:23:40 +01:00
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
Lennart Poettering 6a4a4f0302 bootspec: honour profile number when sorting properly
This corrects sorting of menu entries regarding profile numbers:

1. If the profile number is unset, let's treat this identical to profile
   0, when ordering stuff, because an item with no profile is
   conceptually the same as an item with only a profile 0.

2. Let's take the profile number into account also if sort keys are
   used. This was makes profiles work sensibly in type 1 entries, via
   the recently added "profile" stanza.

Follow-up for: 5fb90fa319
2026-03-27 10:44:14 +01:00
Lennart Poettering 208cc69c50 boot: do no show pixel width/height in text mode
When running in pure text mode (i.e. serial terminal) the pixel
width/height is zero and makes no sense to report. Suppress it.
2026-03-27 10:44:14 +01:00
Lennart Poettering 3d4e3c1a5e boot: properly track internal menu entries
When showing the list of menu entries via "p", the "internal call:"
field was showing nonsense, since
fb6cf4bbb7.

Fix that by adding a proper entry type for "internal" menu items such as
reboot/firmware/poweroff, and then check for that.

With this in place all entries now have a loader type that makes sense
and describes precisely what an entry is about.
2026-03-27 10:44:14 +01:00
Lennart Poettering 6e2a452118 fundamental: move strv_isempty() into src/fundamental/ 2026-03-27 09:54:28 +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