1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-28 20:25:38 +03:00
Commit Graph

65283 Commits

Author SHA1 Message Date
Lennart Poettering
db41880d34
Merge pull request #27902 from poettering/round-up
add ROUND_UP() macro for rounding integer up to next multiple of some value
2023-06-02 21:46:50 +02:00
Lennart Poettering
5596fd8ff7 update TODO 2023-06-02 18:43:11 +02:00
Lennart Poettering
093d545658 test: add integration test for soft reboots incl. fdstore passing 2023-06-02 18:43:11 +02:00
Lennart Poettering
8af66251a1 test: disable SoftReboot() in dfuzzer test for now
As requested:

https://github.com/systemd/systemd/pull/27435#issuecomment-1527810336
2023-06-02 18:43:11 +02:00
Lennart Poettering
4de665812a man: document the soft reboot operation 2023-06-02 18:43:10 +02:00
Lennart Poettering
ba1af88c3c fstab-util: consider /run/nextroot/ among extrinsic mounts
This way we'll not add deps for the mount point that unmount it during
shutdown. This is similar as for /run/initramfs/ which we want to
transition into during shutdown.

This way we don't have to add "-o x-initrd.mount" to all bind mounts for
/run/nextroot anymore to make it survive the reboot, it will be implied.
2023-06-02 18:43:10 +02:00
Lennart Poettering
d585065624 mount-setup: exclude /run/nextroot/ from relabelling
Just like /run/initramfs/ the data in /run/nextroot/ should be a
self-contained OS tree, and not require labelling, hence don't.
2023-06-02 18:43:10 +02:00
Lennart Poettering
f717d7a40a switch-root: automatically make target switch root dir a mount point
Let's make sure implicitly that the target directory is a mount point,
instead of doing so manually beforehand. This allows us to drop this
step from the transition into the /run/initramfs/ dir at shutdown.

During the initrd→host transition the switch root operations so far
where towards pre-existing mount points, but there are cetrainly
usecases where it might make sense to siwtch into arbitrary
subdirectories, too.
2023-06-02 18:43:10 +02:00
Lennart Poettering
f9ad896ee2 mount-util: add fd_make_mount_point() helper 2023-06-02 18:43:10 +02:00
Daan De Meyer
cc532533b8 mkosi: Enable more options
We build with support for selinux/apparmor where applicable but
disable them at runtime as even in permissive mode they're horribly
broken.
2023-06-02 17:25:23 +02:00
Frantisek Sumsal
50fb26d237 test: probe a couple more paths in systemd-run 2023-06-02 16:59:58 +02:00
Lennart Poettering
1795252caa switch-root: disable sync() again when we switch root during shutdown
Our shutdown binary that takes over as PID 1 when shutting down puts
great efforts into a sync() that comes with a time-out once sync'ing
process stops. If we'd add another dumb sync() here, we kinda defeat all
it is good for. Hence, let's keep the sync() in for most codepats, but
let's disable it for the final shutdown logic when we transition back
into the exitrd. After all we sync()ed more than enough here, no need to
sync() even more.
2023-06-02 16:49:39 +02:00
Lennart Poettering
2932161bf6 switch-root: introduce SwitchRootFlags flags parameter to switch_root()
Let's replace the current boolean param with a proper flags param. With
a single flag this doesn't appear to make much sense, though it does
already make things more readable I think.

However, once we add a second flag, it starts to make more sense.

Also, while we are at it, condition the "istmp" determinaton with this
flag too, since we only need it when the flag is set.
2023-06-02 16:49:39 +02:00
Lennart Poettering
7c764d4599 switch-root: always use MS_BIND to move api vfs over
We previously would use MS_MOVE to move the old procfs, sysfs, /dev/ and
/run to the new place in some places, and MS_BIND in others.

The logic when to use MS_MOVE and when to use MS_BIND was pretty
arbitrary so far: we'd use MS_MOVE during the initrd → host transition
and MS_BIND when transitioning from host into the exitrd during
shutdown.

Traditionally, using MS_MOVE was preferable, because we didn't bother
with unmounting the old mount hierarchy before the switch root, and thus
using MS_MOVE did some clean-up as side-effect (because the old mounts
went away this way). But since we nowadays properly umount all remaining
mount points (since 268d1244e8) when
transitioning it's pointless.

Let's just use MS_BIND always. Let's tweak it though: let's use
MS_BIND|MS_REC for the kernel API VFS, and MS_BIND without MS_REC for
/run/. The latter reflects the fact that the submounts /run/ has usually
are not so much about just accessing kernel APIs but about auxiliary
user resources. Hence let's only move the main mount over for that.

While we are at it, also set up the base filesystem *before* we move the
mounts from the old to the new root, since the base filesystem setup
logic creates various needed inodes for us, which we really should make
use of instead of creating on our own.
2023-06-02 16:49:39 +02:00
Lennart Poettering
34f21ff610 systemctl: add "systemctl soft-reboot" command 2023-06-02 16:49:38 +02:00
Lennart Poettering
9edf5af57b logind: add support for 'soft-reboot' reboots 2023-06-02 16:49:38 +02:00
Lennart Poettering
13ffc60749 pid1: add "soft-reboot" reboot method
This adds a new mechanism for rebooting, a form of "userspace reboot"
hereby dubbed "soft-reboot". It will stop all services as in a usual
shutdown, possibly transition into a new root fs and then issue a fresh
initial transaction. The kernel is not replaced.

File descriptors can be passed over, thus opening the door for leaving
certain resources around between such reboots.

Usecase: this is an extremely quick way to reset userspace fully when
updating image based systems, without going through a full
hardware/firmware/boot loader/kernel/initrd cycle. It minimizes "grayout time"
for OS updates. (In particular when combined with kernel live patching)
2023-06-02 16:49:38 +02:00
Lennart Poettering
4dcaab9c89 tree-wide: port various pieces of code over to ROUND_UP()
There's probably more than we can convert to this.
2023-06-02 16:43:39 +02:00
Lennart Poettering
beda8529b9 test-macro: add ROUND_UP() macro for rounding up to next multiple
In case of overflow will return -1 cast to the first parameter type.
2023-06-02 16:41:36 +02:00
Frantisek Sumsal
878ec7942f coverage: add a wrapper for execvpe()
It's the exactly same stuff as for execveat() - gcov doesn't have a
wrapper for execvpe() so introduce our own.
2023-06-02 16:25:06 +02:00
Daan De Meyer
8f9a307fec
Merge pull request #27849 from DaanDeMeyer/sign-pcr
mkosi: Sign expected PCRs
2023-06-02 16:16:41 +02:00
Lennart Poettering
9dd2da5b72 shutdown: tone down failure messages a bit
If we are not able to detach all MD/DM/loopback devices this is not
necessarily a failure, it's simply because we might be running off them.
Hence let's tone down our language a bit, and just say "Unable to"
rather than "Failed to".
2023-06-02 15:56:06 +02:00
Lennart Poettering
9959797dbf detach-loopback: also don't bother detaching loopback block device /usr/ is running off
While we are at it, let's also clean this up a bit: unlike DM/MD devices
loopback devices are likely partitioned, hence trace the block device
through the partition layer and LUKS.
2023-06-02 15:56:06 +02:00
Lennart Poettering
2067a7ec7f detach-md: similar to the DM case, also don't try to detach MD device backing /usr/ 2023-06-02 15:56:06 +02:00
Lennart Poettering
31d346206c shutdown: don't attempt to detach DM volume backing /usr/
Since we run off /usr/ it makes no sense to attempt to try to detach any
DM device backing it. Hence skip it just like we skip detaching the DM
device backing the root fs.

Addresses: https://github.com/systemd/systemd/issues/27682#issuecomment-1573328188
2023-06-02 15:56:06 +02:00
Lennart Poettering
f5fcacdf2c detach-loopback: also decouple from umount.h
Let's introduce LoopbackDevice as replacement for MountPoint, with just
the fields we actually need.
2023-06-02 15:56:06 +02:00
Lennart Poettering
6514a6fd82 detach-md: also decouple structures from umount.h 2023-06-02 15:56:06 +02:00
Lennart Poettering
015937f901 detach-dm: decouple from umount.[ch]
Let's also define our own little structure here with just the fields we
need.
2023-06-02 15:56:06 +02:00
Lennart Poettering
a0fb20672d detach-swap: decouple from umount.h
So far detach-swap.[ch] were still using the MountPoint structure to
store swap device info in. Since it was only using a single field of it
sharing the whole structure is kinda pointless. Hence, let's decouple
this and only add the field we really need.
2023-06-02 15:56:06 +02:00
Lennart Poettering
82a1d6d096 umount: split out swap detachment code too 2023-06-02 15:56:06 +02:00
Lennart Poettering
2e2c472b1c umount: split out loopback detach code
Like the similar commits, no actual code changes, just splitting up
large C files.
2023-06-02 15:56:06 +02:00
Lennart Poettering
b44411c702 umount: similar as previous commit, split out DM detaching 2023-06-02 15:56:06 +02:00
Lennart Poettering
49427110a0 umount: split out MD detaching code from umount.c
umount.c does so much stuff, and MD detaching is relatively separate,
hence split it out into its own .c/.h file pair.
2023-06-02 15:56:06 +02:00
Lennart Poettering
ca6cdd2605 dissect-image: fix partition label version compare
The logic was borked: if we find multiple partitions of the same
designator, we should first prefer the better arch, and then prefer the
better version, and then the first found. Fix that.

Fixes: #27897
2023-06-02 15:54:13 +02:00
Daan De Meyer
a47c48cbb2 mkosi: Only lower device timeout instead of all timeouts
We only really care about lowering the device timeout so we get to
a shell faster when the root device doesn't appear so let's only
lower that timeout instead of lowering all default timeouts.
2023-06-02 15:43:28 +02:00
Daan De Meyer
6b818cd7e5 core: Add systemd.default_device_timeout_sec= cmdline option 2023-06-02 15:43:28 +02:00
Daan De Meyer
ee6eedab82 mkosi: Sign expected PCRs
This is now possible without a TMP device so let's start signing
PCRs when building images with mkosi.
2023-06-02 15:43:28 +02:00
Daan De Meyer
e577318ddb mkosi: Remove file blacklisting erofs module in opensuse initrd 2023-06-02 15:43:28 +02:00
Daan De Meyer
2d1d0a6cce mkosi: Enable set -e in postinst script 2023-06-02 15:43:28 +02:00
Daan De Meyer
88f7fb16f2 mkosi: Move python3-pytest-flakes to build packages on opensuse 2023-06-02 15:43:28 +02:00
Daan De Meyer
2ee97f56e1 mkosi: Add missing tss2 dependencies 2023-06-02 15:43:28 +02:00
Daan De Meyer
d7a5730848 meson: Add missing tss2-tcti-device dependency 2023-06-02 15:43:28 +02:00
Daan De Meyer
2af9d5dc0e mkosi: Update to latest 2023-06-02 13:32:53 +02:00
Lennart Poettering
2130a2e5a6 fstab-generator: if we mount via roothash=/usrhash= let's imply "ro" mount option
If we discover the root or /usr/ fs via roothash=/usrhash= we know the
file system mounted on it will be read-only, since Verity volumes are by
definition immutable. Hence, let's imply the "ro" mount option for them.

This way the "kernel: /dev/mapper/usr: Can't open blockdev" boot-time
log message goes away, reported here:

https://github.com/systemd/systemd/issues/27682

(I do wonder though why erofs even tries to open the block device as
writable, that sounds utterly pointless for a file system that carries
the fact it is read-only even in the name...)
2023-06-02 13:31:31 +02:00
Frantisek Sumsal
1326d2dd05 test: sync with the fake binary before killing it
On faster machines we might be too fast and kill the fake binary during
fork() which then makes kernel report a "wrong" binary in the coredump,
e.g.:

[   31.408078] testsuite-74.sh[548]: + /tmp/make-dump /tmp/test-dump SIGTRAP
[   31.409720] testsuite-74.sh[560]: + bin=/tmp/test-dump
[   31.409720] testsuite-74.sh[560]: + sig=SIGTRAP
[   31.409720] testsuite-74.sh[560]: + ulimit -c unlimited
[   31.409720] testsuite-74.sh[560]: + pid=561
[   31.409720] testsuite-74.sh[560]: + sleep 1
[   31.409720] testsuite-74.sh[560]: + kill -s SIGTRAP 561
[   31.409720] testsuite-74.sh[560]: + wait 561
[   31.491757] systemd[1]: Created slice system-systemd\x2dcoredump.slice.
[   31.524488] systemd[1]: Started systemd-coredump@0-563-0.service.
[   31.616372] systemd-coredump[564]: [🡕] Process 561 (make-dump) of user 0 dumped core.

                                      Stack trace of thread 561:
                                      #0  0x00007ff86bb49af7 _Fork (libc.so.6 + 0xd4af7)
                                      #1  0x00007ff86bb4965f __libc_fork (libc.so.6 + 0xd465f)
                                      #2  0x000055e88011b0ad make_child (bash + 0x550ad)
                                      #3  0x000055e8800fd05f n/a (bash + 0x3705f)
                                      #4  0x000055e880100116 execute_command_internal (bash + 0x3a116)
                                      #5  0x000055e8801011f2 execute_command_internal (bash + 0x3b1f2)
                                      #6  0x000055e8801025b6 execute_command (bash + 0x3c5b6)
                                      #7  0x000055e8800f134b reader_loop (bash + 0x2b34b)
                                      #8  0x000055e8800e757d main (bash + 0x2157d)
                                      #9  0x00007ff86ba98850 n/a (libc.so.6 + 0x23850)
                                      #10 0x00007ff86ba9890a __libc_start_main (libc.so.6 + 0x2390a)
                                      #11 0x000055e8800e83b5 _start (bash + 0x223b5)
                                      ELF object binary architecture: AMD x86-64
[   31.666617] testsuite-74.sh[560]: /tmp/make-dump: line 12:   561 Trace/breakpoint trap   (core dumped) "$bin" infinity
...
$ coredumpctl list --file system.journal
TIME                         PID UID GID SIG     COREFILE EXE            SIZE
Fri 2023-06-02 10:42:10 CEST 561   0   0 SIGTRAP journal  /usr/bin/bash     -
Fri 2023-06-02 10:42:11 CEST 570   0   0 SIGABRT journal  /tmp/test-dump    -
Fri 2023-06-02 10:42:12 CEST 582   0   0 SIGTRAP missing  /tmp/test-dump    -
Fri 2023-06-02 10:42:13 CEST 593   0   0 SIGABRT missing  /tmp/test-dump    -
2023-06-02 13:24:32 +02:00
Frantisek Sumsal
e8ee168344 test: clean up our mess after the pstore test 2023-06-02 10:07:57 +02:00
Frantisek Sumsal
014e811e86
Merge pull request #27891 from mrc0mmand/more-tests-again
test: improve systemd-pstore tests & add a couple of tests for systemd-run
2023-06-02 10:05:17 +02:00
Lennart Poettering
881d616ee0
Merge pull request #27889 from poettering/no-usr-verity-detach
veritysetup: make sure we don't try to detach /usr/ verity on shutdown
2023-06-02 06:24:13 +02:00
Frantisek Sumsal
dee4a9923b test: add a couple of tests for systemd-run 2023-06-01 23:12:47 +02:00
Frantisek Sumsal
f8b21a08aa socket: avoid memory leak on incomplete SocketPort object
==1==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 17 byte(s) in 1 object(s) allocated from:
    #0 0x7fc096c7243b in strdup (/lib64/libasan.so.8+0x7243b)
    #1 0x7fc095db3899 in bus_socket_set_transient_property ../src/core/dbus-socket.c:386
    #2 0x7fc095db5140 in bus_socket_set_property ../src/core/dbus-socket.c:460
    #3 0x7fc095dd20f1 in bus_unit_set_properties ../src/core/dbus-unit.c:2473
    #4 0x7fc095d87d53 in transient_unit_from_message ../src/core/dbus-manager.c:1025
    #5 0x7fc095d8872f in method_start_transient_unit ../src/core/dbus-manager.c:1112
    #6 0x7fc0944ddf4f in method_callbacks_run ../src/libsystemd/sd-bus/bus-objects.c:406
    #7 0x7fc0944e7854 in object_find_and_run ../src/libsystemd/sd-bus/bus-objects.c:1319
    #8 0x7fc0944e8f03 in bus_process_object ../src/libsystemd/sd-bus/bus-objects.c:1439
    #9 0x7fc09454ad78 in process_message ../src/libsystemd/sd-bus/sd-bus.c:3011
    #10 0x7fc09454b302 in process_running ../src/libsystemd/sd-bus/sd-bus.c:3053
    #11 0x7fc09454e158 in bus_process_internal ../src/libsystemd/sd-bus/sd-bus.c:3273
    #12 0x7fc09454e2f2 in sd_bus_process ../src/libsystemd/sd-bus/sd-bus.c:3300
    #13 0x7fc094551a59 in io_callback ../src/libsystemd/sd-bus/sd-bus.c:3642
    #14 0x7fc094727830 in source_dispatch ../src/libsystemd/sd-event/sd-event.c:4187
    #15 0x7fc094731009 in sd_event_dispatch ../src/libsystemd/sd-event/sd-event.c:4808
    #16 0x7fc094732124 in sd_event_run ../src/libsystemd/sd-event/sd-event.c:4869
    #17 0x7fc095f7af9f in manager_loop ../src/core/manager.c:3242
    #18 0x41cc7c in invoke_main_loop ../src/core/main.c:1937
    #19 0x4252e0 in main ../src/core/main.c:3072
    #20 0x7fc092a4a50f in __libc_start_call_main (/lib64/libc.so.6+0x2750f)

SUMMARY: AddressSanitizer: 17 byte(s) leaked in 1 allocation(s).
2023-06-01 22:14:59 +02:00