Commit Graph

2284 Commits

Author SHA1 Message Date
Valentin David
0dc39dffbd Use paths specified from environment variables for /etc configuration files
Some configuration files that need updates are directly under in /etc. To
update them atomically, we need write access to /etc. For Ubuntu Core this is
an issue as /etc is not writable. Only a selection of subdirectories can be
writable. The general solution is symlinks or bind mounts to writable places.
But for atomic writes in /etc, that does not work. So Ubuntu has had a patch
for that that did not age well.

Instead we would like to introduce some environment variables for alternate
paths.

 * SYSTEMD_ETC_HOSTNAME: /etc/hostname
 * SYSTEMD_ETC_MACHINE_INFO: /etc/machine-info
 * SYSTEMD_ETC_LOCALTIME: /etc/localtime
 * SYSTEMD_ETC_LOCALE_CONF: /etc/locale.conf
 * SYSTEMD_ETC_VCONSOLE_CONF: /etc/vconsole.conf
 * SYSTEMD_ETC_ADJTIME: /etc/adjtime

While it is for now expected that there is a symlink from the standard, we
still try to read them from that alternate path. This is important for
`/etc/localtime`, which is a symlink, so we cannot have an indirect symlink or
bind mount for it.

Since machine-id is typically written only once and not updated. This commit
does not cover it. An initrd can properly create it and bind mount it.
2025-06-23 15:32:11 +02:00
Lennart Poettering
222b0b05ce core: escape UTF-8 in mount unit Where field before sending to clients
Followup for: 4804da5853 #27541

Fixes: #36206
2025-06-21 02:22:28 +09:00
Jan Čermák
a2015ad126 journal-gatewayd: make num_entries in Range header optional again
Since 435c372ce5 added in v256,
num_entries part of the Range header is mandatory and error is returned
when it's not filled in. This makes using the "follow" argument clumsy,
because for an indefinite following of the logs, arbitrary high number
must be specified. This change makes it possible to omit it again and
documents this behavior in the man page.

Moreover, as the cursor part of the header was never mandatory, enclose
it in square brackets in the documentation as well and elaborate how
indexing works.

Following are some concrete examples of the Range header which are now
accepted:

 entries= (or entries=:)
  - everything starting from the first event

 entries=cursor
  - everything starting from `cursor`

 entries=:-9:10
  - last 10 events and close the connection

If the follow flag is set:

 entries=:-4:10
  - last 5 events, wait for 5 new and close connection

 entries=:-9:
  - last 10 events and keep streaming

Note that only the very last one is changing current behavior, but
reintroduces pre-v256 compatibility.

Fixes #37172
2025-06-21 02:08:03 +09:00
Lennart Poettering
576a2bc79b resolved: honour RefuseRecordTypes= also in proxy mode
Fixes: #36491
2025-06-19 18:02:54 +02:00
Matteo Croce
030b227cec test: add test for systemd upgrade
Add a basic test to check that systemd works after an upgrade
2025-06-18 09:51:21 +01:00
Arkadiusz Bokowy
998aa62a21 sd-bus: Preserve interfaces addition order
When adding a new interface to the object add it at the end of the list.
This way, when iterating over the list, e.g., during handling introspect
call, the order of returned interfaces will mach the order in which they
were added.
2025-06-17 17:28:35 +09:00
Yu Watanabe
888e3f4357 TEST-75-RESOLVED: add test case for reloading DNSStubListenerExtra= 2025-06-16 22:04:52 +09:00
Mike Yuan
a14a6f1df6 socket-activate: add a --now option to instantly start service (#37620) 2025-06-16 02:08:57 +02:00
Daniel Foster
9e0d0c3fdf test: add simple tests for systemd-socket-activate tool 2025-06-15 16:34:16 +10:00
Dan Streetman
db83bd7e36 test: update keyutil test to verify new pkcs7 --hash-algorithm param 2025-06-10 08:46:36 -04:00
Yu Watanabe
b5bd717fcd test: extend timeout and enable generating debugging logs
Not sure why the test failed, but maybe the test environment is too
slow? Even this does not fix the failure, by enabling debugging logs,
this hopefully provides more useful information for debugging.

For issue #37685.
2025-06-06 19:43:32 +01:00
Daan De Meyer
f8f67eab70 core: Make sure we handle DelegateSubgroup= in combo with cgroupns
Currently, if we use a cgroup namespace together with DelegateSubgroup=,
the subgroup becomes the root of the cgroup namespace because we move the
service process to the subgroup before we unshare the cgroup namespace, and
the current cgroup becomes the root of the cgroup namespace when we unshare
the cgroup namespace.

Let's fix the problem by not moving the service process to the subgroup until
we've unshared the cgroup namespace. Note that this doesn't break the primary use
case of CLONE_INTO_CGROUP since we still use it to immediately clone into the service
main cgroup, just not anymore into the subgroup, but this shouldn't matter in practice.

Additionally, we need special handling for control processes, as those *do*
need to get spawned into the subcgroup immediately if delegation is configured to
avoid violating the cgroupsv2 "no inner processes" rule.

Effectively, this leaves us with the following logic:
- In exec_spawn(), spawn into subgroup if we're spawning a control process
  that needs to be spawned into a subgroup immediately. Otherwise, spawn into
  main service cgroup.
- In exec_invoke(), move into subgroup early if we don't need a cgroup namespace.
  Otherwise, move into subgroup after we've unshared the cgroup namespace.
2025-06-05 12:37:02 +02:00
Yu Watanabe
d2b41bd69e TEST-17-UDEV: acquire SYS_UID_MAX/SYS_GID_MAX from userdbctl
Suse build systemd with -Dsystem-uid-max=499 -Dsystem-gid-max=499,
and seems to not provide /etc/login.defs file. See
2dc224ae5d/packages/s/systemd/systemd.spec
2025-06-04 21:54:32 +09:00
Lennart Poettering
ccd2bf48b2 pcrlock: add "is-supported" verb that checks if the local TPM supports the commands we need for pcrlock
systemd-pcrlock requires support for the PolicyAuthorizeNV command,
which is not implemented in the first TPM2 releases. We also strictly
require SHA-256 support. Hence add a tool for checking for both of
these.

This is a tighter version of "systemd-analyze has-tpm2", that checks for
the precise feature that systemd-pcrlock needs, on top of basic TPM2
functionality.

Fixes: #37607
2025-06-03 16:12:45 +02:00
Luca Boccassi
6cd1842e33 test: send monotonic timestamp rather than unix seconds for MONOTONIC_USEC= argument
Follow-up for 3998b30a04
2025-06-03 10:54:03 +09:00
Yu Watanabe
0436240dd2 udevadm: allow to specify device by device ID (#37636) 2025-06-02 18:02:36 +09:00
Christian Glombek
0af9937691 portable,sysext: match extension OS ID also against host ID_LIKE 2025-05-31 10:02:11 +09:00
Luca Boccassi
703fbb0bba test: wait for coredump to appear before parsing
A new core was added to the test, but the loop counter was not increased
to wait for it, so the test races against systemd-coredump's processing.

This failed at least once in debci:

8015s [   32.227813] TEST-87-AUX-UTILS-VM.sh[1038]: + coredumpctl info COREDUMP_TIMESTAMP=1679509902000000
8015s [   32.228684] TEST-87-AUX-UTILS-VM.sh[1723]: No coredumps found.

Follow-up for 0c49e0049b

Fixes https://github.com/systemd/systemd/issues/37666
2025-05-31 10:01:30 +09:00
Yu Watanabe
ab5587d674 core/transaction: restart dependency loop when a new dependency is added (#37465)
Fixes #36031.
2025-05-31 04:01:06 +09:00
Zbigniew Jędrzejewski-Szmek
505a5d2bcd Merge remote-tracking branch 'systemd-security/coredump-d' 2025-05-29 17:22:19 +02:00
Luca Boccassi
60491ceb12 test: fix TEST-84-STORAGETM with nvme-cli < 2.7
The -vv parameter was added in version 2.7, check before using it

Follow-up for ebc0514a65
2025-05-29 01:15:56 +01:00
Zbigniew Jędrzejewski-Szmek
0c49e0049b coredump: use %d in kernel core pattern
The kernel provides %d which is documented as
"dump mode—same as value returned by prctl(2) PR_GET_DUMPABLE".

We already query /proc/pid/auxv for this information, but unfortunately this
check is subject to a race, because the crashed process may be replaced by an
attacker before we read this data, for example replacing a SUID process that
was killed by a signal with another process that is not SUID, tricking us into
making the coredump of the original process readable by the attacker.

With this patch, we effectively add one more check to the list of conditions
that need be satisfied if we are to make the coredump accessible to the user.

Reportedy-by: Qualys Security Advisory <qsa@qualys.com>

In principle, %d might return a value other than 0, 1, or 2 in the future.
Thus, we accept those, but emit a notice.
2025-05-29 00:10:08 +02:00
Yu Watanabe
7824e70a07 test: add test case for issue #36031 2025-05-29 05:41:29 +09:00
Yu Watanabe
d0ba749e8c udevadm: allow to specify device by device ID
We have already exposed device ID in the output of device ID in J
fields. Also sd_device_get_device_id() and sd_device_new_from_device_id()
are already public. Hence, making udevadm accept device IDs may be
useful.

With this change, as we save several data in /run/udev with device ID,
we can call udevadm something like the following:
```
udevadm info $(ls /run/udev/tags/uaccess)
```
Then, we can show all devices that has uaccess tag.
2025-05-29 04:04:22 +09:00
Jan Čermák
c9f931b737 journal-gatewayd: add /boots endpoint (#37574)
Add endpoint for listing boots. Output format mimics `journalctl
--list-boots -o json`, so it's a plain array containing index, boot ID
and timestamps of the first and last entry. Initial implementation
returns boots ordered starting with the current one and doesn't allow
any filtering (i.e. equivalent of --lines argument).

Fixes: #37573
2025-05-29 03:33:03 +09:00
Daan De Meyer
4793dbc56e core: introduce io.systemd.Unit.List (first PR) (#37432) 2025-05-27 12:42:11 +02:00
Lennart Poettering
8215935180 ci: add test case for io.systemd.MountFileSystem.MakeDirectory() and varlinkctl --push-fd= 2025-05-27 10:41:52 +02:00
Ivan Kruglov
dd14c3eab1 test: simple tests for io.systemd.Unit varlink interface 2025-05-27 01:16:56 -07:00
Ivan Kruglov
92fa38c99d test: quote entire path to socket in io.systemd.Manager tests 2025-05-27 01:16:56 -07:00
Ivan Kruglov
738a47fd98 tests: fix TEST-74-AUX-UTILS.varlinkctl.sh (#37562)
per Daan's explanation:
other subtests running as testuser apparently use systemd-run --user
--machine testuser@.host which turns user tracking in logind into "by
pin" mode. when the last pinning session exits it terminates the user.
2025-05-22 22:40:30 +01:00
Zbigniew Jędrzejewski-Szmek
61d78f1788 Restore compatibility for coredump --backtrace (#37559) 2025-05-22 13:40:29 +02:00
Zbigniew Jędrzejewski-Szmek
ded0aac389 coredump: restore compatibility with older patterns
This was broken in f45b801551. Unfortunately
the review does not talk about backward compatibility at all. There are
two places where it matters:
- During upgrades, the replacement of kernel.core_pattern is asynchronous.
  For example, during rpm upgrades, it would be updated a post-transaction
  file trigger. In other scenarios, the update might only happen after
  reboot. We have a potentially long window where the old pattern is in
  place. We need to capture coredumps during upgrades too.
- With --backtrace. The interface of --backtrace, in hindsight, is not
  great. But there are users of --backtrace which were written to use
  a specific set of arguments, and we can't just break compatiblity.
  One example is systemd-coredump-python, but there are also reports of
  users using --backtrace to generate coredump logs.

Thus, we require the original set of args, and will use the additional args if
found.

A test is added to verify that --backtrace works with and without the optional
args.
2025-05-21 23:45:14 +02:00
Lennart Poettering
88d2cb3668 test: add simple integration test for delegation feature 2025-05-20 23:00:53 +02:00
Luca Boccassi
6946eed3fa core: Also refresh confext extensions when reloading notify-reload service (#33995)
`ExtensionImages=` and `ExtensionDirectories=` now let you specify
vpick-named extensions; however, since they just get set up once when
the service is started, you can't see newer versions without restarting
the service entirely. Here, also reload confext extensions when you
reload a service. This allows you to deploy a new version of some
configuration and have it picked up at reload time without interruption
to your workload.

Right now, we would only reload confext extensions and leave the sysext
ones behind, since it didn't seem prudent to swap out what is likely
program code at reload. This is made possible by only going for the
`SYSTEMD_CONFEXT_HIERARCHIES` overlays (which only contains `/etc`).

This PR:
- Adjusts `service.c` to also refresh extensions when needed. 
- Adds integration tests to check that a confext reload actually
occurred.
- Adds to the `systemd.exec` man pages to document this behavior.

This is a follow up to #24864 and #31364. Thank you to @bluca and
@goenkam for help in getting this up.
2025-05-20 11:27:34 +01:00
maia x.
3998b30a04 test: check reloading notify-reload service refreshes vpick extensions
In TEST-50-DISSECT.dissect, this adds the following cases:
- testservice-50g: vpick extension in ExtensionDirectories
- testservice-50h: vpick extension in ExtensionImages
- testservice-50i: ExtensionDirectories + RootImage
- testservice-50j: ExtensionDirectories + RootDirectory
2025-05-19 13:36:21 +01:00
Yu Watanabe
a31edb4e71 TEST-07-PID1: drop journal message flood test
This partially reverts f9b186c21a.

The test case is unstable, and fills debugging logs after journald
is restarted.
2025-05-16 22:24:54 +09:00
Mike Yuan
7762e9bbb2 core: always enable CPU accounting; cgtop: drop cgv1 handling (#37448) 2025-05-15 14:41:07 +02:00
Tommy Unger
ef3a0478bb test: write file from systemd service in transient unit
This integration test demonstrates that a containerized systemd instance can
write to a bind mounted file observable to the host. Specifically, the bash
script uses systemd-run to start a systemd instance as a transient unit
container. This systemd-run command bind mounts a directory the container will
share with the host, and runs an internal service which creates and writes to a
file from the container's view of this directory. When finished writing, the
service runs the exit target, terminating the internal systemd instance, and
ending the lifetime of the container.

The script waits for the container to finish running, then verifies that the
expected file contents were written on the host side of the filesystem mount.

This test employs a workaround, creating an unmasked procfs mount on the host
which enables the privileged guest to create its own mounts internally. This
may indicate a systemd bug, as the privileged container should not rely on
the existence of an unmasked procfs on the host in order to mount its own
filesystems internally.
2025-05-15 11:33:23 +02:00
Mike Yuan
29da53dde3 core: always enable CPU accounting
Our baseline is v5.4 and cgroup v2 is enforced now,
which means CPU accounting is cheap everywhere without
requiring any controller, hence just remove the directive.
2025-05-15 02:19:16 +02:00
Daan De Meyer
17b0d165f6 capability-util: Ignore unknown capabilities instead of aborting
capability_quintet_mangle() can be called with capability sets
containing unknown capabilities. Let's not crash when this is the
case but instead ignore the unknown capabilities.

Fixes d5e12dc75e
2025-05-15 03:33:32 +09:00
Yu Watanabe
eba8cc8981 integration-tests: several cleanups (#37394) 2025-05-15 01:45:10 +09:00
Lennart Poettering
4fefc10c0d validatefs: fix checks on file systems backed by multiple devices (i.e. verity) (#37434)
Fixes #37157
2025-05-14 17:53:06 +02:00
Lennart Poettering
c019ad849f test: attempt to fix resolved wait-online testcase
Fixes: #37430
2025-05-14 16:09:32 +02:00
Lennart Poettering
61b15b78e5 ci: extend validatefs testcase to validate verity partitions 2025-05-14 15:44:54 +02:00
Yu Watanabe
18609909d9 TEST-73-LOCALE: skip lv keymap and friends
The following failure should be in libxkbcommon and/or sanitizer.
There is nothing we can do here. Let's skip it.

```
TEST-73-LOCALE.sh[3733]: + assert_rc 0 localectl set-keymap lv
TEST-73-LOCALE.sh[6699]: + set +ex
TEST-73-LOCALE.sh[6700]: Failed to set keymap: Remote peer disconnected
TEST-73-LOCALE.sh[6703]: FAIL: expected: '0' actual: '1'
TEST-73-LOCALE.sh[157]: + rm -f /etc/dbus-1/system.d/systemd-localed-read-only.conf
[FAILED] Failed to start TEST-73-LOCALE.service - TEST-73-LOCALE.
```
```
==3719==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x7fa51f161000 at pc 0x7fa521250be4 bp 0x7ffe49130a80 sp 0x7ffe49130240
READ of size 19126 at 0x7fa51f161000 thread T0
    #0 0x7fa521250be3 in strndup (/usr/lib/clang/20/lib/x86_64-redhat-linux-gnu/libclang_rt.asan.so+0x50be3) (BuildId: aa6231e817f72469c44a6c6cee9f0694a87db7fb)
    #1 0x7fa51f128325  (/lib64/libxkbcommon.so.0+0x1c325) (BuildId: 72e8cb985db37963272d140f7b2aee551c465ff5)
    #2 0x7fa51f121952  (/lib64/libxkbcommon.so.0+0x15952) (BuildId: 72e8cb985db37963272d140f7b2aee551c465ff5)
    #3 0x7fa51f123d3a  (/lib64/libxkbcommon.so.0+0x17d3a) (BuildId: 72e8cb985db37963272d140f7b2aee551c465ff5)
    #4 0x7fa51f117c86  (/lib64/libxkbcommon.so.0+0xbc86) (BuildId: 72e8cb985db37963272d140f7b2aee551c465ff5)
    #5 0x7fa51f12548f  (/lib64/libxkbcommon.so.0+0x1948f) (BuildId: 72e8cb985db37963272d140f7b2aee551c465ff5)
    #6 0x7fa51f125c9e  (/lib64/libxkbcommon.so.0+0x19c9e) (BuildId: 72e8cb985db37963272d140f7b2aee551c465ff5)
    #7 0x7fa51f126a59  (/lib64/libxkbcommon.so.0+0x1aa59) (BuildId: 72e8cb985db37963272d140f7b2aee551c465ff5)
    #8 0x7fa51f12cec6  (/lib64/libxkbcommon.so.0+0x20ec6) (BuildId: 72e8cb985db37963272d140f7b2aee551c465ff5)
    #9 0x7fa51f12e3c2  (/lib64/libxkbcommon.so.0+0x223c2) (BuildId: 72e8cb985db37963272d140f7b2aee551c465ff5)
    #10 0x7fa51f12a4e5 in xkb_keymap_new_from_names (/lib64/libxkbcommon.so.0+0x1e4e5) (BuildId: 72e8cb985db37963272d140f7b2aee551c465ff5)
    #11 0x5574dd63f864 in verify_xkb_rmlvo /usr/src/debug/systemd/src/locale/xkbcommon-util.c:69:14
(snip)
```
2025-05-14 02:28:27 +09:00
Yu Watanabe
59dd650501 TEST-21-DFUZZER: skip test when no sanitizer is enabled 2025-05-14 02:28:22 +09:00
Lennart Poettering
f9b186c21a test: add test for "systemd-run -v" 2025-05-13 15:39:57 +02:00
Lennart Poettering
80ab0e04d3 test: add sync request until all logging about the test unit is done 2025-05-13 14:42:34 +02:00
Ivan Kruglov
f08c134661 tests: tests for io.systemd.manager.Describe 2025-05-13 01:55:15 -07:00
Mike Yuan
2950fb1b9b run0: drop -a short switch for --area=
Follow-up for f44e7a8c11

This breaks the rule stated at the beginning of help_sudo_mode():

> NB: Let's not go overboard with short options: we try to keep a modicum of compatibility with
> sudo's short switches, hence please do not introduce new short switches unless they have a roughly
> equivalent purpose on sudo. Use long options for everything private to run0.
2025-05-13 08:33:10 +09:00