Commit Graph
56037 Commits
Author SHA1 Message Date
Luca Boccassi 855b6b77e0 test: fix typo in comment 2025-08-16 10:53:07 +01:00
Luca Boccassi fd51a7d8b5 pidfd-util: force alignment of file_handle union to avoid assert on 32bit
On 32bit the union won't be aligned automatically, needs to be enforced:

Assertion '((uintptr_t) _p) % alignof(uint64_t) == 0' failed at src/basic/pidfd-util.c:251, function pidfd_get_inode_id_impl(). Aborting.

Follow-up for 9c039ef5ff
2025-08-15 12:36:20 +01:00
Mate KukriandTobias Heider 428cd7bfba Reuse the parent_image handle and parent_loaded_image
- Reuse parent_image instead of allocating new ones. Firmware might cast
  EFI_LOADED_IMAGE_PROTOCOL * to a larger struct causing issues
- Remove loaded image protocol installation and uninstallation which are no
  longer required

Fixes a bug introduced by cab9c7b5a4.
Fixes #38567.

Co-authored-by: Tobias Heider <tobias.heider@canonical.com>
2025-08-14 19:59:37 +09:00
Yu Watanabe 1a360ed196 condition: fix unexpected assertion triggered
Follow-up for c154bb65ad.
Fixes oss-fuzz#438513119.
Fixes #38570.
2025-08-14 10:31:03 +01:00
Luca Boccassi 4f9f0e5041 ukify: drop NX bit from UKI if kernel doesn't have it
If the kernel is not NX_COMPAT ready (W^X memory compatible) then the
UKI should not be marked as NX_COMPAT ready either, as the kernel
section is the loadable code in the image.

https://microsoft.github.io/mu/WhatAndWhy/enhancedmemoryprotection/
https://www.kraxel.org/blog/2023/12/uefi-nx-linux-boot/

While the sd-stub EFI code itself is NX ready, it is more useful
to think of it as one unit of execution together with the kernel
it embeds, as that's what it is used for.

Fixes https://github.com/systemd/systemd/issues/38545
2025-08-14 03:49:20 +09:00
Yu Watanabe 30f1d29f39 tree-wide: various terminal related fixlets (#38544)
Fixes #38524.
Fixes #38527.
Fixes #38552.
2025-08-14 03:40:44 +09:00
Yu Watanabe 660244a7fc core: do not start watchdog for frozen service on daemon-reload/-reexec (#38553)
Fixes #38551.
2025-08-14 01:18:50 +09:00
Yu Watanabe 2633ed01ca import: add a debugging log of importing blob
This should be helpful for debugging issue #38524.
2025-08-13 23:44:58 +09:00
Yu Watanabe defac931c0 import: align table 2025-08-13 23:44:58 +09:00
Yu Watanabe 00085ba6c2 import,sysupdate: make notify event processed before SIGCHLD of worker processes
This fixes the following warning:
```
[    5.628796] TEST-13-NSPAWN.sh[299]: + importctl import-raw --class=confext /var/tmp/importtest
(snip)
[    5.638894] systemd-importd[302]: (transfer1) Operation completed successfully.
[    5.640760] TEST-13-NSPAWN.sh[318]: ^MTotal:   0%^MTotal:  40%
[    5.638902] systemd-importd[302]: (transfer1) Exiting.
[    5.638931] systemd-importd[302]: Got percentage from client: 40%
[    5.638956] systemd-importd[302]: Transfer process succeeded.
[    5.638988] systemd-importd[302]: Got notification datagram from unexpected peer, ignoring.
```
2025-08-13 23:44:58 +09:00
Yu Watanabe 3796391497 pretty-print: show progress bar only when we are running on a TTY
Otherwise, when a command is running with e.g. StandardError=journal+console,
journal contains [xxxB blob data]:
```
[    5.628796] TEST-13-NSPAWN.sh[299]: + importctl import-raw --class=confext /var/tmp/importtest
[    5.632350] systemd-importd[302]: Successfully forked off '(sd-transfer)' as PID 319.
[    5.633671] TEST-13-NSPAWN.sh[318]: [83B blob data]
[    5.632598] (sd-transfer)[319]: Calling: /usr/lib/systemd/systemd-import raw --class confext - importtest
[    5.637769] systemd-importd[302]: (transfer1) Importing '/var/tmp/importtest', saving as 'importtest'.
[    5.637947] TEST-13-NSPAWN.sh[318]: [82B blob data]
[    5.638313] TEST-13-NSPAWN.sh[318]: [75B blob data]
[    5.638151] systemd-importd[302]: (transfer1) Operating on image directory '/var/lib/confexts'.
[    5.638863] systemd-importd[302]: (transfer1) Imported 40%.
[    5.638882] systemd-importd[302]: (transfer1) Wrote 40K.
[    5.639653] TEST-13-NSPAWN.sh[318]: [39B blob data]
[    5.639653] TEST-13-NSPAWN.sh[318]: [36B blob data]
[    5.639653] TEST-13-NSPAWN.sh[318]: [59B blob data]
[    5.639653] TEST-13-NSPAWN.sh[318]: [34B blob data]
[    5.638894] systemd-importd[302]: (transfer1) Operation completed successfully.
[    5.640760] TEST-13-NSPAWN.sh[318]: [25B blob data]
[    5.638902] systemd-importd[302]: (transfer1) Exiting.
```
The blob data entries are something like the following:
```
[    5.628796] TEST-13-NSPAWN.sh[299]: + importctl import-raw --class=confext /var/tmp/importtest
[    5.632350] systemd-importd[302]: Successfully forked off '(sd-transfer)' as PID 319.
[    5.633671] TEST-13-NSPAWN.sh[318]: ^M           ^MEnqueued transfer job 1. Press C-c to continue download in background.
[    5.632598] (sd-transfer)[319]: Calling: /usr/lib/systemd/systemd-import raw --class confext - importtest
[    5.637769] systemd-importd[302]: (transfer1) Importing '/var/tmp/importtest', saving as 'importtest'.
[    5.637947] TEST-13-NSPAWN.sh[318]: ^MTotal:   0%^M           ^MImporting '/var/tmp/importtest', saving as 'importtest'.
[    5.638313] TEST-13-NSPAWN.sh[318]: ^MTotal:   0%^M           ^MOperating on image directory '/var/lib/confexts'.
[    5.638151] systemd-importd[302]: (transfer1) Operating on image directory '/var/lib/confexts'.
[    5.638863] systemd-importd[302]: (transfer1) Imported 40%.
[    5.638882] systemd-importd[302]: (transfer1) Wrote 40K.
[    5.639653] TEST-13-NSPAWN.sh[318]: ^MTotal:   0%^M           ^MImported 40%.
[    5.639653] TEST-13-NSPAWN.sh[318]: ^MTotal:   0%^M           ^MWrote 40K.
[    5.639653] TEST-13-NSPAWN.sh[318]: ^MTotal:   0%^M           ^MOperation completed successfully.
[    5.639653] TEST-13-NSPAWN.sh[318]: ^MTotal:   0%^M           ^MExiting.
[    5.638894] systemd-importd[302]: (transfer1) Operation completed successfully.
[    5.640760] TEST-13-NSPAWN.sh[318]: ^MTotal:   0%^MTotal:  40%
[    5.638902] systemd-importd[302]: (transfer1) Exiting.
```

Fixes #38552.
2025-08-13 23:44:58 +09:00
Yu Watanabe d62adb5554 core/execute: add one more FIXME comment 2025-08-13 23:44:58 +09:00
Yu Watanabe 379d9ae222 core: do not touch tty when StandardOutput=/StandardError=journal+console/kmsg+console 2025-08-13 23:44:42 +09:00
Yu Watanabe da34c27bb1 core: make is_terminal_input() and friends inline
Then, rename them to exec_input_is_terminal() and so on.
2025-08-13 23:43:52 +09:00
Yu Watanabe 18924bc784 core: do not print OSC sequence on reverting TTY settings when running on a dumb terminal
Like we do in prepare_terminal() in exec-invoke.c.
2025-08-13 23:43:52 +09:00
Yu Watanabe 92366b8fbc nspawn: always set TERM=dumb when running with a pipe
Otherwise, we will get unexpected OSC sequences.
2025-08-13 23:43:52 +09:00
Yu Watanabe cace9cf6f6 machinectl: set TERM=dumb when running on a dumb terminal or with a pipe
Fixes #38527.
2025-08-13 23:43:51 +09:00
keentux 3e14d02500 detect-virt: bare-metal GCE only for x86 and i386
From the previous changes, bare-metal support has been added by using
the `detect_vm_cpuid()` which works only for x86_64 and i386 architecture.
Do not use this change for other architectures to avoid wrong result of
the detect-virt tool.

Follow-up for fb71571d3a.
Fixes #38125.
2025-08-13 21:16:19 +09:00
Antonio Alvarez Feijoo 13358b7ce2 bootctl: specify that kernel image commands require a kernel image argument 2025-08-13 11:28:22 +01:00
Yu Watanabe b39815ebf7 core/cgroup: allow to set cgroup path for frozen unit
Otherwise, after 'systemctl daemon-reload' or 'daemon-reexec', frozen
units cannot gain cgroup paths and we cannot operate anything on them,
especially, we cannot thaw or stop them.
```
Aug 12 16:26:09 systemd[1]: wd.service: Job 1278 wd.service/stop finished, result=frozen
Aug 12 16:26:09 systemd[1]: Cannot stop frozen unit wd.service.
Aug 12 16:26:09 systemd[1]: wd.service: Cannot realize cgroup for frozen unit.
Aug 12 16:26:09 systemd[1]: Failed to realize cgroups for queued unit wd.service, ignoring: Device or resource busy
```

Follow-up for 23ac08115a.
2025-08-13 10:45:25 +09:00
Yu Watanabe c70816fd09 core/service: do not start watchdog on frozen unit when service manager is reloaded or reexecuted
Otherwise, when service manager is reloaded or reexecuted, watchdong
will be started for frozen services, and they may be killed after
timeout.

Fixes #38551.
2025-08-13 10:38:04 +09:00
Luca Boccassi 998bb9600e test-cgroup: cleanup test cgroup
One test cgroup gets left behind by the test, as it moves itself
into it. Move itself and back to the original cgroup at the end
and clean up.

This fixes a failure when running the test first as root, and then
as unprivileged (initial cleanup fails as the leftover test cgroup
is owned by root).
2025-08-13 10:00:33 +09:00
Luca Boccassi 637b3904c1 tpm2-util: fixlets for tpm2_serialize/_deserialize() (#38520)
Fixes #38507.
2025-08-12 19:54:44 +01:00
Matteo Croce 814bff5e28 core: suppress warning
Avoid definition of `exec_context_get_tty_for_pam` if pam support is
disabled, to avoid the following warning:
```
../src/core/exec-invoke.c:1231:12: warning: ‘exec_context_get_tty_for_pam’ defined but not used [-Wunused-function]
 1231 | static int exec_context_get_tty_for_pam(const ExecContext *context, char **ret) {
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
2025-08-12 19:45:04 +01:00
Yu Watanabe 48d06b99e6 tpm2-util: copy serialized result in tpm2_serialize()
For safety, though typically Esys_Free() is just a simple wrapper of
free(), but let's do unconditionally. See the comment in the code.

While at it, this makes it store the result into struct iovec.
2025-08-12 06:11:34 +09:00
Yu Watanabe 8d40f3f42e tpm2-util: gracefully skip deserialization when no input
While at it, this also makes tpm2_deserialize() take struct iovec.

Fixes #38507.
2025-08-12 06:11:34 +09:00
Lennart Poettering 5bd2538405 Enable KEY_PERFORMANCE key present on Linux 6.17 (#38533)
Linux 6.17 defines a key called KEY_PERFORMANCE for machines that have a
perfomance mode, like Alienware and Dell G-series.
2025-08-11 18:38:58 +02:00
Yu Watanabe 59c26be53c pcrlock: make-policy should use path specified by --policy= rather than --pcrlock
Follow-up for a434270139.
Fixes #38506.
2025-08-11 18:34:07 +02:00
Yu Watanabe 4dfadc90fd include: update kernel headers from v6.17-rc1 2025-08-11 22:22:16 +09:00
Tobias Heider 5a64f158ec chid: don't hardcode magic numbers for non-official CHIDs
They are constructed from EXTRA_CHID_BASE + offset
2025-08-11 11:18:53 +02:00
Yu Watanabe 1405d46bf9 core/exec-invoke: fallback to set TTY specified by TTYPath= to PAM
Follow-up for 2b0087e5b1.
Fixes #38486.
2025-08-11 10:26:51 +09:00
Luca Boccassi 25178aadb2 service: stop/reset watchdog on freeze/thaw
Otherwise the unit will be killed by the watchdog given it's frozen
but the clock keeps ticking

Fixes https://github.com/systemd/systemd/issues/38517
2025-08-11 10:26:32 +09:00
Yu Watanabe d858b1b10a udev-rules: add missing device name prefix in log message
Otherwise, it is hard to find the dump in journal. With this change,
we can find the entry by e.g.
journalctl -b -u systemd-udevd.service DEVICE=eth0

Follow-up for b4ffb77669.
2025-08-09 11:41:57 +01:00
Yu Watanabe 570210eb28 network/bridge-vlan: fix segfault
Fixes a bug introduced by 78738adf88.
Fixes #38515.
2025-08-08 19:39:31 +09:00
Luca Boccassi c892e33979 nspawn: fix recursive bind mounts
Follow-up for 90fa161b5b

Fixes https://github.com/systemd/systemd/issues/38505
2025-08-08 10:53:02 +09:00
Kevin P. Fleming 2fe2ee9adb logging: Improve logging messages related to NFTSet.
The 'NFTSet' directive in various units adds and removes entries in nftables
sets, it does not add or remove entire sets. The logging messages should
indicate that an entry was added or removed, not that a set was added or
removed.
2025-08-07 08:10:02 +09:00
Luca Boccassi f391d6c9ba test: use Europe/Helsinki instead of Europe/Kyiv in test-calendarspec
Europe/Kyiv was added somewhat recently. Use Europe/Helsinki which is
much older and thus works with older tzdata like version 2022a.

line 193: "2016-03-27 03:17:00" new_tz=:Europe/Kyiv
At: Sun 2016-03-27 03:17:00.000000 Europe
Assertion 'r == -ENOENT' failed at src/test/test-calendarspec.c:70, function _test_next(). Aborting.

Follow-up for aa077884c1
2025-08-06 16:08:54 +01:00
Luca Boccassi 0fa09581b7 Fix build with older python/glibc/bpf and add CI job to cover it (#38500) 2025-08-06 16:08:18 +01:00
Luca Boccassi 0d333ed8e3 test: fix repeated runs of test-oomd-util by clearing test cgroup
If the test is ran multiple times in a row, without an ephemeral
scope (eg: non-booted nspawn), then subsequent runs will fail as
the test cgroup is not cleared so the previous xattrs are still
present. Trim the test cgroup before and after the test.

Follow-up for 61ff7397d0
2025-08-06 14:09:33 +01:00
Luca Boccassi 14cb1fba91 test: fix assert when running test-cgroup in container
When running in nspawn and thus from the namespaced root cgroup:

Paths for test:
//test-a
//test-b
src/test/test-cgroup.c:77: Assertion failed: Expected "path == test_b", got "/test-b != //test-b"

Use path_simplify() in the test like the code does, so that the results
always match
2025-08-06 14:09:33 +01:00
Luca Boccassi 64a4f3110a test-bpf-token: fix build with libbpf < 0.6
../s/src/test/test-bpf-token.c: In function ‘intro’:
../s/src/test/test-bpf-token.c:10:5: error: "__LIBBPF_CURRENT_VERSION_GEQ" is not defined, evaluates to 0 [-Werror=undef]
   10 | #if __LIBBPF_CURRENT_VERSION_GEQ(1, 5)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
../s/src/test/test-bpf-token.c:10:33: error: missing binary operator before token "("
   10 | #if __LIBBPF_CURRENT_VERSION_GEQ(1, 5)

Follow-up for ea9826eb94
2025-08-06 14:09:33 +01:00
Luca Boccassi 7108a882b3 network: fix build with libbpf < 0.7
bpf_loop() and bpf_strncmp(), used by sysctl-monitor, were introduced
in libbpf 0.7, so skip the module if using an older version

Follow-up for 6d9ef22acd
2025-08-06 13:33:21 +01:00
Luca Boccassi 3ec74b96b7 seccomp: fix build with glibc < 2.39
../src/shared/seccomp-util.c: In function ‘seccomp_restrict_sxid’:
../src/shared/seccomp-util.c:2228:25: error: ‘__NR_fchmodat2’ undeclared (first use in this function); did you mean ‘fchmodat2’?
 2228 |                         __NR_fchmodat2,
      |                         ^~~~~~~~~~~~~~
      |                         fchmodat2

The override/sys/syscalls.h needs to be included before the seccomp
headers, otherwise the internal seccomp preprocessor machinery will
not see the local definitions, so the local ifdef will be true but
the seccomp own definitions will be empty
2025-08-06 12:41:03 +01:00
Luca Boccassi 2793d6acf0 meson: fix compatibility with Python 3.7
[8/2759] Generating src/basic/filesystem-sets.c with a custom command (wrapped by meson to capture output)
FAILED: src/basic/filesystem-sets.c
/mnt/work/.local/bin/meson --internal exe --capture src/basic/filesystem-sets.c -- /mnt/work/src/systemd/upstream-fork/main/src/basic/filesystem-sets.py fs-type-to-string filesystem-sets fs-in-group
--- stderr ---
Traceback (most recent call last):
  File "/mnt/work/src/systemd/upstream-fork/main/src/basic/filesystem-sets.py", line 372, in <module>
    generate_fs_in_group()
  File "/mnt/work/src/systemd/upstream-fork/main/src/basic/filesystem-sets.py", line 311, in generate_fs_in_group
    start=[])))
TypeError: sum() takes no keyword arguments
2025-08-06 12:40:27 +01:00
Yu Watanabe 6d30c40d6c user-runtime-dir: fix logged quota size
'v' is a number of blocks, rather than bytes.
2025-08-06 12:54:26 +09:00
Yu Watanabe ef7698f7aa user-runtime-dir: skip setting quota if not requested
Fixes the following spurious warning:

systemd-user-runtime-dir[865]: Failed to set disk quota limit to '15.9P' on /tmp for UID 991, ignoring: Numerical result out of range

Fixes #38493.
2025-08-06 12:54:23 +09:00
Abderrahim Kitouni 83c1e8ff5f updatectl: allow interactive authorization 2025-08-05 17:03:20 +01:00
Luca Boccassi 9cd3e63014 stub: also pickup global .raw sysexts, like per-UKI ones
It is extremely confusing to use different filenames for different
locations, so pick up the same images for both per-UKI and global
extensions

Follow-up for 9f7e3820e9
2025-08-05 17:06:15 +02:00
Yu WatanabeandDeli Zhang 406d8cb029 udev/spawn: continue to read stdout even if the result buffer is full
Previously, when the stdout of a spawned process (e.g. dmi_memory_id) is
truncated, the event source was not re-enabled, that will cause the process
to remain in a write-blocked state if the stdout buffer is full, and the
process will time out:
```
Spawned process 'dmi_memory_id' [1116] timed out after 2min 59s, killing.
Process 'dmi_memory_id' terminated by signal KILL.
```

The solution is to continue enabling the event source so that on_spawn_io()
can continue reading the stdout buffer. When the result buffer is full, the
local `buf` variable will be used to drain remaining stdout.

Co-authored-by: Deli Zhang <deli.zhang@cloud.com>
2025-08-05 10:37:02 +02:00
Yu Watanabe 948b186f46 test-dns-question: use ASSERT_OK_POSITIVE/ZERO() rather than ASSERT_TRUE/FALSE()
Similar to 100a98960a.

E.g. dns_question_contains_key() may return negative errno, hence we
should not use ASSERT_TRUE/FALSE() for the function.

This also has bunch of cleanups:
- call functions in ASSERT_NOT_NULL(),
- add short comments for constant function arguments,
- merge several test cases,
- use memstream, rather than temporal files.

Fixes CID#1619185.
2025-08-04 11:35:03 +01:00