Commit Graph
80198 Commits
Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek a9cee8f4de core/manager: do not exclude watchdog logic from busy-loop protection
As reported in https://github.com/systemd/systemd/issues/35405, if the watchdog
ping failed, we effectively started a busy loop here. The previous commits
should fix this, but in general, the protection here is intended as a safety
net in case the logic is broken somewhere else. We shouldn't exclude the
watchdog stuff from this.
2025-03-24 10:45:49 +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
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 839db33687 test-watchdog: modernize 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
Zbigniew Jędrzejewski-Szmek 18284f5a1b core: drop duplicated check in manager_{set,override}_watchdog
Those functions call watchdog_setup() and watchdog_setup_pretimeout(), which
internally do a similar check against the static variables watchdog_timeout and
watchdog_pretimeout. The second check is not useful.
2025-03-21 11:30:26 +01:00
Daan De Meyer 511bf79b4e userdb: Add userdb.user.* and userdb.group.* credentials (#36740)
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 /run/userdb.
2025-03-19 10:30:52 +01:00
Daan De Meyer 04a44e25b9 units: Add systemd-machined.socket 2025-03-19 09:28:12 +01:00
Daan De Meyer 95f94bc804 Update TODO 2025-03-18 22:46:10 +01:00
Daan De Meyer a8a44b7ce5 mkosi: Create testuser at runtime
Now that we have userdb credentials, let's ship testuser as a userdb
credential instead of including it in the image.
2025-03-18 22:46:10 +01: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
Daan De Meyer e5039d459e mkosi: Make sure systemd-userdbd.socket is enabled 2025-03-18 22:46:10 +01:00
Daan De Meyer 5ecc08e033 mkosi: Add unix_chkpwd to sanitizer wrapped binaries
unix_chkpwd will retrieve the user name of the uid it is invoked as
and as such needs the asan workaround.
2025-03-18 22:46:10 +01:00
Daan De Meyer 9165d92406 mkosi: Bump to Fedora 42
Beta was just released, let's switch to Fedora 42 which coincidentally
also has a crucial fix for its nsswitch.conf to make the next commits
actually work.
2025-03-18 20:35:59 +01:00
Daan De Meyer d2ce0db7a7 Several fixes and cleanups around sd_listen_fds() (#36788) 2025-03-18 20:10:33 +01:00
Lennart Poettering bc78fc4de3 update TODO 2025-03-18 18:12:48 +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
Yu Watanabe 024bb0c63e oomd: do not ignore failure in sd_lisen_fds()
Also, use -EBADF for an invalid file descriptor.
2025-03-19 01:47:48 +09:00
Yu Watanabe d50b9cbe56 vmspawn: do not use r for loop count
In a future, we may call some functions and r may be used for storing
error code of them. Let's not use r for the maximum number of loop count.
2025-03-19 01:47:48 +09:00
Yu Watanabe a65d2de6d1 sd-varlink: fix overwrite of loop count
Fixes a bug introduced by 206504a594 (v255).
2025-03-19 01:47:20 +09:00
Yu Watanabe 59cb9b12ab initctl: fix error handling
Fixes a bug introduced by cc090ca7fe (v246).
2025-03-19 01:44:01 +09:00
Yu Watanabe a0272b8356 nsresourced: fix assignment of target_gid
Follow-up for 00b1f67313.

Fixes CID#1593901.
2025-03-18 12:13:38 +00:00
Lennart Poettering 160a4281f5 man: base64 is not hex 2025-03-18 12:13:15 +00:00
Lennart Poettering 7b0c843b87 TODO 2025-03-18 11:48:37 +01:00
Lennart Poettering 8d3acc8387 update TODO 2025-03-18 10:45:32 +01:00
Yu Watanabe 910dcd7049 getty-generator: unify add_serial_getty() and add_container_getty()
This also makes the generator not trigger an assertion added by
1cd3c49d09. If getty.ttys.container
credential contains a line prefixed with '/dev/', then the assertion
    assert(!path_startswith(tty, "/dev/"));
was triggered. This drops the offending assertion, and such lines
are handled gracefully now.

Also, an empty string, "/dev/", and "/dev/pts/" (that is, a directory
without tty name) are gracefully skipped now.
2025-03-18 18:25:10 +09:00
Lennart Poettering 0364329a03 xattr-util: refuse embedded NUL bytes in getxattr_at_malloc() (#36713) 2025-03-18 09:10:19 +01:00
Lennart Poettering 2d47f43b43 cgroup-util: remove cg_get_xattr(), it's apparently unused 2025-03-18 07:17:10 +01: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
Sonia Zorba 147511c643 hwdb: fix backspace not working on HP Pavilion laptop (#36777)
PR #34685 moved the handling of keys 66/65 from specific models to
generic HP laptops.

Key 66 has been linked to the `pickup_phone` function; however, this
action key is not available on all HP laptop models, particularly older
versions. On my HP Pavilion laptop, key 66 is mapped to the `backspace`
function, which caused the backspace key to stop working after the
change.

The following PR fixes the issue on my **HP Pavilion Laptop 15-eg0xxx**.
I have placed the modifications under the Pavilion section, but I cannot
guarantee that this solution will apply to all Pavilion models.

Additionally, I have included a line that checks for "HP" instead of
solely searching for "Hewlett-Packard," as my model is simply labeled as
HP.
2025-03-18 09:25:51 +09:00
Yu Watanabe c9c2679a62 some user record fixes (#36776)
Fixes: https://github.com/systemd/systemd/issues/36775
2025-03-18 09:24:05 +09:00
Mike Yuan 2b983b43c6 run: Ref() the unit again after reconnecting to the bus
Follow-up for c8f59296bf

Currently, the unit is only reffed in transient_unit_set_properties()
via AddRef(), which however would be dropped if a reconnection
is attempted. Make sure to explicitly re-add reference in that case.
2025-03-18 09:23:44 +09:00
Yu Watanabe 8e29a5b9b3 nsresourced,vmspawn: allow unpriv "tap" based networking in vmspawn (#36688)
This extends nsresourced to also allow delegation of a network tap
device (in addition to veth) to unpriv clients, with a strictly enforced
naming scheme.

also tightens security on a couple of things:

* enforces polkit on all nsresourced ops too (though by default still
everything is allowed)
* put a limit on delegated network devices
* forcibly clean up delegated network devices when the userns goes away
2025-03-18 07:34:03 +09:00
Lennart Poettering 91d11d53a1 tree-wide: refuse user/group records lacking UID or GID
userdb allows user/group records without UID/GID (it only really
requires a name), in order to permit "unfixated" records. But that means
we cannot just rely on the field to be valid. And we mostly got that
right, but not everywhere. Fix that.
2025-03-17 22:37:14 +01:00
Lennart Poettering d43a440767 nspawn: go via user_record_home_directory() accessor for .home_directory UserRecord field
Fixes: #36775
2025-03-17 22:23:18 +01:00
Lennart Poettering ca4560f6a8 tree-wide: go via user_record_gid() accessor for UserRecord's .gid field
Sometimes we went for the field directly, where we really should go via
the accessor. Fix it.
2025-03-17 22:21:58 +01:00
Lennart Poettering 2f3314bce6 update TODO 2025-03-17 21:39:06 +01:00
Lennart Poettering ef197d6ab2 test: add test for nsresourced 2025-03-17 21:39:05 +01:00
Lennart Poettering 6e09c46a51 nsresource: turn feature absence error into EOPNOTSUPP
Let's make it easy for local clients to treat feature absence as a
simple EOPNOTSUPP check.
2025-03-17 16:03:18 +01:00
Lennart Poettering 3b6d1fb49f varlink: add full introspection comments for io.systemd.NamespaceResource 2025-03-17 16:03:18 +01:00
Lennart Poettering d2f3ddfc65 nsresourced: check polkit before executing our operations
Let's tighten rules on namespace operations: let's always ask PK for
permission before doing anything.

Note that if polkit is absent we'll still allow things, and the default
PK policy will also still allow things, but there's now a clear way how
people can not allow things if they want, by modifying the PK policy.
2025-03-17 16:03:18 +01:00
Lennart Poettering b2c43674a7 nsresourced: put a limit on delegated network interfaces too 2025-03-17 16:03:18 +01:00
Lennart Poettering 7d2e2900f1 nsresourced: explicitly remove network interfaces when their userns goes away
Let's tighten the screws a bit on the network interfaces we delegate,
and explicitly destroy them, just like we destroy delegated cgroups.

Ideally, this should happen automatically because the userns goes away
that pins the veth, or because the client holding an fd for a tap device
goes away as the userns goes away. But you never know who keeps a
reference, hence let's explicitly destroy this too.
2025-03-17 16:03:18 +01:00
Lennart Poettering e29d5385b6 vmspawn: support unpriv tap networking 2025-03-17 16:03:18 +01:00
Lennart Poettering 716bf93c4b nsresource: add client-side wrapper for creating tap links 2025-03-17 16:03:18 +01:00
Lennart Poettering 19ac01efef network: also manage namespace tap links 2025-03-17 16:03:18 +01:00
Lennart Poettering 1365034727 nsresourced: add ability to delegate tap device 2025-03-17 16:03:18 +01:00