Commit Graph

6513 Commits

Author SHA1 Message Date
Yu Watanabe
95cd21928f Merge pull request #22939 from yuwata/tree-wide-space
tree-wide: add space after if, switch, for, and while
2022-04-02 01:32:26 +09:00
Yu Watanabe
798931160e tree-wide: add a space after if, switch, for, and while 2022-04-01 22:48:42 +09:00
Lennart Poettering
63e8df046b pid1: add taint flag if uid/gid userns range too small
This will taint systemd if invoked in containers that do not have the
full 16bit range of UIDs defined.

we pretty much need uid root…nobody to be defined for a variety of
purposes, hence let's add this taint flag. Of course taints are
graceful, but it at least communicates the mess in some way...
2022-04-01 11:21:44 +02:00
Lennart Poettering
40efaaed42 pid1: check for kernels older than baseline
Let's make this detectable explicitly.
2022-03-31 22:11:20 +01:00
Zbigniew Jędrzejewski-Szmek
53877d0385 Merge pull request #22649 from keszybz/symlink-enablement-yet-again-punish-me-harder
Fixups to the unit enablement logic
2022-03-29 21:10:03 +02:00
наб
0017be9d77 Fix typos in user-util.c and dbus-unit.c 2022-03-29 17:58:37 +01:00
Zbigniew Jędrzejewski-Szmek
b380b64383 Rename UnitFileScope to LookupScope
As suggested in
8b3ad3983f (r837345892)

The define is generalized and moved to path-lookup.h, where it seems to fit
better. This allows a recursive include to be removed and in general makes
things simpler.
2022-03-29 16:17:57 +02:00
Zbigniew Jędrzejewski-Szmek
99aad9a2b9 systemctl: fix silent failure when --root is not found
Some calls to lookup_path_init() were not followed by any log emission.
E.g.:
$ SYSTEMD_LOG_LEVEL=debug systemctl --root=/missing enable unit; echo $?
1

Let's add a helper function and use it in various places.

$ SYSTEMD_LOG_LEVEL=debug build/systemctl --root=/missing enable unit; echo $?
Failed to initialize unit search paths for root directory /missing: No such file or directory
1
$ SYSTEMCTL_SKIP_SYSV=1 build/systemctl --root=/missing enable unit; echo $?
Failed to initialize unit search paths for root directory /missing: No such file or directory
Failed to enable: No such file or directory.
1

The repeated error in the second case is not very nice, but this is a niche
case and I don't think it's worth the trouble to trying to avoid it.
2022-03-29 16:17:56 +02:00
Zbigniew Jędrzejewski-Szmek
172e9cc3ee shared/specifier: fix %u/%U/%g/%G when called as unprivileged user
We would resolve those specifiers to the calling user/group. This is mostly OK
when done in the manager, because the manager generally operates as root
in system mode, and a non-root in user mode. It would still be wrong if
called with --test though. But in systemctl, this would be generally wrong,
since we can call 'systemctl --system' as a normal user, either for testing
or even for actual operation with '--root=…'.

When operating in --global mode, %u/%U/%g/%G should return an error.

The information whether we're operating in system mode, user mode, or global
mode is passed as the data pointer to specifier_group_name(), specifier_user_name(),
specifier_group_id(), specifier_user_id(). We can't use userdata, because
it's already used for other things.
2022-03-29 16:17:56 +02:00
Yu Watanabe
2afb2f4a9d Merge pull request #22885 from poettering/kill-clock-boottime-or-monotonic
time-util: assume CLOCK_BOOTTIME always exists
2022-03-29 03:06:54 +09:00
Yu Watanabe
288bd40620 fix typo 2022-03-29 01:21:51 +09:00
Lennart Poettering
ba4e0427e9 time-util: assume CLOCK_BOOTTIME always exists
Let's raise our supported baseline a bit: CLOCK_BOOTTIME started to work
with timerfd in kernel 3.15 (i.e. back in 2014), let's require support
for it now.

This will raise our baseline only modestly from 3.13 → 3.15.
2022-03-28 16:55:41 +02:00
Yu Watanabe
00adc340bb inotify-util: declare iterator in FOREACH_INOTIFY_EVENT()
This also makes the macro check if the event is actually in the buffer,
and if it is not, then log about that and finish the loop.
2022-03-24 23:12:34 +00:00
Lennart Poettering
d01133125c bpf-firewall: invert test
Following our coding style of exiting early (instead of deep nesting),
let's invert the if check here.

Inspired by: https://github.com/systemd/systemd/pull/21602#pullrequestreview-919960060
2022-03-24 13:54:50 +01:00
Yu Watanabe
e7bf2fcab0 core/namespace: inline one more iterator variable 2022-03-23 21:57:39 +09:00
Zbigniew Jędrzejewski-Szmek
5980d46304 strv: declare iterator of FOREACH_STRING() in the loop
Same idea as 03677889f0.

No functional change intended. The type of the iterator is generally changed to
be 'const char*' instead of 'char*'. Despite the type commonly used, modifying
the string was not allowed.

I adjusted the naming of some short variables for clarity and reduced the scope
of some variable declarations in code that was being touched anyway.
2022-03-23 11:50:18 +01:00
Nishal Kulkarni
38c41427c7 core/oomd: Use oom-kill ServiceResult for oomd
To notify user of kill events from systemd-oomd we now use
`SERVICE_FAILURE_OOM_KILL` as the failure result.

`unit_check_oomd_kill` now calls `notify_cgroup_oom` to
update the service result to `oom-kill`.

We add a new xattr `user.oomd_ooms` to keep track of the OOM kills
initiated by systemd-oomd, this helps us resolve a race between sending
SIGKILL to processes and checking for OOM kill status from the xattr.

Related to: #20649
2022-03-22 17:57:59 +05:30
Nishal Kulkarni
f7829525be core/cgroup: Add OOM check
Check if process(es) of a cgroup were killed by Kernel OOM killer
or systemd-oomd before we send the cgroup empty notification.

This allows us to show the right exit state(ServiceResult)
2022-03-22 00:52:35 +05:30
Zbigniew Jędrzejewski-Szmek
b0a5e59622 Merge pull request #22740 from yuwata/list
tree-wide: declare iterator of LIST_FOREACH() in the loop
2022-03-21 10:52:03 +01:00
Yu Watanabe
de010b0b2e strv: make iterator in STRV_FOREACH() declaread in the loop
This also avoids multiple evaluations in STRV_FOREACH_BACKWARDS()
2022-03-19 08:33:33 +09:00
Yu Watanabe
80a226b26b list: make LIST_FOREACH() and LIST_FOREACH_BACKWARDS() safer 2022-03-19 08:10:29 +09:00
Yu Watanabe
03677889f0 list: declare iterator of LIST_FOREACH() in the loop 2022-03-19 08:10:29 +09:00
Lennart Poettering
ec75e8e07a sd-event: add a single implementation of an event source that runs on clock changes
We basically had the same code in three places. Let's unify it in a
common helper function.

event_add_time_change() might be something we should add to the official
sd-event API sooner or later, given its general usefulness.
2022-03-18 23:53:34 +01:00
Lennart Poettering
52bb308c13 time-util: add macros around timespec_store() that operates on compund literal allocated timespec struct
This way we can convert usec_t to timespec on-the-fly, without a buffer.

No actual behaviour change just some shortening of code.
2022-03-18 17:13:36 +01:00
Zbigniew Jędrzejewski-Szmek
d29cc4d6e1 tree-wide: use strv_contains() in more places 2022-03-18 10:22:20 +01:00
Luca Boccassi
4355c04fef core: insist on sandboxing if ExtensionImages/Directories are configured
Same as other image mounting in the namespace
2022-03-18 10:02:47 +01:00
Lennart Poettering
55c8f9ecb0 Merge pull request #22754 from mrc0mmand/creds_dir_specifier
core: add %d specifier for the $CREDENTIALS_DIRECTORY
2022-03-18 09:23:01 +01:00
Frantisek Sumsal
43b9b2053c core: add %d specifier for the $CREDENTIALS_DIRECTORY
Resolves: #22549
2022-03-17 17:45:01 +01:00
Frantisek Sumsal
598a1d7633 core: drop an unnecessary initialization 2022-03-17 14:39:51 +01:00
Yu Watanabe
8fe84dc8de core: ExecContext::restrict_filesystems is set of string 2022-03-17 20:09:59 +09:00
Lennart Poettering
1fa3b6c247 cgroup: also set user.invocation_id in addition to trusted.invocation_id
Similar thinking as the preceeding commit.

(While we are at it, let's unify some code we use over and over again in
two helper functions)
2022-03-16 16:47:07 +01:00
Lennart Poettering
d9bc1c3614 cgroup: also indicate cgroup delegation state in user-accessible xattr
So far we set the "trusted.delegate" xattr on cgroups where delegation
is on. This duplicates this behaviour with the "user.delegate" xattr.
This has two benefits:

1. unprivileged clients can *read* the xattr. "systemd-cgls" can thus
   show delegated cgroups as such properly, even when invoked without
   privs

2. unprivileged systemd instances can set the xattr, i.e. when systemd
   --user delegates a cgroup to further payloads.

This weakens security a tiny bit, given that code that got a cgroup
delegated can manipulate the xattr, but I think that's OK, given they
have a higher trust level regarding cgroups anyway, if they got a
subtree delegated, and access controls on the cgroup itself are still
enforced. Moreover PID 1 as the cgroup manager only sets these xattrs,
never reads them — the xattr is primarily a way to tell payloads about
the delegation, and it's strictly this one way.
2022-03-16 16:32:44 +01:00
Daan De Meyer
cc20479f42 bpf: Fix error handling
The __open() functions actually set errno on failure so let's
update the error handling to account for that.
2022-03-15 17:14:19 +00:00
Daan De Meyer
8f048bb76a bpf: Log at debug when checking if restricting ifaces is supported
Same change as 1a9e33aee3 did for
socket-bind.
2022-03-15 17:12:06 +00:00
Lennart Poettering
15e152acd1 Merge pull request #22618 from yuwata/network-safe-string
network: dhcp-server: refuse unsafe filename
2022-03-11 11:33:07 +01:00
Luca Boccassi
0d3c36641d Merge pull request #22701 from poettering/raise-memlock
pid1/nspawn: raise RLIMIT_MEMLOCK to 8M matching kernel 5.16's new default
2022-03-11 01:09:33 +00:00
Clyde Byrd III
f4ca32a1bc core/dbus-job: Use new way of specifying sd-bus vtable parameter names 2022-03-11 09:00:18 +09:00
Luca Boccassi
24759d8f08 core: support ExtensionDirectories in user manager
Unprivileged overlayfs is supported since Linux 5.11. The only
change needed to get ExtensionDirectories to work is to avoid
hard-coding the staging directory to the system manager runtime
directory, everything else just works (TM).
2022-03-10 20:38:10 +00:00
Lennart Poettering
69a21030b1 Merge pull request #22460 from bluca/monitor_refactor
core: split $MONITOR_METADATA and return it only if a single unit triggers OnFailure/OnSuccess
2022-03-10 18:34:20 +01:00
Lennart Poettering
852b62507b pid1,nspawn: raise default RLIMIT_MEMLOCK to 8M
This mirrors a similar check in Linux kernel 5.16
(9dcc38e2813e0cd3b195940c98b181ce6ede8f20) that raised the
RLIMIT_MEMLOCK to 8M.

This change does two things: raise the default limit for nspawn
containers (where we try to mimic closely what the kernel does), and
bump it when running on old kernels which still have the lower setting.

Fixes: #16300
See: https://lwn.net/Articles/876288/
2022-03-10 18:30:24 +01:00
Lennart Poettering
eadb4f19b3 main: add 'const' on two function arguments 2022-03-10 18:30:24 +01:00
Luca Boccassi
a8c5363ba9 Merge pull request #22682 from bluca/start_skip
core: do not return 'skipped' when Condition*= fail with StartUnitWithFlags()
2022-03-10 17:25:44 +00:00
Luca Boccassi
e2cb73c946 Merge pull request #22695 from poettering/crash-handle-refactor
pid1: add comment clarifying not to use memory allocation from crash handler
2022-03-10 16:42:50 +00:00
Zbigniew Jędrzejewski-Szmek
a257c941ad manager: pass monitor metadata in more cases
The first ExecStartPre or the first ExecStart commands would get the metadata,
but not the subsequent ones. Also check that we do not pass it in
ExecStartPost.
2022-03-10 14:51:28 +00:00
Zbigniew Jędrzejewski-Szmek
02de9614d4 manager: prevent cleanup of triggering units before we start the handler
This fixes the following case:
OnFailure= would be spawned correctly, but OnSuccess= would be
spawned without the MONITOR_* metadata, because we'd "collect" the unit
that started successfully. So let's block cleanup while we have a job
running for the handler. The job cannot last infinitely, so at some point
we'll be able to collect both.
2022-03-10 14:51:28 +00:00
Zbigniew Jędrzejewski-Szmek
7a5049c780 manager/service: when we have multiple candidates to handle, warn
This would be very confusing to users, so let's warn if they configured the
same handler for multiple units and we're not running it as expected.
2022-03-10 14:51:28 +00:00
Zbigniew Jędrzejewski-Szmek
edbf8984a4 manager/service: when we spawn, say why
We already logged what we are spawning, but not so much why. Let's
add this, so it's easier to distinguish execstartpre/execstart/execstartpost
and such.
2022-03-10 14:51:28 +00:00
Zbigniew Jędrzejewski-Szmek
82acee149c manager: log how many OnSuccess/OnFailure jobs were started 2022-03-10 14:51:28 +00:00
Zbigniew Jędrzejewski-Szmek
adf769b06c manager: adjust comment 2022-03-10 14:51:28 +00:00
Zbigniew Jędrzejewski-Szmek
fb1381662b various: align vertically for ease of reading 2022-03-10 14:51:28 +00:00