diff options
| author | Bartosz Golaszewski <bgolaszewski@baylibre.com> | 2020-04-10 14:41:35 +0200 |
|---|---|---|
| committer | Armin Kuster <akuster808@gmail.com> | 2020-05-15 05:28:21 -0700 |
| commit | d6369c9aafc433b08f9bb000142b274738be3fb3 (patch) | |
| tree | d62718bfbdf83ad41946f4fca911c358328ddd56 /recipes-core/initrdscripts | |
| parent | b329e1650daa860c7dfdbd771ddff611452c382b (diff) | |
| download | meta-security-d6369c9aafc433b08f9bb000142b274738be3fb3.tar.gz | |
dm-verity: add a working example for BeagleBone Black
This adds various bits and pieces to enable generating a working example
of a full chain of trust up to dm-verity-protected rootfs level on Beagle
Bone Black.
The new initramfs is quite generic and should work for other SoCs as well
when using fitImage.
The following config can be used with current master poky,
meta-openembedded & meta-security to generate a BBB image using verified
boot and dm-verity.
UBOOT_SIGN_KEYDIR = "/tmp/test-keys/"
UBOOT_SIGN_KEYNAME = "dev"
UBOOT_SIGN_ENABLE = "1"
UBOOT_MKIMAGE_DTCOPTS = "-I dts -O dtb -p 2000"
UBOOT_MACHINE_beaglebone-yocto = "am335x_boneblack_vboot_config"
IMAGE_CLASSES += "dm-verity-img"
IMAGE_FSTYPES += "wic.xz ext4"
DM_VERITY_IMAGE = "core-image-full-cmdline"
DM_VERITY_IMAGE_TYPE = "ext4"
KERNEL_CLASSES += "kernel-fitimage"
KERNEL_IMAGETYPE_beaglebone-yocto = "fitImage"
IMAGE_INSTALL_remove = " kernel-image-zimage"
IMAGE_BOOT_FILES_remove = " zImage"
IMAGE_BOOT_FILES_append = " fitImage-${INITRAMFS_IMAGE}-${MACHINE}-${MACHINE};fitImage"
# Using systemd is not strictly needed but deals nicely with read-only
# filesystem by default.
DISTRO_FEATURES_append = " systemd"
DISTRO_FEATURES_BACKFILL_CONSIDERED += "sysvinit"
VIRTUAL-RUNTIME_init_manager = "systemd"
VIRTUAL-RUNTIME_initscripts = "systemd-compat-units"
INITRAMFS_IMAGE = "dm-verity-image-initramfs"
INITRAMFS_FSTYPES = "cpio.gz"
INITRAMFS_IMAGE_BUNDLE = "1"
WKS_FILE = "beaglebone-yocto-verity.wks.in"
KERNEL_FEATURES_append = " features/device-mapper/dm-verity.scc"
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: Armin Kuster <akuster808@gmail.com>
Diffstat (limited to 'recipes-core/initrdscripts')
| -rw-r--r-- | recipes-core/initrdscripts/initramfs-dm-verity.bb | 13 | ||||
| -rw-r--r-- | recipes-core/initrdscripts/initramfs-dm-verity/init-dm-verity.sh | 46 |
2 files changed, 59 insertions, 0 deletions
diff --git a/recipes-core/initrdscripts/initramfs-dm-verity.bb b/recipes-core/initrdscripts/initramfs-dm-verity.bb new file mode 100644 index 0000000..b614956 --- /dev/null +++ b/recipes-core/initrdscripts/initramfs-dm-verity.bb | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | SUMMARY = "Simple init script that uses devmapper to mount the rootfs in read-only mode protected by dm-verity" | ||
| 2 | LICENSE = "MIT" | ||
| 3 | LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" | ||
| 4 | |||
| 5 | SRC_URI = "file://init-dm-verity.sh" | ||
| 6 | |||
| 7 | do_install() { | ||
| 8 | install -m 0755 ${WORKDIR}/init-dm-verity.sh ${D}/init | ||
| 9 | install -d ${D}/dev | ||
| 10 | mknod -m 622 ${D}/dev/console c 5 1 | ||
| 11 | } | ||
| 12 | |||
| 13 | FILES_${PN} = "/init /dev/console" | ||
diff --git a/recipes-core/initrdscripts/initramfs-dm-verity/init-dm-verity.sh b/recipes-core/initrdscripts/initramfs-dm-verity/init-dm-verity.sh new file mode 100644 index 0000000..307d2c7 --- /dev/null +++ b/recipes-core/initrdscripts/initramfs-dm-verity/init-dm-verity.sh | |||
| @@ -0,0 +1,46 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | PATH=/sbin:/bin:/usr/sbin:/usr/bin | ||
| 4 | RDEV="" | ||
| 5 | ROOT_DIR="/new_root" | ||
| 6 | |||
| 7 | mkdir -p /proc | ||
| 8 | mkdir -p /sys | ||
| 9 | mkdir -p /run | ||
| 10 | mkdir -p /tmp | ||
| 11 | mount -t proc proc /proc | ||
| 12 | mount -t sysfs sysfs /sys | ||
| 13 | mount -t devtmpfs none /dev | ||
| 14 | |||
| 15 | udevd --daemon | ||
| 16 | udevadm trigger --type=subsystems --action=add | ||
| 17 | udevadm trigger --type=devices --action=add | ||
| 18 | udevadm settle --timeout=10 | ||
| 19 | |||
| 20 | for PARAM in $(cat /proc/cmdline); do | ||
| 21 | case $PARAM in | ||
| 22 | root=*) | ||
| 23 | RDEV=${PARAM#root=} | ||
| 24 | ;; | ||
| 25 | esac | ||
| 26 | done | ||
| 27 | |||
| 28 | if ! [ -b $RDEV ]; then | ||
| 29 | echo "Missing root command line argument!" | ||
| 30 | exit 1 | ||
| 31 | fi | ||
| 32 | |||
| 33 | case $RDEV in | ||
| 34 | UUID=*) | ||
| 35 | RDEV=$(realpath /dev/disk/by-uuid/${RDEV#UUID=}) | ||
| 36 | ;; | ||
| 37 | esac | ||
| 38 | |||
| 39 | . /usr/share/dm-verity.env | ||
| 40 | |||
| 41 | echo "Mounting $RDEV over dm-verity as the root filesystem" | ||
| 42 | |||
| 43 | veritysetup --data-block-size=1024 --hash-offset=$DATA_SIZE create rootfs $RDEV $RDEV $ROOT_HASH | ||
| 44 | mkdir -p $ROOT_DIR | ||
| 45 | mount -o ro /dev/mapper/rootfs $ROOT_DIR | ||
| 46 | exec switch_root $ROOT_DIR /sbin/init | ||
