Commit Graph

85054 Commits

Author SHA1 Message Date
Yu Watanabe
7214aa9a2c pam-util: make pam_debug_syslog_errno() returns pam error
Currently, the result of pam_debug_syslog_errno() is unused, hence this
does not change anything and may be slightly redundant. But let's follow
our usual coding style.
2025-11-22 09:42:41 +09:00
Yu Watanabe
82f2eb73b1 pam-util: use correct errno
- pam_log_oom() passes ENOMEM rather than -ENOMEM, hence previously
  pam_log_oom() did not return PAM_BUF_ERR.
- We may (mistakenly) pass SYNTHETIC_ERRNO(). Let's gracefully handle that.
- Introduce errno_to_pam_error() helper function.
2025-11-22 09:42:41 +09:00
Yu Watanabe
7582679d0e apparmor: update log message
Follow-up for c3b3eea2e5.
Addresses https://github.com/systemd/systemd/pull/39826#discussion_r2547327325.
2025-11-22 09:42:41 +09:00
Nick Rosbrook
7d23e27e4c test: skip test-reread-partition-table if missing privileges
Right now, this test runs inside unprivileged chroots, despite the
running_in_chroot() check. This is because running_in_chroot() fails
with -EACCES, which is ignored.

Hence, check for privileges before calling running_in_chroot(),
otherwise call is inconclusive. Note, the test will fail later on if
running without privileges anyways.
2025-11-21 19:28:05 +00:00
Luca Boccassi
12d2abe082 test: check for all errors in test-reread-partition-table
Otherwise if opening the loop dev fails, the test segfaults
dereferencing a NULL variable later

Follow-up for 757887d01d
2025-11-21 19:13:39 +01:00
Chris Down
d1ae5e26c4 nspawn: Fix broken host links for container journals (#39727)
Commit 88252ca changed nspawn to always run from a temporary mount
directory (e.g., /tmp/nspawn-root-XXXXXX). This was a good
simplification for mount logic, but it unintentionally broke the
--link-journal feature.

The setup_journal() helper was subsequently passed this ephemeral path
instead of the persistent machine path (from --directory= or --image=).
This caused the host to create broken symlinks pointing to a temporary
directory that would soon be gone.

Fix this by storing the original path and plumbing it through to
setup_journal().

All other mount-related logic in outer_child() continues to use the
temporary `directory` variable.

Fixes: #39472
2025-11-21 23:42:23 +08:00
Chris Down
887f54adce nspawn: Add integration test for --link-journal 2025-11-21 21:04:34 +08:00
Chris Down
11eebc2357 nspawn: Fix broken host links for container journals
Commit 88252ca changed nspawn to always run from a temporary mount
directory (e.g., /tmp/nspawn-root-XXXXXX). This was a good
simplification for mount logic, but it unintentionally broke the
--link-journal feature.

The setup_journal() helper was subsequently passed this ephemeral path
instead of the persistent machine path (from --directory= or --image=).
This caused the host to create broken symlinks pointing to a temporary
directory that would soon be gone.

Fix this by storing the original path and plumbing it through to
setup_journal().

All other mount-related logic in outer_child() continues to use the
temporary `directory` variable.

Fixes: #39472
2025-11-21 21:04:34 +08:00
Daan De Meyer
2691e7558b run0: Add note about processes having privileges over --empower sessions 2025-11-21 13:08:50 +01:00
Daan De Meyer
cf063b8a1c sd-bus: Exit event loop with error code instead of EXIT_FAILURE
Instead of failing the event loop with a generic EXIT_FAILURE
error code when exit-on-disconnect is used, let's propagate the
error code instead of swallowing it.

Whereas previously sd_event_loop() would always fail with exit code
'1' when exit-on-disconnect is used with an sd-bus instance registered
with the event loop that encounters a failure, now we'll correctly
propagate the error to sd_event_loop() that caused sd-bus to fail and
exit the event loop. Additionally, the error is now also properly
propagated to outstanding reply callbacks for async dbus calls started
with sd_bus_call_async() and friends, whereas before we always used
ETIMEDOUT for these calls which is extremely confusing for users.

Why is this confusing? We always start sd-bus instances asynchronously,
in other words, sd_bus_start() will not actually wait until the bus instance
is connected, but it'll happen in the background, either driven by the first
sd_bus_call() when there is no event loop or by sd-event when there is an
event loop attached to the sd-bus instance. Assuming an event loop is attached,
when we fail to connect to the bus, the sd-bus instance will close down and the
first async method call we queued will fail with ETIMEDOUT. Nowhere in this process
do we inform the user that we failed to connect to the bus because of e.g. a permission
error, except for a debug log message.

By propagating the error to sd_event_exit() if exit-on-disconnect is enabled
and always propagating it to outstanding reply callbacks, debugging failures
becomes much easier as users will now get the actual error code causing the
bus instance to close down instead of ETIMEDOUT and 1 respectively.
2025-11-21 09:57:51 +01:00
Luca Boccassi
dff4fb7c35 test: skip test-loop-block udev part in chroot too
Same reason as containers, need full udev/uevent machinery for this
2025-11-21 09:16:57 +01:00
Matteo Croce
38e9d40c80 oomd: check if a cgroup can be killed before attempting to kill it
On OOM event, oomd tries to kill a cgroup until it succeedes.
The kill can fail with EPERM in case a pid is not killed, this leaves
the cgroup with only half of the processed killed.
This is unlikely but theoretically possible in a user namespace,
where systemd run as root inside the container and tries to kill a
cgroup with some PID from the host namespace.

To address this, send the SIG0 signal to all the processes to check
that we have privileges to kill them.
2025-11-21 09:15:37 +01:00
Zbigniew Jędrzejewski-Szmek
f295cfa1a7 apparmor: move dlopen() into mac_apparmor_use() check (#39826)
This mirrors what we do for mac_selinux_use(), which also loads
libselinux.
2025-11-20 20:10:44 +01:00
Luca Boccassi
4902a7f18d virt: debug log when inode_same() fails
If this fails with an error there's no log messages and tests
typically don't log it either as they just check, so add a
message to aid in debugging
2025-11-20 20:02:06 +01:00
Daan De Meyer
6629107404 mkosi: Drop IWYU
We use clang-tidy's include checker, so let's stop installing IWYU.
2025-11-20 18:46:14 +01:00
Christoph Anton Mitterer
2e5f717545 man: fix typo 2025-11-20 15:37:54 +00:00
Daan De Meyer
e1f9de9739 mkosi: update fedora commit reference to 12f95f807fef5075a8842dd107f83b4c41d5ac26
* 12f95f807f Wrap %autosetup in %_build_in_place check
* f9916b6fd1 Revert "Use %autosetup -C"
* 044cff4700 Allow empower group
* a0acca210d Version 259~rc1
* e455d82fd8 Add various extra explicit Requires
* 1a7506a105 Version 258.2
* 256463d690 Restore runlevelX.target units
* b17d9c3474 Use %autosetup -C
* fe18084a05 Remove hack to stop systemd-networkd-resolve-hook.socket
2025-11-20 15:26:26 +01:00
Mike Yuan
53eda862c1 labeler: shell-completion -> "shell completion"
The latter is what we actually use. We didn't observe the issue
because the rule was effectively inactive before
bcf95c4116.
2025-11-20 14:13:20 +00:00
Yu Watanabe
6df082a039 pam_systemd: fix OSC write failure message appearing in error logs (#39791) 2025-11-20 23:07:00 +09:00
Lennart Poettering
b5dbe7179b apparmor-util: shortcut mac_apparmor_use() if compile-time disabled 2025-11-20 14:21:56 +01:00
Lennart Poettering
c3b3eea2e5 apparmor: move dlopen() into mac_apparmor_use() check
This mirrors what we do for mac_selinux_use(), which also loads
libselinux.
2025-11-20 14:19:56 +01:00
Daan De Meyer
8137c6bf2d mkosi: Install valgrind in tools tree 2025-11-20 12:03:01 +01:00
val4oss
6c32492932 pam_systemd: fix OSC write failure message appearing in error logs
Create and use new function pam_debug_syslog_errno() instead to ensure the
message only appears when debug mode is enabled. Pass the debug flag to
open_osc_context() and close_osc_context() to support this change.
2025-11-20 11:43:01 +01:00
val4oss
bc9dc63f4f pam-util: fix pam_syslog_errno() ignoring the level parameter
The function accepts a level parameter but was always logging at
LOG_ERR. Fix by passing the level parameter to sym_pam_vsyslog()
instead of hardcoding LOG_ERR.

This caused debug and warning messages to incorrectly appear in error
logs.
2025-11-20 11:00:48 +01:00
Daan De Meyer
3c6af4cc79 Make file-hierarchy.7 link to two online docs and drop most of the contents (#39412) 2025-11-20 09:56:41 +01:00
Christoph Anton Mitterer
b3d99e2308 man: improve BindsTo= documentation
Make “effect” plural to indicate that BindsTo= also includes the other effects
of Requires= (like starting the listed units).

The documentation of Requires= already describes that the configuring unit is
stopped/restarted if any of the list units is explicitly stopped/restarted.
This made the previous wording “in addition to the effect of Requires, it
declares that if the unit bound to is stopped, this unit will be stopped too.”
ambiguous – this is no in addition, Requires= already does that, at least for
some (namely the explicit) cases.
Resolve this by making it clear what the actual difference to Requires= is and
further mention that this also includes failed units.

Signed-off-by: Christoph Anton Mitterer <mail@christoph.anton.mitterer.name>
2025-11-20 09:51:08 +01:00
Frantisek Sumsal
3605b3ba87 timer: rebase last_trigger timestamp if needed
After bdb8e584f4 we stopped rebasing the
next elapse timestamp unconditionally and the only case where we'd do
that was when both last trigger and last inactive timestamps were empty.
This covered timer units during boot just fine, since they would have
neither of those timestamps set. However, persistent timers
(Persistent=yes) store their last trigger timestamp on a persistent
storage and load it back after reboot, so the rebasing was skipped in
this case.

To mitigate this, check the last_trigger timestamp is older than the
current machine boot - if so, that means that it came from a stamp file
of a persistent timer unit and we need to rebase it to make
RandomizedDelaySec= work properly.

Follow-up for bdb8e584f4.

Resolves: #39739
2025-11-20 09:47:11 +01:00
Zbigniew Jędrzejewski-Szmek
72cbc28347 meson: sort shell completions and exit earlier when shell completion is disabled (#39816) 2025-11-20 08:35:21 +01:00
Zbigniew Jędrzejewski-Szmek
0f7d3e34e1 Avoid multiple evaluations in STRERROR_XYZ() macros (#39794) 2025-11-20 08:29:32 +01:00
Yu Watanabe
d2b8e42742 meson: exit earlier from the subdirectory when bash/zshcompletiondir is 'no' 2025-11-20 14:50:30 +09:00
Yu Watanabe
c74dc8cf14 meson: sort shell completions 2025-11-20 14:48:33 +09:00
Luca Boccassi
f16518ce86 shell-completion: add bash script for varlinkctl 2025-11-20 14:34:40 +09:00
Yu Watanabe
70fa7d4ccc core: SMACK label to Unix socket path and FD (#39772)
Currently, when a socket unit specifies SmackLabel=,
the label is not applied to the underlying Unix socket file or its file
descriptor.

This change ensures that the SMACK label is applied both to the
Unix socket path on the filesystem and to all associated socket FDs
when the socket is created.

Testing:

- Tested on Fedora 43 with kernel 6.17.7 with SMACK enabled.
- Created a systemd socket unit:

    [Unit]
    Description=UNIX socket

    [Socket]
    ListenStream=/run/test.sock
    SmackLabel=label

    [Install]
    WantedBy=sockets.target

- Created a corresponding service:

    [Unit]
    Description=UNIX socket service
    Requires=test.socket

    [Service]
    ExecStart=/usr/bin/socat -v - -
    StandardInput=socket

    [Install]
    WantedBy=multi-user.target

- Verified SMACK labels using getfattr:

  - Without SmackLabel:
    ```
    # file: run/test.sock
    security.SMACK64="_"
    # file: proc/<pid>/fd/*
    security.SMACK64="*"
    ```
  - With SmackLabel=label:
    ```
    # file: run/test.sock
    security.SMACK64="label"
    # file: proc/<pid>/fd/*
    security.SMACK64="label"
    ```
2025-11-20 13:23:51 +09:00
Yu Watanabe
5de39570c8 Simplify source lists in meson config (#39811) 2025-11-20 13:20:41 +09:00
Yu Watanabe
a7947d54db NEWS: fix typo 2025-11-20 10:08:38 +09:00
Zbigniew Jędrzejewski-Szmek
5220bb8c3f meson: automatically add 'extract' to 'sources'
In all cases, everything that we list in 'extract', we also list in
'sources'. We can simplify things by automatically appending the first
list to the second.

In the listings, move 'extract' key right below 'sources', since now
they are both "sources", just with slightly different meanings.
2025-11-20 10:03:48 +09:00
Marc-Antoine Riou
360f750b01 socket-label: apply SMACK label to socket and its file descriptor
When a socket unit specifies SmackLabel=, the label was previously
not applied to the underlying Unix socket file or its file descriptor.
This change ensures that the SMACK label is applied both to the
socket path on the filesystem and to the opened socket FD.
2025-11-20 09:59:37 +09:00
Yu Watanabe
cb4b36928a socket-label: move prototype of socket_address_listen() and string table for SocketAddressBindIPv6Only
The function socket_address_listen() is declared at shared/socket-label.c,
however its prototype was in basic/socket-util.h. This moves the
prototype to shared/socket-label.h.

Also, enum SocketAddressBindIPv6Only is not used anymore in basic/*.[ch].
Let's move the definition and its string table to shared/socket-label.[ch].

Follow-up for b25a930f0e.
2025-11-20 09:58:53 +09:00
Yu Watanabe
5feb65c5b1 user-util: avoid double evaluation in STRERROR_USER/GROUP()
Follow-up for 6e6e96f628.
2025-11-20 09:07:57 +09:00
Yu Watanabe
459000e8c5 errno-util: avoid double evaluation in STRERROR_OR_EOF()
Follow-up for f69ae8585f.
2025-11-20 09:04:35 +09:00
Yu Watanabe
18f280a478 test: fix tested function name
The test tests STRERROR_OR_EOF(), but logged as STRERROR_OR_ELSE.
2025-11-20 08:58:37 +09:00
Yu Watanabe
3f91ffe0fe core: Verify inherited FDs are writable for stdout/stderr (#39674)
When inheriting file descriptors for stdout/stderr (either from stdin or
when making stderr inherit from stdout), we previously just assumed they
would be writable and dup'd them. This could lead to broken setups if
the inherited FD was actually opened read-only.

Before dup'ing any inherited FDs to stdout/stderr, verify they are
actually writable using the new fd_is_writable() helper. If not, fall
back to /dev/null (or reopen the terminal in the TTY case) with a
warning, rather than silently creating a broken setup where output
operations would fail.
2025-11-20 08:19:46 +09:00
Quentin Deslandes
5b0e262f45 network: clear existing routes if Gateway= is empty in [Network]
Add support for an empty Gateway= in [Network] to clear the existing
routes. This change will allow users to remove the default route from a
drop-in file.
2025-11-20 07:16:26 +09:00
Zbigniew Jędrzejewski-Szmek
9d7a70003d man: add 'testing' as one of the suggestions for DEPLOYMENT=
Looking at the list, "test" or "testing" seems to be a fairly generic entry
that is missing from the list of suggestions. I went with "testing" because it
fits better with the other item, e.g. "staging".

In https://github.com/systemd/systemd/issues/38743 "laboratory" was also
suggested. I didn't include this because that is more about the location, not
deployment type. Any of the other deployments could be in a "laboratory".

Closes https://github.com/systemd/systemd/issues/38743.
2025-11-19 22:01:15 +01:00
Chris Down
0b7dfc036d tests: ASSERT_SIGNAL: Prevent hallucinating parent as child and confusing exit codes with signals (#39807)
This series fixes two distinct, pretty bad bugs in `ASSERT_SIGNAL`.
These bugs can allow failing tests to pass, and can also cause the test
runner to silently terminate prematurely in a way that looks like
success.

This is not theoretical, see
https://github.com/systemd/systemd/pull/39674#discussion_r2540552699 for
a real case of this happening.

---

Bug 1: Parent process hallucinates it is the child and re-executes the
expression being tested

Previously, assert_signal_internal() returned 0 in two mutually
exclusive states:

1. We are the child process (immediately after fork()).
2. We are the parent process, and the child exited normally (status 0).

The macro failed to distinguish these cases. If a child failed to crash
as expected, the parent received 0, incorrectly interpreted it as it
being the child, and re-executed the test expression inside the parent
process.

This can cause tests to falsely pass. The parent would successfully run
the expression (which wasn't supposed to crash in the parent), succeed,
and call _exit(EXIT_SUCCESS).

The second consequence is silent truncation. When the parent called
_exit(), it terminated the entire test runner immediately. Any
subsequent tests in the same binary were never executed.

---

Bug 2: Conflation of exit codes and signals

The harness returned the raw si_status without checking si_code. This
meant that an exit code was indistinguishable from a signal number. For
example, if a child process failed and called exit(6), the harness
reported it as having been killed by SIGABRT (signal 6).

---

This PR both fixes the bugs and reworks the ASSERT_SIGNAL infrastructure
to ensure this is very unlikely to regress:

- assert_signal_internal now returns an explicit control flow enum
(FORK_CHILD / FORK_PARENT) separate from the status data. This makes it
structurally impossible for the parent to hallucinate that it is the
child.
- The output parameter is only populated with a signal number if si_code
confirms the process was killed by a signal. Normal exits return 0.
2025-11-20 03:52:02 +08:00
Luca Boccassi
6d36d07599 docs: elf metadata specs have moved to uapi-group 2025-11-19 20:00:25 +01:00
Chris Down
e21a431ec4 tests: ASSERT_SIGNAL: Do not allow parent to hallucinate it is the child
assert_signal_internal() returns 0 in two distinct cases:

1. In the child process (immediately after fork returns 0).
2. In the parent process, if the child exited normally (no signal).

ASSERT_SIGNAL fails to distinguish these cases. When a child exited
normally (case 2), the parent process receives 0, incorrectly interprets
it as meaning it is the child, and re-executes the test expression
inside the parent process. Goodness gracious!

This causes two severe test integrity issues:

1. False positives. The parent can run the expression, succeed, and call
   _exit(EXIT_SUCCESS), causing the test to pass even though no signal
   was raised.
2. Silent truncation. The _exit() call in the parent terminates the test
   runner prematurely, preventing subsequent tests in the same file from
   running.

Example of the bug in action, from #39674:

    ASSERT_SIGNAL(fd_is_writable(closed_fd), SIGABRT)

This test should fail (fd_is_writable does not SIGABRT here), but with
the bug, the parent hallucinated being the child, re-ran the expression
successfully, and exited with success.

Fix this by refactoring assert_signal_internal() to be much more strict
about separating control flow from data.

The signal status is now returned via a strictly typed output parameter,
guaranteeing that determining whether we are the child is never
conflated with whether the child exited cleanly.
2025-11-20 02:40:07 +08:00
Chris Down
d759ed527c tests: ASSERT_SIGNAL: Ensure sanitisers do not mask expected signals
ASAN installs signal handlers to catch crashes like SIGSEGV or SIGILL.
When these signals are raised, ASAN traps them, prints an error report,
and then typically terminates the process with a different signal (often
SIGABRT) or a non-zero exit code.

This interferes with ASSERT_SIGNAL when checking for specific crash
signals (for example, checking that a function raises SIGSEGV). In such
a case, the test harness sees the ASAN termination signal rather than
the expected signal, causing the test to fail.

Fix this by resetting the signal handler to SIG_DFL in the child process
immediately before executing the test expression. This ensures the
kernel kills the process directly with the expected signal, bypassing
ASAN's interceptors.
2025-11-20 02:40:07 +08:00
Chris Down
39adecfcd8 tests: ASSERT_SIGNAL: Stop exit codes from masquerading as signals
When a child process exits normally (si_code == CLD_EXITED),
siginfo.si_status contains the exit code. When it is killed by a signal
(si_code == CLD_KILLED or CLD_DUMPED), si_status contains the signal
number.  However, assert_signal_internal() returns si_status blindly.
This causes exit codes to be misinterpreted as signal numbers.

This allows failing tests to silently pass if their exit code
numerically coincides with the expected signal. For example, a test
expecting SIGABRT (6) would incorrectly pass if the child simply exited
with status 6 instead of being killed by a signal.

Fix this by checking si_code. Only return si_status as a signal number
if the child was actually killed by a signal (CLD_KILLED or CLD_DUMPED).
If the child exited normally (CLD_EXITED), return 0 to indicate that no
signal occurred.
2025-11-20 02:40:07 +08:00
Chris Down
171ceb4a00 core: Verify inherited FDs are writable for stdout/stderr
When inheriting file descriptors for stdout/stderr (either from stdin
or when making stderr inherit from stdout), we previously just assumed
they would be writable and dup'd them. This could lead to broken setups
if the inherited FD was actually opened read-only.

Before dup'ing any inherited FDs to stdout/stderr, verify they are
actually writable using the new fd_is_writable() helper. If not, fall
back to /dev/null (or reopen the terminal in the TTY case) with a
warning, rather than silently creating a broken setup where output
operations would fail.
2025-11-20 02:02:21 +08:00