Commit Graph
9757 Commits
Author SHA1 Message Date
Yu Watanabe 3a1231f4c7 core: several follow-ups (#40140)
Replaces #39925
Closes #39925
2026-01-05 06:31:48 +09:00
Mike Yuan 75f04abf16 core: move several checks from _start() to _test_startable() where appropriate
If these basic sanity checks fail, there's no point in
bumping ratelimit.
2026-01-05 06:11:26 +09:00
Mike Yuan 252b40c449 core/dynamic-user: use fd_verify_linked() 2026-01-03 21:25:02 +01:00
Mike Yuan 776dc1b9d5 core/dynamic-user: flock() does not return EBUSY 2026-01-03 21:14:32 +01:00
Yu Watanabe cb39d66ec8 core: do not provide non-dynamic user through DBus/Varlink
With a service with DynamicUser= with static user or group, e.g.,
```
$ systemd-run -p DynamicUser=yes -p Group=disk sleep infinity
```
previously the lookup by name and ID through DBus/Varlink are inconsistent:
```
$ busctl call org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager LookupDynamicUserByUID "u" 6
Call failed: Dynamic user ID 6 does not exist.

$ busctl call org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager LookupDynamicUserByName "s" disk
u 6

$ userdbctl group 6
  Group name: disk
 Disposition: system
         GID: 6
   Passwords: 1
     Service: io.systemd.NameServiceSwitch

$ userdbctl group disk
  Group name: disk
 Disposition: dynamic
         GID: 6
 Description: Dynamic Group
     Service: io.systemd.DynamicUser
```

With this change, the results of these methods are consistent.

Fixes #40228.
2026-01-03 19:57:44 +01:00
Daan De Meyer 52ecf376fa tree-wide: Migrate to pidref_safe_fork()
Let's migrate all remaining callers of safe_fork()
to pidref_safe_fork() and get rid of safe_fork().
2026-01-02 20:08:41 +01:00
Daan De Meyer e6703a9aa4 process-util: Use ret as output parameter name
There's only one output parameter for all these
functions, so let's just name it ret following the
coding style.
2026-01-02 19:44:18 +01:00
Daan De Meyer 944ae1286b tree-wide: Use pamh as pam_handle_t parameter name
libpam uses pamh in its function declarations for
the plugin API so let's use the same name in our
tree as well.

Making sure the plugin function definitions match
the plugin function declarations is required to
enable clang-tidy's
readability-inconsistent-declaration-parameter-name
check, but to keep things consistent everywhere we
opt to use pamh tree-wide.
2026-01-02 09:21:43 +01:00
Yu Watanabe 431fc656bc Bump required minimum version of libseccomp to 2.4.0
Major distributions already have libseccomp 2.5.x or newer.
Let's bump to the required minimum version to 2.4.0, which provides
SCMP_ACT_KILL_PROCESS, SCMP_ACT_LOG, SCMP_ARCH_PARISC, and
SCMP_ARCH_PARISC64.

Note, libseccomp 2.4.0 was released on 2019-03-15.

See also #38608.
2026-01-02 12:54:18 +09:00
Mike Yuan 05aea9f73b core/dynamic-user: drop unused /run/systemd/dynamic-uid/direct: kludge
Follow-up for 1684c56f40
This effectively reverts fd63e712b2

This was originally introduced to resolve deadlock caused by
dbus broker calling into nss-systemd which in turn goes via
dbus for user lookup. This is now handled differently and
the interface has been sitting unused for half a decade now.
Kill it.
2026-01-02 04:28:01 +09:00
Daan De Meyer aec52c1e6e string-table: Introduce DECLARE_STRING_TABLE_LOOKUP() and friends
Let's introduce these for the following two reasons:
- Using them makes sure the parameter names match between declaration
  and definition (if both use the corresponding macros).
- They make sure developers can't forget the _const_ and _pure_
  attributes for the declarations.

This commit also includes some include sorting fixes
2026-01-02 04:05:45 +09:00
Daan De Meyer daff8ea8bb tree-wide: Introduce DECLARE_TRIVIAL_REF_UNREF_FUNC() and friends 2026-01-02 04:04:19 +09:00
Franck BuiandMike Yuan 8e92910b98 core/transaction: when isolating, keep triggered units only if their triggers are actually active
Follow-up for 32d6707dd1.

Co-authored-by: Mike Yuan <me@yhndnzj.com>
2025-12-31 19:33:19 +01:00
Mike Yuan 2716906246 core/unit: do not check for unreachable job type
Refer to 7cb0030f6c for the rationale.
2025-12-31 19:33:19 +01:00
Mike Yuan d7bc1e3be9 core/exec-invoke: use RET_NERRNO to avoid clobbering errno
Follow-up for 72ce1046e8

string_table_lookup_to_string_fallback() might interfere
with errno, hence store it in r first.
2025-12-31 19:32:58 +01:00
Mike Yuan ecd677bcc9 core/cgroup: no need to handle empty bind_network_interface
We always normalize empty setting to NULL, hence per our usual
coding style a simply NULL check would suffice.
2025-12-27 23:47:55 +01:00
Mike Yuan 705d2c527f core/dbus-cgroup: actually allow empty assignment for BindNetworkInterface= 2025-12-27 23:47:55 +01:00
Mike Yuan 5af2df38df core/cgroup: fix bpf-bind-iface serialization
Follow-up for c1c787651b

The commit added serialization, but deserialization wasn't in place.
Follow the usual practice of pinning the bpf link fd until we install
the new instance.
2025-12-27 23:44:53 +01:00
Mike Yuan e78f615763 core/cgroup: fix potential bpf link fd leak during deserialization
Also add a comment explaining the deserialization mechanism, as requested
in https://github.com/systemd/systemd/pull/40202#discussion_r2649274628
2025-12-27 20:51:05 +01:00
Mike Yuan d90cfb7e30 core/bpf-restrict-ifaces: avoid duplicate unit_get_cgroup_runtime() call 2025-12-27 20:14:57 +01:00
Mike Yuan e4c43ca7d6 core/cgroup: CGContext must be available if Unit has CGRuntime
Follow-up for e03e5056db
2025-12-27 20:14:56 +01:00
Luiz Amaral c1c787651b Add support for binding a unit to a network iface 2025-12-24 07:37:58 +01:00
Mike Yuan 65d173a02d core/socket: modernize listen/accept_in_cgroup 2025-12-20 22:56:33 +01:00
Mike Yuan 72ce1046e8 core/exec-invoke: log about name of CPU sched policy
Follow-up for 4dcbfbb1ad

Also, do not encode errno in log if we know the precise cause,
i.e. unsupported.
2025-12-20 21:40:56 +01:00
Matt Fleming 4dcbfbb1ad process-util: Add support SCHED_EXT scheduling policy
Allow CPUSchedulingPolicy to be set to "ext". SCHED_EXT is a new
scheduling policy in Linux v6.12 that allows processes to be scheduled
using custom BPF schedulers instead of the default in-kernel ones.

Selectively setting the SCHED_EXT policy is useful for systems running
in "partial mode" where not all processes are run using a custom
scheduler.

Fallback to SCHED_OTHER and print an error message for systems where
SCHED_EXT isn't available.
2025-12-20 18:31:55 +01:00
Daan De Meyer fbd276cb86 tree-wide: Use pidref_wait_for_terminate_and_check()
Let's use the pidref variants for waiting and
checking a process everywhere and get rid of the
non pidref variants.
2025-12-20 15:50:47 +01:00
Daan De Meyer e74b571004 pidref: Add pidref_wait_for_terminate_full()
We can use this to replace wait_for_terminate_with_timeout(). Because
we poll a pidfd, we don't need to block SIGCHLD anymore in umount.c.
2025-12-20 15:49:26 +01:00
Daan De MeyerandMike Yuan 8c007f68ff process-util: Migrate namespace_fork() to PidRef
Co-authored-by: Mike Yuan <me@yhndnzj.com>
2025-12-20 13:45:22 +01:00
Luca Boccassi 0bd766553c core: reuse existing dm-verity device for single filesystem images pinned by policy
Loading images is, generally speaking, the slowest part of sd-executor
when spawning a service. This is due to multiple factors. dm-verity is
obviously a big part of the cost, but dissecting in general via libblkid
also can take a lot of time, due to probing the images and their filesystems.

A performance test doing service restarts in a row shows these
results, ran on a production system (low power and slow ARM64 SOC) with
a real production service, show the following service interruption intervals:

Count | P50 (ms)  | P90 (ms) | P95 (ms) | P99 (ms) | P99.9 (ms)
507   | 1,532     | 1,726    | 2,548    | 4,112    | 4,592

One iteration is 507 restarts in this case, but this has ran hundreds
of times and the results are always in line within margin of error.
This also holds true for metrics from live systems, same numbers.
Between 1.0s and 1.2s can be attributed by profiling to the time needed
for the service code itself to start up and sd_notify, the rest is spent
inside systemd's code.

This means there is currently a tradeoff for services - either use secure
images, or make restarting fast. Downtime of services is a very important
metric, as for many cases this directly translates to outages, total or
partial (blackouot or greyout).

In order to facilitate using secure images without downsides, skip the
slow dissect steps (probing, loop devices, etc) when the configured
image is a single filesystem dm-verity image with a policy that pins it
to a single filesystem, and an already existing and open dm-verity device
can be found and reused.

This allows orchestrators to pre-open images on download, before restarting
services, to minimize downtimes.
2025-12-19 11:20:48 +00:00
Mike Yuan 79e6bfb1e6 core/manager: use UNIT_IS_ACTIVE_OR_RELOADING rather than hardcoding service states
except for SERVICE_EXITED which has to be checked manually.
2025-12-19 02:18:44 +01:00
Mike Yuan 58e9239fd7 core/dbus-manager: drop dangling verify_run_space_and_log() prototype
Follow-up for 65d9ef40f2
2025-12-18 17:37:26 +01:00
Mike Yuan f145fc8c7e core/manager: constify DEFAULT_TASKS_MAX 2025-12-18 17:37:25 +01:00
Mike Yuan 4a6e5b0ae9 core: various cleanups for setup_input/output (#39860) 2025-12-18 15:56:42 +01:00
Mike Yuan 16bae207c2 core/dbus-execute: respect write flags for empty assignments too 2025-12-18 00:39:59 +01:00
Mike Yuan 8619c65fcf core/service: const and pure'ify service_restart_usec_next() 2025-12-18 00:39:59 +01:00
Mike Yuan 7498c391ec core/exec-invoke: remove redundant accmode validation on stderr
Follow-up for 171ceb4a00

In setup_output() we assume stdout has been set up properly
before stderr, hence the stdout we're inheriting from must
be writable (or more precisely, would have been adjusted to be).
Hence no need to duplicate it.
2025-12-17 23:23:22 +00:00
Mike Yuan a8e1796b09 core/exec-invoke: split out maybe_inherit_stdout_from_stdin(), use exec_input_is_inheritable()
Note that exec_input_is_inheritable() rightfully refuses EXEC_INPUT_FILE,
in which case std_output would have been reset in service_fix_stdio()
already.

While at it, use the generic fallback logic of first trying user manager
stdout when stdin is not writable.
2025-12-17 23:23:22 +00:00
Mike Yuan e04382384d core/execute: introduce exec_input_is_inheritable() helper 2025-12-17 23:23:22 +00:00
Mike Yuan b34aee0440 core/exec-invoke: socket_fd must be set if any of stdio requests it
This is checked as one of the very first things in exec_invoke(),
hence remove the condition in fixup_input() and the whole
fixup_output().
2025-12-17 23:23:22 +00:00
Mike Yuan c8a6c42e53 core/exec-invoke: use path_equal() on for stdio files 2025-12-17 23:23:22 +00:00
Mike Yuan 4dac3c6d76 core/execute-serialize: clean up stdio serialization
* Do not interleave root_directory_as_fd with stdio fields
* Do not use different serialization key for different modes
  pointing to same path
* Escape stdio file paths (as per
  9be46b1da8)
2025-12-17 23:23:22 +00:00
Mike Yuan 27660b470f core/dbus-execute: path is required if stdio is specified as file
This partially reverts d6ff82d37c.
2025-12-17 23:23:22 +00:00
Mike Yuan eac3867764 core/exec-invoke: fix stdout and stderr sharing the same named fd
Previously such usage would be refused by exec_context_named_iofds()
with -ENOENT, however setup_output() carried relevant logic.
2025-12-17 23:23:22 +00:00
Luca Boccassi 90f4c0473a core: set Result=start-limit-hit when a unit is rate limited
There is currently no way to figure out a rate limit was hit on a unit,
as the last result is stripped in order to keep reporting the first
result, which is useful in case of a watchdog failure, which is the
reason why it was changed as such.

But rate limiting is also an important information to provide to
users, so allow the Result property to reflect it when it
happens.
2025-12-18 00:19:09 +01:00
Yu Watanabe b6abe84602 core: fix extensions refreshing (dlopen() shenanigans) (#40112) 2025-12-17 18:41:23 +09:00
Mike Yuan 4d136f1462 core: dlopen() libcryptsetup in extensions refreshing
Follow-up for a08f2ea02d

This fixes extensions refreshing + verity-protected DDIs.
TEST-50-DISSECT previously passed because confext refreshing
is tested after live mount, the latter of which used to
load libcryptsetup in pid1.
2025-12-16 22:11:45 +01:00
Mike Yuan 12df39fadf core/service: defer cryptsetup dlopen to helper process
This should still be safe, as we block dlopen() in namespace_fork().

Partially reverts 9252e26f4c.
2025-12-16 21:57:37 +01:00
Mike Yuan 8f397d5922 core/unit: add unit_fork_helper_process_full() that takes ForkFlags 2025-12-16 21:30:36 +01:00
Mike Yuan 6c1bcdd614 core/exec-credential: fix credentials plain dir exchanging
Follow-up for d796c6b7c6

rename() may yield ENOTEMPTY rather than EEXIST for existing dir,
so catch that too. Also, both the source and target must be
writable when exchanging.

Test coverage for this logic (i.e. user units with ExecStartPre=)
will be added later.
2025-12-16 21:25:51 +01:00
Mike Yuan 552822992c core/service: do not honor SuccessExitStatus= for our own helpers
They're exclusively under our control, hence errors should not be
suppressed based on external user input.
2025-12-17 04:04:02 +09:00