1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-18 10:04:04 +03:00

52380 Commits

Author SHA1 Message Date
Luca Boccassi
ed803ee195
journalctl: make --setup-keys honor --output=json and --quiet (#35507)
Closes #35503.
Closes #35504.
2024-12-13 13:40:09 +00:00
Daan De Meyer
284dd31e9d core: Bind mount notify socket to /run/host/notify in sandboxed units
To be able to run systemd in a Type=notify transient unit, the notify
socket can't be bind mounted to /run/systemd/notify as systemd in the
transient unit wants to use that as its own notify socket which conflicts
with systemd on the host.

Instead, for sandboxed units, let's bind mount the notify socket to
/run/host/notify as documented in the container interface. Since we don't
guarantee a stable location for the notify socket and insist users use
$NOTIFY_SOCKET to get its path, this is safe to do.
2024-12-13 13:37:02 +01:00
Daan De Meyer
5575bf5fac
core/namespace: several fixes for recently merged PRs (#35580)
Fixes #35546.
Fixes #35566.
2024-12-13 12:34:11 +00:00
Luca Boccassi
6dfd290031
core: Add PrivateUsers=full (#35183)
Recently, PrivateUsers=identity was added to support mapping the first
65536 UIDs/GIDs from parent to the child namespace and mapping the other
UID/GIDs to the nobody user.

However, there are use cases where users have UIDs/GIDs > 65536 and need
to do a similar identity mapping. Moreover, in some of those cases,
users want a full identity mapping from 0 -> UID_MAX.

To support this, we add PrivateUsers=full that does identity mapping for
all available UID/GIDs.

Note to differentiate ourselves from the init user namespace, we need to
set up the uid_map/gid_map like:
```
0 0 1
1 1 UINT32_MAX - 1
```

as the init user namedspace uses `0 0 UINT32_MAX` and some applications
- like systemd itself - determine if its a non-init user namespace based
on uid_map/gid_map files.

Note systemd will remove this heuristic in running_in_userns() in
version 258 (https://github.com/systemd/systemd/pull/35382) and uses
namespace inode. But some users may be running a container image with
older systemd < 258 so we keep this hack until version 259 for version
N-1 compatibility.

In addition to mapping the whole UID/GID space, we also set
/proc/pid/setgroups to "allow". While we usually set "deny" to avoid
security issues with dropping supplementary groups
(https://lwn.net/Articles/626665/), this ends up breaking dbus-broker
when running /sbin/init in full OS containers.

Fixes: #35168
Fixes: #35425
2024-12-13 12:25:13 +00:00
Florian Schmaus
718b31138b logind: let system-wide idle begin at the time logind was initialized
Initialize the start of the system-wide idle time with the time logind was
initialized and not with the start of the Unix epoch. This means that systemd
will not repport a unreasonable long idle time (around 54 years at the time of
writing this), especially at in the early boot, while no login manager session,
e.g,. gdm, had a chance to provide a more accurate start of the idle period.

Fixes #35163
2024-12-13 12:12:21 +00:00
Mike Yuan
8a1068931d
Couple small cleanups (#35593) 2024-12-13 13:01:27 +01:00
Daan De Meyer
1c43f92a2a
basic/fileio: two modernizations (#35559) 2024-12-13 11:49:12 +00:00
Mike Yuan
8abeebdf83 core/mount: don't keep cred mounts around after mounted
Follow-up for 6577cf1ba96027053cedce97ebb22d4ea96887bd
2024-12-13 10:29:27 +00:00
Luca Boccassi
81e0693465 test-loop-block: return -77 on skip in more places 2024-12-12 23:11:29 +00:00
Luca Boccassi
60d23b7f4a battery-check: parse options before checking for kernel command line
Otherwise --help/--version/etc which exit immediately will do pointless work
2024-12-12 23:11:29 +00:00
Luca Boccassi
9fdf10604b
core: fix loading verity settings for MountImages= (#35577)
The MountEntry logic was refactored to store the verity
settings, and updated for ExtensionImages=, but not for
MountImages=.

Follow-up for a1a40297dbfa5bcd926d1a19320deb73c033c6f5
2024-12-12 13:06:07 +00:00
Luca Boccassi
fc35981fda
network: several cleanups (#35267) 2024-12-12 12:47:23 +00:00
Ryan Wilson
2665425176 core: Set /proc/pid/setgroups to allow for PrivateUsers=full
When trying to run dbus-broker in a systemd unit with PrivateUsers=full,
we see dbus-broker fails with EPERM at `util_audit_drop_permissions`.

The root cause is dbus-broker calls the setgroups() system call and this
is disallowed via systemd's implementation of PrivateUsers= by setting
/proc/pid/setgroups = deny. This is done to remediate potential privilege
escalation vulnerabilities in user namespaces where an attacker can remove
supplementary groups and gain access to resources where those groups are
restricted.

However, for OS-like containers, setgroups() is a pretty common API and
disabling it is not feasible. So we allow setgroups() by setting
/proc/pid/setgroups to allow in PrivateUsers=full. Note security conscious
users can still use SystemCallFilter= to disable setgroups() if they want
to specifically prevent this system call.

Fixes: #35425
2024-12-12 11:36:10 +00:00
Luca Boccassi
184ce19841
gpt-auto: take timeout opts in rootflags= into account; hibernate-resume: always respect user-defined timeout (#35518) 2024-12-12 11:01:40 +00:00
Luca Boccassi
47859053ba
Export two more functions, and update symbol tests (#35578)
Prompted by #35554.
Continuation of #35555.
2024-12-12 10:39:29 +00:00
Yu Watanabe
2e6025b1b1 core/namespace: use ProtectHostname in NamespaceParameters
To make the type of NamespaceParameters.protect_hostname consistent
with the one in ExecContext.

Addresses https://github.com/systemd/systemd/pull/35447#discussion_r1880372452.
Fixes #35566.
2024-12-12 19:33:34 +09:00
Yu Watanabe
831bbaf5cd creds: support --transcode=help and --with-key=help 2024-12-12 15:25:34 +09:00
Yu Watanabe
2a92e0bc6c string-table: make DUMP_STRING_TABLE() returns 0
Then, we can use it as
===
  return DUMP_STRING_TABLE(...);
===
2024-12-12 15:21:16 +09:00
Yu Watanabe
66d2c693ac tpm2-util: allow to control if legend and/or footer shown by tpm2_list_devices() 2024-12-12 15:21:16 +09:00
Yu Watanabe
0b39dc23ba test: also generate list of symbols from header files
To make the generated tests able to detect issues like #35554.
2024-12-12 15:04:28 +09:00
Yu Watanabe
6e399ece1f test: modernize generate-sym-test.py 2024-12-12 15:03:36 +09:00
Yu Watanabe
5fcabde35b sd-json: properly export sd_json_variant_type_from_string() and _to_string()
These exist in the header file, but were not exporeted.

Continuation of e11f5aa7226253bf31b2ed61be8599bb213c1819.
2024-12-12 13:08:35 +09:00
Luca Boccassi
59a83e1188 core: fix loading verity settings for MountImages=
The MountEntry logic was refactored to store the verity
settings, and updated for ExtensionImages=, but not for
MountImages=.

Follow-up for a1a40297dbfa5bcd926d1a19320deb73c033c6f5
2024-12-12 00:58:20 +00:00
Yu Watanabe
46c26454bd exec-util: use strv_from_stdarg_alloca()
No functional change, just refactoring.
2024-12-12 08:35:16 +09:00
Yu Watanabe
f0ace1655d exec-util: use open_terminal() in fork_agent() for safety 2024-12-12 08:35:16 +09:00
Yu Watanabe
90579fd0b3 exec-util: drop handling of ENXIO in opening /dev/tty
This effectively reverts 0bcf1679007e71d1d37666c10ab1f8d46de8d570.

The handling is not necessary anymore after 61242b1f0f9cac399deb67c88c3b62d38218dba3.
2024-12-12 08:35:16 +09:00
Yu Watanabe
fc3691a70a exec-util: split out common checks before fork_agent() to can_fork_agent()
No functional change, just refactoring.
2024-12-12 08:32:42 +09:00
Yu Watanabe
388d6c5f37 polkit-agent: modernize code a bit
- Use _cleanup_close_pair_ attribute for the pipe FDs,
- Return earlier on failure in forking polkit agent.
2024-12-12 08:30:55 +09:00
Yu Watanabe
0f81c8406f exec-util: allow to invoke polkit/ask-password agent even if STDIN is not a tty
Closes #35018.
2024-12-12 08:30:55 +09:00
Yu Watanabe
4899255aa2
format-table: trivial cleanups (#35572) 2024-12-12 06:12:07 +09:00
Mike Yuan
3ae314afdc Revert "run: disable --expand-environment by default for --scope"
This reverts commit 8167c56bfa97525a7b12e7c5685576657364e3cf.

We've announced the breaking change during v254-v257. Let's actually
apply it for v258.
2024-12-12 06:05:30 +09:00
Yu Watanabe
7e438055a6
pretty-print: don't use OSC 8 for incompatible URLs (#35223) 2024-12-12 05:43:36 +09:00
Mike Yuan
eded4272d2 cgroup-util: introduce cg_get_cgroupid_at()
Suggested in https://github.com/systemd/systemd/pull/35242#discussion_r1862658163
2024-12-12 05:19:07 +09:00
Mike Yuan
2522757a89 nsresourced: drop unneeded REMOVE_PHYSICAL flag for rm_rf()
Even without REMOVE_PHYSICAL, rm_rf() permits cgroupfs.
2024-12-12 05:17:17 +09:00
Yu Watanabe
ab5de638e9
process-util: modernize is_main_thread(); make sure get_process_ppid() won't return ppid == 0 (#35561)
Split out from #35242
2024-12-12 05:16:04 +09:00
Lennart Poettering
e11f5aa722 sd-varlink: properly export sd_varlink_reset_fds()
This function was listed in the public sd-varlink.h header, but not
actually made public. Fix that. It's quite useful, the comment in it
describes the usecase nicely.

Fixes: #35554
2024-12-12 05:13:12 +09:00
Yu Watanabe
e53be91e5d
libfido2-util: show also verity features when listing FIDO2 devices (#35295)
This way, users don't have to check those features using an external
program, or wait for later failure when trying to enroll using an
unsupported feature.

E.g.:

```
# systemd-cryptenroll --fido2-device list
PATH         MANUFACTURER PRODUCT               RK  CLIENTPIN UP  UV
/dev/hidraw2 Yubico       YubiKey OTP+FIDO+CCID yes no        yes no
```
2024-12-12 05:11:46 +09:00
Yu Watanabe
bfff0f5ac8
Add credential support for mount units (#34732)
Add `EXEC_SETUP_CREDENTIALS` flag to allow using credentials with mount units.
Fixes: #23535
2024-12-12 05:07:35 +09:00
Daan De Meyer
1c658c639d test-bpf-restrict-fs: Migrate to new assertion macros 2024-12-12 05:05:30 +09:00
Lennart Poettering
3c702e8210 condition: add new ConditionKernelModuleLoaded=
This introduces a new unit condition check: that matches if a specific
kmod module is allowed. This should be generally useful, but there's one
usecase in particular: we can optimize modprobe@.service with this and
avoid forking out a bunch of modprobe requests during boot for the same
kmods.

Checking if a kernel module is loaded is more complicated than just
checking if /sys/module/$MODULE/ exists, since kernel modules typically
take a while to initialize and we must check that this is complete (by
checking if the sysfs attr "initstate" is "live").
2024-12-12 05:03:52 +09:00
Yu Watanabe
c9011f170b
journalctl: also mangle unit name when --invocation= or --list-invocations is specified (#35542)
Fixes #35538.
2024-12-12 05:01:54 +09:00
Ronan Pigott
9171384149 manager: add list of subscribers to dump info
This is handy for debugging.
2024-12-11 12:12:14 -07:00
Ronan Pigott
11ee1bab60 dbus: log disconnect on api and system busses
This is an interesting event. Let's log about it.
2024-12-11 12:12:14 -07:00
Daan De Meyer
15816441ca namespace: Rename notify_socket to host_notify_socket
Preparation for next commit.
2024-12-11 19:08:38 +00:00
Lennart Poettering
9948b4668c virt: drop userns detection heuristic
Now that we have an explicit userns check we can drop the heuristic for
it, given that it's kinda wrong (because mapping the full host UID range
into a userns is actually a thing people do).

Hence, just delete the code and only keep the userns inode check in
place.
2024-12-11 19:23:03 +01:00
Lennart Poettering
7f0a615ef8 virt: dont check for cgroupns anymore
Now that we have a reliable pidns check I don't think we really should
look for cgroupns anymore, it's too weak a check. I mean, if I myself
would implement a desktop app sandbox (like flatpak) I'd always enable
cgroupns, simply to hide the host cgroup hierarchy.

Hence drop the check.

I suggested adding this 4 years ago here:

https://github.com/systemd/systemd/pull/17902#issuecomment-745548306
2024-12-11 19:23:03 +01:00
Mike Yuan
8f3862ceed
userdbctl: use ansi_highlight_green_red() where appropriate 2024-12-11 19:19:46 +01:00
Mike Yuan
26c29eed53
format-table: drop pointless table_data_rgap_color() func
Follow-up for aab79f52784b4778ae0534452757d9fbf608076a
2024-12-11 19:19:46 +01:00
Mike Yuan
da7cd0f500
format-table: minor modernization 2024-12-11 19:14:28 +01:00
Mike Yuan
ad9a66fee8
basic/fileio: clean up executable_is_script() a bit
- Rename to script_get_shebang_interpreter and return
  -EMEDIUMTYPE if the executable is not a script.
  We nowadays utilize the scheme of making ret param
  of getters optional, and use them directly as checkers.
- Don't unnecessarily read the whole line, but check
  only the shebang first.
2024-12-11 19:11:22 +01:00