Commit Graph

82724 Commits

Author SHA1 Message Date
DaanDeMeyer
88444243b8 ruff: Default to python 3.7 version
For some use cases we still want python 3.7 compat so let's default
to that and only target python 3.9 in a few specific cases.
2025-07-10 18:09:17 +02:00
Li Tian
b6d4997683 Add --entry-type=type1|type2 option to kernel-install.
Both kernel-core and kernel-uki-virt call kernel-install upon removal. Need an additional argument to avoid complete removal for both traditional kernel and UKI.

Signed-off-by: Li Tian <litian@redhat.com>
2025-07-10 18:07:23 +02:00
DaanDeMeyer
33a5cc768c socket-activate: Always send NOTIFY=ready
Even if we're not using --accept=, it's very useful to be able to
synchronize on systemd-socket-activate having binded to its listen
socket, so let's always send READY=1. This means the payload can't
send READY=1 anymore but it's doubtful whether that's useful in this
case in the first place.
2025-07-10 16:19:46 +02:00
Daan De Meyer
6a9cb1936f Two trivial nspawn fixes (#38152) 2025-07-10 16:19:18 +02:00
DaanDeMeyer
1f24a954e4 vmspawn: Use virtio-blk-pci for image instead of virtio-scsi-pci
We don't need a full blown SCSI controller just to present the main
root drive device to the VM. Let's simplify the storage stack by using
virtio-blk-pci instead.

Additionally, virtio-blk-pci is a builtin module in Arch and Fedora
which means we can do qemu direct kernel boot without needing an initrd.
2025-07-10 16:18:33 +02:00
DaanDeMeyer
6ed684db41 escape: Make quote_command_line() argument const 2025-07-10 16:18:10 +02:00
DaanDeMeyer
8ba6c2b7f5 vmspawn: Disable hpet for vmspawn x86 virtual machines
hpet is an emulated clocksource that is generally discouraged in favor
of kvm-clock or tsc for virtual machines. While vmspawn's virtual machines
already use kvm-clock, leaving hpet enabled causes qemu on the host to
consume a non-trivial amount of cpu, so let's disable the hpet feature since
we're not making use of it anyway.
2025-07-10 16:14:52 +02:00
Yu Watanabe
0b565facc4 Revert "resolve: query the parent zone for DS records"
This reverts commit 49ff90c70d.
2025-07-10 15:18:07 +02:00
DaanDeMeyer
4f54d81ace nspawn: Use in_child_chown() in one more place 2025-07-10 13:55:45 +02:00
DaanDeMeyer
6f60ce002b nspawn: Improve log message 2025-07-10 13:55:43 +02:00
Eisuke Kawashima
dc6e9c548b zsh-completion: generate completion for systemd-run from systemd-analyze
continuation of #37641
2025-07-10 11:39:06 +02:00
Jörg Behrmann
693f11d5ba news: fix typo 2025-07-10 10:23:28 +02:00
Christian Hesse
8dfe176adc man: clean up list of literals 2025-07-10 15:23:56 +09:00
Yu Watanabe
0777d821ad ci: also set TEST_RUNNER environment variable in coverage test
Otherwise, integration-test-wrapper.py will fail.
```
Traceback (most recent call last):
  File "/home/runner/work/systemd/systemd/test/integration-tests/integration-test-wrapper.py", line 693, in <module>
    main()
    ~~~~^^
  File "/home/runner/work/systemd/systemd/test/integration-tests/integration-test-wrapper.py", line 677, in main
    runner = os.environ['TEST_RUNNER']
             ~~~~~~~~~~^^^^^^^^^^^^^^^
  File "<frozen os>", line 717, in __getitem__
KeyError: 'TEST_RUNNER'
```

Follow-up for c0a5801f7b.
2025-07-10 07:39:15 +02:00
Yu Watanabe
f436c64e61 man: fix typo
Follow-up for 7baf403430.
2025-07-10 14:02:00 +09:00
Zbigniew Jędrzejewski-Szmek
85830b0d62 ukify: fix version detection for aarch64 zboot kernels with gzip or lzma compression
Fixes https://github.com/systemd/systemd/issues/34780. The number in the header
is the size of the *compressed* data, so for gzip we'd read the initial part of
the decompressed data (equal to the size of the compressed data) and not find
the version string. Later on, Fedora switched to zstd compression, and there we
correctly use the number as the size of the compressed data, so we stopped
hitting the issue, but we should still fix it for older kernels.

I verified that the fix works for gzip-compressed kernels. I also made the same
change for the code for lzma compression. I'm pretty sure it is the right thing,
even though I don't have such a kernel at hand to test.

>>> ukify.Uname.scrape('/lib/modules/6.12.0-0.rc2.24.fc42.aarch64/vmlinuz')
Real-Mode Kernel Header magic not found
+ readelf --notes /lib/modules/6.12.0-0.rc2.24.fc42.aarch64/vmlinuz
readelf: Error: Not an ELF file - it has the wrong magic bytes at the start
Found uname version: 6.12.0-0.rc2.24.fc42.aarch64
2025-07-10 13:37:07 +09:00
Zbigniew Jędrzejewski-Szmek
d871e07285 TEST-04-JOURNAL: drop unexpected whitespace 2025-07-10 13:37:07 +09:00
Lennart Poettering
03b4a607f6 core: followups for the recent subgroup killing commits
This is a follow-up for 0f23564ad4 and
6b02854f50, as suggested here:

https://github.com/systemd/systemd/pull/37855#pullrequestreview-2997596953
2025-07-10 13:32:51 +09:00
Antonio Alvarez Feijoo
dee77ac201 generate-bpf-delegate-configs: fix compatibility with Python 3.7
- Operator ":=" requires Python 3.8 or newer.
- list[str] requires Python 3.9 or newer.

Follow-up for ea9826eb94
2025-07-10 13:30:44 +09:00
Yu Watanabe
1cf5b39d64 core: add 'DefaultRestrictSUIDSGID' config option (#38126)
closes #37602, see there for extra motivation and considered
alternatives.

On typical systems, only few services need to create SUID/SGID files.
This often is limited to the user explicitly setting suid/sgid, the
`systemd-tmpfiles*` services, and the package manager. Allowing a
default to globally restrict creation of suid/sgid files makes it easier
to apply this restriction precisely.

## testing done
- built on aarch64-linux and x86_64-linux
- ran a VM test on x86_64-linux, checking for:
    - VM system boots successfully
    - defaults apply (both `yes`, `no`, and undefined)
    - systemd tmpfiles can set suid/sgid on journal log path
- Other services explicitly defining `RestrictSUIDSGID=no` can create
suid files
2025-07-10 13:30:07 +09:00
Yu Watanabe
6e619d6c8d man/systemd.exec: update documentation for PrivateBPF= (#38142)
Follow-up for #36134

Add a short description about what PrivateBPF=yes does and how it can be
useful.
2025-07-10 13:13:54 +09:00
Matteo Croce
7baf403430 man/systemd.exec: update documentation for PrivateBPF=
Add a short description about what PrivateBPF=yes does
and how it can be useful.
2025-07-10 01:57:14 +02:00
Matteo Croce
6b099b8369 man/systemd.exec: use constant instead of literal
Use <constant> instead of <literal> otherwise every configuration item
is wrapped in double quotes.
2025-07-10 01:26:46 +02:00
Lennart Poettering
733454ae8f update TODO 2025-07-09 22:32:31 +02:00
Grimmauld
0316fb8219 core: document 'DefaultRestrictSUIDSGID' 2025-07-09 21:45:46 +02:00
Grimmauld
aa668230c9 core/varlink-manager: Support 'DefaultRestrictSUIDSGID' option 2025-07-09 21:45:41 +02:00
Grimmauld
97998d1cbe core/dbus-manager: Support 'DefaultRestrictSUIDSGID' option 2025-07-09 21:45:38 +02:00
Lennart Poettering
726183627b cgroup: handle ENODEV on cg_read_pid() gracefully
The recently added test case TEST-07-PID1.subgroup-kill.sh surfaced a
race: if we enumerate PIDs in a cgroup, and the cgroup is unlinked at
the very same time reading will result in ENODEV. We need to handle that
gracefully. Hence let's do so.

Noticed while looking at:

https://github.com/systemd/systemd/actions/runs/16143084441/job/45554929264?pr=38120
2025-07-09 20:45:59 +02:00
Yu Watanabe
da412f3be2 recurse-dir: coding style cleanups; mount-util: teach open_tree_attr_fallback() our usual AT_EMPTY_PATH trick (#38130) 2025-07-10 03:32:33 +09:00
Grimmauld
30bbdf0771 core: add 'DefaultRestrictSUIDSGID' config option
closes #37602

On typical systems, only few services need to create SUID/SGID files.
This often is limited to the user explicitly setting suid/sgid, the
`systemd-tmpfiles*` services, and the package manager. Allowing a default
to globally restrict creation of suid/sgid files makes it easier to apply
this restriction precisely.
2025-07-09 11:08:34 +02:00
Grimmauld
fd3b207011 units/systemd-tmpfiles-setup.service: explicitly set RestrictSUIDSGID=no
The tmpfiles service is used to set file permissions, e.g. for setting
suid bit on the journal log directory [1].

[1] 48e0f7bc2f/tmpfiles.d/systemd.conf.in (L24-L25)
2025-07-09 11:08:31 +02:00
Fabian Vogt
e21cd6db9c units/initrd-cleanup.service: Conflict with emergency.target
This is very similar to 327cd2d3db:

If emergency.target is started while initrd-cleanup.service/start is queued,
the initrd-cleanup job did not get canceled. In parallel to the emergency
units, it eventually runs the service, which in turn isolates and starts
initrd-switch-root.target. This stops the emergency units and effectively
starts the initrd boot process again, which likely fails again like the
initial attempt. The system is thus stuck in a loop, never really reaching
emergency.target.

This can be triggered if a service in between initrd-parse-etc.service
and initrd.target fails.

With this conflict added, starting emergency.target automatically cancels
initrd-cleanup.service/start, avoiding the loop.
2025-07-09 10:28:29 +02:00
Mike Yuan
56c6d90f8c mount-util: teach open_tree_attr_fallback() our usual AT_EMPTY_PATH trick
While at it, rename it to _with_fallback following
the naming scheme we use elsewhere.
2025-07-09 10:14:00 +02:00
Mike Yuan
2b4999acb4 mount-util: regroup functions 2025-07-09 10:14:00 +02:00
Mike Yuan
ba010e14f2 recurse-dir: switch to FOREACH_ARRAY 2025-07-09 10:13:59 +02:00
Mike Yuan
8d4b2689ca recurse-dir: use -EBADF as placeholder for invalid fd
As per our coding style.
2025-07-09 10:13:59 +02:00
Yu Watanabe
f17c49c569 Add support for BPF tokens (#36134)
Add a new option `PrivateBPF=` to mount a private instance of bpffs.
Add also four configuration options
`BPFDelegate{Commands,Maps,Programs,Attachments}=` which set the
corresponding bpffs mount options in order to create BPF tokens:
https://lwn.net/Articles/947173/

Closes#35108.
2025-07-09 15:12:22 +09:00
Matteo Croce
ea9826eb94 core: add options to delegate BPFFS token creation
Add four new options BPFDelegate{Commands,Maps,Programs,Attachments}=
in order to delegate to a BPFFS instance the permission to create tokens.

The value is a list of options taken from:
https://github.com/torvalds/linux/blob/v6.14/include/uapi/linux/bpf.h#L922-L1121
The special value "any" means to allow every possible values.

More informations about BPF tokens here:
https://lwn.net/Articles/947173/
2025-07-08 22:35:29 +02:00
Matteo Croce
3a47437fc9 core: Introduce PrivateBPF= to mount a private BPFFS
Add a new option PrivateBPF= to mount a new instance of bpffs within a
namespace.
PrivateBPF= can be set to "no" to use the host bpffs in readonly mode
and "yes" to do a new mount.
The mount is done with the new fsopen()/fsmount() API because in future
we'll hook some commands between the two calls.
2025-07-08 22:33:28 +02:00
Matteo Croce
2c7dabff50 core: split out setup_private_users_child()
Drop support for kernels older than 3.19, as this is where
/proc/<pid>/setgroups was added.

9cc46516dd
2025-07-08 18:23:46 +02:00
Matteo Croce
9554ac3052 tests: run test with CAP_BPF
Add CAP_BPF to tests run with nspawn, so we don't have to use a VM
to test BPF calls.
2025-07-08 18:23:46 +02:00
Matteo Croce
a80c06cf02 nspawn: create mountpoint for bpffs
When we mount a tmpfs as /sys, create a mountpoint for bpf, as we
already do for cgroup
2025-07-08 18:23:46 +02:00
Yu Watanabe
48e0f7bc2f core: fix owner check of PIDFile=, and update document (#38115)
Closes #38108.
2025-07-08 23:58:19 +09:00
Yu Watanabe
4fef8b916e A few changes related to linking and bitfields (#38118) 2025-07-08 23:57:44 +09:00
Zbigniew Jędrzejewski-Szmek
6eb805f42a meson: drop -ffunction-sections -fdata-sections
I added them in 41afb5eb72 without too
much explanation. Most likely the idea was to get rid of unused code
in libsystemd.so [1]. But now that I'm testing this, it doesn't seem
to have an effect. LTO is needed to get rid of unused functions, and
it's enough to have LTO without those options. Those options might have
some downsides [2], so let's disable them since there are doubts and no
particularly good reason to have them.

But keep the -Wl,--gc-sections option. Without this, libsystemd.so
grows a little:
-rwxr-xr-x 1 zbyszek zbyszek 5532424 07-08 13:24 build/libsystemd.so.0.40.0-orig
-rwxr-xr-x 1 zbyszek zbyszek 5614472 07-08 13:26 build/libsystemd.so.0.40.0-no-sections
-rwxr-xr-x 1 zbyszek zbyszek 5532392 07-08 13:27 build/libsystemd.so.0.40.0

Let's apply the --gc-sections option always to make the debug and final
builds more similar.

We need to verify that distro packages don't unexpectedly grow after this.

[1] https://unix.stackexchange.com/a/715901
[2] https://stackoverflow.com/a/36033811
2025-07-08 14:51:56 +02:00
Zbigniew Jędrzejewski-Szmek
048a94c8f6 basic/stdio-util: use a fixed message in xsprintf
We put the name of the variable in the message, but it is a local variable
and the name does not have global meaning. We end up with pointless copies
of the error string:

$ strings build/libsystemd.so.0.40.0 | grep 'big enough'
xsprintf: p[] must be big enough
xsprintf: error[] must be big enough
xsprintf: prefix[] must be big enough
xsprintf: pty[] must be big enough
xsprintf: mode[] must be big enough
xsprintf: t[] must be big enough
xsprintf: s[] must be big enough
xsprintf: spid[] must be big enough
xsprintf: header_priority[] must be big enough
xsprintf: header_pid[] must be big enough
xsprintf: path[] must be big enough
xsprintf: buf[] must be big enough

The error message already shows the file, line, and function name, which
is enough to identify the problem:

  Assertion 'xsprintf: buffer too small' failed at src/test/test-string-util.c:20, function test_xsprintf(). Aborting.
2025-07-08 13:02:37 +02:00
Zbigniew Jędrzejewski-Szmek
1e99c4e2be test-string-util: add a small test for xsprintf 2025-07-08 13:02:37 +02:00
Zbigniew Jędrzejewski-Szmek
c179466616 Merge shared/exec-directory-util.? into basic/unit-def.?
Suggested in
https://github.com/systemd/systemd/pull/35892#discussion_r2180322856.

This is a tiny amount of code and does not warrant having a separate file
and spawning a separate instance of the compiler during the build.

Note: it took me a while to confirm that the contents of that table and
function don't end up in libsystemd.so. The issue is that they _are_ present in
it, unless LTO is used. We actually use link_whole[libbasic_static] for
libsystemd, so we end up with all that code there. LTO is needed to clean
that up.
2025-07-08 12:57:33 +02:00
Yu Watanabe
293cc8866d man: mention relative PIDFile= in user service is prefixed with $XDG_RUNTIME_DIR 2025-07-08 18:02:38 +09:00
Yu Watanabe
7e26912677 core: allow to use PIDFile= in user session services
Fixes #38108.

Co-authored-by: 铝箔 <38349409+Sodium-Aluminate@users.noreply.github.com>
2025-07-08 18:02:34 +09:00