Commit Graph

84544 Commits

Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek
492ae9ec4e ssh-generator: filter out bogus vsock addresses
When VirtIO VSOCK device is not present, IOCTL_VM_SOCKETS_GET_LOCAL_CID
returns VMADDR_CID_LOCAL/1, and we issue a hint to connect to vsock%1.
This does not work. Filter out VMADDR_CID_LOCAL and VMADDR_CID_HOST,
those are not real addresses that can be used from the outside.
2025-11-06 10:32:12 +01:00
Zbigniew Jędrzejewski-Szmek
3bfdc950f7 basic/vsock: report result of IOCTL_VM_SOCKETS_GET_LOCAL_CID 2025-11-05 18:33:44 +01:00
Chris Down
666cd35be4 core: Only apply unprivileged userns logic to user managers
Commit 38748596f0 ("core: Make DelegateNamespaces= work for user
managers with CAP_SYS_ADMIN") refactored the logic for when an
unprivileged process should create a new user namespace for sandboxing.

This refactor inadvertently removed a check (`params->runtime_scope !=
RUNTIME_SCOPE_USER`) that differentiated between system services and user
services.

This causes a regression in rootless containers where systemd runs
unprivileged. When starting a system service (like `dbus-broker`) that
uses sandboxing features (eg. with `PrivateTmp=yes`), systemd now
incorrectly creates a new, minimal `PRIVATE_USERS_SELF` namespace.

This new namespace only maps UID/GID 0. When dbus-broker attempts to
drop privileges to the `dbus` user (GID 81), the `setresgid(81, 81, 81)`
call fails because GID 81 is not mapped.

Restore the check to ensure that the special unprivileged sandboxing
logic is only applied to user services, as was the original intent.
System services in a rootless context will now correctly run in the
container's main user namespace, where all necessary UIDs/GIDs are
mapped.

Fixes: https://github.com/systemd/systemd/issues/39563
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2391343
2025-11-05 21:12:52 +08:00
Yu Watanabe
3a2c46dfbe core/manager: small cleanups (#39562) 2025-11-05 21:17:54 +09:00
Mike Yuan
f873ac8727 core/manager: rearrange several struct fields 2025-11-05 10:40:22 +01:00
Mike Yuan
4fc9e19f7f core/manager: drop unneeded "struct" 2025-11-05 10:40:21 +01:00
Mike Yuan
185af6ebd3 core/manager: kill unused default_unit_job_id field
While at it, make sure the "Queued ... job for default target"
message is always logged, i.e. also when we fall back to
start job instead of isolate.
2025-11-05 10:39:30 +01:00
Yu Watanabe
5468cd269f tpm2-setup: fix typo
Follow-up for 8a6e77f1a8.
2025-11-05 18:18:49 +09:00
Yu Watanabe
f91fd8d5a1 tar-util: fix typo
Follow-up for 4ded7f7a43.
2025-11-05 18:17:23 +09:00
Daan De Meyer
81c7c6b62e tree-wide: cleanup headers (#39559) 2025-11-05 08:41:14 +01:00
Yu Watanabe
8457f2a395 TEST-64-UDEV-STORAGE: generate debugging logs
Let's see if it provides something useful for debugging issue #39544.
2025-11-05 05:16:48 +09:00
Yu Watanabe
bb1c5449fb sd-dns-resolver: move header to src/systemd
This also adds missing license header.

Follow-up for ee2108dcd5.
2025-11-05 05:16:34 +09:00
Yu Watanabe
89040373dd libsystemd: drop unused header
Follow-up for 2dbf1c0f15.
2025-11-05 05:16:34 +09:00
Yu Watanabe
5963cdf498 tree-wide: add missing '#pragma once' 2025-11-05 05:16:34 +09:00
Luca Boccassi
1e1f63e63b test: rework dmsetup test to wait for device to disappear
There might be a delay between an umount and a refcounted device
to disappear, so the test can be flaky:

[   36.107128] TEST-50-DISSECT.sh[1662]: ++ dmsetup ls
[   36.108314] TEST-50-DISSECT.sh[1663]: ++ grep loop
[   36.109283] TEST-50-DISSECT.sh[1664]: ++ grep -c verity
[   36.110284] TEST-50-DISSECT.sh[1360]: + test 1 -eq 1
[   36.111555] TEST-50-DISSECT.sh[1360]: + umount -R /tmp/TEST-50-IMAGES.hxm/mount
[   36.112237] TEST-50-DISSECT.sh[1668]: ++ dmsetup ls
[   36.113039] TEST-50-DISSECT.sh[1669]: ++ grep loop
[   36.113833] TEST-50-DISSECT.sh[1670]: ++ grep -c verity
[   36.114517] TEST-50-DISSECT.sh[1360]: + test 0 -eq 1
[   36.116734] TEST-50-DISSECT.sh[1000]: + echo 'Subtest /usr/lib/systemd/tests/testdata/units/TEST-50-DISSECT.dissect.sh failed'

https://github.com/systemd/systemd/actions/runs/19062162467/job/54444112653?pr=39540#logs

Switch to searching for the dm entry and check for it specifically,
and wait for it to disappear before checking that it is no longer
in the dm table.

Follow-up for 10fc43e504
2025-11-05 04:08:44 +09:00
Yu Watanabe
71d64f0527 core/service: reload fixlets (#39376)
Fixes https://github.com/systemd/systemd/issues/37515
2025-11-05 02:54:38 +09:00
Yu Watanabe
d954161f9b core/exec-invoke: gracefully handle lack of privilege for initgroups() in user mode (#39039)
Fixes #39038
2025-11-05 02:53:05 +09:00
Yu Watanabe
cfc7fd426d sysext: Check for /etc/initrd-release in given --root= tree (#39473) 2025-11-05 02:51:25 +09:00
Yu Watanabe
82b6dc1a17 sd-json: accept NULL path in sd_json_parse_file_at() too, port one manual fdopen() to it (#39538) 2025-11-05 01:40:27 +09:00
jouyouyun
2b8c7adbec cgls: print error messages when --unit and --user-unit are used together
Mixing the `--unit` and `--user-unit` options will result in error messages.
During the parsing phase, only the `arg_show_unit` record of the last
occurrence of the option is used; all names are placed in the same `arg_names`,
thus mixing the two types of units in the query.

For example, `-u foo --user-unit bar` will also treat `foo` as a user unit and
query it in the user service.
2025-11-05 01:38:18 +09:00
Chris Down
a8c3ac6672 systemctl: Fix shutdown time parsing across DST changes
When parsing an absolute time specification like `hh:mm` for the
`shutdown` command, the code interprets a time in the past as "tomorrow
at this time". It currently implements this by adding a fixed 24-hour
duration (`USEC_PER_DAY`) to the timestamp.

This assumption breaks across DST transitions, as the day might not be
24 hours long. This can cause the shutdown to be scheduled at the wrong
time (typically off by one hour in either direction).

Change the logic to perform calendar arithmetic instead of timestamp
arithmetic. If the calculated time is in the past, we increment
`tm.tm_mday` and call `mktime_or_timegm_usec()` a second time.

This delegates all date normalization logic to `mktime()`, which
correctly handles all edge cases, including DST transitions, month-end
rollovers, and leap years.

Fixes: https://github.com/systemd/systemd/issues/39232
2025-11-05 01:36:47 +09:00
jouyouyun
05b880ac46 nss-myhostname: use FAMILY_ADDRESS_SIZE instead of the integer 16 when copying ip addr
To avoid copying extra characters when using IPv4.
2025-11-05 01:33:31 +09:00
Daan De Meyer
9d129ea34e machined/import: allow running in per-user mode (#38728) 2025-11-04 17:27:43 +01:00
Quentin Deslandes
6971798864 core: use proper service type of TEST-07-PID.user-namespace-path.sh
TEST-07-PID.user-namespace-path.sh is flaky as Type=simple is used
(implicitly), explicitly use Type=exec instead to ensure the namespaces
are created before starting another service reusing the same namespaces.

Fixes #39546.
2025-11-04 15:54:06 +00:00
Luca Boccassi
22311a1291 test: stop piping post-test journalctl commands to /failed
We can't see what the actual issues are when tests fail at that point, eg:

https://github.com/systemd/systemd/actions/runs/19034752357/job/54356278052
2025-11-04 15:53:23 +00:00
Lennart Poettering
9a1d72fe99 update TODO 2025-11-04 14:12:39 +01:00
Lennart Poettering
4248b02c44 test: add test case 2025-11-04 14:12:39 +01:00
Lennart Poettering
78a738f4cf tar-util: squash high UIDs in user mode 2025-11-04 14:12:39 +01:00
Lennart Poettering
4ded7f7a43 tar-util: add support for acls 2025-11-04 14:12:39 +01:00
Lennart Poettering
e1e170feca tar-util: add support for file flags 2025-11-04 14:12:39 +01:00
Lennart Poettering
a54f4520f3 tar-util: properly deal with sparse files
The extractor already deals with sparse files properly (because
archive_read_data_into_fd() does).

Let's also make sure the archiver also does this, and attaches the
necessary sparse file metadata to each file.
2025-11-04 14:12:39 +01:00
Lennart Poettering
63bf3ca8b0 tar-util: recognize hardlinks when generating tarballs 2025-11-04 14:12:39 +01:00
Lennart Poettering
d4d94fceba tar-util: include xattrs in generated tarballs
We can already unpack them, let's pack them up to.
2025-11-04 14:12:39 +01:00
Lennart Poettering
f89c914968 acl-util: add new acl_set_perm() helper 2025-11-04 14:12:39 +01:00
Kai Lueke
570eae5007 sysext: Check for /etc/initrd-release in given --root= tree
Both sysext and confext used the host's /etc/initrd-release file even
when --root=/somewhere was specified. A workaround was the
SYSTEMD_IN_INITRD= env var but without knowing this it was quite
confusing. Aside from users validating their extensions, the primary
use case for this to matter is when the extensions are set up from the
initrd where the initrd-release file is present when running but we want
to prepare the extensions for the final system and thus should match
for the right scope.
Make systemd-sysext check for /etc/initrd-release inside the given
--root= tree. An alternative would be to always ignore the
initrd-release check when --root= is passed but this way it is more
consistent. The image policy logic for EFI-loader-passed extensions
won't take effect when --root= is used, though.
2025-11-04 22:10:50 +09:00
Kai Lueke
6649562924 test: Add missing test cleanup for the last sysext test
The last sysext test leaked things into new tests added later,
uncovered by any new tests leftover check.
Remove the mutable folder state through a trap as done in other tests.
2025-11-04 22:10:18 +09:00
Lennart Poettering
030f239a19 varlink-idl: add infra to test our enum parsers against varlink IDL enums
In many cases we want to expose enums for which we have the usual
xyz_to_string()/xyz_from_string() via Varlink as enums. Let's add some
infra to test the tables against each other, to automatically detect
when they deviate.

In order to implement this properly, let's export/introduce clean
json_underscorefy()/json_dashify(), for dealing with the fact that our
enums usually use dash separates ames, but Varlink doesn't allow that.

(This does not add the test cases for all enum types we expose right
now, but only adds the general infra).
2025-11-04 11:46:17 +00:00
Mike Yuan
ca8658120e TEST-80-NOTIFYACCESS: add test case for #37515 2025-11-04 12:18:34 +01:00
Mike Yuan
b03e1b09af core/service: rework ExecReload= + Type=notify-reload interaction, add ExecReloadPost=
When Type=notify-reload got introduced, it wasn't intended to be
mutually exclusive with ExecReload=. However, currently ExecReload=
is immediately forked off after the service main process is signaled,
leaving states in between essentially undefined. Given so broken
it is I doubt any sane user is using this setup, hence I took a stab
to rework everything:

1.  Extensions are refreshed (unchanged)
2.  ExecReload= is forked off without signaling the process
3a. If RELOADING=1 is sent during the ExecReload= invocation,
    we'd refrain from signaling the process again, instead
    just transition to SERVICE_RELOAD_NOTIFY directly and
    wait for READY=1
3b. If not, signal the process after ExecReload= finishes
    (from now on the same as Type=notify-reload w/o ExecReload=)
4.  To accomodate the use case of performing post-reload tasks,
    ExecReloadPost= is introduced which executes after READY=1

The new model greatly simplifies things, as no control processes
will be around in SERVICE_RELOAD_SIGNAL and SERVICE_RELOAD_NOTIFY
states.

See also: https://github.com/systemd/systemd/issues/37515#issuecomment-2891229652
2025-11-04 12:18:33 +01:00
Mike Yuan
b3c6709fde macro: add 21st case for IN_SET 2025-11-04 12:17:33 +01:00
Mike Yuan
48632305c7 man/org.freedesktop.systemd1: fix typo (ExecStop -> -Post) 2025-11-04 12:17:33 +01:00
Mike Yuan
1b4cf02ada core/service: fix missing error handling for refresh-extensions control process 2025-11-04 12:17:33 +01:00
Mike Yuan
5fb8387c67 core/service: reset all reload-related states once a cycle completes
Fixes #37515
2025-11-04 12:17:33 +01:00
Mike Yuan
584e89f26e core/service: consolidate where to initialize reload_result 2025-11-04 12:17:32 +01:00
Mike Yuan
98734ac74d core/service: forbid reverting STOPPING=1
We don't permit state transition from STOPPING back to RUNNING,
hence refrain from resetting notify_state too.
2025-11-04 12:17:32 +01:00
Mike Yuan
ed834f11cb core/service: split out service_notify_message_process_state()
No functional change, preparation for later changes.
2025-11-04 12:17:32 +01:00
Mike Yuan
3d888e2dad core/service: add missing serialization for notify_state
This really should be persisted across daemon-reload since
it might contain deferred state transitions.
2025-11-04 12:17:32 +01:00
Mike Yuan
38ea58a907 core/service: remove effectively unused NOTIFY_UNKNOWN state
We usually use _INVALID enum value as placeholder.

While at it, reset notify_state in service_enter_dead() for consistency.
2025-11-04 12:17:31 +01:00
Mike Yuan
1b5a9a7d56 core/service: avoid duplicate unit_add_to_dbus_queue() call
If we're changing state anyways, service_set_state() -> unit_notify()
will take care of dbus signaling for us.
2025-11-04 12:17:31 +01:00
Mike Yuan
1b272d778a core/service: introduce SERVICE_STATE_WITH_WATCHDOG 2025-11-04 12:17:31 +01:00