initial dm-verity documentation
cover initial dm-verity documentation
As time marches on, it seems that more attention is given to the various security features out there. We have the framework to incorporate dm-verity into our builds, but it seems we have a rather steep learning curve for people to overcome in order to use it, and accordingly only two sample conflgs for people to reference.
This changeset attempts to rectify that by capturing the Yocto specific settings relating to dm-verity -- in two categories ; global/generic settings and board specific settings.
Credit to Niko Mauno who laid out a lot of information in a 0/N series preamble[1] some time ago - hopefully this puts the information a bit closer to where people can easily find it.
This series only documents the beaglebone-black ; I'm hoping to do some testing with systemd-bootdisk-dmverity.wks.in and get us some documentation for other use cases involving that. In the meantime, I figured I'd see if there was any special doc requirements/layout/format etc. that I might have overlooked -- or if there is any interest in this at all.
Paul.
[1] https://lists.yoctoproject.org/g/yocto/message/50621
---
Paul Gortmaker (2):
dm-verity: add basic non-arch/non-BSP yocto specific settings
dm-verity: document board specifics for Beaglebone Black
docs/dm-verity-beaglebone.txt | 37 +++++++++++ docs/dm-verity.txt | 114 ++++++++++++++++++++++++++++++++++ 2 files changed, 151 insertions(+) create mode 100644 docs/dm-verity-beaglebone.txt create mode 100644 docs/dm-verity.txt
Signature · 1 line
2.33.0
PATCH 1/2 dm-verity: add basic non-arch/non-BSP yocto specific settings
As things stand currently, the only way to learn about the Yocto specific settings for implementing dm-verity is by reading the source.
Here we try and capture some of the basic information that exists out there in mailing list posts and get that in-tree.
Board specific settings/tips will be stored in board specific files.
--- docs/dm-verity.txt | 114 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 docs/dm-verity.txt
docs/dm-verity.txt new file +114 -0
@@ -0,0 +1,114 @@ +dm-verity and Yocto/OE +---------------------- +The dm-verity feature provides a level of data integrity and resistance to +data tampering. It does this by creating a hash for each data block of +the underlying device as the base of a hash tree. There are many +documents out there to further explain the implementaion, such as the +in-kernel one itself: + +https://docs.kernel.org/admin-guide/device-mapper/verity.html + +The goal of this document is not to reproduce that content, but instead to +capture the Yocto/OE specifics of the dm-verity infrastructure used here. + +Ideally this should enable a person to build and deploy an image on one of +the supported reference platforms, and then further adapt to their own +platform and specific storage requirements. + +Basic Settings +-------------- +Largely everything is driven off of a dm-verity image class; a typical +block of non MACHINE specific settings are shown below: + +INITRAMFS_IMAGE = "dm-verity-image-initramfs" +DM_VERITY_IMAGE = "core-image-minimal" +DM_VERITY_IMAGE_TYPE = "ext4" +IMAGE_CLASSES += "dm-verity-img" +INITRAMFS_IMAGE_BUNDLE = "1" + +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] + +Supported Platforms +------------------- +In theory, you can use dm-verity anywhere - there is nothing arch/BSP +specific in the core kernel support. However, at the BSP level, one +eventually has to decide what device(s) are to be hashed, and where the +hash tables are stored. + +To that end, the BSP storage specifics live in meta-security/wic dir and +represent the current set of example configurations that have been tested +and submitted at some point. + +Getting Started +--------------- +This document assumes you are starting from the basic auto-created +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: + +EXTRA_IMAGE_FEATURES = "read-only-rootfs" + +For more details, see the associated documentation: + +https://docs.yoctoproject.org/dev/dev-manual/read-only-rootfs.html + +Also add the basic block of dm-verity settings shown above, and select +your MACHINE from one of the supported platforms. + +If there is a dm-verity-<MACHINE>.txt file for your BSP, check that for +any additional platform specific recommended settings, such as the +WKS_FILES which can specify board specific storage layout discussed below. + +Then you should be able to do a "bitbake core-image-minimal" just like any +other normal build. What you will notice, is the content in +tmp/deploy/images/<MACHINE>/ now have suffixes like "rootfs.ext4.verity" + +While you can manually work with these images just like any other build, +this is where the BSP specific recipes in meta-security/wic can simplify +things and remove a bunch of manual steps that might be error prone. + +Consider for example, the beaglebone black WIC file, which contains: + +part /boot --source bootimg-partition --ondisk mmcblk0 --fstype=vfat +--label boot --active --align 4 --fixed-size 32 --sourceparams="loader=u-boot" --use-uuid +part / --source rawcopy --ondisk mmcblk0 --sourceparams="file=${IMGDEPLOYDIR}/${DM_VERITY_IMAGE}-${MACHINE}.${DM_VERITY_IMAGE_TYPE}.verity" +bootloader --append="console=ttyS0,115200" + +As can be seen, it maps out the partitions, including the bootloader, and +saves doing a whole bunch of manual partitioning and dd steps. + +This file is copied into tmp/deploy/images/<MACHINE>/ with bitbake +variables expanded with their corresponding values for wic to make use of. + +Continuing with the beaglebone example, we'll see output similar to: + + ---------------------- +$ wic create -e core-image-minimal beaglebone-yocto-verity + +[...] + +INFO: Creating image(s)... + +INFO: The new image(s) can be found here: + ./beaglebone-yocto-verity.wks-202303070223-mmcblk0.direct + +The following build artifacts were used to create the image(s): + BOOTIMG_DIR: /home/paul/poky/build-bbb-verity/tmp/work/beaglebone_yocto-poky-linux-gnueabi/core-image-minimal/1.0-r0/recipe-sysroot/usr/share + KERNEL_DIR: /home/paul/poky/build-bbb-verity/tmp/deploy/images/beaglebone-yocto + NATIVE_SYSROOT: /home/paul/poky/build-bbb-verity/tmp/work/cortexa8hf-neon-poky-linux-gnueabi/wic-tools/1.0-r0/recipe-sysroot-native + +INFO: The image(s) were created using OE kickstart file: + /home/paul/poky/meta-security/wic/beaglebone-yocto-verity.wks.in + ---------------------- + +The "direct" image contains the partition table, bootloader, and dm-verity +enabled ext4 image all in one -- ready to write to a raw device, such as a +u-SD card in the case of the beaglebone.
Signature · 1 line
2.33.0
PATCH 2/2 dm-verity: document board specifics for Beaglebone Black
In reply to Paul GortmakerThis is meant to augment the generic dm-verity instructions with the board specifics for this platform.
--- docs/dm-verity-beaglebone.txt | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 docs/dm-verity-beaglebone.txt
docs/dm-verity-beaglebone.txt new file +37 -0
@@ -0,0 +1,37 @@ +dm-verity and beaglebone-black +------------------------------ +Set/uncomment the MACHINE line for "beaglebone-yocto" if you haven't yet. + +In addition to the basic dm-verity settings, you'll also want in local.conf: + +IMAGE_BOOT_FILES:remove = "zImage" +IMAGE_BOOT_FILES:append = " zImage-initramfs-${MACHINE}.bin;zImage" +WKS_FILES = "${MACHINE}-verity.wks.in" + +Read-only issues: The beaglebone BSP by default declares the following: + + SERIAL_CONSOLES ?= "115200;ttyS0 115200;ttyO0 115200;ttyAMA0" + SERIAL_CONSOLES_CHECK = "${SERIAL_CONSOLES}" + +...which are variables used by sysV init, in order to determine the +appropriate /etc/inittab entries. The problem that arises is that by +default, an on-target runtime check of /proc/consoles is used to finalize +the /etc/inittab -- and of course that fails a build with read-only-rootfs +[see the pkg_postinst_ontarget rule in the sysvinit rule for details.] + +If you don't need a serial console, the quick fix is to add in local.conf + +SERIAL_CONSOLES = "" + +If you do need/want a serial console, then probably a local bbappend to +manually set the /etc/inittab as desired is easiest. + +After running "wic create -e core-image-minimal beaglebone-yocto-verity" +you should have a "direct" image ready to write to a u-SD card. Remember +that the "direct" image contains the bootloader and partition table +already, so you'll be writing it to a device such as /dev/sdb and not +just a partition -- like /dev/sdb1 + +Also recall that booting from u-SD requires pressing and holding the S2 +(SYSBOOT) button during power-on in order to divert the boot from the normal +soldered on storage and to the removable u-SD card.
Signature · 1 line
2.33.0