Commit Graph
87535 Commits
Author SHA1 Message Date
Luca Boccassi 4f5b28b72c sd-bus: add assert_cc for message allocation size
Use CONST_ALIGN_TO to express the compile-time overflow check for
the ALIGN(sizeof(sd_bus_message)) + sizeof(BusMessageHeader)
allocation, since ALIGN() is not constexpr.

CID#1548031

Follow-up for de1c301ed1
2026-03-30 09:37:32 +01:00
Luca Boccassi aa2cc18c76 sd-bus: use usec_add() for auth timeout calculation
Use the overflow-safe usec_add() instead of raw addition for
computing the authentication timeout.

CID#1548036

Follow-up for e3017af973
2026-03-30 09:37:32 +01:00
Luca Boccassi a05483a921 nss-myhostname: add asserts for buffer index accumulation
Coverity flags idx += 2*sizeof(char*) and idx += sizeof(char*)
as potential overflows. The idx is bounded by the ms buffer size
calculation, add asserts to document this.

CID#1548028

Follow-up for e8a7a31539
2026-03-30 09:37:32 +01:00
Luca Boccassi 331461a5a2 tree-wide: add assert_cc for time constant multiplications
Coverity flags compile-time constant multiplications of
USEC_PER_SEC, USEC_PER_MSEC, and USEC_PER_HOUR as potential
overflows. Add assert_cc() to prove they fit at build time.

CID#1548025
CID#1548048
CID#1548055
CID#1548059

Follow-up for 500727c220
Follow-up for 27d340c772
Follow-up for e537352b9b
Follow-up for 1007ec60e6
2026-03-30 09:37:32 +01:00
Luca Boccassi 96b085c4be repart: add assert for offset + current_size overflow safety
Coverity flags a->after->offset + a->after->current_size as a
potential overflow. Both values are validated as not UINT64_MAX
by existing asserts, add an explicit overflow check to document
the invariant for static analyzers.

CID#1548063

Follow-up for e594a3b154
2026-03-30 09:37:31 +01:00
Luca Boccassi 3fd6774633 networkd-ndisc: add assert for DNSSL allocation overflow safety
Coverity flags ALIGN(sizeof(NDiscDNSSL)) + strlen(*j) + 1 as a
potential overflow. Domain names are protocol-bounded but add an
assert to make this explicit for static analyzers.

CID#1548066

Follow-up for 1e7a0e21c9
2026-03-30 09:37:31 +01:00
Luca Boccassi 21cc3216a7 dns-packet: add asserts for allocation overflow safety
Coverity flags ALIGN(sizeof(DnsPacket)) + size calculations in
dns_packet_new() and dns_packet_dup() as potential overflows. The
sizes are bounded by DNS_PACKET_SIZE_MAX but add asserts to make
this explicit for static analyzers.

CID#1548058
CID#1548076

Follow-up for c73ce96b56
2026-03-30 09:37:31 +01:00
Luca Boccassi 09bb6448ae limits-util: add assert for physical memory calculation overflow
Coverity flags (uint64_t) sc * (uint64_t) ps as a potential
overflow. Add an assert to make the bounds explicit for static
analyzers.

CID#1548042

Follow-up for eefc66aa8f
2026-03-30 09:37:31 +01:00
Luca Boccassi 02f848b375 user-util: add asserts for buffer allocation overflow safety
Coverity flags ALIGN(sizeof(struct passwd/group)) + bufsize as
potential overflows in the getpw/getgr helpers. Add asserts to
make the bounds explicit for static analyzers.

CID#1548047
CID#1548049
CID#1548069
CID#1548070

Follow-up for 75673cd8ae
2026-03-30 09:37:31 +01:00
Luca Boccassi 55354d5930 sd-bus: add asserts for message size overflow safety
Coverity flags arithmetic in BUS_MESSAGE_SIZE(),
BUS_MESSAGE_BODY_BEGIN() and message_from_header() as potential
overflows. The values are validated at message creation time, but
add asserts to make the invariants explicit for static analyzers.

CID#1548023
CID#1548030
CID#1548046

Follow-up for 6629161f82
2026-03-30 09:37:31 +01:00
Luca Boccassi 56df6e5669 sd-daemon: add assert before CMSG_SPACE subtraction
Coverity flags the subtraction from msg_controllen as a potential
underflow. The CMSG_SPACE was added when send_ucred was set, and
the subtraction only runs when send_ucred was true, so it is safe.
Add an assert to document this invariant.

CID#1548074

Follow-up for 64144440a5
2026-03-30 09:37:31 +01:00
Luca Boccassi a702b9b6ea sd-json: silence false positive in sd_json_variant_filter
Same pattern as the fix for sd_json_variant_unset_field in
9b3715d529: cache the element
count in a local variable and assert it is at least 2 before
subtracting.

CID#1548029

Follow-up for f2ff34ff2a
2026-03-30 09:37:31 +01:00
Luca Boccassi 4ff8fb899b journal: add assert for max_size overflow safety
Coverity flags max_size*2 as a potential overflow. The value is
bounded by MAX_SIZE_UPPER (128 MiB) or JOURNAL_COMPACT_SIZE_MAX
(4 GiB), so doubling is safe within uint64_t. Add an assert to
document this.

CID#1548019

Follow-up for 8580d1f73d
2026-03-30 09:37:31 +01:00
Adam Dinwoodie 566a4f3437 man: fix caps in example path 2026-03-30 09:14:32 +01: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
Luca Boccassi 34c82cbe2f systemd-repart man page fixes (#41410)
Found two small issues in the man page.
2026-03-29 13:58:04 +01:00
Morten Linderud 3242308ce3 man/systemd-repart: quote jq expression
Some shells will try to parse this, or expand it, causing an error. Lets
quote it so it's simpler for people.

Signed-off-by: Morten Linderud <morten@linderud.pw>
2026-03-29 14:20:28 +02:00
Morten Linderud a0ba770edc man/systemd-repart: remove extra pipe character in manpage
Signed-off-by: Morten Linderud <morten@linderud.pw>
2026-03-29 14:15:05 +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
Adrian Wannenmacher f377be7081 fix list of inhibitor lock types
Markdown and HTML don't support mixing ordered and unordered items
within a single list. This means the previous syntax actually produced
three separate lists.

Also, markdown converters don't necesarrily respect the first number in
an ordered list, and may just overwrite it to one. This is the case for
the one that generates the systemd.io page. And even if that wasn't the
case, the numbering of the second ordered list would be off by one.
2026-03-28 20:57:52 +00: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
RiskoZS 7471dc2994 hwdb: Add keymaps for Acer Nitro 5 AN517-54
Add mappings for the Fn+F7 (microphone mute), NitroSense and power keys for the Acer Nitro 5 AN517-54
2026-03-28 12:07:56 +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
Luca Boccassi 9094caf66e mkosi: add CI for Ubuntu 26.04 (#41383)
It is in final beta now, so we can start building and testing it
2026-03-28 01:19:35 +00:00
Luca Boccassi b4335ea9fc mkosi: add test job for Ubuntu 26.04
It is now in beta freeze, so we can start adding test coverage
2026-03-27 23:08:35 +00:00
Luca Boccassi 1d6585f218 mkosi: pull in gnu coreutils for Ubuntu 26.04 and newer
The default coreutils in Ubuntu 26.04 moved to uutils, which is broken
in many subtle and annoying ways, breaking various tests. It's also
a giant monolithic megabinary which makes the minimal image size
go up and break other tests.

Force the gnu coreutils to be pulled in all images.
2026-03-27 23:08:35 +00:00
Luca Boccassi f737b38977 test: exclude gnusleep from coredumps parsing
In Ubuntu 26.04 the actual binary is called gnusleep, and sleep is a symlink,
so fix the regex exclusion for the coredump checks
2026-03-27 22:40:09 +00:00
Luca Boccassi 9f56d62f92 test: check for bin/bash in dissect --mtree instead of cat
Ubuntu is doing shenanigans with their coreutils so they are now
symlinks instead of binaries, so the grep fails. Check bash instead
to fix test failure on 26.04.
2026-03-27 22:40:09 +00:00
Luca Boccassi a1dada941d mkosi: depend on bpftool for Ubuntu 26.04 build image
bpftool was disentangled, so we can depend on it, and build with bpf
2026-03-27 22:40:09 +00: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