Commit Graph
87892 Commits
Author SHA1 Message Date
Daan De Meyer 4d91b0366a libc: Add kexec_file_load() syscall wrapper
Allow tabs in UAPI headers in .gitattributes since they are copied
verbatim from the kernel.
2026-04-13 11:13:04 +02:00
Daan De Meyer 0a8578a6ee compress: rework decompressor_detect() on top of compression_detect_from_magic()
Replace the duplicated magic byte signatures in decompressor_detect()
with a call to the new compression_detect_from_magic() helper and use a
switch statement to initialize the appropriate decompression context.
2026-04-13 11:13:04 +02:00
Lennart Poettering e700d5134d time-util: encode our assumption that clock_gettime() never can return 0 or USEC_INFINITY
We generally assume that valid times returned by clock_gettime() are > 0
and < USEC_INFINITY. If this wouldn't hold all kinds of things would
break, because we couldn't distuingish our niche values from regular
values anymore.

Let's hence encode our assumptions in C, already to help static
analyzers and LLMs.

Inspired by: https://github.com/systemd/systemd/pull/41601#pullrequestreview-4094645891
2026-04-13 08:52:43 +02:00
Milan Kyselica aa85a742fe nss-systemd: fix off-by-one in nss_pack_group_record_shadow()
nss_count_strv() counts trailing NULL pointers in n. The pointer area
then used (n + 1), reserving one slot more than the size check
accounted for.

Drop the + 1 since n already includes the trailing NULLs, unlike the
non-shadow nss_pack_group_record() where n does not.

Fixes: https://github.com/systemd/systemd/issues/41591
2026-04-12 21:20:15 +01:00
Luca Boccassi 03fa2f8982 More assorted coverity fixes (#41601)
One more round, this time with the help of the claudebot, especially for
spelunking in git blame to find the original commit and writing commit
messages from the list of warnings exported from coverity

Co-developed-by: Claude
[claude@anthropic.com](mailto:claude@anthropic.com)
2026-04-12 21:19:12 +01:00
Lennart Poettering d1e1696902 core: varlink enum for io.systemd.Unit interface (#40972)
Convert string fields to varlink enums in io.systemd.Unit

Following
https://github.com/systemd/systemd/pull/39391#discussion_r2489599449,
convert all configuration setting fields in the io.systemd.Unit varlink
interface from bare SD_VARLINK_STRING to proper enum types, adding type
safety to the IDL.

This converts ~30 fields across ExecContext, CGroupContext, and
UnitContext, adding 25 new varlink enum types.

Weak compatibility breakage (per
https://github.com/systemd/systemd/pull/40972#issuecomment-4222294318):
Varlink enum identifiers cannot contain - or +, so affected values are
underscorified on the wire. For example, "tty-force" becomes tty_force,
"kmsg+console" becomes kmsg_console.

The full list of affected values:
```
  - ExecInputType: tty-force, tty-fail
  - ExecOutputType: kmsg+console, journal+console
  - ProtectHome: read-only
  - CGroupController: bpf-firewall, bpf-devices, bpf-foreign, bpf-socket-bind, bpf-restrict-network-interfaces, bpf-bind-network-interface
  - CollectMode: inactive-or-failed
  - EmergencyAction: exit-force, reboot-force, reboot-immediate, poweroff-force, poweroff-immediate, soft-reboot, soft-reboot-force, kexec-force, halt-force, halt-immediate
  - JobMode: replace-irreversibly, ignore-dependencies, ignore-requirements, restart-dependencies
```
2026-04-12 21:47:54 +02:00
Luca Boccassi 44296e41db test-json: add iszero_safe guards for float division at index 0 and 1
The existing iszero_safe guards at index 9 and 10 were added to
silence Coverity, but the same division-by-float-zero warning also
applies to the divisions at index 0 (DBL_MIN) and 1 (DBL_MAX).

CID#1587762

Follow-up for 7f133c996c
2026-04-12 13:25:28 +01:00
Luca Boccassi efccc0dc23 debug-generator: assert breakpoint type is valid before bit shift
The BreakpointType enum includes _BREAKPOINT_TYPE_INVALID (-EINVAL),
so Coverity flags the bit shift as potentially using a negative shift
amount. Add an assert to verify the type is in valid range, since the
static table only contains valid entries.

CID#1568482

Follow-up for 1929226e7e
2026-04-12 13:25:28 +01:00
Luca Boccassi 1afc0c6c60 nss-myhostname: add more INC_SAFE for buffer index accumulation
Use overflow-safe INC_SAFE() instead of raw addition for idx
accumulation, so that Coverity can see the addition is checked.

CID#1548028

Follow-up for a05483a921
2026-04-12 13:24:50 +01:00
Luca Boccassi ff102359b7 uid-range: add assert to prevent underflow in coalesce loop
Coverity flags range->n_entries - j as a potential underflow
in the memmove size calculation. Add assert(range->n_entries > 0)
before decrementing n_entries, which holds since the loop condition
guarantees j < n_entries.

CID#1548015

Follow-up for 8dcc66cefc
2026-04-12 13:24:50 +01:00
Zbigniew Jędrzejewski-Szmek 04e05ab724 Some coverity cleanups (#41596) 2026-04-12 14:00:49 +02:00
Zbigniew Jędrzejewski-Szmek 2835f55948 Another batch of option+verb conversions (#41586) 2026-04-12 13:58:38 +02:00
Frantisek Sumsal d9da339bf1 sd-varlink: scale down the limit of connections per UID to 128
1024 connections per UID is unnecessarily generous, so let's scale this
down a bit. D-Bus defaults to 256 connections per UID, but let's be even
more conservative and go with 128.
2026-04-12 13:57:39 +02:00
joo es 043689f8e0 po: Translated using Weblate (Arabic)
Currently translated at 100.0% (266 of 266 strings)

Co-authored-by: joo es <jonnyse@users.noreply.translate.fedoraproject.org>
Translate-URL: https://translate.fedoraproject.org/projects/systemd/main/ar/
Translation: systemd/main
2026-04-11 22:05:50 +01:00
Zbigniew Jędrzejewski-Szmek 3fac59557c homed: drop unnecessary cast to double
Coverity was complaining that we we're doing a integer division and then
casting that to double. This was OK, but it was also a bit pointless.
An operation on a double and unsigned promoted the unsigned to a double,
so it's enough if we have a double somewhere as an argument early enough.
Drop noop casts and parens to make the formulas easier to read.

CID#1466459
2026-04-11 14:58:34 +02:00
Zbigniew Jędrzejewski-Szmek efbd8a26d6 fundamental: add ABS_DIFF macro
Sometimes we want need to diff two unsigned numbers, which is awkward
because we need to cast them to something with a sign first, if we want
to use abs(). Let's add a helper that avoids the function call
altogether.

Also drop unnecessary parens arounds args which are delimited by commas.
2026-04-11 14:58:34 +02:00
Zbigniew Jędrzejewski-Szmek c9defc1beb varlinkctl: drop bogus variable assignment
Coverity complains that r is overridden. In fact it isn't, but
we shouldn't set it like this anyway. exec_with_listen_fds() already
logs, so we only need to call _exit() if it fails.

CID#1646716
2026-04-11 14:58:34 +02:00
Zbigniew Jędrzejewski-Szmek 1c9fbbab1d sd-event: replace dead code path with an assert
Coverity complains that the -EOPNOTSUPP can never be returned, because
we always have !watch_fallback==locked.

CID#1654169
2026-04-11 14:53:07 +02:00
Zbigniew Jędrzejewski-Szmek 98c57879b6 cryptsetup: convert to the new option and verb parsers
The synopisis is moved from the header to the a new section:

  -systemd-cryptsetup attach VOLUME SOURCE-DEVICE [KEY-FILE] [CONFIG]
  -systemd-cryptsetup detach VOLUME
  +systemd-cryptsetup [OPTIONS...] {COMMAND} ...

   Attach or detach an encrypted block device.

  +Commands:
  +  attach VOLUME SOURCE-DEVICE [KEY-FILE] [CONFIG] Attach an encrypted block
  +                                                  device
  +  detach VOLUME                                   Detach an encrypted block
  +                                                  device
  +
  +Options:

I think that's OK… With the autogenerated table that's the natural
thing to do.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-11 13:30:42 +02:00
Zbigniew Jędrzejewski-Szmek 85c1c04a4e cryptenroll: convert to the new option parser
--help is the same, apart from linewrapping.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-11 13:30:42 +02:00
Zbigniew Jędrzejewski-Szmek 227460f4ef cryptenroll: reorder option cases to match --help output
Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-11 13:30:42 +02:00
Zbigniew Jędrzejewski-Szmek ddc97d68d6 cat: convert to the new option parser
--help is identical except for whitespace.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-11 13:30:42 +02:00
Zbigniew Jędrzejewski-Szmek c5f444e85b bsod: convert to the new option parser
Option indentation in --help is fixed.
Description for --continuous is shortened.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-11 13:30:42 +02:00
Zbigniew Jędrzejewski-Szmek 120edabb4f delta: convert to the new option parser
--help for --diff= is changed from old-style "1|0" to "yes|no".

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-11 13:30:42 +02:00
Zbigniew Jędrzejewski-Szmek c15550e1df escape: convert to the new option parser
Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-11 13:30:42 +02:00
Zbigniew Jędrzejewski-Szmek e517eadbd2 pull: convert to the new option and verb parsers
Duplicated word in description of --keep-download= is fixed.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-11 13:30:42 +02:00
Zbigniew Jędrzejewski-Szmek 959116d5de importctl: convert to the new option and verb parsers
Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-11 13:30:42 +02:00
Zbigniew Jędrzejewski-Szmek ee96f934c6 importctl: fix -N to actually clear keep-download flag
-N was clearing and re-setting the same bit in arg_import_flags_mask,
which is a no-op. It should clear the bit in arg_import_flags instead,
matching what --keep-download=no does via SET_FLAG().
2026-04-11 13:30:42 +02:00
Zbigniew Jędrzejewski-Szmek 4319ca43f9 import: convert to the new option and verb parsers
--help output is the same.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-11 13:30:42 +02:00
Zbigniew Jędrzejewski-Szmek 11505ac135 bootctl: convert options and verbs to the new macros
-RR is formatted using the new OPTION_HELP_ENTRY_VERBATIM so that
we get the same --help as before.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-11 13:30:42 +02:00
Zbigniew Jędrzejewski-Szmek 4f6fdbcf7a shared/verbs: add _SCOPE variants of the verb macros
In some of the large programs, verbs are defined as non-static
functions. To support this cases, add variants of the VERB macros that
take an explicit scope parameter. The existing macros then call those
new macros with scope=static. The variant without static is the
exception, so the macros are "optimized" toward the static helpers.

I also considered allowing VERB macros to be used in different files,
i.e. in different compilation units. This would actually work without
too many changes, except for one caveat: the order in the array would be
unspecified, so we'd need to somehow order the verbs appropriately. This
most likely means that the verbs would need to be annotated with a
number. But that doesn't seem attractive at all: we'd need to coordinate
changes in different files. So just listing the verbs in one file seems
like least bad option.
2026-04-11 09:54:57 +02:00
Zbigniew Jędrzejewski-Szmek 10e78e0b0e shared/options: add option to generate a help line for custom option format
Sometimes we want to document what -RR or -vv does or some other
special thing. Let's allow this by (ab-)using long_code pointer
to store a preformatted string.
2026-04-11 09:54:56 +02:00
Luca Boccassi 53c87c096c json-stream: fix NULL pointer passed to memcpy on first read with INPUT_SENSITIVE
When JSON_STREAM_INPUT_SENSITIVE is set before the first read,
input_buffer is NULL, input_buffer_size is 0, and input_buffer_index
is 0. The old condition '!INPUT_SENSITIVE && index == 0' would route
this case into the else branch which calls memcpy() with a NULL source
pointer, which is undefined behavior even when the length is zero, and
is caught by UBSan.

Fix by checking input_buffer_index == 0 first, then allowing the
GREEDY_REALLOC fast path also when input_buffer_size == 0, since
there is no sensitive data to protect from realloc() copying in that
case. The else branch is now only entered when there is actual data
to copy (input_buffer_size > 0), guaranteeing input_buffer is
non-NULL.

Follow-up for 6b1a59d594
2026-04-11 06:42:28 +02:00
Nandakumar Raghavan 056bc106e1 core: fix EBUSY on restart and clean of delegated services
When a service is configured with Delegate=yes and DelegateSubgroup=sub,
the delegated container may write domain controllers (e.g. "pids") into the
service cgroup's cgroup.subtree_control via its cgroupns root. On container
exit the stale controllers remain, and on service restart clone3() with
CLONE_INTO_CGROUP fails with EBUSY because placing a process into a cgroup
that has domain controllers in subtree_control violates the no-internal-
processes rule. The same issue affects systemctl clean, where cg_attach()
fails with EBUSY for the same reason.

Add unit_cgroup_disable_all_controllers() helper in cgroup.c that clears
stale controllers via cg_enable(mask=0) and updates cgroup_enabled_mask to
keep internal tracking in sync. Call it from service_start() and
service_clean() right before spawning, so that resource control is preserved
for any lingering processes from the previous invocation as long as possible.
2026-04-11 00:07:05 +01:00
Frantisek Sumsal 1016dd315f sd-json: limit the stack depth during parsing as well 2026-04-10 21:33:11 +01:00
Zbigniew Jędrzejewski-Szmek 5cd61c1330 Define array cleanup funcs through macros (#41559) 2026-04-10 21:45:14 +02:00
Daan De Meyer 6b1a59d594 sd-json: add JsonStream transport-layer module and migrate sd-varlink
Introduces JsonStream, a generic transport layer for JSON-line message
exchange over a pair of file descriptors. It owns the input/output
buffers, SCM_RIGHTS fd passing, the deferred output queue, the
read/write/parse step functions, sd-event integration (input/output/time
event sources), the idle timeout machinery, and peer credential caching,
but knows nothing about the specific JSON protocol on top — the consumer
drives its state machine via phase/dispatch callbacks supplied at
construction.

sd-varlink is reworked to delegate the entire transport layer to a
JsonStream owned by sd_varlink. The varlink struct drops every
transport-related field (input/output buffers and fds, output queue,
fd-passing state, ucred/pidfd cache, prefer_read/write fallback, idle
timeout, description, event sources) — all of that lives in JsonStream
now. What remains in sd_varlink is the varlink-protocol state machine
(state, n_pending, current/previous/sentinel, server linkage, peer
credentials accounting, exec_pidref, the varlink-specific quit and defer
sources) and a thin wrapper layer over the JsonStream API. The
should_disconnect / get_timeout / get_events / wait helpers all live in
JsonStream now and are driven by a JsonStreamPhase the consumer reports
via its phase callback.
2026-04-10 20:04:12 +02:00
Ivan Kruglov 23f0c9070b news: new record about strings vs enums in varlink 2026-04-10 08:37:04 -07:00
Ivan Kruglov 99fe3283c5 test: add core-specific varlink enum sync test
Add test-varlink-idl-unit that validates all varlink enum types in
io.systemd.Unit match their corresponding C string tables. This
catches drift between varlink IDL enum definitions and internal
enum values.

Uses core_test_template since it links against libcore for access
to the string table lookup functions.

ExecOutput uses TEST_IDL_ENUM_TO_STRING only because the '+' in
'kmsg+console' doesn't survive the underscorify/dashify round-trip.
2026-04-10 08:37:04 -07:00
Luca Boccassi a1813a40ec docs: beef up SECURITY.md rules for reporting
With yeswehack.com suspended due to funding issues for triagers being
worked out, reports on GH are starting to pile up. Explicitly define
some ground rules to avoid noise and time wasting.
2026-04-10 17:34:03 +02:00
Ivan Kruglov 1912b3585d varlink: add enum types for configuration settings in io.systemd.Unit
Define proper varlink enum types for unit configuration settings that
are part of the user-facing API (values users/clients can select).
This replaces SD_VARLINK_STRING with SD_VARLINK_DEFINE_FIELD_BY_TYPE
for these fields, giving them strong type semantics in the IDL.

Enum types added for ExecContext (ExecInputType, ExecOutputType,
ExecUtmpMode, ExecPreserveMode, ExecKeyringMode, MemoryTHP,
ProtectProc, ProcSubset, ProtectSystem, ProtectHome, PrivateTmp,
PrivateUsers, ProtectHostname, ProtectControlGroups, PrivatePIDs,
PrivateBPF), CGroupContext (CGroupDevicePolicy, ManagedOOMMode,
ManagedOOMPreference, CGroupPressureWatch, NFTSetSource, NFProto,
BPFCGroupAttachType, CGroupController), and UnitContext (CollectMode,
EmergencyAction, JobMode).

Engine-reported runtime state fields (Type, LoadState, ActiveState,
FreezerState, SubState, UnitFileState) remain as strings since only
the engine selects those values.
2026-04-10 07:05:36 -07:00
Zbigniew Jędrzejewski-Szmek 79f90f4ae0 various: use DEFINE_ARRAY_FREE_FUNC 2026-04-10 15:08:03 +02:00
Zbigniew Jędrzejewski-Szmek 2a23e43f70 sysupdate: use DEFINE_POINTER_ARRAY_FREE_FUNC, rename func 2026-04-10 15:08:03 +02:00
Zbigniew Jędrzejewski-Szmek 7024c0c38c shared/tar-util: use DEFINE_ARRAY_FREE_FUNC, rename funcs 2026-04-10 15:08:03 +02:00
Zbigniew Jędrzejewski-Szmek 90c6157100 sd-journal: use NormalCasing for struct 2026-04-10 15:08:03 +02:00
Zbigniew Jędrzejewski-Szmek 5ceaab3d4f nsresourced: use DEFINE_ARRAY_FREE_FUNC, make func static and rename 2026-04-10 15:08:02 +02:00
Zbigniew Jędrzejewski-Szmek b8514cff52 libsystemd-network: use DEFINE_POINTER_ARRAY_FREE_FUNC, rename cleanup function 2026-04-10 15:08:02 +02:00
Zbigniew Jędrzejewski-Szmek 954243f2bc libsystemd-network: use DEFINE_ARRAY_FREE_FUNC, rename cleanup func 2026-04-10 15:08:02 +02:00
Zbigniew Jędrzejewski-Szmek 3b478198e9 stub: use DEFINE_ARRAY_FREE_FUNC 2026-04-10 15:08:02 +02:00
Zbigniew Jędrzejewski-Szmek 81d2d0270b Add DEFINE_ARRAY_FREE_FUNC and mount_image_free_array
This is similar to DEFINE_POINTER_ARRAY_FREE_FUNC, but one
pointer chase less. The name of the outer and inner functions are
specified separately. The inner function does not free, so it'll
be generally something like 'foo_done', but the outer function
does free, so it can be called 'foo_array_free'.
2026-04-10 15:08:02 +02:00