Skip to content

udev: new "image_dissect" builtin that can be used to generate symlinks based on partition designators - #36631

Merged
poettering merged 23 commits into
systemd:mainfrom
poettering:dissect-udev-prove-v2
Apr 3, 2025
Merged

poettering merged 23 commits into
systemd:mainfrom
poettering:dissect-udev-prove-v2

Conversation

@poettering

@poettering poettering commented Mar 6, 2025 •

Copy link
Copy Markdown
Member

This replaces #36209 and implements this via a new builtin, rather than by shelling out to systemd-dissect.

Replaces: #36209
Replaces: #28894
Fixes: #34319
Fixes: #33453
Fixes: #27897
Fixes: #18035

@poettering poettering added udev dissect please-review PR is ready for (re-)review by a maintainer labels Mar 6, 2025
Comment thread rules.d/90-image-dissect.rules Resolved
Comment thread src/udev/udev-builtin-dissect_image.c Resolved
@poettering

Copy link
Copy Markdown
Member Author

this needs more thinking, don't bother reviewing.

the security angle matters a lot, i.e. how to apply image policy.

@poettering

Copy link
Copy Markdown
Member Author

current thinking:

  1. manage set of dissect-based symlinks before initrd transition. based on boot loader esp var info
  2. manage another set of dissect-based symlinks after initrd transition, this time based on backing of actual fs that is /
  3. neither of these sets should be mixed up with the current gpt-auto-root stuff (since those came without any trust, i.e. without image policy applied – and the new ones come with)
  4. introduce a new root=gpt-auto-dissect setting that uses the new symlinks from 1 instead of the traditional ones. i.e. symlinks taking image policy into account

@bluca bluca removed the please-review PR is ready for (re-)review by a maintainer label Mar 11, 2025
@poettering
poettering force-pushed the dissect-udev-prove-v2 branch from 3daeb32 to feddda9 Compare March 14, 2025 15:56
@poettering

Copy link
Copy Markdown
Member Author

So this is a much more comprehensive solution, fully taking the image policy into account.

There's now /dev/disk/by-designator/* and it creates symlinks for verity + luks too there, so that everything's there.

with this in place we can relatively easily add support for also setting up verity this way, so that we can finally take verity signature data into account for mounting the root/usr file systems too.

@poettering

Copy link
Copy Markdown
Member Author

(this would then also be an alternative to #34413)

@poettering
poettering force-pushed the dissect-udev-prove-v2 branch from feddda9 to 5173db9 Compare March 14, 2025 17:20
Comment thread src/udev/udev-builtin-blkid.c Resolved
Comment thread rules.d/90-image-dissect.rules Resolved
Comment thread src/udev/udev-builtin-dissect_image.c Resolved
Comment thread src/udev/udev-builtin-dissect_image.c Resolved
Comment thread src/udev/udev-builtin-dissect_image.c Resolved
Comment thread rules.d/90-image-dissect.rules Resolved
Comment thread src/shared/dissect-image.c Resolved
Comment thread src/core/namespace.c Resolved
Comment thread TODO Resolved
@yuwata yuwata added reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks and removed please-review PR is ready for (re-)review by a maintainer labels Mar 14, 2025
@poettering
poettering force-pushed the dissect-udev-prove-v2 branch from 5173db9 to 009b095 Compare March 17, 2025 15:02
@poettering poettering added the good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed label Apr 3, 2025
@poettering

Copy link
Copy Markdown
Member Author

(setting green label, since @bluca already gave it before)

…just look at /

So far the gpt-auto symlinks would point to:

   1. the disk the ESP/XBOOTLDR is located on
   2. or to a loopback device whose filename field is set to "rootdisk"
      or "rootdisk.raw"

This makes sense in the initrd. But once we transition to the host this
is quite confusing, since the symlinks might point to a different place
than what we actually ended up transitioning too: the actual backing
device of the root file system might be different from what gpt-auto
found.

Let's clean this up: let's avoid any ambiguities here: let's extend the
rules above with one more rule:

   3. if we left the initrd, we'll make gpt-auto point to the selected
      root file system, if it otherwise would have been a candidate.

Or in other words, the ID_PART_GPT_AUTO_ROOT_DISK=1 udev property now
always makes sense: in the initrd it points to the future root disk, and
on the host to the actual root disk.

Fixes: systemd#34319
…/verity-sig

Previously, if during early enumeration of the partition table we
figured out we have a verity + verity-sig partition, we determined we are
"ready" to do verity/verity-sig, as reported by the "verity_ready" and
"verity_ready_sig" fields of DissectedImage.

Let's rework this: only determine we are ready in case the VeritySettings
structure is fully populated. Mark verity-sig/verity only as ready once
we actually *load* the verity sig metadata from the special partition.

This is conceptually more correct, as we consider things "ready" only if
we actually have all data for it loaded. It's also preparation for a
later commit that guesses the verity root hash based on what we discover.
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.
Previously if we found a verity signature partition in an image, and the
image policy required "verity" (but did not allow "signature") we'd
refuse the image. This is of course unnecessarily strict: if "verity" is
allowed, we can make use of the verity data, and ignore the signature
data.

hence, relax the rules here: when we pick up a partition and want to
test it against the policy, always consider all "weaker" uses too, maybe
they are allowed if the "stronger" users isn't.
This introduces root=dissect, which is a lot like root=gpt-auto, but
uses the image dissection logic to find the root partition. It's also
based on the GPT efi var telling us about the root disk, but instead of
just picking some suitable root disk manually it uses the dissection
logic.

This is a big step forward, since it means we can actually make
use of the image policy logic for the root fs too.
This is useful when booting into storage target mode, where we do not
want to enter a root fs, we just want to stay forever in the initrd,
and hence there's value in not even generating and jobs to find the
rootfs
So far, we did not support auto-discovery the /usr/ partition at boot.
Change that: on explicit request (i.e. mount.usr=dissect) automatically
discover the /usr/ partition based on our usual dissection logic.
…matically

So far the gpt-auto-generator would only cover unprotected and encrypted
partitions. Teach it handling of verity too.
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.
…re logic, retry without

Currently, there's no nice way to get a key into the dm-verity kernel
keyring unless recompiling the kernel, or enabling SB or buying into
shim. Neither sounds particularly attractive.

hence provide a reasonable fallback: if unlocking with signed roothash
doesn#t work, just try without. maybe the kernel policy allows this,
maybe not. It's worth a try.
We generally let gpt-auto-generator write to the "late" generator dir,
so that the explicit fstab-generator can write to the "middle" one. And
I think we should leave it that way. But we also want to override the
generic systemd-fsck-root.service service potentially, and if we'd do
that in the "late" generator dir, it would be pointless, since that's
ordered *after* the static version hence would never be taken into
consdiration.

Hence clean this up: keep writing to the late dir for everything,
except for the fsck stuff.
@poettering
poettering force-pushed the dissect-udev-prove-v2 branch from 1512780 to 50270ec Compare April 3, 2025 09:09
@poettering

Copy link
Copy Markdown
Member Author

CI failures are unrelated. Let's merge.

@poettering
poettering merged commit 3777c6e into systemd:main Apr 3, 2025
@github-actions github-actions Bot removed the good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed label Apr 3, 2025
knelsonmeister pushed a commit to knelsonmeister/systemd that referenced this pull request Apr 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment