Commit Graph
7092 Commits
Author SHA1 Message Date
Lennart Poettering 84b4c78570 switch-root: add a comment regarding the safety limits of rm_rf_children() 2023-05-17 01:42:01 +09:00
Mike Yuan 0313c41068 Merge pull request #27638 from YHNdnzj/upheldby-unit-file
unit-file: support UpheldBy= in [Install] settings (adding Upholds= deps from .upholds/)
2023-05-16 21:53:24 +08:00
Lennart Poettering 93d4a200fb Merge pull request #27648 from poettering/common-dissect-dir
pid1: add common root dir inode to mount disk images to in private namespaces
2023-05-16 05:26:48 -07:00
Lennart Poettering b10c4acfa3 Merge pull request #27647 from poettering/mount-setup-tweaklets
mount-setup: minor tweaks
2023-05-16 05:26:09 -07:00
Lennart Poettering 84c61aea0f base-filesystem: mention why we don't carry an entry for /tmp/ for now 2023-05-16 11:45:21 +02:00
Lennart Poettering 4d88d83924 base-filesystem: also set up /run/ mount point if missing
We don't support images without, hence create this one too, like we
create all other relevant mount points we definitely require for
booting.
2023-05-16 11:32:56 +02:00
Lennart Poettering 04dc2db08a mount-setup: minor modernization 2023-05-16 10:01:28 +02:00
Lennart Poettering ce6fa09567 mount-setup: minor log improvement 2023-05-16 10:00:04 +02:00
Lennart Poettering 4900c3e5b1 mount-setup: port to logging about mount attempts via mount_*follow_verbose() 2023-05-16 10:00:04 +02:00
Lennart Poettering a4b3e94236 dissect-image: port mount_image_privately_interactively() to use /run/systemd/mount-rootfs/ too
Let's use the same common directory as the unit logic uses.

This means we have less to clean up, and opens the door to eventually
allow unprivileged operation of the
mount_image_privately_interactively() logic.
2023-05-16 09:26:17 +02:00
Lennart Poettering 3690bfb5b2 namespace: introduce a common dir in /run/ that we can use to see new root fs up on
This creates a new dir /run/systemd/mount-rootfs/ early in PID 1 that
thus always exists. It's supposed to be used by any code that creates
its own mount namespace and then sets up a new root dir to switch into.
So far in many cases we used a temporary dir (which needed explicit
clean-up) or a purpose-specific fixed dir.

Let's create a common dir instead, that always exists (as it is created
in PID 1 early on, always).

Besides making things more robust, as manual clean-up of the inode is
not necessary anymore this also opens the door for unprivileged programs
to use the same dir, since it now always exists.

Set the access mode to 555 (instead of the otherwise previously used
0755, 0700 or similar), so that unprivileged programs can access it, but
we make clear it's not supposed to be written directly to, by anyone,
not even root.
2023-05-16 09:24:45 +02:00
Lennart Poettering a789f72ed2 mount-util: add umount_and_free() helper 2023-05-16 09:24:45 +02:00
Lennart Poettering f81048f8f5 watchdog: always disarm watchdog properly before closing it
If we change the watchdog device we should disarm the old one first.

Similar, if we open the watchdog, but then fail setting it up, disarm it
before closing it again.
2023-05-15 21:55:19 +08:00
Mike Yuan 38f901791f unit-file: support UpheldBy= in [Install] settings (adding Upholds= deps
from .upholds/)

Closes #26896
2023-05-15 15:04:38 +08:00
Daan De Meyer 947f59ba2b conf-parser: Add root argument to config_parse_many() 2023-05-12 17:52:32 +02:00
Daan De Meyer 2bc161dddb mkfs-util: Add quiet argument to make_filesystem()
We default to quiet operation everywhere except for repart, where
we disable quiet and have the mkfs tools write to stdout.

We also make sure --quiet or equivalent is implemented for all mkfs
tools.
2023-05-12 07:51:50 +02:00
Yu Watanabe d94027ad16 bus-util: drop unnecessary continue 2023-05-09 08:08:53 +09:00
Yu Watanabe d2132d3d8d parse-util: make parse_fd() return -EBADF
The previous error code -ERANGE is slightly ambiguous, and use more
specific one. This also drops unnecessary error handlings.

Follow-up for 754d8b9c33 and
e652663a04.
2023-05-08 09:49:55 +02:00
Luca Boccassi 3be6943e07 Merge pull request #26357 from ddstreet/tpm2_policy_session
Tpm2 policy session
2023-05-06 17:02:26 +01:00
Dan Streetman 2cd9d57548 tpm2: move policy building out of policy session creation
This retains the use of policy sessions instead of trial sessions
in most cases, based on the code comment that some TPMs do not
implement trial sessions correctly. However, it's likely that the
issue was not the TPMs, but our code's incorrect use of PolicyPCR
inside a trial session; we are not providing expected PCR values
with our call to PolicyPCR inside a trial session, but the spec
indicates that in a trial session, the TPM *may* return error if
the expected PCR value(s) are not provided. That may have been the
source of the original confusion about trial sessions.

More details:
https://github.com/systemd/systemd/pull/26357#pullrequestreview-1409983694

Also, future commits will replace the use of trial sessions with
policy calculations, which avoids the problem entirely.
2023-05-05 18:34:46 -04:00
Dan Streetman e976445d03 tpm2: add tpm2_is_encryption_session() 2023-05-05 18:32:39 -04:00
Frantisek Sumsal cc938f1ce0 shared: refuse fd == INT_MAX
Since we do `FD_TO_PTR(fd)` that expands to `INT_TO_PTR(fd) + 1` which
triggers an integer overflow.

Resolves: #27522
2023-05-05 22:15:23 +02:00
Luca Boccassi 6ad7989ea0 Merge pull request #27536 from dtardon/checked-fd-parsing
Always check parsed fds for validity
2023-05-05 20:55:48 +01:00
OMOJOLA d685a5f6a4 tpm2 PCRs: fix unchecked attempt to set PCR[24] 2023-05-05 13:07:10 +01:00
David Tardon e652663a04 tree-wide: use parse_fd() 2023-05-05 09:10:56 +02:00
Lennart Poettering ea0f3289a2 mount-util: simplify mount_switch_root() a bit
There's no need to fchdir() out of the rootfs and back into it around
the umount2(), hence don't.

This brings the logic closer to what the pivot_root() man page suggests.

While we are at it, always operate based on fds, once we opened the
original dir, and pass the path string along only for generating
messages (i.e. as "decoration").

Add tests for both code paths: the pivot_root() one and the MS_MOUNT.
2023-05-03 20:52:19 +01:00
Lennart Poettering 9a22b098d2 base-filesystem: unify common parts of base_filesystem_create_fd() branches
The error handling and fchmodat() invocation is pretty much the same in
the directory and symlink branches, hence make them the same.

No real change in behaviour. Just refactoring.
2023-05-03 17:55:55 +02:00
Lennart Poettering 8aefedce14 base-filesystem: add new helper base_filesystem_create_fd() that operates on an fd, instead of a path
This also changes the open flags from
O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|O_NOFOLLOW to
O_DIRECTORY|O_CLOEXEC. O_RDONLY is redundant, since O_RDONLY is zero
anyway, and O_DIRECTORY pins the acces mode enough: it doesn't allow
read()/write() anyway when specified. O_NONBLOCK is also pointless given
that O_DIRECTORY is specified, it has no meaning on directories. (It is
useful if we don't know much about the inode we are opening, and could
be a device node or fifo, but the O_DIRECTORY excludes that case.)

O_NOFOLLOW is dropped since there's really no point in blocking out the
initial entrypoint being a symlink. Once we pinned the the root of the
tree it might make sense to restrict symlink use below it, but for the
entrypoint itself it doesn't matter.
2023-05-03 17:55:55 +02:00
Lennart Poettering f2c1d491a5 switch-root: don't require /mnt/ when switching root into host OS
So far, we invoked pivot_root() specifying /mnt/ as second argument,
which then unmounted right-after. We'd create /mnt/ if needed. This
sucks, because it means /mnt/ must strictly be pre-created on immutable
images.

Remove this limitation, by using pivot_root() with "." as source and
target, which will result in two stacked mounts afterwards: the new one
underneath, the old one ontop. We can then simply unmount the top one,
and have what we want without needing any extra /mnt/ dir.

Since we don't need /mnt/ anymore we can get rid of the extra
unmount_old_root parameter and simply specify it as NULL if we don't
want the old mount to stick around.
2023-05-03 17:55:55 +02:00
Yu Watanabe a76dc1f3a0 Merge pull request #27504 from mrc0mmand/fuzz-manager-serialize
test: add a simple fuzzer for manager serialization
2023-05-03 21:45:26 +09:00
Frantisek Sumsal 740831076c shared: reject empty attachment path 2023-05-03 10:09:53 +02:00
Frantisek Sumsal 1febf60f9d shared: ignore invalid valink socket fd when deserializing 2023-05-03 10:09:53 +02:00
Mike Yuan 5e15fec23d Merge pull request #27492 from poettering/base-filesystem-000
base-filesystem: create /proc, /sys, /dev mount points as 555
2023-05-02 20:53:35 +08:00
Daan De Meyer a3b076f641 tree-wide: Handle EADDRNOTAVAIL as journal corruption
Journal corruption is not only indicated by EBADMSG but also by
EADDRNOTAVAIL so treat that as corruption in a few more cases.
2023-05-02 12:17:41 +02:00
Lennart Poettering 2a10774caa mount-setup: use size_t when iterating through array indexes 2023-05-02 12:06:03 +02:00
Lennart Poettering 7243cefec1 base-filesystem: create /proc, /sys, /dev mount points as 0555
These inodes are going to be overmounted anyway, hence let's create them
with access mode 555, so that they are as close to being immutable as
regular UNIX access modes allow them to be. In other words: this takes
the "w" mode away for root. This of course usually has little effect --
unless CAP_DAC_OVERRIDE is dropped. But at the very least it makes the
point clear that inodes should be considered immutable.

(I intended to make this 0000 originally, but that doesn't work, as many
tools – including our own – have fallback paths that when they see
ENOENT in /proc/ they can handle this gracefully. But changing the mode
to 000 would turn this to EACCES - something they usually have no
fallback path for)
2023-05-02 12:06:03 +02:00
Dan Streetman 9589824158 tpm2: move openssl-required ifdef code out of policy-building function 2023-05-01 00:52:28 +01:00
Lennart Poettering 535358ad2e copy: shortcut reflink_range() to reflink() in some cases 2023-04-28 15:16:30 +02:00
Lennart Poettering 427ad121c2 copy: don't call clone ioctls twice
The btrfs name and the generic name have the same values, hence there's
no point in bothering with the former.
2023-04-28 15:10:24 +02:00
Luca Boccassi 91010bd6cc Merge pull request #27440 from yuwata/reflink-follow-ups
copy: follow ups for reflink()
2023-04-28 11:34:41 +01:00
Yu Watanabe 75fd8ad008 Merge pull request #27424 from dtardon/auto-cleanup
More automatic cleanup
2023-04-28 18:46:36 +09:00
Yu Watanabe 71e84b4be6 copy: rename reflink_full() -> reflink_range()
The commit b640e274a7 introduced reflink()
and reflink_full(). We usually name function xyz_full() for fully
parameterized version of xyz(), and xyz() is typically a inline alias of
xyz_full(). But in this case, reflink() and reflink_full() call
different ioctl().
Moreover, reflink_full() does partial reflink, while reflink() does full
file reflink. That's super confusing.
Let's rename reflink_full() to reflink_range(), the new name is
consistent with ioctl name, and should be fine.
2023-04-28 14:06:00 +09:00
Daan De Meyer b640e274a7 copy: Introduce reflink() and reflink_full()
The kernel has had filesystem independent reflink ioctls for a
while now, let's try to use them and fall back to the btrfs specific
ones if they're not supported.
2023-04-28 00:57:03 +01:00
David Tardon 1cc3a1302f specifier: use _cleanup_ 2023-04-27 21:42:38 +02:00
Lennart Poettering ba8d00e859 pam-systemd: disconnect bus connection when leaving session hook, even on error
This adds support for systematically destroying connections in
pam_sm_session_open() even on failure, so that under no circumstances
unserved dbus connection are around while the invoking process waits for
the session to end.  Previously we'd only do this on success, now do it
in all cases.

This matters since so far we suggested people hook pam_systemd into
their pam stacks prefixed with "-", so that login proceeds even if
pam_systemd fails. This however means that in an error case our
cached connection doesn't get disconnected even if the session then is
invoked. This fixes that.
2023-04-27 17:04:05 +02:00
Lennart Poettering 402014086d pam-util: include PID in PAM data field id
Let's systematically avoid sharing cached busses between processes (i.e.
from parent and child after fork()), by including the PID in the field
name.

With that we're never tempted to use a bus object the parent created in
the child.

(Note this is about *use*, not about *destruction*. Destruction needs to
be checked by other means.)
2023-04-27 17:02:49 +02:00
Mike Yuan 82060b62c9 Merge pull request #25622 from YHNdnzj/tmpfiles-X-bit-support
tmpfiles: add conditionalized execute permission (X) support
2023-04-27 22:40:09 +08:00
Lennart Poettering bcd9b98159 core: change ownership of subcgroup we create recursively, it shall be owned by the user delegated to
If we create a subcroup (regardless if the '.control' subgroup we
always created or one configured via DelegateSubgroup=) it's inside of
the delegated territory of the cgroup tree, hence it should be owned
fully by the unit's users. Hence do so.
2023-04-27 12:18:32 +02:00
Lennart Poettering a8b993dc11 core: add DelegateSubgroup= setting
This implements a minimal subset of #24961, but in a lot more
restrictive way: we only allow one level of subcgroup (as that's enough
to address the no-processes in inner cgroups rule), and does not change
anything about threaded cgroup logic or similar, or make any of this new
behaviour mandatory.

All this does is this: all non-control processes we invoke for a unit
we'll invoke in a subgroup by the specified name.

We'll later port all our current services that use cgroup delegation
over to this, i.e. user@.service, systemd-nspawn@.service and
systemd-udevd.service.
2023-04-27 12:18:32 +02:00
Mike Yuan 26d98cdd78 tmpfiles: add conditionalized execute bit (X) support
According to setfacl(1), "the character X stands for
the execute permission if the file is a directory
or already has execute permission for some user."

After this commit, parse_acl() would return 3 acl
objects. The newly-added acl_exec object contains
entries that are subject to conditionalized execute
bit mangling. In tmpfiles, we would iterate the acl_exec
object, check the permission of the target files,
and remove the execute bit if necessary.

Here's an example entry:
A /tmp/test - - - - u:test:rwX

Closes #25114
2023-04-27 15:15:09 +08:00