Skip to content

veritysetup: parse signature from DPS partition - #34413

Closed
bluca wants to merge 1 commit into
systemd:mainfrom
bluca:veritysetup_dps
Closed

bluca wants to merge 1 commit into
systemd:mainfrom
bluca:veritysetup_dps

Conversation

@bluca

@bluca bluca commented Sep 13, 2024

Copy link
Copy Markdown
Member

If the signature is not specified manually, and sd-veritysetup is running on a device, try to find the parent and if it's a DPS-compliant GPT image with a signature partition, parse it and use it. This allows automatically using the signature on boot, which allows setting an IPE policy that enforces a validated signature on the rootfs too.

@github-actions github-actions Bot added documentation veritysetup please-review PR is ready for (re-)review by a maintainer labels Sep 13, 2024
Comment thread src/veritysetup/veritysetup.c Resolved
Comment thread src/veritysetup/veritysetup.c Resolved
Comment thread src/veritysetup/veritysetup.c 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 Sep 15, 2024
@poettering

Copy link
Copy Markdown
Member

it's a bit weird to search for the signature this way, but not also for the hash data?

@bluca

bluca commented Sep 15, 2024

Copy link
Copy Markdown
Member Author

it's a bit weird to search for the signature this way, but not also for the hash data?

The current usage can derive the hash data from the roothash in the generator, so in practice it is not needed when that is specified.

I am planning more changes to try and make that optional too, and then we'll discover more, but that's more complicated, so one thing at a time. This fixes the common use case of booting via mkosi, which did not use the signature so far, which is an issue for IPE among other things.

If the signature is not specified manually, and sd-veritysetup is running
on a device, try to find the parent and if it's a DPS-compliant GPT
image with a signature partition, parse it and use it.
This allows automatically using the signature on boot, which allows
setting an IPE policy that enforces a validated signature on the
rootfs too.
@github-actions github-actions Bot added please-review PR is ready for (re-)review by a maintainer and removed reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks labels Sep 15, 2024
@bluca bluca added please-review PR is ready for (re-)review by a maintainer and removed please-review PR is ready for (re-)review by a maintainer documentation labels Sep 15, 2024
@poettering

Copy link
Copy Markdown
Member

So, I claimed earlier that we had a protocol for finding the verity sig data, if you have a root hash already. Turns out we do not, I was talking BS.

We probably should have though, for example by calulating HMAC(roothash, "verity-sig")[:16] or something like that), and suggesting this in the DPS (but only suggesting for cases like this, but not mandate it strictly, because it probably should be fine if a single verity sig partition covers multiple root hashes, which wouldn't work anymore if the verity sig partition uuid has to be derived from the root hash). repart should then be fixed to generate partitions like this automatically.

That said, I wonder what the end game is here. I mean, if I understand your situation with this correctly you are working in an environment where roothash= is specified on the kernel cmdline but the signature partition isn't? But it sounds to me, that if you can specify the roothash you could as well specify the sgnature partition explicitly and that would be safer? (i mean, specifying the explicit root hash should disable the dissection logic I think, and not turn it on in a some indirect way?).

Hence, we should fix the explicit configuration path for this first:

  1. add a way to tell systemd-verity-generator the sig part to use via kernel cmdline (systemd.verity_root_hash_signature= or so?)
  2. add a new option to systemd-veritysetup to accept the sig part device node (i.e. extend the 5th argument to the comand). Make systemd-verity-generator write any path from the kernel cmdline here.

And then, separately from that, in a later PR:

  1. Teach the systemd-gpt-auto-generator tool the verity logic, searching for the triplet of partitions and writing it explicitly to [email protected] files. i.e. determine the data, the hash and the sig partition in the generator, and pass them explicitly to the veritysetup tool.
  2. Beef up src/udev/udev-builtin-blkid.c in similar style: search for the triplet of partitions if nothing is configured explicitly. Whether to look for just a root fs, or for the verity triplet of partitions probably needs to be configured on the kernel cmdline, so that we know we can use a root fs already when it shows up, or wait until the verity sidecars have shown up.

The approach suggested in this PR currently (i.e. to do searching at moment of activation instead of during the generator/udev) I don't like very much tbh, because it means we do dissection/search at multiple somewhat redundant places, and might come to different results on each. I find it much cleaner, if we do dissection/search at as few places as we can get away with (which I guess means: find root fs triplet of parts in udev + find the rest from gpt-generator)

@poettering poettering 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 Oct 2, 2024
@bluca

bluca commented Oct 2, 2024

Copy link
Copy Markdown
Member Author

That said, I wonder what the end game is here. I mean, if I understand your situation with this correctly you are working in an environment where roothash= is specified on the kernel cmdline but the signature partition isn't? But it sounds to me, that if you can specify the roothash you could as well specify the sgnature partition explicitly and that would be safer? (i mean, specifying the explicit root hash should disable the dissection logic I think, and not turn it on in a some indirect way?).

This is just what mkosi does, just try it and you'll see. I don't think it can add partition numbers to the kernel command line as those appear after, so you'd need to mount it which requries privileges. Also I don't think hard-coding partition numbers in a UKI is a good idea in general, as that's a detail of the disk device, it shouldn't leak into the cmdline.

(which I guess means: find root fs triplet of parts in udev + find the rest from gpt-generator)

You cannot dissect in the generators, it's way too early for that, we have discussed this many times already.

You are also assuming this is only for a single device, the one backing the root filesystem, but it isn't, it works just fine with any other DDI being opened by sd-veritysetup too. The gpt generator only looks at the device where the ESP was by design (and it makes sense to work that way).

What happens here is the slowest operation of them all, setting up the verity devices via dm, so dissecting is really trivial and fast in comparison, it's not really a problem to do it at this point.

@daandemeyer

daandemeyer commented Oct 2, 2024 •

Copy link
Copy Markdown
Collaborator

This is just what mkosi does, just try it and you'll see. I don't think it can add partition numbers to the kernel command line as those appear after, so you'd need to mount it which requries privileges. Also I don't think hard-coding partition numbers in a UKI is a good idea in general, as that's a detail of the disk device, it shouldn't leak into the cmdline.

This isn't a problem, UKI is built after the verity stuff is calculated by repart

You cannot dissect in the generators, it's way too early for that, we have discussed this many times already.

You can't dissect in the initrd for the root partition, that's why Lennart says udev. You can dissect everything else just fine after switch root in generators, that's what we already do.

@bluca

bluca commented Oct 2, 2024

Copy link
Copy Markdown
Member Author

This is just what mkosi does, just try it and you'll see. I don't think it can add partition numbers to the kernel command line as those appear after, so you'd need to mount it which requries privileges. Also I don't think hard-coding partition numbers in a UKI is a good idea in general, as that's a detail of the disk device, it shouldn't leak into the cmdline.

This isn't a problem, UKI is built after the verity stuff is calculated by repart

Ok I thought it was the other way around, thanks - still, I don't think hard coding partition numbers in the kernel command line is the way to go

You cannot dissect in the generators, it's way too early for that, we have discussed this many times already.

You can't dissect in the initrd for the root partition, that's why Lennart says udev. You can dissect everything else just fine after switch root in generators, that's what we already do.

sure but again this is useful for anything that uses this service, not just for things coming from the gpt generator, and this is already going to open the device by definition as it's its job, so there's no much point optimizing it away

@poettering

Copy link
Copy Markdown
Member

I guess we can close this, given that 0a64b7b got merged: we can now set up verity with sig automatically, when using gpt-auto-generator

@poettering poettering closed this Oct 23, 2025
@github-actions github-actions Bot removed the reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks label Oct 23, 2025
@bluca
bluca deleted the veritysetup_dps branch October 23, 2025 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants