Commit Graph
250 Commits
Author SHA1 Message Date
Daan De Meyer 104579e401 dissect: Go via service on ENOENT from loop_device_make() as well
ENOENT means /dev/loop-control isn't there which means we're in a
container and should go via mountfsd.

At the same time, reverse the check for fatal actions as almost all
actions can be done via mountfsd, only --attach needs the loop device.
2026-02-24 18:29:37 +01:00
Mike Yuan 577e5e9a5e parse-argument: make parse_tristate_argument() do something useful
I expressed the issue I have with parse_tristate_argument()
in #37751: it doesn't add any value to direct use of parse_tristate();
on the contrary, it doesn't support means to reset the arg to "auto"/-1 state.
The mere reason it existed is that we need a int type ret param.

Since the previous attempt to address this mess failed, let's
try to make the function more useful by making it accept "auto".
I figure this is useful on its own.

As requested in
https://github.com/systemd/systemd/pull/40652#discussion_r2831833996,
the function name is suffixed with _with_auto() to establish
that "auto" is handled internally.
2026-02-20 21:20:45 +01:00
Lennart Poettering 68ed4f3c66 mountfsd,nsresource: allow recycling mountfsd/nsresourced client connections
So far we opened a new Varlink connection for every mountfsd/nsresourced
method call. Given each tool only does a very small number of calls
(usually 1…5) on them and the connections are cheap this is not too
wasteful. Nonetheless, let's do something about it, and allow reusing
the connection for multiple calls.

This not only makes things a bit more efficient, but has one more
important benefit: Varlink connections pin the security context of the
client when connecting. This means that varlink method calls done with a
connection established while some code was privileged will still operate
as privieged once privs are dropped, until the connection is closed.
This pinning effect is really nice, as it gives us behaviour in a
"capability system" like scheme. Later code is going to use that to
continue doing certain priv userns ops even after unsharing userns and
becoming fully unpriv.
2026-02-19 15:08:19 +01:00
Lennart Poettering 116394f7ce tree-wide: move logging from varlink clients in nsresource.c/dissect-image.c into callers
These calls are "library-like", hence better should only debug log on
their own, not more.
2026-02-19 15:05:15 +01:00
Daan De Meyer e8055af5f0 dissect: Various cleanups and fixes
- Only call have_effective_cap() if needed
- Fix comments and logging

Follow up for #40212
2026-02-13 17:18:33 +01:00
Daan De Meyer 01fb2d4a9e dissect: Use must_be_root() 2026-02-12 10:38:33 +01:00
Daan De Meyer dbd1a6e34f dissect: Allow --shift for users with CAP_CHOWN 2026-02-12 09:46:37 +01:00
DaanDeMeyer ba37ed9634 dissect: Introduce --copy-ownership= to configure chown behavior
Currently, if we're copying a file, we won't copy the owner UID/GID
from the source. If we're copying a directory, we will copy the owner
UID/GID from the source. Let's give users a bit more control over this
behavior by introducing --copy-ownership= which will default to the
current behavior but allows users to explicitly enable/disable copying
of ownership.
2026-02-12 09:45:13 +01:00
DaanDeMeyer ef155c909a dissect: Make --mount/--unmount/--with work unprivileged
Let's check for CAP_SYS_ADMIN instead of root for these, and make
unmounting more graceful if we can't access the backing loop device
because of permission issues. This allows mounting and unmounting images
from an unprvileged mount namespace. The actual files in the image will
end up owned by nobody:nobody because we'll be in an unprivileged user
namespace, but assuming the directory permissions are not too strict, this
still allows interacting with the image in useful ways.
2026-02-12 09:43:07 +01:00
DaanDeMeyer fe0114db8e dissect: Fix wrong errno passed to log message 2026-02-12 09:43:07 +01:00
DaanDeMeyer a0a4e9d7d2 dissect: Fix segmentation fault if loop device is not provided 2026-02-12 09:43:07 +01:00
DaanDeMeyer 53d1d6e49c dissect: Fix logging in (with) 2026-02-12 09:43:07 +01:00
DaanDeMeyer 09e38c2709 dissect: Don't use private userns for --copy-to/--copy-from
These actions interact with the host. The former needs privileges to
write into the image, the latter needs privileges to write on the host.
Neither will have the privileges required if the image is attached under
a private userns, hence, don't use one.
2026-02-12 09:43:07 +01:00
Luca Boccassi 3e2a5dc2e1 dissect: support mount options when going through mountfsd, requiring privileges via polkit (#39394)
RootImageOptions=/ExtensionImages=/MountImages= all support custom
mount options, but mountfsd does not support it. Add varlink
parameters to allow callers to specify mount options so that
those directives can work as expected. Require additional privs via
polkit.
2026-01-16 14:55:02 +00:00
Daan De Meyer 3fa3a4fd15 vpick: Fix pick_filter_image_any
Currently, pick_filter_image_any matches any image
with any suffix, which is way more than it should
be doing. It should only be matching images with
the .raw suffix.

Let's address this shortcoming by allowing to pass
multiple filters to path_pick(), and define
pick_filter_image_any as the combination of the
raw and directory image filters.

Fixes #40083
2026-01-16 13:07:47 +01:00
Luca Boccassi 3a8759e5d4 dissect: support mount options when going through mountfsd
RootImageOptions=/ExtensionImages=/MountImages= all support
custom mount options, use the new mountfsd parameters to
configure them if they are specified.

This requires additioanl privileges via polkit due to security
implications of mount options, so document an example policy
that allows to use the nosuid mount option.
2026-01-07 00:47:53 +01:00
Daan De Meyer 52ecf376fa tree-wide: Migrate to pidref_safe_fork()
Let's migrate all remaining callers of safe_fork()
to pidref_safe_fork() and get rid of safe_fork().
2026-01-02 20:08:41 +01:00
Daan De Meyer 2253b4c35d dissect: Stop refusing external verity settings for mountfsd
These are supported now so no point in refusing them in systemd-dissect
2025-12-03 22:13:48 +00:00
Yu Watanabe caf7cb2737 SD_JSON_BUILD_PAIR() conversions with coccinelle script (#39858) 2025-11-26 16:35:35 +09:00
Daan De Meyer 9a6a8f35eb tree-wide: Small fixes for various clang-tidy warnings 2025-11-26 16:22:00 +09:00
Jelle van der Waa c12966c14f treewide: prefer using SD_JSON_BUILD_PAIR_* over SD_JSON_BUILD_PAIR()
Include a coccinelle script that patches this automatically.
2025-11-24 21:05:10 +01:00
Lennart Poettering e30738c20c dissect-tool: accept encryption password via $PASSWORD 2025-11-17 16:42:58 +01:00
Lennart Poettering 08d75cfb99 dissect-image,execute: switch root hash/root hash sig storage to struct iovec
let's go one step further on our iovec'ification journey.

No change in behaviour, just rework to make struct iovec used
everywhere.
2025-11-16 23:36:11 +01:00
Lennart Poettering faaed501e0 dissect: move tar make code into tar-util.[ch] and make it generic
That way we can later use it for importd's "export" verb
2025-10-29 10:09:44 +01:00
Lennart Poettering a6146b250e machined: support image clone/rm operations unpriv, and make hidden images always read-only (#39408) 2025-10-27 17:06:26 +01:00
Yu Watanabe fc945d22d5 libarchive-util: drop 'sym_' prefix from cleanup functions 2025-10-25 11:25:19 +09:00
Lennart Poettering ee327e086e discover-image: imply that hidden images are read-only
Marking a whole directory tree OS image as read-only is difficult
privilege-wise, because so far we rely on the FS_IMMUTABLE_FL which is
not accessible to unpriv clients.

One fundamental place where we currently rely on marking images
read-only is for keeping pristine copies of the originally downloaded
image around, which we place in "hidden" image directories. This is
probably the most relevant usecase for the read-only flag. And moreover,
the only usecase for the hidden images are these read-only pristine
copies.

Hence, let's make this work reasonably in the unpriv case, and simply
imply the read-only flag for hidden images. This is strictly speaking a
change in behaviour, but effectively it shouldn't be, because for nspawn
containers that are executed we insist on names that are hostname
compatible, and hidden names aren't (because they start with a dot).
2025-10-24 17:51:00 +02:00
Lennart Poettering bcafa70974 nsresource: add constants for the only supported UID range size allocations
As requested: https://github.com/systemd/systemd/pull/39322#discussion_r2447366728
2025-10-21 23:09:50 +02:00
Luca Boccassi fad01f798d dissect: add support for verity-protected bare filesystems via mountfsd
Needed to implement support for RootHashSignature=/RootVerity=/RootHash=
and friends when going through mountfsd, for example with user units,
so that system and user units provide the same features at the same
level
2025-10-16 16:22:33 +01:00
Lennart Poettering d20dff2814 dissect-image: take policy into consideration when unlocking verity, too
Previously, we'd take the image policy only into consideration when
dissecting the mage, but for the unlock/verity step we'd go via best
effort. Change that. This means we can now enforce policies such as
activating by root hash only even if a signature exists and similar.

Also, introduce a separate error code if we try to unlock a Verity
volume but have no root hash. Previously we'd return ENOKEY for that,
exactly like we do for encrypted volumes where we have no passparse. The
interctive unlock loop dissected_image_decrypt_interactively() is
otherwise very confused and will ask for a root hash, which makes no
sense. Hence use two distinct errors for this.
2025-10-13 22:26:34 +02:00
Yu Watanabe 6c32948b25 dissect: include unistd.h
This is required by e.g. geteuid(), for the case when unistd.h is
indirectly included by other headers.

Continuation of 4f18ff2e29.
2025-09-14 09:47:30 +02:00
Yu Watanabe 5918ba9c69 tree-wide: fix log messages: "Failed VERB" -> "Failed to VERB" 2025-07-22 03:05:33 +09:00
Yu Watanabe 624d369868 discover-image: make image_discover() allocate hashmap when necessary 2025-06-11 22:45:08 +09:00
Adrian Vovk 554130faf3 Define uid range for greeter
In multi-seat scenarios, a display manager might need to start multiple
greeter sessions. But systemd allows at most one graphical session per
user. So, display managers now have a range of UIDs to dynamically
allocate users for their greeter sessions.
2025-06-02 11:19:12 +02:00
Daan De Meyer 86b9a3e31d tree-wide: Clean up includes
This removes more unused includes from the components already cleaned
up in #37467 and #37457.

Split out of #37344.
2025-05-21 10:49:42 +02:00
Lennart Poettering 22b5ddb90f tree-wide: fix use of flink_tmpfile()
Let's always make sure the temporary file returned by fopen_tmpfile()
and friends is removed on failure (via _cleanup_). Conversely, make sure
that once the file is renamed into its final place, we no longer try to
remove the temporary file (since it's not going to exist anymore).
2025-05-16 08:28:42 +02:00
Daan De Meyer 8857aa74e5 tree-wide: Clean up includes
This commit cleans up the includes for all the small tools across
the tree.

A few cases of returning EXIT_SUCCESS are replaced with returning
0 to avoid including <stdlib.h>.

Split out of #37344.
2025-05-14 22:34:02 +02:00
Yu Watanabe ab1bd9daed device-util: introduce several more helper functions
This also makes device_in_subsystem() and device_is_devtype() return
negative error on critical error
2025-05-14 02:06:02 +09:00
Daan De Meyer 6553db6063 strv: Reduce transitive includes 2025-05-07 22:04:46 +09:00
Daan De Meyer 76d62b63ef main-func: Reduce transitive includes
Let's move some logic from _DEFINE_MAIN_FUNCTION() and other places
in main-func.h into functions that we implement in main-func.c to
allow moving some included headers from the header to the .c file.
2025-05-06 10:07:27 +02:00
Lennart Poettering 743667e069 dissect-tool: expose image filtering via new --image-filter= parameter 2025-04-03 11:08:57 +02:00
Lennart Poettering f1395724f6 dissect-image: add a concept for "filtering" partitions we dissect
DDIs may contain multiple versions of the same OS, or even multiple
OSes. Hence it makes sense to not just pick the "newest", whatever that
might be, but only partitions associated with specific images, or in a
specific version.

Let's a concept for such filtering: a per-designator glob expression
that can be applied to the partition label string, and can be used for
such filtering.

Usecase: when picking UKI belonging to OS image X in version Y, make
sure we only pick a /usr/ partition belonging to X in version Y, and a
root and home partition belonging to X in any version.

This only adds the basic infrastructure, but doesn't actually expose it
anywhere.
2025-04-03 11:08:57 +02:00
Lennart Poettering e34c89897a dissect-image: guess verity root hash from the resources we found
When dissecting an image, let's make use of the Verity data even if we
got told no root hash explicitly: we can simply determine it by
concatenating the data partition uuid with the verity partition uuid.

Of course, on first thought this doesn't really add much: if the root
hash is not pinned from somewhere, this does not guarantee trust in
the image.

However, this is very useful for attestation: if we have the root hash
we can measure it before mounting things, even if we don't actually
authenticate it.

Hence, at best this helps us with attestation, at worst it doesn't improve
security but certainly doesn't hurt it.
2025-04-03 11:08:57 +02:00
Zbigniew Jędrzejewski-Szmek 1ae9b0cfa8 basic/glyph-util: rename "special glyph" to just "glyph"
Admittedly, some of our glyphs _are_ special, e.g. "O=" for SPECIAL_GLYPH_TOUCH ;)
But we don't need this in the name. The very long names make some invocations
very wordy, e.g. special_glyph(SPECIAL_GLYPH_SLIGHTLY_UNHAPPY_SMILEY).
Also, I want to add GLYPH_SPACE, which is not special at all.
2025-03-15 14:40:39 +01:00
Yu Watanabe c0cc01de8a meson: use install_symlink() where applicable
Now our baseline of meson is 0.62, hence install_symlink() can be used.

Note, install_symlink() implies install_emptydir() for specified
install_dir. Hence, this also drops several unnecessary
install_emptydir() calls.

Note, the function currently does not support 'relative' and 'force' flags,
so several 'ln -frsT' inline calls cannot be replaced.
2025-03-10 02:41:40 +09:00
Lennart Poettering 10b8d65f3f dissect: accept --usr-hash=… too, similar to --root-hash=…
This addresses an omission, given that we have both kinds of hashes
these days.
2025-03-06 23:35:31 +01:00
Yu Watanabe 5c9feb2d6e tree-wide: drop unnecessary break in default branch 2025-03-06 11:42:20 +01:00
Lennart Poettering 3568c47664 dissect: show basic image data even when can't enter the file systems 2025-03-05 21:21:36 +01:00
Lennart Poettering 172fadda65 dissect: add --quiet mode 2025-02-21 09:57:02 +01:00
Lennart Poettering 6b3fd03eac dissect: optionally derive loop-ref from image filename 2025-02-21 09:57:02 +01:00