Commit Graph
9526 Commits
Author SHA1 Message Date
Lennart Poettering e04c7a92cc generator: downgrade complaint about trying to fsck a non-block device 2025-04-03 10:22:46 +02:00
Lennart Poettering bed3ff8ebc generator: also suppress fsck early if we are adding a bind mount
There's no point in "fscking a bind mount". Let's not do it hence.
2025-04-03 10:22:46 +02:00
Yu Watanabe a345f47625 Two trivial cleanups (#36980) 2025-04-03 08:56:46 +09:00
Lennart Poettering 4dba936a03 dissect-image: after probing file systems, we still have the chance to not use a partition
Just because we found something we should still allow it to not be used,
hence include UNUSED in the found flags.
2025-04-03 06:09:01 +09:00
Yu Watanabe 9ec7d7ae90 tree-wide: replace unsigned int -> unsigned, long int -> long 2025-04-03 06:01:31 +09:00
Yu Watanabe daaf66fb1b journald: split out varlink code into .c/.h file and add varlink documentation to it (#36965)
No real code changes.
2025-04-03 04:31:15 +09:00
Yu Watanabe abaa8bc7ca some selinux modernizations (#36955) 2025-04-03 01:30:03 +09:00
Yu Watanabe d4a6d44210 udev: introduce rm_rf_safep() and modernize udev_watch_restore() (#36923) 2025-04-03 01:28:34 +09:00
Lennart Poettering 737bf89cca journald: document Varlink interface 2025-04-02 17:32:05 +02:00
Yu Watanabe b0c9ba4eb1 core: delegate mountns implicitly when any of pidns/cgns/netns is in use, clean up private cgroupfs mount (#36892)
Fixes #36952
2025-04-03 00:15:33 +09:00
Yu Watanabe 1b84efa4cd rm-rf: introduce rm_rf_safe() and rm_rf_safep() 2025-04-02 23:18:43 +09:00
Lennart Poettering ab4a5982c1 selinux-util: rename return parameter to ret_xyz
mac_selinux_get_create_label_from_exe() didn't get this right. Clean
this up, and stick to a uniform name for all three related functions.
2025-04-02 16:09:20 +02:00
Zbigniew Jędrzejewski-Szmek 5b7c1f34e1 Tweak log messages around efivarsfs and hibernation (#36921) 2025-04-02 11:30:26 +02:00
Yu Watanabe c5855d9640 notify-recv: several follow-ups for notify_socket_prepare()
Follow-ups for 2351bc991e.
Addresses post-merge review:
https://github.com/systemd/systemd/pull/36911#pullrequestreview-2732136658
2025-04-01 22:22:10 +09:00
Zbigniew Jędrzejewski-Szmek 0a5b70f3b1 shared/mount-setup: use '' to signify empty option string
We said:
systemd[1]: Mounting efivarfs to /sys/firmware/efi/efivars of type efivarfs with options n/a.
I think '' is clearer.
2025-04-01 11:28:00 +02:00
Yu Watanabe 2351bc991e notify-recv: introduce notify_socket_prepare() 2025-04-01 03:26:22 +09:00
Lennart Poettering f872373a26 generators: hook in validatefs on gpt-auto and fstab generator mounts
Let's turn on validatefs automatically for all auto-discovered
partitions.

Let's add an x-systemd.validatefs option to optionally turn this on for
fstab listed file systems.
2025-03-31 15:14:28 +02:00
Yu Watanabe 072ebe3ece watchdog: fix typo
Follow-up for ab596e4cde.
2025-03-31 21:27:00 +09:00
Yu Watanabe b457af42e5 Log message improvements (#35237)
Various improvements to log messages. Inspired by
https://bugzilla.redhat.com/show_bug.cgi?id=2327296.
2025-03-31 21:23:23 +09:00
Lennart Poettering 5daca30b0f homed: always use quotactl_fd() if its available
Let's always prefer quotactl_fd() when it's available and use quotactl()
only as as a fallback on old kernels.

This way we can operate on the fds we typically already have open, or if
needed we can open a new one, and use for multiple fs operation.

In the long run we should really focus on operating exclusively by fd
instead of by path, by device nor or otherwise. This gets us a step
closer to that.
2025-03-31 11:51:15 +02:00
Mike Yuan 1614d0c451 core/namespace: stop applying mount options on private cgroupfs mount
We always unshare cgroup ns for ProtectControlGroups=private/strict,
while the mount options only apply to the cgroupfs instance
in initial cgns (c.f.
https://github.com/torvalds/linux/blob/b69bb476dee99d564d65d418e9a20acca6f32c3f/kernel/cgroup/cgroup.c#L1984)
Hence let's drop the thing wholesale.

Also, as noted in the comment already, mount_private_apivfs()
internally enforces nosuid/noexec, so drop explicit flags too.
2025-03-30 18:57:18 +02:00
Zbigniew Jędrzejewski-Szmek 6bb9caa256 shared/exec-util: fix logging of the args of an executed program
The debug logs has lots of "About to execute /some/path (null)". This
occurs when the args array is empty. Instead, only print "(null)" if
we failed with oom.

Having strv_skip() return NULL makes this pleasant to write without repeating
strv_isempty() a few times.
2025-03-27 12:04:43 +01:00
Nick Rosbrook 971fb3b0bc polkit: use -EBUSY to indicate shortcut after error or denial
Commit 536c18e5c3 ("bus-polkit: shortcut auth. after first denial")
added logic to async_polkit_query_check_action() that returns
-EALREADY when a failure or denial decision was made for a previous
action.

Tweak this to return -EBUSY instead of -EALREADY. This hopefully makes
the intent of the error more clear. EALREADY suggests that the request
is OK, but polkit is processing something else, and we should come back
later. EBUSY suggests that polkit is busy or unusable, hence the
request cannot be processed, and we should go away.
2025-03-25 16:15:34 -04:00
Nick Rosbrook 94a5969b31 polkit: fix the ordering of a log message 2025-03-25 16:15:34 -04:00
Zbigniew Jędrzejewski-Szmek c4876f604b Ratelimit attempts to open watchdog, increase logging (#35708) 2025-03-24 21:06:57 +01:00
Daan De Meyer d2c1242c6d user-record: Allow/strip status for mask/extract privileged helpers
If we're using these helpers, we want to split a user record into two,
one with the privileged section, and one without. This should work even
when the user record has a "status" section, so adapt the helpers to
account for that.
2025-03-24 11:36:16 +01:00
Zbigniew Jędrzejewski-Szmek ab596e4cde shared/watchdog: give up after a few failed pings
Closes https://github.com/systemd/systemd/issues/35405. Apparently some
watchdog devices can be opened, but then the pings start failing after some
time. Since the timestamp of the last successful ping is not updated, we try to
ping again immediately, causing a busy loop and excessive logging.

After trying a few different approaches to fit this into the existing framework
without changing the logic too much, I settled on an approach with a second
timestamp. In particular, the timestamp of the last successful ping is public,
exposed as WatchdogLastPingTimestamp over dbus. It'd be wrong to redefine this
to mean the last ping *attempt*. So we need a second timestamp in some form.

Also, if we give up on pinging, we probably should attempt to disarm the
watchdog. It's possible that the pinging fails, but the watchdog would still
fire. I don't think we want that, since it seems that our internal loop is
working, it's just the watchdog that is broken.

Structured message with SD_MESSAGE_WATCHDOG_PING_FAILED is logged if we fail
to ping.

I tested this by attaching gdb to pid 1 and calling close(watchdog_fd).
We get a bunch of warning messages and then an attempt to close the watchdog:
Mar 21 15:46:17 fedora systemd[1]: Failed to ping hardware watchdog /dev/watchdog0: Bad file descriptor
Mar 21 15:46:20 fedora systemd[1]: Failed to ping hardware watchdog /dev/watchdog0: Bad file descriptor
Mar 21 15:46:23 fedora systemd[1]: Failed to ping hardware watchdog /dev/watchdog0: Bad file descriptor
Mar 21 15:46:26 fedora systemd[1]: Failed to ping hardware watchdog /dev/watchdog0: Bad file descriptor
Mar 21 15:46:29 fedora systemd[1]: Failed to ping hardware watchdog /dev/watchdog0: Bad file descriptor
Mar 21 15:46:32 fedora systemd[1]: Failed to ping hardware watchdog /dev/watchdog0: Bad file descriptor
Mar 21 15:46:35 fedora systemd[1]: Failed to ping hardware watchdog /dev/watchdog0: Bad file descriptor
Mar 21 15:46:37 fedora systemd[1]: Failed to ping hardware watchdog /dev/watchdog0: Bad file descriptor
Mar 21 15:46:40 fedora systemd[1]: Failed to ping hardware watchdog /dev/watchdog0: Bad file descriptor
Mar 21 15:46:43 fedora systemd[1]: Failed to ping hardware watchdog /dev/watchdog0: Bad file descriptor
Mar 21 15:46:46 fedora systemd[1]: Failed to ping hardware watchdog /dev/watchdog0: Bad file descriptor
Mar 21 15:46:49 fedora systemd[1]: Failed to ping hardware watchdog /dev/watchdog0: Bad file descriptor
Mar 21 15:46:52 fedora systemd[1]: Failed to ping hardware watchdog /dev/watchdog0: Bad file descriptor
Mar 21 15:46:55 fedora systemd[1]: Failed to ping hardware watchdog /dev/watchdog0: Bad file descriptor
Mar 21 15:46:58 fedora systemd[1]: Failed to ping hardware watchdog /dev/watchdog0, closing watchdog after 15 attempts: Bad file descriptor
Mar 21 15:46:58 fedora systemd[1]: Failed to disable hardware watchdog, ignoring: Bad file descriptor
Mar 21 15:46:58 fedora systemd[1]: Failed to disarm watchdog timer, ignoring: Bad file descriptor
2025-03-24 10:45:49 +01:00
Zbigniew Jędrzejewski-Szmek 236ac39b65 shared/watchdog: add MESSAGE_IDs to logs about watchdog opening
One ID for the success case, with WATCHDOG_DEVICE= showing the device,
and one ID for the failure case, with WATCHDOG_DEVICE= if configured,
and ERRNO= set automatically.
2025-03-21 15:55:50 +01:00
Zbigniew Jędrzejewski-Szmek b27c9279f6 shared/watchdog: ratelimit the number of attempts to open watchdog
We need to retry the open attempts for the watchdog, because the device becomes
available asynchronously.

The watchdog is opened in two places:

- in pid1 in the main loop. The loop has a ratelimit, but during a boot we
  iterate in it fairly quickly. On my test VM with 'iTCO_wdt', version 2:

    $ journalctl -b --grep 'Failed to open any watchdog' | wc -l
    3398

  After the device has been processed by udev, it is initialized successfully.

- in shutdown. In that case, we most likely don't need to try more than once,
  because we mostly care about the case where the watchdog device was present
  and configured previously. But in principle it is possible that we might
  attempt shutdown while the machine was initializing, so we don't want to
  disable retries. Nevertheless, watchdog_ping() is called from a loop that
  might be fairly tight, so we could end up trying to reopen the device fairly
  often. This probably doesn't matter *too* much, but it's still ugly to try to
  open the device without any ratelimit.

Usually the watchdog timeout would be set to something like 30 s or a few
minutes. OTOH, on my VM, the device becomes avaiable at 4.35 s after boot. So
let's use 5 s or half the watchdog timeout, whatever is smaller, as the
interval.
2025-03-21 15:55:50 +01:00
Yu Watanabe 90670111a9 udev: make udevadm and friends not warn about unknown settings
Without this change, when e.g. event_timeout= is specified in udev.conf,
udevadm and friends which loads udev.conf warn about unknown key:
===
$ udevadm info /sys/class/net/lo
/run/udev/udev.conf.d/test-17.conf:1: Unknown key 'event_timeout', ignoring.
/run/udev/udev.conf.d/test-17.conf:2: Unknown key 'timeout_signal', ignoring.
===

Follow-up for 07f5e35fe7 (v256).
2025-03-21 12:51:39 +00:00
Zbigniew Jędrzejewski-Szmek 2c6397d1c2 pid1: log if we failed to find a watchdog device
I think we need to log at some point if the user configured a watchdog device,
but no devices were found. We can't log ENOENT immediately, because the device
may likely appear during boot. So wait until the end of the initial transaction
and log then.
2025-03-21 11:38:43 +01:00
Zbigniew Jędrzejewski-Szmek 0b291130e8 shared/watchdog: raise log levels for watchdog errors
If we failed to open the watchdog device for any reason, we'd only log at debug
level. This seems iffy: if the user configured a timeout for the watchdog, we
should report when we can't set it up. ENOENT is still logged at debug level
only, since it's somewhat expected to have a watchdog timeout set up, even for
systems which don't have a watchdog, or the device might appear later.

If the device doesn't support WDIOC_GETSUPPORT, still log that we opened a
device.

No change in behaviour, except for the log level threshold. As a side effect,
the reason why we failed to open the device is now stored in watchdog_fd
(previously it was -1 always), but this isn't used for anything.
2025-03-21 11:30:26 +01:00
Zbigniew Jędrzejewski-Szmek ab37e9cdb2 core/watchdog: initialize variables only if they'll be used
This is not a hot path, but let's move the variables to the
minimal scope in which they are needed.

Also, all functions which call watchdog_open() check for fd < 0 first,
so change the conditional return into an assert.
2025-03-21 11:30:26 +01:00
Yu Watanabe 3cb0551ecb edit-util: don't leave custom editor args around if we shall fall back (#36813)
Also, let's complain loudly if the editor acquired from envvar is not
present.

Fixes #36796
2025-03-21 08:48:05 +09:00
Matteo Croce dcde1e903a match glibc in ConditionVersion
Extend ConditionVersion= to allow matching against glibc version,
as proposed in https://github.com/systemd/systemd/pull/36468#issuecomment-2674600909
2025-03-21 06:57:28 +09:00
Mike Yuan d2e49d9389 edit-util: don't leave custom editor args around if we shall fall back
Also, let's complain loudly if the editor acquired from envvar
is not present.

Fixes #36796
2025-03-20 17:31:54 +01:00
Yu Watanabe db4b4e0cd3 core: Make DelegateNamespaces= work for user managers with CAP_SYS_ADMIN (#36771)
Currently DelegateNamespaces= only works for services spawned by the
system manager. User managers will always unshare the user namespace
first even if they're running with CAP_SYS_ADMIN.

Let's add support for DelegateNamespaces= for user managers if they're
running with CAP_SYS_ADMIN. By default, we'll still delegate all
namespaces
for user managers, but this can now be overridden by explicitly passing
DelegateNamespaces=.

If a user manager is running without CAP_SYS_ADMIN, the user manager is
still always unshared first just like before.
2025-03-20 06:28:18 +09:00
Lennart Poettering b0fe8df5a9 Several fixlets for Coverity (#36791) 2025-03-19 22:27:00 +01:00
Yu Watanabe bb8c74d7f2 Introduce ConditionVersion (#36468)
Add a new condition which can check against systemd version.

        $ systemctl --version
        systemd 258 (258~devel-g53ca5f6)

        $ systemd-analyze condition 'ConditionVersion=systemd>255'
        test.service: ConditionVersion=>255 succeeded.

        $ systemd-analyze condition 'ConditionVersion=systemd>260'
        test.service: ConditionVersion=>260 failed.

        $ systemd-analyze condition 'ConditionVersion=systemd>=258'
        test.service: ConditionVersion=>=258 succeeded.

        $ systemd-analyze condition 'ConditionVersion=systemd>=257.1'
        test.service: ConditionVersion=>=257.1 succeeded.

        $ uname -r
        6.12.13-200.fc41.aarch64

        $ systemd-analyze condition 'ConditionVersion=kernel > 4.4'
        test.service: ConditionVersion=kernel > 4.4 succeeded.

        $ systemd-analyze condition 'ConditionVersion=kernel > 6.20'
        test.service: ConditionVersion=kernel > 6.20 failed.

        $ systemd-analyze condition 'ConditionVersion=kernel < 9.0'
        test.service: ConditionVersion=kernel < 9.0 succeeded.
2025-03-20 06:15:35 +09:00
Lennart Poettering 0015502168 tpm2-util: return better errors if we try to unlock a tpm key on the wrong tpm
Let's improve error handling in case one tries to unlock a TPM2 locked
volume on a different machine via TPM than it was originally enrolled
on. Let's recognize this case and print a clearer error message.
2025-03-19 21:27:54 +01:00
Lennart Poettering f21090d217 generator: skip fsck early for non-blockdev file systems, or file systems that are always read-only 2025-03-19 18:18:43 +01:00
Daan De Meyer ad9b5d4732 bus-unit-util: Fix DelegateNamespaces= parser
Similarly to the config file parse method, let's fix the systemd-run
parser as well.

Follow up for 11b982053b
2025-03-19 10:00:45 +01:00
Yu Watanabe 707bea6a48 ptyfwd: use usec_add()
Fixes CID#1548038.
2025-03-19 11:41:25 +09:00
Yu Watanabe 11065c598c logs-show: comment out dead code
Follow-up for 280e85224e.
Fixes CID#1548921 and CID#1548922.
2025-03-19 11:41:12 +09:00
Yu Watanabe 6a6cc56125 bus-unit-procs: add one more assertion for Coverity
Hopefully fixes CID#1562447.
2025-03-19 10:41:29 +09:00
Daan De Meyer fe0342edf4 userdb: Add userdb.user.* and userdb.group.* credentials
Let's allow providing extra userdb users and groups via credentials.
Similarly to systemd-udev-load-credentials.service, we ship
systemd-userdb-load-credentials.service which transform the JSON
user/group records provided via the corresponding credentials to static
userdb dropins in /etc/userdb.

Replaces #33811
2025-03-18 22:46:10 +01:00
Yu Watanabe b8d5303733 nspawn: make failure in sd_listen_fds() critical
Also, drop doubled call of sd_listen_fds().
2025-03-19 02:09:40 +09:00
Matteo Croce c154bb65ad condition: introduce ConditionVersion=/AssertVersion=
Add a new condition wich checks against systemd version.
Change condition_test_kernel_version() into a generic condition_test_version()
so most of the code can be reused.

    $ systemctl --version
    systemd 258 (258~devel-g53ca5f6)

    $ systemd-analyze condition 'ConditionVersion=systemd>255'
    test.service: ConditionVersion=>255 succeeded.

    $ systemd-analyze condition 'ConditionVersion=systemd>260'
    test.service: ConditionVersion=>260 failed.

    $ systemd-analyze condition 'ConditionVersion=systemd>=258'
    test.service: ConditionVersion=>=258 succeeded.

    $ systemd-analyze condition 'ConditionVersion=systemd>=257.1'
    test.service: ConditionVersion=>=257.1 succeeded.

    $ uname -r
    6.12.13-200.fc41.aarch64

    $ systemd-analyze condition 'ConditionVersion=kernel > 4.4'
    test.service: ConditionVersion=kernel > 4.4 succeeded.

    $ systemd-analyze condition 'ConditionVersion=kernel > 6.20'
    test.service: ConditionVersion=kernel > 6.20 failed.

    $ systemd-analyze condition 'ConditionVersion=kernel < 9.0'
    test.service: ConditionVersion=kernel < 9.0 succeeded.
2025-03-18 18:36:59 +09:00
Yu Watanabe f91273f4fc condition: align string table 2025-03-18 18:36:59 +09:00
Lennart Poettering 33cbda04eb xattr-util: rework getxattr_at_malloc()
Let's return the size in a return parameter instead of the return value.
And if NULL is specified this tells us the caller doesn't care about the
size and expects a NUL terminated string. In that case look for an
embedded NUL byte, and refuse in that case.

This should lock things down a bit, as we'll systematically refuse
embedded NUL strings now when we expect strings.
2025-03-18 07:17:10 +01:00