Skip to contentSkip to conversation

Various initramfs hook improvements

PATCH In review Jan Kiszka 2 participants 16 messages Dec 2, 2024 – Dec 6, 2024

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

cover Various initramfs hook improvements

This uses the new initramfs hook generator of isar to simplify our own hook recipes.

It furthermore brings support for expanding the last partition before encrypting it. This needs to be done as part of the initramfs-crypt-hook because we only know there which device and which partition to use.

Finally, this improves the security of the disk encryption keys by preventing access to them after initramfs usage. Thus, the main Linux is now no longer able to leak the keys during an attack.

Jan

Jan Kiszka (10):
Update isar revision
initramfs-abrootfs-hook: Convert to hook.inc
initramfs-crypt-hook: Convert awk statement into simple variable
evaluation
initramfs-crypt-hook: Convert to hook.inc initramfs-erofs/squashfs-hook: Convert to hook.inc
initramfs-overlay-hook: Convert to hook.inc
initramfs-verity-hook: Drop dead verity.conf-hook artifact
initramfs-verity-hook: Convert to hook.inc
initramfs-crypt-hook: Add support for expanding encrypted partition
initramfs-crypt-hook: invalidate PCR7 after unlocking partitions

 kas-cip.yml                                   |   2 +-
 kas/opt/expand-on-first-boot.yml              |   3 +
 .../files/abrootfs.hook                       |  24 -----
 .../initramfs-abrootfs-hook/files/hook        |   5 +
 .../{abrootfs.script => local-top-complete}   |   0
 ..._0.1.bb => initramfs-abrootfs-hook_0.2.bb} |  25 ++---
 ...pt_partition.clevis.bullseye_or_later.hook |  34 ------
 .../encrypt_partition.clevis.buster.hook      |  29 -----
 .../files/encrypt_partition.clevis.hook       |  88 ---------------
 .../files/encrypt_partition.systemd.hook      |  68 ------------
 .../initramfs-crypt-hook/files/hook           |  11 ++
 ...artitions.script => local-bottom-complete} |   0
 ...pt_partition.script => local-top-complete} |  68 +++++++++++-
 .../initramfs-crypt-hook_0.4.bb               |  96 -----------------
 .../initramfs-crypt-hook_0.5.bb               | 101 ++++++++++++++++++
 .../initramfs-erofs-hook/files/erofs.hook     |  25 -----
 .../initramfs-erofs-hook_0.1.bb               |  24 -----
 .../initramfs-erofs-hook_0.2.bb               |  14 +++
 ...{overlay.script.tmpl => local-bottom.tmpl} |  23 +---
 .../initramfs-overlay-hook/files/overlay.hook |  34 ------
 ...k_0.1.bb => initramfs-overlay-hook_0.2.bb} |  20 ++--
 .../initramfs-squashfs-hook_0.1.bb            |  24 -----
 .../initramfs-squashfs-hook_0.2.bb            |  14 +++
 .../initramfs-verity-hook/files/hook          |   5 +
 ...ty.script.tmpl => local-top-complete.tmpl} |   0
 .../files/verity.conf-hook                    |   1 -
 .../initramfs-verity-hook/files/verity.hook   |  23 ----
 ...ok_0.1.bb => initramfs-verity-hook_0.2.bb} |  24 ++---
 28 files changed, 250 insertions(+), 535 deletions(-)
 delete mode 100644 recipes-initramfs/initramfs-abrootfs-hook/files/abrootfs.hook
 create mode 100644 recipes-initramfs/initramfs-abrootfs-hook/files/hook
 rename recipes-initramfs/initramfs-abrootfs-hook/files/{abrootfs.script => local-top-complete} (100%)
 rename recipes-initramfs/initramfs-abrootfs-hook/{initramfs-abrootfs-hook_0.1.bb => initramfs-abrootfs-hook_0.2.bb} (61%)
 delete mode 100755 recipes-initramfs/initramfs-crypt-hook/files/encrypt_partition.clevis.bullseye_or_later.hook
 delete mode 100755 recipes-initramfs/initramfs-crypt-hook/files/encrypt_partition.clevis.buster.hook
 delete mode 100755 recipes-initramfs/initramfs-crypt-hook/files/encrypt_partition.clevis.hook
 delete mode 100755 recipes-initramfs/initramfs-crypt-hook/files/encrypt_partition.systemd.hook
 create mode 100644 recipes-initramfs/initramfs-crypt-hook/files/hook
 rename recipes-initramfs/initramfs-crypt-hook/files/{mount_crypt_partitions.script => local-bottom-complete} (100%)
 rename recipes-initramfs/initramfs-crypt-hook/files/{encrypt_partition.script => local-top-complete} (71%)
 delete mode 100644 recipes-initramfs/initramfs-crypt-hook/initramfs-crypt-hook_0.4.bb
 create mode 100644 recipes-initramfs/initramfs-crypt-hook/initramfs-crypt-hook_0.5.bb
 delete mode 100644 recipes-initramfs/initramfs-erofs-hook/files/erofs.hook
 delete mode 100644 recipes-initramfs/initramfs-erofs-hook/initramfs-erofs-hook_0.1.bb
 create mode 100644 recipes-initramfs/initramfs-erofs-hook/initramfs-erofs-hook_0.2.bb
 rename recipes-initramfs/initramfs-overlay-hook/files/{overlay.script.tmpl => local-bottom.tmpl} (91%)
 delete mode 100644 recipes-initramfs/initramfs-overlay-hook/files/overlay.hook
 rename recipes-initramfs/initramfs-overlay-hook/{initramfs-overlay-hook_0.1.bb => initramfs-overlay-hook_0.2.bb} (71%)
 delete mode 100644 recipes-initramfs/initramfs-squashfs-hook/initramfs-squashfs-hook_0.1.bb
 create mode 100644 recipes-initramfs/initramfs-squashfs-hook/initramfs-squashfs-hook_0.2.bb
 create mode 100644 recipes-initramfs/initramfs-verity-hook/files/hook
 rename recipes-initramfs/initramfs-verity-hook/files/{verity.script.tmpl => local-top-complete.tmpl} (100%)
 delete mode 100644 recipes-initramfs/initramfs-verity-hook/files/verity.conf-hook
 delete mode 100644 recipes-initramfs/initramfs-verity-hook/files/verity.hook
 rename recipes-initramfs/initramfs-verity-hook/{initramfs-verity-hook_0.1.bb => initramfs-verity-hook_0.2.bb} (65%)
Signature · 1 line
2.43.0
author
#1 lore raw

PATCH 1/10 Update isar revision

From: Jan Kiszka <[email protected]>

Brings initramfs helpers and mmdebstrap support.

---
 kas-cip.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kas-cip.yml +1 -1
index 6c83a0d3..abdf92af 100644
@@ -22,7 +22,7 @@ repos:
 
   isar:
     url: https://github.com/ilbers/isar.git
-    commit: b92e9076e27bf22b8296dd3440bf25ebf348e2c6
+    commit: a6171856de84da3deca1355da7aa9c09588e7ea2
     layers:
       meta:
 
Signature · 1 line
2.43.0
author
#2 lore raw

PATCH 2/10 initramfs-abrootfs-hook: Convert to hook.inc

In reply to Jan Kiszka

From: Jan Kiszka <[email protected]>

Reduces boilerplate code.

---
 .../files/abrootfs.hook                       | 24 ------------------
 .../initramfs-abrootfs-hook/files/hook        |  5 ++++
 .../{abrootfs.script => local-top-complete}   |  0
 ..._0.1.bb => initramfs-abrootfs-hook_0.2.bb} | 25 ++++++++-----------
 4 files changed, 15 insertions(+), 39 deletions(-)
 delete mode 100644 recipes-initramfs/initramfs-abrootfs-hook/files/abrootfs.hook
 create mode 100644 recipes-initramfs/initramfs-abrootfs-hook/files/hook
 rename recipes-initramfs/initramfs-abrootfs-hook/files/{abrootfs.script => local-top-complete} (100%)
 rename recipes-initramfs/initramfs-abrootfs-hook/{initramfs-abrootfs-hook_0.1.bb => initramfs-abrootfs-hook_0.2.bb} (61%)
recipes-initramfs/initramfs-abrootfs-hook/files/abrootfs.hook deleted +0 -24
deleted file mode 100644
index bacbc2ee..00000000
@@ -1,24 +0,0 @@
-#!/bin/sh
-# Copyright (C) Siemens AG, 2020-2022
-#
-# SPDX-License-Identifier: MIT
-
-PREREQ=""
-
-prereqs()
-{
-     echo "$PREREQ"
-}
-
-case $1 in
-prereqs)
-     prereqs
-     exit 0
-     ;;
-esac
-
-. /usr/share/initramfs-tools/scripts/functions
-. /usr/share/initramfs-tools/hook-functions
-
-copy_exec /usr/bin/lsblk
-copy_file library /usr/share/abrootfs/image-uuid.env /usr/share/abrootfs/image-uuid.env
recipes-initramfs/initramfs-abrootfs-hook/files/hook new file +5 -0
new file mode 100644
index 00000000..6d4a6129
@@ -0,0 +1,5 @@
+# Copyright (C) Siemens AG, 2020-2022
+#
+# SPDX-License-Identifier: MIT
+
+copy_file library /usr/share/abrootfs/image-uuid.env /usr/share/abrootfs/image-uuid.env
recipes-initramfs/initramfs-abrootfs-hook/files/local-top-complete renamed from recipes-initramfs/initramfs-abrootfs-hook/files/abrootfs.script +0 -0
similarity index 100%
rename from recipes-initramfs/initramfs-abrootfs-hook/files/abrootfs.script
rename to recipes-initramfs/initramfs-abrootfs-hook/files/local-top-complete
recipes-initramfs/initramfs-abrootfs-hook/initramfs-abrootfs-hook_0.2.bb renamed from recipes-initramfs/initramfs-abrootfs-hook/initramfs-abrootfs-hook_0.1.bb +10 -15
similarity index 61%
rename from recipes-initramfs/initramfs-abrootfs-hook/initramfs-abrootfs-hook_0.1.bb
rename to recipes-initramfs/initramfs-abrootfs-hook/initramfs-abrootfs-hook_0.2.bb
index 17c60da4..592f305f 100644
@@ -1,7 +1,7 @@
 #
 # CIP Core, generic profile
 #
-# Copyright (c) Siemens AG, 2020-2022
+# Copyright (c) Siemens AG, 2020-2024
 #
 # Authors:
 #  Quirin Gylstorff <[email protected]>
@@ -9,17 +9,19 @@
 #
 # SPDX-License-Identifier: MIT
 
+require recipes-initramfs/initramfs-hook/hook.inc
 
-inherit dpkg-raw
-
-DEBIAN_DEPENDS = "initramfs-tools"
+DEBIAN_DEPENDS .= ", util-linux"
 DEBIAN_CONFLICTS = "initramfs-verity-hook"
 
-SRC_URI += "file://abrootfs.hook \
-            file://abrootfs.script"
+SRC_URI += " \
+    file://hook \
+    file://local-top-complete"
 
 ABROOTFS_IMAGE_RECIPE ?= "cip-core-image"
 
+HOOK_COPY_EXECS = "lsblk"
+
 # This is defined in image.bbclass which cannot be used in a package recipe.
 # However, we need to use IMAGE_FULLNAME to pick up any extensions of it.
 IMAGE_FULLNAME ??= "${ABROOTFS_IMAGE_RECIPE}-${DISTRO}-${MACHINE}"
@@ -27,19 +29,12 @@ IMAGE_FULLNAME ??= "${ABROOTFS_IMAGE_RECIPE}-${DISTRO}-${MACHINE}"
 IMAGE_UUID_ENV_FILE = "${DEPLOY_DIR_IMAGE}/${IMAGE_FULLNAME}.uuid.env"
 
 do_install[depends] += "${ABROOTFS_IMAGE_RECIPE}:do_generate_image_uuid"
-do_install[cleandirs] += " \
-    ${D}/usr/share/initramfs-tools/hooks \
-    ${D}/usr/share/abrootfs \
-    ${D}/usr/share/initramfs-tools/scripts/local-top"
+do_install[cleandirs] += "${D}/usr/share/abrootfs"
 
-do_install() {
+do_install:append() {
     if [ -f "${IMAGE_UUID_ENV_FILE}" ]; then
         install -m 0600 "${IMAGE_UUID_ENV_FILE}" "${D}/usr/share/abrootfs/image-uuid.env"
     else
         bberror "Did not find ${IMAGE_UUID_ENV_FILE}. initramfs will not be build correctly!"
     fi
-    install -m 0755 "${WORKDIR}/abrootfs.script" \
-        "${D}/usr/share/initramfs-tools/scripts/local-top/abrootfs"
-    install -m 0755 "${WORKDIR}/abrootfs.hook" \
-        "${D}/usr/share/initramfs-tools/hooks/abrootfs"
 }
Signature · 1 line
2.43.0
author
#3 lore raw

PATCH 3/10 initramfs-crypt-hook: Convert awk statement into simple variable evaluation

In reply to Jan Kiszka

From: Jan Kiszka <[email protected]>

Use suffix removal to convert "/dev/some-device" into "some-device". It's simpler and avoids sub-processes.

---
 .../initramfs-crypt-hook/files/encrypt_partition.script         | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
recipes-initramfs/initramfs-crypt-hook/files/encrypt_partition.script +1 -1
index 2cd6798d..28548502 100644
@@ -62,7 +62,7 @@ service_watchdog() {
 }
 
 reencrypt_existing_partition() {
-	part_size_blocks="$(cat /sys/class/block/"$(awk -v dev="$1" 'BEGIN{split(dev,a,"/"); print a[3]}' )"/size)"
+	part_size_blocks="$(cat /sys/class/block/"${1##*/}"/size)"
 	# reduce the filesystem and partition by 32M to fit the LUKS header
 	partition_fstype=$(get_fstype "${1}")
 	reduce_device_size=32768
Signature · 1 line
2.43.0
author
#4 lore raw

PATCH 4/10 initramfs-crypt-hook: Convert to hook.inc

In reply to Jan Kiszka

From: Jan Kiszka <[email protected]>

Here, we specifically benefit from the new generator by pulling a lot of the variations into the bitbake domain. Most of the hook bits are now generated, code duplications are avoided.

---
 ...pt_partition.clevis.bullseye_or_later.hook | 34 -------
 .../encrypt_partition.clevis.buster.hook      | 29 ------
 .../files/encrypt_partition.clevis.hook       | 88 -----------------
 .../files/encrypt_partition.systemd.hook      | 68 -------------
 .../initramfs-crypt-hook/files/hook           | 11 +++
 ...artitions.script => local-bottom-complete} |  0
 ...pt_partition.script => local-top-complete} |  0
 .../initramfs-crypt-hook_0.4.bb               | 96 ------------------
 .../initramfs-crypt-hook_0.5.bb               | 97 +++++++++++++++++++
 9 files changed, 108 insertions(+), 315 deletions(-)
 delete mode 100755 recipes-initramfs/initramfs-crypt-hook/files/encrypt_partition.clevis.bullseye_or_later.hook
 delete mode 100755 recipes-initramfs/initramfs-crypt-hook/files/encrypt_partition.clevis.buster.hook
 delete mode 100755 recipes-initramfs/initramfs-crypt-hook/files/encrypt_partition.clevis.hook
 delete mode 100755 recipes-initramfs/initramfs-crypt-hook/files/encrypt_partition.systemd.hook
 create mode 100644 recipes-initramfs/initramfs-crypt-hook/files/hook
 rename recipes-initramfs/initramfs-crypt-hook/files/{mount_crypt_partitions.script => local-bottom-complete} (100%)
 rename recipes-initramfs/initramfs-crypt-hook/files/{encrypt_partition.script => local-top-complete} (100%)
 delete mode 100644 recipes-initramfs/initramfs-crypt-hook/initramfs-crypt-hook_0.4.bb
 create mode 100644 recipes-initramfs/initramfs-crypt-hook/initramfs-crypt-hook_0.5.bb
recipes-initramfs/initramfs-crypt-hook/files/encrypt_partition.clevis.bullseye_or_later.hook deleted +0 -34
deleted file mode 100755
index b244d45f..00000000
@@ -1,34 +0,0 @@
-#!/bin/sh
-# Copyright (C) Siemens AG, 2020-2023
-#
-# SPDX-License-Identifier: MIT
-
-PREREQ=""
-
-prereqs()
-{
-     echo "$PREREQ"
-}
-
-case $1 in
-prereqs)
-     prereqs
-     exit 0
-     ;;
-esac
-
-. /usr/share/initramfs-tools/hook-functions
-
-if [ -f /etc/os-release ]; then
-    . /etc/os-release
-fi
-hook_error() {
-    echo "(ERROR): $1" >&2
-    exit 1
-}
-
-copy_exec /usr/bin/clevis-luks-list || hook_error "/usr/bin/clevis-luks-list not found"
-copy_exec /usr/bin/clevis-luks-common-functions || hook_error "/usr/bin/clevis-luks-common-functions not found"
-copy_exec /usr/bin/tpm2_pcrread || hook_error "Unable to copy /usr/bin/tpm2_pcrread"
-copy_exec /usr/bin/tpm2_testparms || hook_error "Unable to copy /usr/bin/tpm2_testparms"
-copy_exec /usr/bin/tpm2_flushcontext || hook_error "Unable to copy /usr/bin/tpm2_flushcontext"
recipes-initramfs/initramfs-crypt-hook/files/encrypt_partition.clevis.buster.hook deleted +0 -29
deleted file mode 100755
index 617d40f9..00000000
@@ -1,29 +0,0 @@
-#!/bin/sh
-# Copyright (C) Siemens AG, 2020-2023
-#
-# SPDX-License-Identifier: MIT
-
-PREREQ=""
-
-prereqs()
-{
-     echo "$PREREQ"
-}
-
-case $1 in
-prereqs)
-     prereqs
-     exit 0
-     ;;
-esac
-
-. /usr/share/initramfs-tools/hook-functions
-
-if [ -f /etc/os-release ]; then
-    . /etc/os-release
-fi
-hook_error() {
-    echo "(ERROR): $1" >&2
-    exit 1
-}
-copy_exec /usr/bin/tpm2_pcrlist || hook_error "Unable to copy /usr/bin/tpm2_pcrlist"
recipes-initramfs/initramfs-crypt-hook/files/encrypt_partition.clevis.hook deleted +0 -88

88 lines not on this page · raw message

recipes-initramfs/initramfs-crypt-hook/files/encrypt_partition.systemd.hook deleted +0 -68

68 lines not on this page · raw message

recipes-initramfs/initramfs-crypt-hook/files/hook new file +11 -0
new file mode 100644
index 00000000..1e64f624
@@ -0,0 +1,11 @@
+# Copyright (C) Siemens AG, 2020-2024
+#
+# SPDX-License-Identifier: MIT
+
+for _LIBRARY in /usr/lib/*/libtss2*; do
+    copy_exec "$_LIBRARY"
+done
+
+copy_file library /usr/share/encrypt_partition/encrypt_partition.env /usr/share/encrypt_partition/encrypt_partition.env
+copy_file library /usr/share/encrypt_partition/encrypt_partition_tpm2 /usr/share/encrypt_partition/encrypt_partition_tpm2
+copy_file pwmake-config /usr/share/encrypt_partition/pwquality.conf /etc/security/pwquality.conf
recipes-initramfs/initramfs-crypt-hook/files/local-bottom-complete renamed from recipes-initramfs/initramfs-crypt-hook/files/mount_crypt_partitions.script +0 -0
similarity index 100%
rename from recipes-initramfs/initramfs-crypt-hook/files/mount_crypt_partitions.script
rename to recipes-initramfs/initramfs-crypt-hook/files/local-bottom-complete
recipes-initramfs/initramfs-crypt-hook/files/local-top-complete renamed from recipes-initramfs/initramfs-crypt-hook/files/encrypt_partition.script +0 -0
similarity index 100%
rename from recipes-initramfs/initramfs-crypt-hook/files/encrypt_partition.script
rename to recipes-initramfs/initramfs-crypt-hook/files/local-top-complete
recipes-initramfs/initramfs-crypt-hook/initramfs-crypt-hook_0.4.bb deleted +0 -96

96 lines not on this page · raw message

recipes-initramfs/initramfs-crypt-hook/initramfs-crypt-hook_0.5.bb new file +97 -0

97 lines not on this page · raw message

Signature · 1 line
2.43.0
author
#5 lore raw

PATCH 5/10 initramfs-erofs/squashfs-hook: Convert to hook.inc

In reply to Jan Kiszka

From: Jan Kiszka <[email protected]>

Simplifies the recipes to their minimum.

The Debian dependency on erofs-utils was actually not needed, drop it at this chance.

---
 .../initramfs-erofs-hook/files/erofs.hook     | 25 -------------------
 .../initramfs-erofs-hook_0.1.bb               | 24 ------------------
 .../initramfs-erofs-hook_0.2.bb               | 14 +++++++++++
 .../initramfs-squashfs-hook_0.1.bb            | 24 ------------------
 .../initramfs-squashfs-hook_0.2.bb            | 14 +++++++++++
 5 files changed, 28 insertions(+), 73 deletions(-)
 delete mode 100644 recipes-initramfs/initramfs-erofs-hook/files/erofs.hook
 delete mode 100644 recipes-initramfs/initramfs-erofs-hook/initramfs-erofs-hook_0.1.bb
 create mode 100644 recipes-initramfs/initramfs-erofs-hook/initramfs-erofs-hook_0.2.bb
 delete mode 100644 recipes-initramfs/initramfs-squashfs-hook/initramfs-squashfs-hook_0.1.bb
 create mode 100644 recipes-initramfs/initramfs-squashfs-hook/initramfs-squashfs-hook_0.2.bb
recipes-initramfs/initramfs-erofs-hook/files/erofs.hook deleted +0 -25
deleted file mode 100644
index cf43bf10..00000000
@@ -1,25 +0,0 @@
-#!/bin/sh
-#
-# CIP Core, generic profile
-#
-# Copyright (c) Siemens AG, 2024
-#
-# Authors:
-#  Jan Kiszka <[email protected]>
-#
-
-PREREQ=""
-prereqs()
-{
-    echo "$PREREQ"
-}
-case $1 in
-prereqs)
-    prereqs
-    exit 0
-    ;;
-esac
-
-. /usr/share/initramfs-tools/hook-functions
-
-manual_add_modules erofs
recipes-initramfs/initramfs-erofs-hook/initramfs-erofs-hook_0.1.bb deleted +0 -24
deleted file mode 100644
index ab679c91..00000000
@@ -1,24 +0,0 @@
-#
-# CIP Core, generic profile
-#
-# Copyright (c) Siemens AG, 2024
-#
-# Authors:
-#  Jan Kiszka <[email protected]>
-#
-# SPDX-License-Identifier: MIT
-#
-
-inherit dpkg-raw
-
-SRC_URI += "file://erofs.hook"
-
-DEBIAN_DEPENDS = "erofs-utils"
-
-do_install[cleandirs] += " \
-    ${D}/usr/share/initramfs-tools/hooks"
-
-do_install() {
-    install -m 0755 "${WORKDIR}/erofs.hook" \
-        "${D}/usr/share/initramfs-tools/hooks/erofs"
-}
recipes-initramfs/initramfs-erofs-hook/initramfs-erofs-hook_0.2.bb new file +14 -0
new file mode 100644
index 00000000..a7dbb673
@@ -0,0 +1,14 @@
+#
+# CIP Core, generic profile
+#
+# Copyright (c) Siemens AG, 2024
+#
+# Authors:
+#  Jan Kiszka <[email protected]>
+#
+# SPDX-License-Identifier: MIT
+#
+
+require recipes-initramfs/initramfs-hook/hook.inc
+
+HOOK_ADD_MODULES = "erofs"
recipes-initramfs/initramfs-squashfs-hook/initramfs-squashfs-hook_0.1.bb deleted +0 -24
deleted file mode 100644
index 332278f5..00000000
@@ -1,24 +0,0 @@
-#
-# CIP Core, generic profile
-#
-# Copyright (c) Siemens AG, 2022
-#
-# Authors:
-#  Felix Moessbauer <[email protected]>
-#
-# SPDX-License-Identifier: MIT
-#
-
-inherit dpkg-raw
-
-SRC_URI += "file://squashfs.hook"
-
-DEBIAN_DEPENDS = "initramfs-tools"
-
-do_install[cleandirs] += " \
-    ${D}/usr/share/initramfs-tools/hooks"
-
-do_install() {
-    install -m 0755 "${WORKDIR}/squashfs.hook" \
-        "${D}/usr/share/initramfs-tools/hooks/squashfs"
-}
recipes-initramfs/initramfs-squashfs-hook/initramfs-squashfs-hook_0.2.bb new file +14 -0
new file mode 100644
index 00000000..4b199834
@@ -0,0 +1,14 @@
+#
+# CIP Core, generic profile
+#
+# Copyright (c) Siemens AG, 2024
+#
+# Authors:
+#  Jan Kiszka <[email protected]>
+#
+# SPDX-License-Identifier: MIT
+#
+
+require recipes-initramfs/initramfs-hook/hook.inc
+
+HOOK_ADD_MODULES = "squashfs"
Signature · 1 line
2.43.0
author
#6 lore raw

PATCH 6/10 initramfs-overlay-hook: Convert to hook.inc

In reply to Jan Kiszka

From: Jan Kiszka <[email protected]>

Simplifies the code.

---
 ...{overlay.script.tmpl => local-bottom.tmpl} | 23 ++-----------
 .../initramfs-overlay-hook/files/overlay.hook | 34 -------------------
 ...k_0.1.bb => initramfs-overlay-hook_0.2.bb} | 20 ++++-------
 3 files changed, 10 insertions(+), 67 deletions(-)
 rename recipes-initramfs/initramfs-overlay-hook/files/{overlay.script.tmpl => local-bottom.tmpl} (91%)
 delete mode 100644 recipes-initramfs/initramfs-overlay-hook/files/overlay.hook
 rename recipes-initramfs/initramfs-overlay-hook/{initramfs-overlay-hook_0.1.bb => initramfs-overlay-hook_0.2.bb} (71%)
recipes-initramfs/initramfs-overlay-hook/files/local-bottom.tmpl renamed from recipes-initramfs/initramfs-overlay-hook/files/overlay.script.tmpl +3 -20
similarity index 91%
rename from recipes-initramfs/initramfs-overlay-hook/files/overlay.script.tmpl
rename to recipes-initramfs/initramfs-overlay-hook/files/local-bottom.tmpl
index 72d13963..f829a9bb 100644
@@ -1,32 +1,13 @@
-#!/bin/sh
 #
 # CIP Core, generic profile
 #
-# Copyright (c) Siemens AG, 2022-2023
+# Copyright (c) Siemens AG, 2022-2024
 #
 # Authors:
 #  Jan Kiszka <[email protected]>
 #  Quirin Gylstorff <[email protected]>
 #
 
-PREREQ=""
-
-prereqs()
-{
-	echo "$PREREQ"
-}
-
-case $1 in
-# get pre-requisites
-prereqs)
-	prereqs
-	exit 0
-	;;
-esac
-
-. /scripts/functions
-
-
 ovl_partition_device="${INITRAMFS_OVERLAY_STORAGE_DEVICE}"
 ovl_storage_path="${INITRAMFS_OVERLAY_STORAGE_PATH}"
 ovl_lower_dirs="${INITRAMFS_OVERLAY_PATHS}"
@@ -76,3 +57,5 @@ for ovl_lower_dir in ${ovl_lower_dirs}; do
 		panic "Can't mount overlay for '$ovl_lower_dir' !"
 	fi
 done
+
+exit 0
recipes-initramfs/initramfs-overlay-hook/files/overlay.hook deleted +0 -34
deleted file mode 100644
index 6f634c50..00000000
@@ -1,34 +0,0 @@
-#!/bin/sh
-#
-# CIP Core, generic profile
-#
-# Copyright (c) Siemens AG, 2022
-#
-# Authors:
-#  Jan Kiszka <[email protected]>
-#
-
-PREREQ=""
-prereqs()
-{
-    echo "$PREREQ"
-}
-case $1 in
-prereqs)
-    prereqs
-    exit 0
-    ;;
-esac
-
-. /usr/share/initramfs-tools/hook-functions
-
-hook_error() {
-    echo "(ERROR): $1" >&2
-    exit 1
-}
-
-manual_add_modules overlay
-copy_exec /usr/bin/mountpoint || hook_error "/usr/bin/mountpoint not found"
-copy_exec /usr/bin/awk || hook_error "/usr/bin/awk not found"
-copy_exec /usr/sbin/e2fsck || hook_error "/usr/sbin/e2fsck not found"
-copy_exec /usr/sbin/mke2fs || hook_error "/usr/sbin/mke2fs not found"
recipes-initramfs/initramfs-overlay-hook/initramfs-overlay-hook_0.2.bb renamed from recipes-initramfs/initramfs-overlay-hook/initramfs-overlay-hook_0.1.bb +7 -13
similarity index 71%
rename from recipes-initramfs/initramfs-overlay-hook/initramfs-overlay-hook_0.1.bb
rename to recipes-initramfs/initramfs-overlay-hook/initramfs-overlay-hook_0.2.bb
index 7097130d..e6ac1e91 100644
@@ -1,7 +1,7 @@
 #
 # CIP Core, generic profile
 #
-# Copyright (c) Siemens AG, 2022 - 2023
+# Copyright (c) Siemens AG, 2022 - 2024
 #
 # Authors:
 #  Jan Kiszka <[email protected]>
@@ -10,13 +10,12 @@
 # SPDX-License-Identifier: MIT
 #
 
-inherit dpkg-raw
+require recipes-initramfs/initramfs-hook/hook.inc
 
 INITRAMFS_OVERLAY_RECOVERY_SCRIPT ??= "overlay_recovery_action.script"
 
 SRC_URI += " \
-    file://overlay.hook \
-    file://overlay.script.tmpl \
+    file://local-bottom.tmpl \
     file://${INITRAMFS_OVERLAY_RECOVERY_SCRIPT} \
     "
 
@@ -34,7 +33,7 @@ INITRAMFS_OVERLAY_STORAGE_PATH ??= "/var/local"
 INITRAMFS_OVERLAY_STORAGE_DEVICE ??= "/dev/disk/by-label/var"
 INITRAMFS_OVERLAY_MOUNT_OPTION ??= "defaults,nodev,nosuid,noexec"
 
-TEMPLATE_FILES = "overlay.script.tmpl"
+TEMPLATE_FILES += "local-bottom.tmpl"
 TEMPLATE_VARS += " INITRAMFS_OVERLAY_STORAGE_PATH \
     INITRAMFS_OVERLAY_PATHS \
     INITRAMFS_OVERLAY_STORAGE_DEVICE \
@@ -43,15 +42,10 @@ TEMPLATE_VARS += " INITRAMFS_OVERLAY_STORAGE_PATH \
 
 DEBIAN_DEPENDS = "initramfs-tools, awk, coreutils, util-linux"
 
-do_install[cleandirs] += " \
-    ${D}/usr/share/initramfs-tools/hooks \
-    ${D}/usr/share/initramfs-tools/scripts/local-bottom"
+HOOK_ADD_MODULES = "overlay"
+HOOK_ADD_EXECS = "mountpoint awk e2fsck mke2fs"
 
-do_install() {
-    install -m 0755 "${WORKDIR}/overlay.hook" \
-        "${D}/usr/share/initramfs-tools/hooks/overlay"
-    install -m 0755 "${WORKDIR}/overlay.script" \
-        "${D}/usr/share/initramfs-tools/scripts/local-bottom/overlay"
+do_install:append() {
     install -m 0755 "${WORKDIR}/${INITRAMFS_OVERLAY_RECOVERY_SCRIPT}" \
         "${D}/usr/share/initramfs-tools/scripts"
 }
Signature · 1 line
2.43.0
author
#7 lore raw

PATCH 7/10 initramfs-verity-hook: Drop dead verity.conf-hook artifact

In reply to Jan Kiszka

From: Jan Kiszka <[email protected]>

This was never used in fact.

---
 .../initramfs-verity-hook/files/verity.conf-hook              | 1 -
 ...tramfs-verity-hook_0.1.bb => initramfs-verity-hook_0.2.bb} | 4 +---
 2 files changed, 1 insertion(+), 4 deletions(-)
 delete mode 100644 recipes-initramfs/initramfs-verity-hook/files/verity.conf-hook
 rename recipes-initramfs/initramfs-verity-hook/{initramfs-verity-hook_0.1.bb => initramfs-verity-hook_0.2.bb} (92%)
recipes-initramfs/initramfs-verity-hook/files/verity.conf-hook deleted +0 -1
deleted file mode 100644
index 9b61fb85..00000000
@@ -1 +0,0 @@
-BUSYBOX=y
recipes-initramfs/initramfs-verity-hook/initramfs-verity-hook_0.2.bb renamed from recipes-initramfs/initramfs-verity-hook/initramfs-verity-hook_0.1.bb +1 -3
similarity index 92%
rename from recipes-initramfs/initramfs-verity-hook/initramfs-verity-hook_0.1.bb
rename to recipes-initramfs/initramfs-verity-hook/initramfs-verity-hook_0.2.bb
index a86e47df..6db4efcc 100644
@@ -12,7 +12,6 @@
 inherit dpkg-raw
 
 SRC_URI += " \
-    file://verity.conf-hook \
     file://verity.hook \
     file://verity.script.tmpl \
     "
@@ -37,8 +36,7 @@ do_install[depends] += "${VERITY_IMAGE_RECIPE}:do_image_verity"
 do_install[cleandirs] += " \
     ${D}/usr/share/initramfs-tools/hooks \
     ${D}/usr/share/verity-env \
-    ${D}/usr/share/initramfs-tools/scripts/local-top \
-    ${D}/usr/share/initramfs-tools/conf-hooks.d"
+    ${D}/usr/share/initramfs-tools/scripts/local-top"
 
 do_install() {
     # Insert the veritysetup commandline into the script
Signature · 1 line
2.43.0
author
#8 lore raw

PATCH 8/10 initramfs-verity-hook: Convert to hook.inc

In reply to Jan Kiszka

From: Jan Kiszka <[email protected]>

Simplifies the code.

---
 .../initramfs-verity-hook/files/hook          |  5 ++++
 ...ty.script.tmpl => local-top-complete.tmpl} |  0
 .../initramfs-verity-hook/files/verity.hook   | 23 -------------------
 .../initramfs-verity-hook_0.2.bb              | 22 ++++++++----------
 4 files changed, 14 insertions(+), 36 deletions(-)
 create mode 100644 recipes-initramfs/initramfs-verity-hook/files/hook
 rename recipes-initramfs/initramfs-verity-hook/files/{verity.script.tmpl => local-top-complete.tmpl} (100%)
 delete mode 100644 recipes-initramfs/initramfs-verity-hook/files/verity.hook
recipes-initramfs/initramfs-verity-hook/files/hook new file +5 -0
new file mode 100644
index 00000000..1550dafe
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: MIT
+# Copyright (c) Siemens AG, 2021-2024
+
+copy_file library /lib/cryptsetup/functions /lib/cryptsetup/functions
+copy_file library /usr/share/verity-env/verity.env /usr/share/verity-env/verity.env
recipes-initramfs/initramfs-verity-hook/files/local-top-complete.tmpl renamed from recipes-initramfs/initramfs-verity-hook/files/verity.script.tmpl +0 -0
similarity index 100%
rename from recipes-initramfs/initramfs-verity-hook/files/verity.script.tmpl
rename to recipes-initramfs/initramfs-verity-hook/files/local-top-complete.tmpl
recipes-initramfs/initramfs-verity-hook/files/verity.hook deleted +0 -23
deleted file mode 100644
index 5eada8a0..00000000
@@ -1,23 +0,0 @@
-#!/bin/sh
-PREREQ=""
-prereqs()
-{
-    echo "$PREREQ"
-}
-case $1 in
-prereqs)
-    prereqs
-    exit 0
-    ;;
-esac
-
-. /usr/share/initramfs-tools/hook-functions
-# Begin real processing below this line
-
-manual_add_modules dm_mod
-manual_add_modules dm_verity
-
-copy_exec /sbin/veritysetup
-copy_exec /sbin/dmsetup
-copy_file library /lib/cryptsetup/functions /lib/cryptsetup/functions
-copy_file library /usr/share/verity-env/verity.env /usr/share/verity-env/verity.env
recipes-initramfs/initramfs-verity-hook/initramfs-verity-hook_0.2.bb +9 -13
index 6db4efcc..d8f62bb4 100644
@@ -9,21 +9,24 @@
 # SPDX-License-Identifier: MIT
 #
 
-inherit dpkg-raw
+require recipes-initramfs/initramfs-hook/hook.inc
 
 SRC_URI += " \
-    file://verity.hook \
-    file://verity.script.tmpl \
+    file://hook \
+    file://local-top-complete.tmpl \
     "
 
 VERITY_BEHAVIOR_ON_CORRUPTION ?= "--restart-on-corruption"
 
-TEMPLATE_FILES = "verity.script.tmpl"
+TEMPLATE_FILES += "local-top-complete.tmpl"
 TEMPLATE_VARS += "VERITY_BEHAVIOR_ON_CORRUPTION"
 
 DEBIAN_DEPENDS = "initramfs-tools, cryptsetup"
 DEBIAN_CONFLICTS = "initramfs-abrootfs-hook"
 
+HOOK_ADD_MODULES = "dm_mod dm_verity"
+HOOK_COPY_EXECS = "veritysetup dmsetup"
+
 VERITY_IMAGE_RECIPE ?= "cip-core-image"
 
 # This is defined in image.bbclass which cannot be used in a package recipe.
@@ -33,22 +36,15 @@ IMAGE_FULLNAME ??= "${VERITY_IMAGE_RECIPE}-${DISTRO}-${MACHINE}"
 VERITY_ENV_FILE = "${DEPLOY_DIR_IMAGE}/${IMAGE_FULLNAME}.verity.env"
 
 do_install[depends] += "${VERITY_IMAGE_RECIPE}:do_image_verity"
-do_install[cleandirs] += " \
-    ${D}/usr/share/initramfs-tools/hooks \
-    ${D}/usr/share/verity-env \
-    ${D}/usr/share/initramfs-tools/scripts/local-top"
+do_install[cleandirs] += "${D}/usr/share/verity-env"
 
-do_install() {
+do_install:append() {
     # Insert the veritysetup commandline into the script
     if [ -f "${VERITY_ENV_FILE}" ]; then
         install -m 0600 "${VERITY_ENV_FILE}" "${D}/usr/share/verity-env/verity.env"
     else
         bberror "Did not find ${VERITY_ENV_FILE}. initramfs will not be build correctly!"
     fi
-    install -m 0755 "${WORKDIR}/verity.script" \
-        "${D}/usr/share/initramfs-tools/scripts/local-top/verity"
-    install -m 0755 "${WORKDIR}/verity.hook" \
-        "${D}/usr/share/initramfs-tools/hooks/verity"
 }
 
 addtask install after do_transform_template
Signature · 1 line
2.43.0
author
#9 lore raw

PATCH 9/10 initramfs-crypt-hook: Add support for expanding encrypted partition

In reply to Jan Kiszka

From: Jan Kiszka <[email protected]>

The crypt hook already performs resizing or appropriately sized formatting of partitions it handles during first boot. If we also add the partition expansion logic from isar's expand-on-first-boot, we get feature-complete expansion of encrypted partitions.

The feature is controlled by appending ":expand" to the affected partition in CRYPT_PARTITIONS. In contrast to isar's expansion logic, we do not have enough information at that time when it is called in order to identify the target partition automatically. That is another reason to embed this feature into the crypt hook.

There is not too much code to be taken from isar for this, so it is easiest to duplicate and adjust that as needed, rather than introducing some reusable upstream. This might be revisited in the future.

---
 kas/opt/expand-on-first-boot.yml              |  3 +
 .../files/local-top-complete                  | 63 +++++++++++++++++++
 .../initramfs-crypt-hook_0.5.bb               |  6 +-
 3 files changed, 71 insertions(+), 1 deletion(-)
kas/opt/expand-on-first-boot.yml +3 -0
index 03d666b2..f5be6992 100644
@@ -15,3 +15,6 @@ header:
 local_conf_header:
   package-expand-on-first-boot: |
     IMAGE_INSTALL:append = " expand-on-first-boot"
+  expand-before-encrypt: |
+    IMAGE_INSTALL:remove:encrypt-partitions = "expand-on-first-boot"
+    CRYPT_PARTITIONS:append:encrypt-partitions = ":expand"
recipes-initramfs/initramfs-crypt-hook/files/local-top-complete +63 -0

81 lines not on this page · raw message

recipes-initramfs/initramfs-crypt-hook/initramfs-crypt-hook_0.5.bb +5 -1
index 6ff315ed..71ee44db 100644
@@ -69,7 +69,7 @@ SRC_URI += "file://encrypt_partition.env.tmpl \
             file://hook \
             file://pwquality.conf"
 
-# CRYPT_PARTITIONS elements are <partition-label>:<mountpoint>:<reencrypt or format>
+# CRYPT_PARTITIONS elements are <partition-label>:<mountpoint>:<reencrypt or format>[:expand]
 CRYPT_PARTITIONS ??= "home:/home:reencrypt var:/var:reencrypt"
 # CRYPT_CREATE_FILE_SYSTEM_CMD contains the shell command to create the filesystem
 # in a newly formatted LUKS Partition
@@ -88,6 +88,10 @@ TEMPLATE_VARS += "CRYPT_PARTITIONS CRYPT_CREATE_FILE_SYSTEM_CMD \
     CRYPT_KEY_ALGORITHM CRYPT_ENCRYPTION_OPTIONAL"
 TEMPLATE_FILES += "encrypt_partition.env.tmpl"
 
+OVERRIDES .= "${@':expand-on-crypt' if ':expand' in d.getVar('CRYPT_PARTITIONS') else ''}"
+DEBIAN_DEPENDS:append:expand-on-crypt = ", fdisk, util-linux"
+HOOK_COPY_EXECS:append:expand-on-crypt = " sed sfdisk tail cut dd partx rm"
+
 do_install[cleandirs] += "${D}/usr/share/encrypt_partition"
 do_install:prepend() {
     install -m 0600 "${WORKDIR}/encrypt_partition.env" "${D}/usr/share/encrypt_partition/encrypt_partition.env"
Signature · 1 line
2.43.0
author
#10 lore raw

PATCH 10/10 initramfs-crypt-hook: invalidate PCR7 after unlocking partitions

In reply to Jan Kiszka

From: Jan Kiszka <[email protected]>

This avoids that the running Linux can still access the partition keys and possibly leak them. In the future, we may better address that by measure boot.

---
 .../initramfs-crypt-hook/files/local-top-complete              | 3 +++
 .../initramfs-crypt-hook/initramfs-crypt-hook_0.5.bb           | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)
recipes-initramfs/initramfs-crypt-hook/files/local-top-complete +3 -0
index 834dea22..4bcb4277 100644
@@ -258,6 +258,9 @@ for partition_set in $partition_sets; do
 	finalize_tpm2_encryption "$part_device"
 done
 
+# invalidate PCR7 to lock access to the disk keys
+tpm2_pcrextend 7:sha1=1111111111111111111111111111111111111111,sha256=1111111111111111111111111111111111111111111111111111111111111111
+
 if [ -n "$watchdog_pid" ]; then
 	kill "$watchdog_pid"
 fi
recipes-initramfs/initramfs-crypt-hook/initramfs-crypt-hook_0.5.bb +1 -1
index 71ee44db..2145a6e5 100644
@@ -42,7 +42,7 @@ HOOK_ADD_MODULES = " \
 HOOK_COPY_EXECS = " \
     openssl mke2fs grep awk expr seq sleep basename uuidparse mountpoint \
     e2fsck resize2fs cryptsetup \
-    tpm2_pcrread tpm2_testparms tpm2_flushcontext \
+    tpm2_pcrread tpm2_pcrextend tpm2_testparms tpm2_flushcontext \
     /usr/lib/*/libgcc_s.so.1"
 
 HOOK_COPY_EXECS:append:clevis = " \
Signature · 1 line
2.43.0
#11 lore raw

RE: [isar-cip-core][PATCH 10/10] initramfs-crypt-hook: invalidate PCR7 after unlocking partitions

Quoted 2 lines

This avoids that the running Linux can still access the partition keys and possibly leak them. In the future, we may better address that by measure boot.

Makes sense to lock the key once we leave initramfs

Quoted 13 lines
---
 .../initramfs-crypt-hook/files/local-top-complete              | 3 +++
 .../initramfs-crypt-hook/initramfs-crypt-hook_0.5.bb           | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)
recipes-initramfs/initramfs-crypt-hook/files/local-top-complete +0 -0
index 834dea22..4bcb4277 100644

recipes-initramfs/initramfs-crypt-hook/files/local-top-complete for partition_set in $partition_sets; do · line 264

Quoted 7 lines
recipes-initramfs/initramfs-crypt-hook/files/local-top-complete +4 -0
@@ -258,6 +258,9 @@ for partition_set in $partition_sets; do
 	finalize_tpm2_encryption "$part_device"
 done
 
+# invalidate PCR7 to lock access to the disk keys tpm2_pcrextend 
+7:sha1=1111111111111111111111111111111111111111,sha256=1111111111111111
+111111111111111111111111111111111111111111111111
+

From TCG Platform Firmware Profile Spec [1]:

"Integrity measurements of the pre-OS environment MUST NOT be extended to the PCRs allocated to the operating system. Any Host Platform configuration change that occurs after the Host Platform transfers control to an operating system, or while resuming from other power states, is the purview of the operating system and measurements of those events are extended to the PCRs allocated to the operating system. PCR[0-7] are exclusively for the use of platform firmware. Operating system and OS present software should never use those PCRs"

Since systemd uses PCR 11 to measure things done in initramfs, including events like enter-initrd and leave-initrd, I recommend binding to PCR 11 in addition to PCR 7 to lock.

Working on a patch...

BR Alexander

[1] https://trustedcomputinggroup.org/wp-content/uploads/TCG-PC-Client-Platform-Firmware-Profile-Version-1.06-Revision-52_pub-2.pdf
[2] https://github.com/systemd/systemd/blob/main/docs/TPM2_PCR_MEASUREMENTS.md

Quoted 18 lines
recipes-initramfs/initramfs-crypt-hook/files/local-top-complete +0 -0
 if [ -n "$watchdog_pid" ]; then
 	kill "$watchdog_pid"
 fi
recipes-initramfs/initramfs-crypt-hook/initramfs-crypt-hook_0.5.bb +1 -2
index 71ee44db..2145a6e5 100644
@@ -42,7 +42,7 @@ HOOK_ADD_MODULES = " \  HOOK_COPY_EXECS = " \
     openssl mke2fs grep awk expr seq sleep basename uuidparse mountpoint \
     e2fsck resize2fs cryptsetup \
-    tpm2_pcrread tpm2_testparms tpm2_flushcontext \
+    tpm2_pcrread tpm2_pcrextend tpm2_testparms tpm2_flushcontext \
     /usr/lib/*/libgcc_s.so.1"
 
 HOOK_COPY_EXECS:append:clevis = " \
--

2.43.0

author
#12 lore raw

Re: [isar-cip-core][PATCH 10/10] initramfs-crypt-hook: invalidate PCR7 after unlocking partitions

Quoted 35 lines · Alexander (FT RPD CED SES-AT)
Quoted 2 lines

This avoids that the running Linux can still access the partition keys and possibly leak them. In the future, we may better address that by measure boot.

Makes sense to lock the key once we leave initramfs

Quoted 13 lines
---
 .../initramfs-crypt-hook/files/local-top-complete              | 3 +++
 .../initramfs-crypt-hook/initramfs-crypt-hook_0.5.bb           | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)
recipes-initramfs/initramfs-crypt-hook/files/local-top-complete +0 -0
index 834dea22..4bcb4277 100644

recipes-initramfs/initramfs-crypt-hook/files/local-top-complete for partition_set in $partition_sets; do · line 264

Quoted 7 lines
recipes-initramfs/initramfs-crypt-hook/files/local-top-complete +4 -0
@@ -258,6 +258,9 @@ for partition_set in $partition_sets; do
 	finalize_tpm2_encryption "$part_device"
 done
 
+# invalidate PCR7 to lock access to the disk keys tpm2_pcrextend 
+7:sha1=1111111111111111111111111111111111111111,sha256=1111111111111111
+111111111111111111111111111111111111111111111111
+

From TCG Platform Firmware Profile Spec [1]:

"Integrity measurements of the pre-OS environment MUST NOT be extended to the PCRs allocated to the operating system. Any Host Platform configuration change that occurs after the Host Platform transfers control to an operating system, or while resuming from other power states, is the purview of the operating system and measurements of those events are extended to the PCRs allocated to the operating system. PCR[0-7] are exclusively for the use of platform firmware. Operating system and OS present software should never use those PCRs"

Quoted 5 lines

Since systemd uses PCR 11 to measure things done in initramfs, including events like enter-initrd and leave-initrd, I recommend binding to PCR 11 in addition to PCR 7 to lock.

Working on a patch...

Looking forward!

Thanks,
Jan

Quoted 23 lines

BR Alexander

[1] https://trustedcomputinggroup.org/wp-content/uploads/TCG-PC-Client-Platform-Firmware-Profile-Version-1.06-Revision-52_pub-2.pdf
[2] https://github.com/systemd/systemd/blob/main/docs/TPM2_PCR_MEASUREMENTS.md

Quoted 18 lines
recipes-initramfs/initramfs-crypt-hook/files/local-top-complete +0 -0
 if [ -n "$watchdog_pid" ]; then
 	kill "$watchdog_pid"
 fi
recipes-initramfs/initramfs-crypt-hook/initramfs-crypt-hook_0.5.bb +1 -2
index 71ee44db..2145a6e5 100644
@@ -42,7 +42,7 @@ HOOK_ADD_MODULES = " \  HOOK_COPY_EXECS = " \
     openssl mke2fs grep awk expr seq sleep basename uuidparse mountpoint \
     e2fsck resize2fs cryptsetup \
-    tpm2_pcrread tpm2_testparms tpm2_flushcontext \
+    tpm2_pcrread tpm2_pcrextend tpm2_testparms tpm2_flushcontext \
     /usr/lib/*/libgcc_s.so.1"
 
 HOOK_COPY_EXECS:append:clevis = " \
--

2.43.0

Signature · 2 lines
Siemens AG, Technology
Linux Expert Center
author
#13 lore raw

Re: [isar-cip-core][PATCH 10/10] initramfs-crypt-hook: invalidate PCR7 after unlocking partitions

Quoted 36 lines · Jan Kiszka
Quoted 35 lines · Alexander (FT RPD CED SES-AT)
Quoted 2 lines

This avoids that the running Linux can still access the partition keys and possibly leak them. In the future, we may better address that by measure boot.

Makes sense to lock the key once we leave initramfs

Quoted 13 lines
---
 .../initramfs-crypt-hook/files/local-top-complete              | 3 +++
 .../initramfs-crypt-hook/initramfs-crypt-hook_0.5.bb           | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)
recipes-initramfs/initramfs-crypt-hook/files/local-top-complete +0 -0
index 834dea22..4bcb4277 100644

recipes-initramfs/initramfs-crypt-hook/files/local-top-complete for partition_set in $partition_sets; do · line 264

Quoted 7 lines
recipes-initramfs/initramfs-crypt-hook/files/local-top-complete +4 -0
@@ -258,6 +258,9 @@ for partition_set in $partition_sets; do
 	finalize_tpm2_encryption "$part_device"
 done
 
+# invalidate PCR7 to lock access to the disk keys tpm2_pcrextend 
+7:sha1=1111111111111111111111111111111111111111,sha256=1111111111111111
+111111111111111111111111111111111111111111111111
+

From TCG Platform Firmware Profile Spec [1]:

"Integrity measurements of the pre-OS environment MUST NOT be extended to the PCRs allocated to the operating system. Any Host Platform configuration change that occurs after the Host Platform transfers control to an operating system, or while resuming from other power states, is the purview of the operating system and measurements of those events are extended to the PCRs allocated to the operating system. PCR[0-7] are exclusively for the use of platform firmware. Operating system and OS present software should never use those PCRs"

Quoted 8 lines
Quoted 5 lines

Since systemd uses PCR 11 to measure things done in initramfs, including events like enter-initrd and leave-initrd, I recommend binding to PCR 11 in addition to PCR 7 to lock.

Working on a patch...

Looking forward!

There is one catch, though: We will have to extend the key binding from PCR7 to 7+11. That will not work for existing deployments using only PCR7. We would have to make this configurable, I suppose.

Jan

Signature · 2 lines
Siemens AG, Technology
Linux Expert Center
author
#14 lore raw

Re: [isar-cip-core][PATCH 10/10] initramfs-crypt-hook: invalidate PCR7 after unlocking partitions

Quoted 43 lines · Jan Kiszka
Quoted 42 lines · Jan Kiszka
Quoted 40 lines · Alexander (FT RPD CED SES-AT)
Quoted 2 lines

This avoids that the running Linux can still access the partition keys and possibly leak them. In the future, we may better address that by measure boot.

Makes sense to lock the key once we leave initramfs

Quoted 13 lines
---
 .../initramfs-crypt-hook/files/local-top-complete              | 3 +++
 .../initramfs-crypt-hook/initramfs-crypt-hook_0.5.bb           | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)
recipes-initramfs/initramfs-crypt-hook/files/local-top-complete +0 -0
index 834dea22..4bcb4277 100644

recipes-initramfs/initramfs-crypt-hook/files/local-top-complete for partition_set in $partition_sets; do · line 264

Quoted 7 lines
recipes-initramfs/initramfs-crypt-hook/files/local-top-complete +4 -0
@@ -258,6 +258,9 @@ for partition_set in $partition_sets; do
 	finalize_tpm2_encryption "$part_device"
 done
 
+# invalidate PCR7 to lock access to the disk keys tpm2_pcrextend 
+7:sha1=1111111111111111111111111111111111111111,sha256=1111111111111111
+111111111111111111111111111111111111111111111111
+

From TCG Platform Firmware Profile Spec [1]:

"Integrity measurements of the pre-OS environment MUST NOT be extended to the PCRs allocated to the operating system. Any Host Platform configuration change that occurs after the Host Platform transfers control to an operating system, or while resuming from other power states, is the purview of the operating system and measurements of those events are extended to the PCRs allocated to the operating system. PCR[0-7] are exclusively for the use of platform firmware. Operating system and OS present software should never use those PCRs"

Since systemd uses PCR 11 to measure things done in initramfs, including events like enter-initrd and leave-initrd, I recommend binding to PCR 11 in addition to PCR 7 to lock.

Working on a patch...

Quoted 7 lines
Quoted 2 lines

Looking forward!

There is one catch, though: We will have to extend the key binding from PCR7 to 7+11. That will not work for existing deployments using only PCR7. We would have to make this configurable, I suppose.

This likely needs some more thoughts and possibly controls. I'm dropping this patch for now so that we are not rushing something into the upcoming release which will cause more headaches than benefits.

Jan

Signature · 2 lines
Siemens AG, Technology
Linux Expert Center
#15 lore raw

RE: [isar-cip-core][PATCH 10/10] initramfs-crypt-hook: invalidate PCR7 after unlocking partitions

Quoted 43 lines · Jan Kiszka
Quoted 42 lines · Jan Kiszka
Quoted 41 lines · Alexander (FT RPD CED SES-AT)
Quoted 40 lines
Quoted 2 lines

This avoids that the running Linux can still access the partition keys and possibly leak them. In the future, we may better address that by measure boot.

Makes sense to lock the key once we leave initramfs

Quoted 17 lines
---
 .../initramfs-crypt-hook/files/local-top-complete              | 3 +++
 .../initramfs-crypt-hook/initramfs-crypt-hook_0.5.bb           | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

a/recipes-initramfs/initramfs-crypt-hook/files/local-top-complete b/recipes-initramfs/initramfs-crypt-hook/files/local-top-complete index 834dea22..4bcb4277 100644
---
a/recipes-initramfs/initramfs-crypt-hook/files/local-top-complete +++ b/recipes-initramfs/initramfs-crypt-hook/files/local-top-comple +++ te

recipes-initramfs/initramfs-crypt-hook/files/local-top-complete for partition_set in $partition_sets; do · line 265

Quoted 8 lines
recipes-initramfs/initramfs-crypt-hook/files/local-top-complete +5 -0
@@ -258,6 +258,9 @@ for partition_set in $partition_sets; do
 	finalize_tpm2_encryption "$part_device"
 done
 
+# invalidate PCR7 to lock access to the disk keys tpm2_pcrextend
+7:sha1=1111111111111111111111111111111111111111,sha256=11111111111
+11111
+111111111111111111111111111111111111111111111111
+

From TCG Platform Firmware Profile Spec [1]:

"Integrity measurements of the pre-OS environment MUST NOT be
extended to the PCRs allocated to the operating system. Any Host
Platform configuration change that occurs after the Host Platform
transfers control to an operating system, or while resuming from other power states, is the purview of the operating system and measurements of those events are extended to the PCRs allocated to the operating system. PCR[0-7] are exclusively for the use of platform firmware. Operating
system and OS present software should never use those PCRs"

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines

Since systemd uses PCR 11 to measure things done in initramfs,
including events like enter-initrd and leave-initrd, I recommend binding to PCR 11 in addition to PCR 7 to lock.

Working on a patch...

Looking forward!

The patch is actually done and works for bookworm, still testing the clevis part for bullseye and buster!

Quoted 6 lines
Quoted 6 lines
Quoted 1 line

There is one catch, though: We will have to extend the key binding from
PCR7 to 7+11. That will not work for existing deployments using only PCR7. We would have to make this configurable, I suppose.

For existing deployments this addition won't apply. But at least we don't break them!
So new deployments will benefit from that change, while old ones remain intact as they are now.

Quoted 3 lines
Quoted 1 line

This likely needs some more thoughts and possibly controls. I'm dropping this patch for now so that we are not rushing something into the upcoming release which will cause more headaches than benefits.

The whole tpm handling needs to be extended to support desired changes of pcr measures like updating the secure boot keys, but also for scenarios where people want to bind to multiple measures e.g. specific ukis.

That way, the addition is still an improvement, although use cases like the one above and limitations of systemd-cryptenroll/systemd-cryptsetup (also incl. current versions) have to be considered!

Quoted 7 lines

Jan

--
Siemens AG, Technology
Linux Expert Center

BR Alexander