dm-verity: add instructions for systemd x86-64
cover dm-verity: add instructions for systemd x86-64
From: Paul Gortmaker <[email protected]>
This second series continues in the same general theme of making it easier to use dm-verity within the Yocto/OE framework by adding a worked example that can boot on x86-64 in QEMU and on physical hardware.
A couple small clarifications to exisitng files are also added.
Based on my reading, I believe there are still two things that would be nice to support if time permits. They are somewhat intertwined.
Firstly, the dm-verity basically has two places to store the hash data - at the end of the filesystem data in an "oversized" partition, or in a completely separate partition/device. Our current support is hardwired to the append single partition support.
Secondly, we currently call veritysetup from within the initramfs with all the parameters (hash size, location etc.) - which was sensible for a sysV init based system. However my reading seems to indicate that recent systemd supports direct enablement of dm-verity device(s) from either boot arguments or autodetection via GPT UUIDs assigned to dm-verity (and dm-verity-hash). Meaning (in theory) we should not need to be manually calling veritysetup in a systemd initramfs at all.
So we'll see how that goes. Might lead to another wks.in example?
---
Paul Gortmaker (4):
dm-verity: ensure people don't ignore the DISTRO_FEATURES warning
dm-verity: don't make read-only-rootfs sound like a requirement
dm-verity: document the meta-intel dependency in the systemd example
dm-verity: add x86-64 systemd based example instructions
docs/dm-verity-systemd-x86-64.txt | 77 ++++++++++++++++++++++++++++ docs/dm-verity.txt | 13 ++++- wic/systemd-bootdisk-dmverity.wks.in | 1 + 3 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 docs/dm-verity-systemd-x86-64.txt
Signature · 1 line
2.40.0
PATCH 1/4 dm-verity: ensure people don't ignore the DISTRO_FEATURES warning
From: Paul Gortmaker <[email protected]>
Some platform creators tend to list a whole bunch of layers by default in conf/bblayers.conf. Without getting into the debate of whether that is a good idea, it can tend to have the effect of people seeing the meta-security DISTRO_FEATURES warning time and time again and becoming essentially numb to it.
After having fallen into this trap myself, I figured it was worth the extra mention in the dm-verity doc so there is a better chance of users realizing "hey - this applies to me!".
--- docs/dm-verity.txt | 2 ++ 1 file changed, 2 insertions(+)
docs/dm-verity.txt +2 -0
@@ -31,6 +31,8 @@ Kernel Configuration Kernel configuration for dm-verity happens automatically via IMAGE_CLASSES which will source features/device-mapper/dm-verity.scc when dm-verity-img is used. [See commit d9feafe991c] +IMPORTANT: As per the top level README, you *must* put security in the +DISTRO_FEATURES, or else you won't get the dm-verity kernel settings. Supported Platforms -------------------
Signature · 1 line
2.40.0
PATCH 2/4 dm-verity: don't make read-only-rootfs sound like a requirement
In reply to Paul GortmakerFrom: Paul Gortmaker <[email protected]>
Adding to your local.conf right out of the gate:
EXTRA_IMAGE_FEATURES = "read-only-rootfs"
while you are trying to sort out other things can be just another complication to an already steep learning curve.
For example, I found simply enabling this with systemd caused:
systemd[1]: Failed to fork off sandboxing environment for executing generators: Protocol error [!!!!!!] Failed to start up manager.
systemd[1]: Freezing execution.
While I'd like to get to the root cause of that, it doesn't change that things boot fine w/o adding to EXTRA_IMAGE_FEATURES, even though the rootfs is still read-only courtesy of dm-verity.
Reword things so as to make it clear it isn't strictly a hard requirement and hence can be delayed as people work through their implementation.
--- docs/dm-verity.txt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
docs/dm-verity.txt +9 -2
@@ -53,11 +53,18 @@ conf/local.conf and conf/bblayers.conf from the oe-init-build-env Firstly, you need the meta-security layer to conf/bblayers.conf along with the dependencies it has -- see the top level meta-security README for that. -Next, assuming you'll be using dm-verity for validation of your rootfs, -you'll need to enable read-only rootfs support in your local.conf with: +Note that if you are using dm-verity for your rootfs, then it enforces a +read-only mount right at the kernel level, so be prepared for issues such +as failed creation of temporary files and similar. + +Yocto does support additional checks and changes via setting: EXTRA_IMAGE_FEATURES = "read-only-rootfs" +...but since read-only is enforced at the kernel level already, using +this feature isn't a hard requirement. It may be best to delay/defer +making use of this until after you've established basic booting. + For more details, see the associated documentation: https://docs.yoctoproject.org/dev/dev-manual/read-only-rootfs.html
Signature · 1 line
2.40.0
RE: [yocto] [meta-security][PATCH 2/4] dm-verity: don't make read-only-rootfs sound like a requirement
Quoted 20 lines
-----Original Message-----
From: [email protected] <[email protected]> On Behalf Of Paul Gortmaker via lists.yoctoproject.org
Sent: den 10 maj 2023 17:05
To: Armin Kuster <[email protected]>
Cc: [email protected]
Subject: [yocto] [meta-security][PATCH 2/4] dm-verity: don't make read- only-rootfs sound like a requirementFrom: Paul Gortmaker <[email protected]>
Adding to your local.conf right out of the gate:
EXTRA_IMAGE_FEATURES= "read-only-rootfs"while you are trying to sort out other things can be just another complication to an already steep learning curve.
For example, I found simply enabling this with systemd caused:
Quoted 8 lines
systemd[1]: Failed to fork off sandboxing environment for executing
generators: Protocol error
[!!!!!!] Failed to start up manager.
systemd[1]: Freezing execution.While I'd like to get to the root cause of that, it doesn't change that things boot fine w/o adding to
EXTRA_IMAGE_FEATURES, even though the rootfs is still read-only courtesy of dm-verity.
The error you are seeing above is due to a bug in systemd. It is fixed in version 253.4 (commit 5ed087fa46dc04ee92da12635777b2b622183a5d).
//Peter
PATCH 3/4 dm-verity: document the meta-intel dependency in the systemd example
In reply to Paul GortmakerFrom: Paul Gortmaker <[email protected]>
The dependency might not be obvious to everyone, so leave a hint.
--- wic/systemd-bootdisk-dmverity.wks.in | 1 + 1 file changed, 1 insertion(+)
wic/systemd-bootdisk-dmverity.wks.in +1 -0
@@ -5,6 +5,7 @@ # Based on OE-core's systemd-bootdisk.wks and meta-security's beaglebone-yocto-verity.wks.in file # # This .wks only works with the dm-verity-img class. +# Also note that the use of microcode.cpio introduces a meta-intel layer dependency. part /boot --source bootimg-efi --sourceparams="loader=systemd-boot,initrd=microcode.cpio" --ondisk sda --label msdos --active --align 1024 --use-uuid
Signature · 1 line
2.40.0
PATCH 4/4 dm-verity: add x86-64 systemd based example instructions
In reply to Paul GortmakerFrom: Paul Gortmaker <[email protected]>
We have systemd-bootdisk-dmverity.wks.in as an example template but no mention of it in docs or config files. Similar to the beaglebone black insructions added earlier, we do the same for (qemu)x86-64.
This hopefully walks through getting things configured for building a systemd based dm-verity image and booting it on qemux86-64 --filling in a lot of blanks and assumptions so that someone relatively new to the feature can get off the ground more quickly by using qemu as a stepping stone towards their final physical implementation.
Finally, the full image is deployed and booted on real hardware.
--- docs/dm-verity-systemd-x86-64.txt | 77 +++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 docs/dm-verity-systemd-x86-64.txt
docs/dm-verity-systemd-x86-64.txt new file +77 -0
@@ -0,0 +1,77 @@ +dm-verity and x86-64 and systemd +-------------------------------- +In this example, we'll target combining qemux86-64 with dm-verity and +also systemd - systemd has dm-verity bindings and is more likely to be +used on x86. + +While dm-verity in a qemu environment doesn't make practial sense as a +deployment - it can be a useful stepping stone for testing and getting to +a final physical deployment. + +Set/uncomment the MACHINE line for "qemux86-64" if you haven't yet. It +should be the default if unspecified, but check to be sure. As of this +writing (kernel v6.1) the resulting qemux86-64 build can also be booted +successfully on physical hardware, but if you don't intend to use qemu, +you might instead want to choose "genericx86-64" + +This will make use of wic/systemd-bootdisk-dmverity.wks.in -- note that it +contains a dependency on the meta-intel layer for microcode, so you'll need +to fetch and add that layer in addition to the meta-security related layers. + +In addition to the basic dm-verity settings, choose systemd in local.conf: + +DISTRO_FEATURES:append = " security systemd" +VIRTUAL-RUNTIME_init_manager = "systemd" +EFI_PROVIDER = "systemd-boot" +PACKAGECONFIG:append:pn-systemd = " cryptsetup" + +Note the last line - you won't typically see that in on-line instructions +for enabling systemd. It is important for dm-verity, since it triggers +the build and installation of components like this onto the rootfs: + + /lib/systemd/system-generators/systemd-veritysetup-generator + /lib/systemd/systemd-veritysetup + +Now build the components for the wic image: + + bitbake intel-microcode + bitbake core-image-minimal + +Assemble the image: + + ------------------------------ +build-qemu-x86_64$wic create systemd-bootdisk-dmverity -e core-image-minimal +INFO: Building wic-tools... + +[...] + +INFO: Creating image(s)... + +INFO: The new image(s) can be found here: + ./systemd-bootdisk-dmverity.wks-202304181413-sda.direct + +The following build artifacts were used to create the image(s): + BOOTIMG_DIR: /home/paul/poky/build-qemu-x86_64/tmp/work/qemux86_64-poky-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share + KERNEL_DIR: /home/paul/poky/build-qemu-x86_64/tmp/deploy/images/qemux86-64 + NATIVE_SYSROOT: /home/paul/poky/build-qemu-x86_64/tmp/work/core2-64-poky-linux/wic-tools/1.0-r0/recipe-sysroot-native + +INFO: The image(s) were created using OE kickstart file: + /home/paul/poky/meta-security/wic/systemd-bootdisk-dmverity.wks.in +build-qemu-x86_64$ + ------------------------------ + +The "runqemu" script defaults were acceptable for testing with only the +verity image needing to be specified, i.e. + + runqemu \ + nographic \ + qemux86-64 \ + tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64-*.rootfs.ext4.verity + +You will see the above "direct" image file and also similarly named +individual partition images. To boot on UEFI enabled physical hardware, +you need to simply write the "direct" image file to a USB stick with dd +and the partition images can largely be ignored. + +Further information on interacting with the systemd UEFI loader is here: +https://www.freedesktop.org/wiki/Software/systemd/systemd-boot/
Signature · 1 line
2.40.0
Quoted 24 lines · On 5/10/23 11:04 AM, [email protected] wrote:
From: Paul Gortmaker <[email protected]>
This second series continues in the same general theme of making it easier to use dm-verity within the Yocto/OE framework by adding a worked example that can boot on x86-64 in QEMU and on physical hardware.
A couple small clarifications to exisitng files are also added.
Based on my reading, I believe there are still two things that would be nice to support if time permits. They are somewhat intertwined.
Firstly, the dm-verity basically has two places to store the hash data - at the end of the filesystem data in an "oversized" partition, or in a completely separate partition/device. Our current support is hardwired to the append single partition support.
Secondly, we currently call veritysetup from within the initramfs with all the parameters (hash size, location etc.) - which was sensible for a sysV init based system. However my reading seems to indicate that recent systemd supports direct enablement of dm-verity device(s) from either boot arguments or autodetection via GPT UUIDs assigned to dm-verity (and dm-verity-hash). Meaning (in theory) we should not need to be manually calling veritysetup in a systemd initramfs at all.
Quoted 1 line
So we'll see how that goes. Might lead to another wks.in example?
Merged
thanks
Quoted 14 lines
---
Paul Gortmaker (4):
dm-verity: ensure people don't ignore theDISTRO_FEATURESwarning
dm-verity: don't make read-only-rootfs sound like a requirement
dm-verity: document the meta-intel dependency in the systemd example
dm-verity: add x86-64 systemd based example instructionsdocs/dm-verity-systemd-x86-64.txt | 77 ++++++++++++++++++++++++++++ docs/dm-verity.txt | 13 ++++- wic/systemd-bootdisk-dmverity.wks.in | 1 + 3 files changed, 89 insertions(+), 2 deletions(-)create mode 100644
docs/dm-verity-systemd-x86-64.txt