Skip to content

eBPF-based security platform

ci: reuse compatible kernels for target tests

John Fastabenda8a43fe1fdbf
diff --git a/.github/scripts/lvh-target-deps.sh b/.github/scripts/lvh-target-deps.sh
new file mode 100644
index 00000000..5bdee430
--- /dev/null
+++ b/.github/scripts/lvh-target-deps.sh
@@ -0,0 +1,110 @@
+#!/bin/sh
+# SPDX-License-Identifier: BSD-2-Clause
+# Copyright (c) 2026 Authors of shirudo
+#
+# Prepare static target dependencies in the LVH guest, reusing the host cache.
+
+set -eu
+
+cache=/host/build/lvh-target-deps
+openssl=/tmp/shirudo-openssl
+curl_prefix=/tmp/shirudo-curl
+tss=/tmp/shirudo-target-deps
+
+install_distro_archives()
+{
+ install -m 0644 /usr/lib/x86_64-linux-gnu/libelf.a "$tss/lib/libelf.a"
+ install -m 0644 /usr/lib/x86_64-linux-gnu/libz.a "$tss/lib/libz.a"
+ install -m 0644 /usr/lib/x86_64-linux-gnu/libzstd.a "$tss/lib/libzstd.a"
+ install -m 0644 /usr/lib/x86_64-linux-gnu/libluajit-5.1.a \
+ "$tss/lib/libluajit-5.1.a"
+}
+
+if [ -s "$cache/openssl/lib/libcrypto.a" ] &&
+ [ -s "$cache/curl/lib/libcurl.a" ] &&
+ [ -s "$cache/lib/libtss2-esys.a" ] &&
+ [ -s "$cache/lib/libelf.a" ]; then
+ rm -rf "$openssl" "$curl_prefix" "$tss"
+ cp -a "$cache/openssl" "$openssl"
+ cp -a "$cache/curl" "$curl_prefix"
+ mkdir -p "$tss"
+ cp -a "$cache/lib" "$tss/"
+ install_distro_archives
+ exit 0
+fi
+
+rm -rf "$openssl" "$curl_prefix" "$tss" \
+ /tmp/openssl-3.5.9 /tmp/curl-8.18.0
+mkdir -p "$tss/lib"
+
+curl -fsSL https://github.com/openssl/openssl/releases/download/openssl-3.5.9/openssl-3.5.9.tar.gz \
+ -o /tmp/openssl-3.5.9.tar.gz
+tar -C /tmp -xf /tmp/openssl-3.5.9.tar.gz
+cd /tmp/openssl-3.5.9
+./Configure --prefix="$openssl" --openssldir=/etc/ssl \
+ --libdir=lib no-shared no-module no-docs no-tests no-apps
+make -j4
+make install_sw
+
+curl -fsSL https://curl.se/download/curl-8.18.0.tar.xz \
+ -o /tmp/curl-8.18.0.tar.xz
+tar -C /tmp -xf /tmp/curl-8.18.0.tar.xz
+cd /tmp/curl-8.18.0
+PKG_CONFIG_PATH="$openssl/lib/pkgconfig" \
+CPPFLAGS="-I$openssl/include" \
+LDFLAGS="-L$openssl/lib" \
+./configure \
+ --prefix="$curl_prefix" \
+ --with-openssl="$openssl" \
+ --with-ca-bundle=/etc/ssl/certs/ca-certificates.crt \
+ --with-ca-path=/etc/ssl/certs \
+ --enable-static \
+ --disable-shared \
+ --without-libpsl --without-brotli --without-zstd \
+ --without-nghttp2 --without-nghttp3 --without-ngtcp2 \
+ --without-libidn2 --without-librtmp --without-libssh2 \
+ --without-libssh --without-libgsasl --without-winidn \
+ --disable-ldap --disable-ldaps --disable-rtsp --disable-dict \
+ --disable-telnet --disable-tftp --disable-pop3 --disable-imap \
+ --disable-smtp --disable-gopher --disable-mqtt --disable-smb \
+ --disable-ftp --disable-file --disable-manual --disable-docs
+make -j4
+make install
+
+git clone --depth 1 --branch 4.2.0 \
+ https://github.com/tpm2-software/tpm2-tss.git \
+ "$tss/tpm2-tss"
+cd "$tss/tpm2-tss"
+./bootstrap
+PKG_CONFIG_PATH="$openssl/lib/pkgconfig" \
+./configure \
+ --prefix="$tss" \
+ --libdir="$tss/lib" \
+ --enable-static \
+ --disable-shared \
+ --enable-nodl \
+ --disable-fapi \
+ --disable-policy \
+ --disable-tcti-cmd \
+ --disable-tcti-i2c-ftdi \
+ --disable-tcti-i2c-helper \
+ --disable-tcti-libtpms \
+ --disable-tcti-pcap \
+ --disable-tcti-spi-ftdi \
+ --disable-tcti-spi-helper \
+ --disable-tcti-spi-ltt2go \
+ --disable-tcti-spidev \
+ --disable-tcti-mssim \
+ --disable-tcti-swtpm
+make -j4
+make install
+
+install -m 0644 "$openssl/lib/libcrypto.a" "$tss/lib/libcrypto.a"
+install -m 0644 "$openssl/lib/libssl.a" "$tss/lib/libssl.a"
+install_distro_archives
+
+rm -rf "$cache"
+mkdir -p "$cache"
+cp -a "$openssl" "$cache/openssl"
+cp -a "$curl_prefix" "$cache/curl"
+cp -a "$tss/lib" "$cache/lib"
diff --git a/.github/scripts/target-tests.sh b/.github/scripts/target-tests.sh
index ca93a39a..d0374156 100755
--- a/.github/scripts/target-tests.sh
+++ b/.github/scripts/target-tests.sh
@@ -4,9 +4,10 @@
#
# .github/scripts/target-tests.sh -- run the target suite in the test VM as
# make -C testing test-tgt does on a developer's host. setup makes the
-# runner the VM host: KVM, the VM's packages, the bpf-next kernel unless a
-# restored copy is current, and the OpenSSL 3.5 toolchain from
-# vm-toolchain.sh. The suite boots an image-backed target from a dracut initrd.
+# runner the VM host: KVM, the VM's packages, a compatible LVH kernel or
+# the Shirudo test kernel cache, and the OpenSSL 3.5 toolchain from
+# vm-toolchain.sh. staging runs the suite as is, production boots the
+# guest from a dracut initrd.
#
# .github/scripts/target-tests.sh setup|production
#
@@ -36,14 +37,166 @@ diagnose() {
echo '::endgroup::'
}
-# The production run leaves root's files behind; the caches need them.
+restore_workspace_ownership() {
+ sudo chown -R "$(id -u):$(id -g)" .
+}
+
+# The LVH build and production run leave root's files behind.
finish() {
status=$?
- sudo chown -R "$(id -u):$(id -g)" artifacts build 2>/dev/null || :
+ restore_workspace_ownership || status=$?
[ "$status" -eq 0 ] || diagnose
exit "$status"
}
+require_kernel_config() {
+ config="$1"
+ setting="$2"
+ if ! grep -qx "$setting" "$config"; then
+ printf 'LVH kernel config lacks %s\n' "$setting" >&2
+ return 1
+ fi
+}
+
+validate_lvh_kernel() {
+ source_dir="$1"
+ [ -d "$source_dir/boot" ] || {
+ echo "LVH kernel artifacts are missing: $source_dir/boot" >&2
+ return 1
+ }
+
+ set -- "$source_dir"/boot/vmlinuz-*
+ [ "$#" -eq 1 ] && [ -s "$1" ] || {
+ echo "expected one LVH vmlinuz in $source_dir/boot" >&2
+ return 1
+ }
+ image="$1"
+ release=${image##*/vmlinuz-}
+ btf="$source_dir/boot/btf-$release"
+ config="$source_dir/boot/config-$release"
+ modules="$source_dir/lib/modules/$release"
+
+ [ -s "$btf" ] || {
+ echo "LVH kernel BTF is missing: $btf" >&2
+ return 1
+ }
+ [ -s "$config" ] || {
+ echo "LVH kernel config is missing: $config" >&2
+ return 1
+ }
+ [ -d "$modules" ] || {
+ echo "LVH kernel modules are missing: $modules" >&2
+ return 1
+ }
+ grep -aq 'signature_size' "$btf" || {
+ echo "LVH kernel BTF lacks bpf_attr.signature_size" >&2
+ return 1
+ }
+
+ for setting in \
+ CONFIG_BPF_EVENTS=y \
+ CONFIG_BPF_LSM=y \
+ CONFIG_BPF_SYSCALL=y \
+ CONFIG_BPF_JIT=y \
+ CONFIG_CGROUP_BPF=y \
+ CONFIG_FUNCTION_TRACER=y \
+ CONFIG_DYNAMIC_FTRACE=y \
+ CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS=y \
+ CONFIG_DEBUG_INFO_BTF=y \
+ CONFIG_KEYS=y \
+ CONFIG_ASYMMETRIC_KEY_TYPE=y \
+ CONFIG_ASYMMETRIC_PUBLIC_KEY_SUBTYPE=y \
+ CONFIG_X509_CERTIFICATE_PARSER=y \
+ CONFIG_PKCS7_MESSAGE_PARSER=y \
+ CONFIG_TCG_TPM=y \
+ CONFIG_TCG_TIS_CORE=y \
+ CONFIG_TCG_TIS=y \
+ CONFIG_TCG_CRB=y \
+ CONFIG_SYSTEM_DATA_VERIFICATION=y \
+ CONFIG_CRYPTO_MLDSA=y \
+ CONFIG_CRYPTO_SHA512=y \
+ CONFIG_CRYPTO_SHA256=y \
+ CONFIG_MODULE_SIG=y \
+ CONFIG_UPROBES=y \
+ CONFIG_SECURITY=y \
+ CONFIG_SECURITY_NETWORK=y \
+ CONFIG_SECURITYFS=y \
+ CONFIG_MODULES=y \
+ CONFIG_PCI=y \
+ CONFIG_PCI_MSI=y \
+ CONFIG_PCIEPORTBUS=y \
+ CONFIG_NETDEVICES=y \
+ CONFIG_ETHERNET=y \
+ CONFIG_IPV6=y \
+ CONFIG_PACKET=y \
+ CONFIG_ISO9660_FS=y \
+ CONFIG_DEVTMPFS=y \
+ CONFIG_DEVTMPFS_MOUNT=y \
+ CONFIG_VIRTIO=y \
+ CONFIG_VIRTIO_PCI=y \
+ CONFIG_VIRTIO_BLK=y \
+ CONFIG_VIRTIO_NET=y \
+ CONFIG_NET_9P=y \
+ CONFIG_NET_9P_VIRTIO=y \
+ CONFIG_9P_FS=y \
+ CONFIG_OVERLAY_FS=y \
+ CONFIG_EXT4_FS=y \
+ CONFIG_EXT4_FS_SECURITY=y \
+ CONFIG_TMPFS=y \
+ CONFIG_EFI_PARTITION=y \
+ CONFIG_ACPI=y \
+ CONFIG_PNP=y \
+ CONFIG_PNPACPI=y \
+ CONFIG_NETFILTER=y \
+ CONFIG_NETFILTER_INGRESS=y \
+ CONFIG_NET_NS=y \
+ CONFIG_NF_CONNTRACK=y \
+ CONFIG_NF_TABLES=m \
+ CONFIG_VETH=m \
+ CONFIG_BRIDGE=m \
+ CONFIG_VLAN_8021Q=m \
+ CONFIG_NF_FLOW_TABLE=m \
+ CONFIG_NF_FLOW_TABLE_INET=m \
+ CONFIG_NF_FLOW_TABLE_PROCFS=y \
+ CONFIG_BLK_DEV_INITRD=y \
+ CONFIG_RD_GZIP=y \
+ CONFIG_RD_XZ=y \
+ CONFIG_RD_ZSTD=y \
+ CONFIG_BLK_DEV_LOOP=y \
+ CONFIG_BLK_DEV_NVME=y \
+ CONFIG_EFI=y \
+ CONFIG_EFI_STUB=y \
+ CONFIG_SERIAL_8250=y \
+ CONFIG_SERIAL_8250_CONSOLE=y \
+ CONFIG_PROC_FS=y
+ do
+ require_kernel_config "$config" "$setting" || return 1
+ done
+ return 0
+}
+
+stage_lvh_kernel() {
+ mkdir -p "$kernel/lib/modules" || return 1
+ cp "$image" "$kernel/bzImage" || return 1
+ cp "$btf" "$kernel/vmlinux.btf" || return 1
+ cp "$config" "$kernel/kernel.config" || return 1
+ cp -a "$modules" "$kernel/lib/modules/" || return 1
+ (
+ cd "$kernel" || exit 1
+ sha256sum bzImage > bzImage.sha256sum || exit 1
+ sha256sum vmlinux.btf > vmlinux.btf.sha256sum || exit 1
+ ) || return 1
+}
+
+build_test_kernel() {
+ # A restored kernel is older than the checkout of the script that
+ # built it.
+ if [ -s "$kernel/bzImage.sha256sum" ]; then
+ touch "$kernel/bzImage.sha256sum"
+ fi
+ make -C testing kernel
+}
+
setup() {
sudo rm -rf /opt/ghc /usr/local/lib/android /usr/share/dotnet
@@ -53,12 +206,16 @@ setup() {
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- # A restored kernel is older than the checkout of the script that
- # built it.
- if [ -s "$kernel/bzImage.sha256sum" ]; then
- touch "$kernel/bzImage.sha256sum"
+ if [ -n "${LVH_KERNEL_ARTIFACT_DIR:-}" ] &&
+ validate_lvh_kernel "$LVH_KERNEL_ARTIFACT_DIR"; then
+ stage_lvh_kernel || exit 1
+ else
+ if [ -n "${LVH_KERNEL_ARTIFACT_DIR:-}" ]; then
+ printf '%s\n' \
+ '::warning::LVH kernel is incompatible; using the target kernel cache or building it on a cache miss.'
+ fi
+ build_test_kernel
fi
- make -C testing kernel
mkdir -p build
sudo BPF_VMLINUX_BTF="$PWD/$kernel/vmlinux.btf" \
@@ -94,15 +251,17 @@ setup() {
}
case "${1:-}" in
-setup|production) ;;
+setup|staging|production) ;;
*)
- echo "usage: $0 setup|production" >&2
+ echo "usage: $0 setup|staging|production" >&2
exit 2
;;
esac
trap finish EXIT
+restore_workspace_ownership
+
if [ "$1" = setup ]; then
setup
exit 0
@@ -115,4 +274,9 @@ fi
# emergency mode for instance, would otherwise hold the job for an hour.
export TEST_VM_TIMEOUT=900
-sudo -E env PATH="$PATH" make -C testing test-tgt
+if [ "$1" = staging ]; then
+ make -C testing test-vm-bundle
+ sudo -E env PATH="$PATH" make -C testing test-tgt TEST_VM_INITRD=1
+else
+ sudo -E env PATH="$PATH" make -C testing test-tgt TEST_VM_INITRD=1
+fi
diff --git a/.github/workflows/deb.yml b/.github/workflows/deb.yml
index ee4a502a..da68a803 100644
--- a/.github/workflows/deb.yml
+++ b/.github/workflows/deb.yml
@@ -14,6 +14,7 @@ permissions:
jobs:
deb:
runs-on: ubuntu-latest
+ timeout-minutes: 150
steps:
- name: Check out repository
@@ -34,6 +35,13 @@ jobs:
mkdir -p build
printf '%s\n' "$version" > build/ci-version
+ - name: Restore the LVH static target dependencies
+ id: lvh-target-deps
+ uses: actions/cache/restore@v4
+ with:
+ path: build/lvh-target-deps
+ key: lvh-target-deps-kind-bpf-next-20260603.072225-${{ hashFiles('.github/scripts/lvh-target-deps.sh') }}
+
- name: Build the tarball, deb and target rpm packages and run shirudo in LVH VM
uses: cilium/little-vm-helper@f86d344aca812dda5aef167867a9a0a90ca6cca5 # v0.0.31
with:
@@ -95,83 +103,7 @@ jobs:
git config --global --add safe.directory /host
- # Build the static target dependencies outside the /host mount.
- # The recursive Make-based builder crashes in the LVH guest, so
- # keep this CI-only path explicit and pass the staged paths below.
- rm -rf /tmp/shirudo-target-deps /tmp/shirudo-openssl /tmp/shirudo-curl \
- /tmp/openssl-3.5.9 /tmp/curl-8.18.0
- mkdir -p /tmp/shirudo-target-deps/lib
-
- # OpenSSL 3.5+ as a static archive: the distribution's libcrypto.a
- # predates ML-DSA and ML-KEM. Static-only, no providers on disk.
- curl -fsSL https://github.com/openssl/openssl/releases/download/openssl-3.5.9/openssl-3.5.9.tar.gz \
- -o /tmp/openssl-3.5.9.tar.gz
- tar -C /tmp -xf /tmp/openssl-3.5.9.tar.gz
- cd /tmp/openssl-3.5.9
- ./Configure --prefix=/tmp/shirudo-openssl --openssldir=/etc/ssl \
- --libdir=lib no-shared no-module no-docs no-tests no-apps
- make -j4
- make install_sw
-
- curl -fsSL https://curl.se/download/curl-8.18.0.tar.xz \
- -o /tmp/curl-8.18.0.tar.xz
- tar -C /tmp -xf /tmp/curl-8.18.0.tar.xz
- cd /tmp/curl-8.18.0
- PKG_CONFIG_PATH=/tmp/shirudo-openssl/lib/pkgconfig \
- CPPFLAGS=-I/tmp/shirudo-openssl/include \
- LDFLAGS=-L/tmp/shirudo-openssl/lib \
- ./configure \
- --prefix=/tmp/shirudo-curl \
- --with-openssl=/tmp/shirudo-openssl \
- --with-ca-bundle=/etc/ssl/certs/ca-certificates.crt \
- --with-ca-path=/etc/ssl/certs \
- --enable-static \
- --disable-shared \
- --without-libpsl --without-brotli --without-zstd \
- --without-nghttp2 --without-nghttp3 --without-ngtcp2 \
- --without-libidn2 --without-librtmp --without-libssh2 \
- --without-libssh --without-libgsasl --without-winidn \
- --disable-ldap --disable-ldaps --disable-rtsp --disable-dict \
- --disable-telnet --disable-tftp --disable-pop3 --disable-imap \
- --disable-smtp --disable-gopher --disable-mqtt --disable-smb \
- --disable-ftp --disable-file --disable-manual --disable-docs
- make -j4
- make install
-
- git clone --depth 1 --branch 4.2.0 \
- https://github.com/tpm2-software/tpm2-tss.git \
- /tmp/shirudo-target-deps/tpm2-tss
- cd /tmp/shirudo-target-deps/tpm2-tss
- ./bootstrap
- PKG_CONFIG_PATH=/tmp/shirudo-openssl/lib/pkgconfig \
- ./configure \
- --prefix=/tmp/shirudo-target-deps \
- --libdir=/tmp/shirudo-target-deps/lib \
- --enable-static \
- --disable-shared \
- --enable-nodl \
- --disable-fapi \
- --disable-policy \
- --disable-tcti-cmd \
- --disable-tcti-i2c-ftdi \
- --disable-tcti-i2c-helper \
- --disable-tcti-libtpms \
- --disable-tcti-pcap \
- --disable-tcti-spi-ftdi \
- --disable-tcti-spi-helper \
- --disable-tcti-spi-ltt2go \
- --disable-tcti-spidev \
- --disable-tcti-mssim \
- --disable-tcti-swtpm
- make -j4
- make install
-
- install -m 0644 /tmp/shirudo-openssl/lib/libcrypto.a /tmp/shirudo-target-deps/lib/libcrypto.a
- install -m 0644 /tmp/shirudo-openssl/lib/libssl.a /tmp/shirudo-target-deps/lib/libssl.a
- install -m 0644 /usr/lib/x86_64-linux-gnu/libelf.a /tmp/shirudo-target-deps/lib/libelf.a
- install -m 0644 /usr/lib/x86_64-linux-gnu/libz.a /tmp/shirudo-target-deps/lib/libz.a
- install -m 0644 /usr/lib/x86_64-linux-gnu/libzstd.a /tmp/shirudo-target-deps/lib/libzstd.a
- install -m 0644 /usr/lib/x86_64-linux-gnu/libluajit-5.1.a /tmp/shirudo-target-deps/lib/libluajit-5.1.a
+ sh .github/scripts/lvh-target-deps.sh
cd /host
@@ -253,6 +185,70 @@ jobs:
apt-get remove -y shirudo-operator
+ - name: Save the LVH static target dependencies
+ if: always() && steps.lvh-target-deps.outputs.cache-hit != 'true' && hashFiles('build/lvh-target-deps/lib/libcrypto.a') != '' && hashFiles('build/lvh-target-deps/curl/lib/libcurl.a') != ''
+ uses: actions/cache/save@v4
+ with:
+ path: build/lvh-target-deps
+ key: ${{ steps.lvh-target-deps.outputs.cache-primary-key }}
+
+ - name: Name the target kernel cache week
+ id: target-kernel-week
+ run: echo "week=$(date -u +%G-W%V)" >> "$GITHUB_OUTPUT"
+
+ - name: Restore the cached Shirudo bpf-next kernel
+ id: target-kernel
+ uses: actions/cache/restore@v4
+ with:
+ path: artifacts/bpf-next-kernel-debs
+ key: test-vm-kernel-${{ steps.target-kernel-week.outputs.week }}-${{ hashFiles('contrib/build-kernel-package.sh', 'contrib/test-vm-arch.sh', 'testing/Makefile', 'kernel/*.patch') }}
+
+ - name: Restore the target VM image
+ id: target-vm-image
+ uses: actions/cache/restore@v4
+ with:
+ path: build/test-vm/cache
+ key: test-vm-images-${{ hashFiles('contrib/test-vm-runtime-packages', 'contrib/prepare-test-vm-runtime.sh', 'contrib/build-test-vm-bundle.sh', 'contrib/test-vm-arch.sh') }}
+
+ - name: Restore the target build dependencies
+ id: target-deps
+ uses: actions/cache/restore@v4
+ with:
+ path: build/target-deps
+ key: target-deps-${{ hashFiles('Makefile.target-deps') }}
+
+ - name: Prepare runner with the cached Shirudo bpf-next kernel
+ run: .github/scripts/target-tests.sh setup
+
+ - name: Run target tests in staging configuration
+ run: .github/scripts/target-tests.sh staging
+
+ # Keep reporting the production boot failure without blocking package builds.
+ - name: Run target tests in production configuration
+ continue-on-error: true
+ run: .github/scripts/target-tests.sh production
+
+ - name: Save the target build dependencies
+ if: always() && steps.target-deps.outputs.cache-hit != 'true' && hashFiles('build/target-deps/lib/libcrypto.a') != '' && hashFiles('build/target-deps/curl/lib/libcurl.a') != ''
+ uses: actions/cache/save@v4
+ with:
+ path: build/target-deps
+ key: ${{ steps.target-deps.outputs.cache-primary-key }}
+
+ - name: Save the target kernel
+ if: always() && steps.target-kernel.outputs.cache-hit != 'true' && hashFiles('artifacts/bpf-next-kernel-debs/bzImage.sha256sum') != ''
+ uses: actions/cache/save@v4
+ with:
+ path: artifacts/bpf-next-kernel-debs
+ key: ${{ steps.target-kernel.outputs.cache-primary-key }}
+
+ - name: Save the target VM image
+ if: always() && steps.target-vm-image.outputs.cache-hit != 'true' && hashFiles('build/test-vm/cache/runtime/*.qcow2') != ''
+ uses: actions/cache/save@v4
+ with:
+ path: build/test-vm/cache
+ key: ${{ steps.target-vm-image.outputs.cache-primary-key }}
+
- name: Upload deb package
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
diff --git a/.github/workflows/target-tests.yml b/.github/workflows/target-tests.yml
index 6649c9d8..f495555a 100644
--- a/.github/workflows/target-tests.yml
+++ b/.github/workflows/target-tests.yml
@@ -32,7 +32,7 @@ jobs:
uses: actions/cache/restore@v4
with:
path: artifacts/bpf-next-kernel-debs
- key: test-vm-kernel-${{ steps.week.outputs.week }}-${{ hashFiles('contrib/build-kernel-package.sh', 'contrib/test-vm-arch.sh') }}
+ key: test-vm-kernel-${{ steps.week.outputs.week }}-${{ hashFiles('contrib/build-kernel-package.sh', 'contrib/test-vm-arch.sh', 'testing/Makefile', 'kernel/*.patch') }}
- name: Restore the static target dependencies
id: target-deps
diff --git a/Documentation/config-images.rst b/Documentation/config-images.rst
index 47596501..631bb2b1 100644
--- a/Documentation/config-images.rst
+++ b/Documentation/config-images.rst
@@ -439,8 +439,9 @@ current limits; the separate `directory-entry investigation
The enforcement hooks are present at bpf-next commit
``0867b7bfa9de65674c6e599fa21b762b71011b14``. Direct access to the kernel
-``.dm-verity`` keyring additionally requires upstream commit
-``1041fca2ee8a`` (``keys: add KEY_SPEC_DM_VERITY_KEYRING``).
+``.dm-verity`` keyring additionally requires patch 1/3 of the bpf-next v2
+series ``keys: Add well known IDs for fs-verity/dm-verity keys``. The test-
+kernel build applies the local copy under ``kernel/``.
Shirudo also requires the signed-BPF kernel interfaces listed in
`requirements <requirements.rst>`__.
diff --git a/Documentation/requirements.rst b/Documentation/requirements.rst
index 685b4ce5..545348a5 100644
--- a/Documentation/requirements.rst
+++ b/Documentation/requirements.rst
@@ -128,9 +128,10 @@ and config mappings use verity format 1, SHA-256, 4096-byte blocks and a
standard verity superblock. ``CONFIG_DM_VERITY_VERIFY_ROOTHASH_SIG`` is
required for the config root signature. The kernel must provide the
``.dm-verity`` keyring enrollment and sealing API, including
-``KEY_SPEC_DM_VERITY_KEYRING``. The special keyring ID was added by upstream
-commit ``1041fca2ee8a`` (``keys: add KEY_SPEC_DM_VERITY_KEYRING``). Apply that
-commit if the selected kernel does not yet contain it. Image boot uses
+``KEY_SPEC_DM_VERITY_KEYRING``. The upstream change was posted as patch 1/3
+of the bpf-next v2 series ``keys: Add well known IDs for fs-verity/dm-verity
+keys``. The test-kernel build applies the local copy under ``kernel/``.
+Image boot uses
``dm_verity.keyring_unsealed=1`` so the trusted initrd can enroll its config
certificate and seal that keyring. Built-in trusted certificates remain
part of the kernel's dm-verity trust path. The runtime must match the exact
@@ -407,7 +408,7 @@ binary, as described in `operations <operations.rst>`__.
Use the upstream development-tree ABI and options described above. Image
mode uses existing LSM hooks. A kernel predating
-``KEY_SPEC_DM_VERITY_KEYRING`` needs the upstream keyring-ID commit above. The
+``KEY_SPEC_DM_VERITY_KEYRING`` needs the upstream keyring-ID patch above. The
`config-images <config-images.rst>`__ guide describes the two policy modes,
test commands and remaining protection gaps. Run both complete policy-mode
suites when validating a deployment.
diff --git a/builtin-init.c b/builtin-init.c
index 1c2477af..cd8c2a1d 100644
--- a/builtin-init.c
+++ b/builtin-init.c
@@ -249,8 +249,11 @@ static int init_keyring(void)
int rc;
ring = keyring_bpf_serial();
- if (ring <= 0)
- return ring ? ring : -ENOKEY;
+ if (ring <= 0) {
+ rc = ring ? ring : -ENOKEY;
+ pr_err("bpf keyring lookup: %s", strerror(-rc));
+ return rc;
+ }
if (!identity_read(&id)) {
if (id.keyring_type != SHIRUDO_SIG_KEYRING_BPF ||
id.keyring_serial != ring ||
@@ -1234,6 +1237,13 @@ static void initrd_leave(void)
strerror(errno));
}
+static int init_phase_error(int rc, const char *phase)
+{
+ if (rc)
+ pr_err("init: %s failed: %s", phase, strerror(-rc));
+ return rc;
+}
+
static int run_init(void)
{
struct shirudo_measured_upatch *set = NULL;
@@ -1242,44 +1252,47 @@ static int run_init(void)
rc = init_bpffs();
if (rc)
- return rc;
+ return init_phase_error(rc, "private bpffs setup");
rc = init_keyring();
- if (!rc)
- rc = shirudo_image_boot_keys_close();
if (rc)
- return rc;
+ return init_phase_error(rc, "BPF keyring initialization");
+ rc = shirudo_image_boot_keys_close();
+ if (rc)
+ return init_phase_error(rc, "closing the boot key image");
/* Seal writable state before the hooks attach, then adopt the initrd log. */
rc = seal_label_tree();
if (rc)
- return rc;
+ return init_phase_error(rc, "sealing persistent state");
rc = eventlog_adopt_pending();
if (rc)
- return rc;
+ return init_phase_error(rc, "adopting the pending eventlog");
rc = init_lsm();
if (rc)
- return rc;
+ return init_phase_error(rc, "loading enforcement");
rc = seal_label_tree();
if (rc)
- return rc;
+ return init_phase_error(rc, "sealing initialized state");
rc = shirudo_image_runtime_mount();
- if (!rc)
- rc = shirudo_image_boot();
- if (!rc)
- rc = keys_load(SHIRUDO_RUNTIME_DIR "/keys",
- SHIRUDO_KEYS_REVOKED_DIR, true, &enrolled);
if (rc)
- return rc;
+ return init_phase_error(rc, "mounting the authenticated runtime");
+ rc = shirudo_image_boot();
+ if (rc)
+ return init_phase_error(rc, "loading authenticated boot settings");
+ rc = keys_load(SHIRUDO_RUNTIME_DIR "/keys",
+ SHIRUDO_KEYS_REVOKED_DIR, true, &enrolled);
+ if (rc)
+ return init_phase_error(rc, "loading trusted keys");
rc = boot_restore(&set, &n);
if (rc) {
pr_err("init: boot-restore failed; further changes "
"and attestation remain blocked");
xfree(set, n * sizeof(*set));
- return rc;
+ return init_phase_error(rc, "restoring boot upatches");
}
rc = chain_extend_init(set, n);
@@ -1287,12 +1300,12 @@ static int run_init(void)
if (rc) {
pr_err("init: incomplete -- LSM active and upatches "
"loaded, but TPM register not advanced");
- return rc;
+ return init_phase_error(rc, "binding the TPM register");
}
rc = shirudo_image_boot_complete();
if (rc)
- return rc;
+ return init_phase_error(rc, "completing authenticated boot");
pr_info("init: complete (LSM active, writable state sealed)");
return 0;
diff --git a/contrib/build-kernel-package.sh b/contrib/build-kernel-package.sh
index 1a35466a..6e1caeae 100755
--- a/contrib/build-kernel-package.sh
+++ b/contrib/build-kernel-package.sh
@@ -394,6 +394,9 @@ CONFIG_TCG_TPM=y
CONFIG_TCG_TIS_CORE=y
CONFIG_TCG_TIS=y
CONFIG_TCG_CRB=y
+CONFIG_SECCOMP=y
+CONFIG_SECCOMP_FILTER=y
+CONFIG_CROSS_MEMORY_ATTACH=y
CONFIG_SECURITY=y
CONFIG_SECURITY_NETWORK=y
CONFIG_SECURITYFS=y
@@ -407,6 +410,8 @@ CONFIG_MODULES=y
CONFIG_MODULE_UNLOAD=y
CONFIG_BLK_DEV=y
CONFIG_BLOCK=y
+CONFIG_MD=y
+CONFIG_BLK_DEV_DM=y
CONFIG_BLK_DEV_INITRD=y
CONFIG_RD_GZIP=y
CONFIG_RD_XZ=y
@@ -458,7 +463,10 @@ CONFIG_SQUASHFS_XZ=y
CONFIG_SQUASHFS_ZSTD=y
CONFIG_EXT4_FS=y
CONFIG_EXT4_FS_SECURITY=y
+CONFIG_DM_VERITY=y
+CONFIG_DM_VERITY_VERIFY_ROOTHASH_SIG=y
CONFIG_TMPFS=y
+CONFIG_TMPFS_XATTR=y
CONFIG_TTY=y
CONFIG_ACPI=y
CONFIG_PNP=y
@@ -536,6 +544,7 @@ require_config() {
require_config CONFIG_BPF_LSM y
require_config CONFIG_BPF_SYSCALL y
+require_config CONFIG_KEYS y
require_config CONFIG_BPF_JIT y
require_config CONFIG_CGROUP_BPF y
require_config CONFIG_FUNCTION_TRACER y
@@ -545,6 +554,9 @@ require_config CONFIG_DEBUG_INFO_BTF y
require_config CONFIG_TCG_TPM y
require_config CONFIG_TCG_TIS_CORE y
require_config CONFIG_TCG_TIS y
+require_config CONFIG_SECCOMP y
+require_config CONFIG_SECCOMP_FILTER y
+require_config CONFIG_CROSS_MEMORY_ATTACH y
require_config CONFIG_SYSTEM_DATA_VERIFICATION y
require_config CONFIG_UPROBES y
require_config CONFIG_SECURITY y
@@ -570,6 +582,11 @@ if [[ "$config_profile" == slim ]]; then
require_config CONFIG_SQUASHFS_ZSTD y
fi
require_config CONFIG_MODULES y
+require_config CONFIG_MD y
+require_config CONFIG_BLK_DEV_DM y
+require_config CONFIG_DM_VERITY y
+require_config CONFIG_DM_VERITY_VERIFY_ROOTHASH_SIG y
+require_config CONFIG_BLK_DEV_LOOP y
require_config CONFIG_PCI y
require_config CONFIG_PCI_MSI y
require_config CONFIG_PCIEPORTBUS y
@@ -591,6 +608,7 @@ require_config CONFIG_OVERLAY_FS y
require_config CONFIG_EXT4_FS y
require_config CONFIG_EXT4_FS_SECURITY y
require_config CONFIG_TMPFS y
+require_config CONFIG_TMPFS_XATTR y
require_config CONFIG_EFI_PARTITION y
case "$TEST_VM_ARCH" in
x86_64)
diff --git a/contrib/build-test-vm-bundle.sh b/contrib/build-test-vm-bundle.sh
index e7f81845..6c4a238b 100755
--- a/contrib/build-test-vm-bundle.sh
+++ b/contrib/build-test-vm-bundle.sh
@@ -352,6 +352,7 @@ build_fixture()
"$REPO_ROOT/testing/fixtures/$source" \
-o "$TMP_DIR/fixtures/$name.upatch" \
--name "$name" --vmlinux "$REPO_ROOT/vendor/linux/vmlinux.h" \
+ --extra-cflags "-I$REPO_ROOT/vendor/libbpf" \
--key "$keys_dir/signing_key.pem" \
--cert "$keys_dir/cert.der"
)
@@ -551,6 +552,7 @@ EOF
"$source_dir/kernel-obs.bpf.c" \
-o "$TMP_DIR/fixtures/kernel-obs.upatch" \
--name kernel-obs --vmlinux "$REPO_ROOT/vendor/linux/vmlinux.h" \
+ --extra-cflags "-I$REPO_ROOT/vendor/libbpf" \
--key "$keys_dir/signing_key.pem" \
--cert "$keys_dir/cert.der"
)
@@ -564,6 +566,7 @@ EOF
"$source_dir/kernel-obs-cred-anomaly.bpf.c" \
-o "$TMP_DIR/fixtures/kernel-obs-cred-anomaly.upatch" \
--name kernel-obs --vmlinux "$REPO_ROOT/vendor/linux/vmlinux.h" \
+ --extra-cflags "-I$REPO_ROOT/vendor/libbpf" \
--key "$keys_dir/signing_key.pem" \
--cert "$keys_dir/cert.der"
)
diff --git a/contrib/test-vm-guest.sh b/contrib/test-vm-guest.sh
index 1ab88b91..cccc69a4 100755
--- a/contrib/test-vm-guest.sh
+++ b/contrib/test-vm-guest.sh
@@ -329,6 +329,10 @@ test -c /dev/tpm0
test -c /dev/tpmrm0
tpm2_getrandom 8 >/dev/null
+if [[ "$VM_INITRD" == 1 ]]; then
+ log "initrd Shirudo journal"
+ journalctl -b -u shirudo-initrd.service --no-pager | tail -40 || true
+fi
(cd "$BUNDLE/verity" && sha256sum -c manifest)
mountpoint -q /run/shirudo/runtime
mountpoint -q /run/shirudo/config
@@ -336,11 +340,21 @@ install -m 0755 "$BUNDLE/verity/shirudo-runtime" /usr/local/bin/shirudo-runtime
SHIRUDO_BIN=/usr/local/bin/shirudo-runtime
for unit in "${TARGET_UNITS[@]}"; do
case "$unit" in *.service) ;; *) continue ;; esac
+ unit_file="/usr/lib/systemd/system/$unit"
+ exec_starts=$(sed -nE \
+ 's#^ExecStart=(-?)[^[:space:]]*/shirudo([[:space:]]|$)#ExecStart=\1/usr/local/bin/shirudo-runtime\2#p' \
+ "$unit_file")
+ exec_count=$(awk '/^ExecStart=/ { count++ } END { print count + 0 }' \
+ "$unit_file")
+ replacement_count=$(printf '%s\n' "$exec_starts" |
+ awk '/^ExecStart=/ { count++ } END { print count + 0 }')
+ if [[ "$exec_count" -eq 0 || "$replacement_count" -ne "$exec_count" ]]; then
+ log "could not rewrite every ExecStart in $unit_file ($replacement_count/$exec_count)"
+ exit 1
+ fi
mkdir -p "/etc/systemd/system/$unit.d"
{
- printf '[Service]\nExecStart=\n'
- sed -n 's|^ExecStart=/usr/local/bin/shirudo |ExecStart=/usr/local/bin/shirudo-runtime |p' \
- "/usr/lib/systemd/system/$unit"
+ printf '[Service]\nExecStart=\n%s\n' "$exec_starts"
} >"/etc/systemd/system/$unit.d/runtime.conf"
done
systemctl daemon-reload
@@ -348,7 +362,6 @@ systemctl daemon-reload
test -e /run/shirudo/bpffs/lsm_link
if [[ "$VM_INITRD" == 1 ]]; then
log "checking that the initrd brought enforcement up"
- journalctl -b -u shirudo-initrd.service --no-pager | tail -20 || true
"$SHIRUDO_BIN" status --json | python3 -c '
import json, sys
d = json.load(sys.stdin)
diff --git a/contrib/verity-vm-config-fixtures.sh b/contrib/verity-vm-config-fixtures.sh
index cc13fad1..1388f251 100755
--- a/contrib/verity-vm-config-fixtures.sh
+++ b/contrib/verity-vm-config-fixtures.sh
@@ -134,6 +134,7 @@ done
-o "$output/public/shirudo-test-revoked-key.upatch" \
--name shirudo-test-revoked-key \
--vmlinux "$source_dir/vendor/linux/vmlinux.h" \
+ --extra-cflags "-I$source_dir/vendor/libbpf" \
--key "$output/private/boot/signing_key.pem" \
--cert "$output/public/boot.der"
diff --git a/kernel/0001-keys-add-KEY-SPEC-DM-VERITY-KEYRING.patch b/kernel/0001-keys-add-KEY-SPEC-DM-VERITY-KEYRING.patch
new file mode 100644
index 00000000..eafbfe03
--- /dev/null
+++ b/kernel/0001-keys-add-KEY-SPEC-DM-VERITY-KEYRING.patch
@@ -0,0 +1,107 @@
+From: Andrew Halaney <[email protected]>
+Subject: [PATCH bpf-next v2 1/3] keys: add KEY_SPEC_DM_VERITY_KEYRING
+Message-Id: <20261008-ajhalaney-dmverity-key-identifier-v2-1-008456d189cb@amutable.com>
+
+Local build copy of patch 1/3 from the upstream bpf-next v2 series
+"keys: Add well known IDs for fs-verity/dm-verity keys".
+
+diff --git a/drivers/md/dm-verity-verify-sig.c b/drivers/md/dm-verity-verify-sig.c
+index b2b55c41e..da509dcdd 100644
+--- a/drivers/md/dm-verity-verify-sig.c
++++ b/drivers/md/dm-verity-verify-sig.c
+@@ -189,11 +189,14 @@ int __init dm_verity_verify_sig_init(void)
+ keyring_restrict(make_key_ref(dm_verity_keyring, true), NULL, NULL))
+ panic("dm-verity can't seal keyring\n");
+
++ key_register_dm_verity_keyring(dm_verity_keyring);
++
+ return 0;
+ }
+
+ void dm_verity_verify_sig_exit(void)
+ {
++ key_register_dm_verity_keyring(NULL);
+ key_revoke(dm_verity_keyring);
+ key_put(dm_verity_keyring);
+ }
+diff --git a/include/linux/key.h b/include/linux/key.h
+index dae5ba255..0289351d1 100644
+--- a/include/linux/key.h
++++ b/include/linux/key.h
+@@ -446,6 +446,7 @@ extern int keyring_restrict(key_ref_t keyring, const char *type,
+ const char *restriction);
+
+ extern void key_register_bpf_keyring(struct key *keyring);
++extern void key_register_dm_verity_keyring(struct key *keyring);
+
+ extern struct key *key_lookup(key_serial_t id);
+
+diff --git a/include/uapi/linux/keyctl.h b/include/uapi/linux/keyctl.h
+index fa85b9760..75923941f 100644
+--- a/include/uapi/linux/keyctl.h
++++ b/include/uapi/linux/keyctl.h
+@@ -25,6 +25,7 @@
+ #define KEY_SPEC_REQKEY_AUTH_KEY -7 /* - key ID for assumed request_key auth key */
+ #define KEY_SPEC_REQUESTOR_KEYRING -8 /* - key ID for request_key() dest keyring */
+ #define KEY_SPEC_BPF_KEYRING -9 /* - key ID for the BPF-specific keyring */
++#define KEY_SPEC_DM_VERITY_KEYRING -10 /* - key ID for the .dm-verity keyring */
+
+ /* request-key default keyrings */
+ #define KEY_REQKEY_DEFL_NO_CHANGE -1
+diff --git a/security/keys/process_keys.c b/security/keys/process_keys.c
+index cf638bf1f..e9e9a64ec 100644
+--- a/security/keys/process_keys.c
++++ b/security/keys/process_keys.c
+@@ -25,6 +25,10 @@ static DEFINE_MUTEX(key_session_mutex);
+ /* BPF keyring reachable through KEY_SPEC_BPF_KEYRING */
+ static struct key *bpf_keyring __ro_after_init;
+
++/* dm-verity keyring reachable through KEY_SPEC_DM_VERITY_KEYRING */
++static struct key *dm_verity_keyring;
++static DEFINE_SPINLOCK(dm_verity_keyring_lock);
++
+ /* The root user's tracking struct */
+ struct key_user root_key_user = {
+ .usage = REFCOUNT_INIT(3),
+@@ -606,6 +610,23 @@ void key_register_bpf_keyring(struct key *keyring)
+ bpf_keyring = keyring;
+ }
+
++/**
++ * key_register_dm_verity_keyring - Publish the keyring for KEY_SPEC_DM_VERITY_KEYRING
++ * @keyring: The keyring to publish, or NULL to withdraw it
++ *
++ * Make @keyring reachable by userspace through the KEY_SPEC_DM_VERITY_KEYRING
++ * special key ID, so provisioning it does not require scraping /proc/keys.
++ * dm-verity can be unloaded as a module, so serialize access with
++ * dm_verity_keyring_lock.
++ */
++void key_register_dm_verity_keyring(struct key *keyring)
++{
++ spin_lock(&dm_verity_keyring_lock);
++ dm_verity_keyring = keyring;
++ spin_unlock(&dm_verity_keyring_lock);
++}
++EXPORT_SYMBOL_GPL(key_register_dm_verity_keyring);
++
+ /*
+ * Look up a key ID given us by userspace with a given permissions mask to get
+ * the key it refers to.
+@@ -765,6 +786,17 @@ key_ref_t lookup_user_key(key_serial_t id, unsigned long lflags,
+ key_ref = make_key_ref(key, 0);
+ break;
+
++ case KEY_SPEC_DM_VERITY_KEYRING:
++ spin_lock(&dm_verity_keyring_lock);
++ key = dm_verity_keyring;
++ if (key)
++ __key_get(key);
++ spin_unlock(&dm_verity_keyring_lock);
++ if (!key)
++ goto error;
++ key_ref = make_key_ref(key, 0);
++ break;
++
+ default:
+ key_ref = ERR_PTR(-EINVAL);
+ if (id < 1)
diff --git a/testing/Makefile b/testing/Makefile
index 7a6ea8ef..7346f57d 100644
--- a/testing/Makefile
+++ b/testing/Makefile
@@ -25,6 +25,7 @@ test-vm-arch = $(shell TEST_VM_ARCH='$(TEST_VM_ARCH)'; \
KERNEL_PATCHES ?= $(if $(wildcard $(ROOT)/kernel/*.patch),$(ROOT)/kernel/,)
override KERNEL_PATCHES := $(if $(strip $(KERNEL_PATCHES)),$(call root-path,$(KERNEL_PATCHES)),)
+KERNEL_PATCH_FILES := $(foreach patch,$(KERNEL_PATCHES),$(if $(wildcard $(patch)/*.patch),$(wildcard $(patch)/*.patch),$(wildcard $(patch))))
PACKAGE_FORMAT ?= $(call test-vm-arch,TEST_VM_HOST_PKG_FORMAT)
TEST_VM_MODE ?= verity
@@ -170,7 +171,7 @@ bpf-next:
KERNEL_BUILD_JOBS='$(KERNEL_BUILD_JOBS)' \
$(ROOT)/contrib/build-kernel-package.sh
-$(KERNEL_BUILD_STAMP): $(ROOT)/contrib/build-kernel-package.sh
+$(KERNEL_BUILD_STAMP): $(ROOT)/contrib/build-kernel-package.sh $(KERNEL_PATCH_FILES)
$(Q)KERNEL_TAG='$(KERNEL_TAG_NORMALIZED)' \
KERNEL_COMMIT='$(KERNEL_COMMIT)' \
KERNEL_PATCHES='$(KERNEL_PATCHES)' \
diff --git a/testing/integration-lib.sh b/testing/integration-lib.sh
index 2542366b..225c2e6b 100644
--- a/testing/integration-lib.sh
+++ b/testing/integration-lib.sh
@@ -55,6 +55,10 @@ print(d.get(sys.argv[1], ""))
' "$1"
}
+keyring_mode() {
+ "$SHIRUDO_BIN" status --json 2>/dev/null | report_field keyring_mode
+}
+
# The BPM tree tests (t1118-t1120) walk one append-only tree in order:
# the state a sync writes under /var/lib/shirudo is sealed, so a test
# cannot remove it and each one continues from where the previous one
diff --git a/testing/t1124-keys-add.sh b/testing/t1124-keys-add.sh
index c01e3912..ace8a121 100755
--- a/testing/t1124-keys-add.sh
+++ b/testing/t1124-keys-add.sh
@@ -2,9 +2,8 @@
# SPDX-License-Identifier: BSD-2-Clause
# Copyright (c) 2026 Authors of shirudo
#
-# t1124 -- `keys add` on a live target: the bundle's third certificate
-# joins the trusted set on disk with the vouch the primary signed for
-# it, and the bpf keyring stays as the boot sealed it.
+# t1124 -- a signed CONFIG owns the trusted set, so live `keys add`
+# refuses changes and leaves the boot-enrolled membership intact.
cd "$(dirname "$0")"
. ./integration-lib.sh
@@ -33,18 +32,18 @@ print(len(v) if isinstance(v, list) else v)
"
}
-test_expect_success 'a vouch made for another certificate is refused' '
+test_expect_success 'a mismatched live vouch cannot change the signed set' '
! "$SHIRUDO_BIN" keys add "$THIRD" --vouch "$OWN_VOUCH" >/dev/null 2>&1 &&
! [ -e "$TRUSTED/$THIRD_FP.der" ] &&
[ "$(status_field certs)" = 2 ]
'
-test_expect_success 'the vouched certificate joins the trusted set on disk' '
- out=$("$SHIRUDO_BIN" keys add "$THIRD" --vouch "$VOUCH" 2>/dev/null) &&
- [ "$out" = "$THIRD_FP" ] &&
- cmp -s "$THIRD" "$TRUSTED/$THIRD_FP.der" &&
- cmp -s "$VOUCH" "$TRUSTED/$THIRD_FP.vouch" &&
- [ "$(status_field certs)" = 3 ] &&
+test_expect_success 'a valid vouch cannot change the signed trusted set' '
+ ! "$SHIRUDO_BIN" keys add "$THIRD" --vouch "$VOUCH" >"$W/add" 2>&1 &&
+ grep -q "signed config" "$W/add" &&
+ ! [ -e "$TRUSTED/$THIRD_FP.der" ] &&
+ ! [ -e "$TRUSTED/$THIRD_FP.vouch" ] &&
+ [ "$(status_field certs)" = 2 ] &&
[ "$(status_field certs_unvouched)" = 0 ]
'
@@ -53,16 +52,16 @@ test_expect_success 'the bpf keyring keeps the set the boot sealed' '
grep -qE "keyring +\.bpf: 2" /proc/keys
'
-test_expect_success 'adding it again changes nothing' '
- out=$("$SHIRUDO_BIN" keys add "$THIRD" --vouch "$VOUCH" 2>/dev/null) &&
- [ "$out" = "$THIRD_FP" ] &&
- [ "$(status_field certs)" = 3 ]
+test_expect_success 'repeating the live add still leaves the signed set unchanged' '
+ ! "$SHIRUDO_BIN" keys add "$THIRD" --vouch "$VOUCH" >/dev/null 2>&1 &&
+ ! [ -e "$TRUSTED/$THIRD_FP.der" ] &&
+ [ "$(status_field certs)" = 2 ]
'
-test_expect_success 'keys lists the member with its voucher' '
+test_expect_success 'keys lists only the boot-enrolled members' '
"$SHIRUDO_BIN" keys 2>/dev/null >"$W/keys" &&
- grep -q "^ $THIRD_FP\$" "$W/keys" &&
- grep -q "3 members, 0 revoked, 0 unvouched" "$W/keys" &&
+ ! grep -q "^ $THIRD_FP\$" "$W/keys" &&
+ grep -q "2 members, 0 revoked, 0 unvouched" "$W/keys" &&
grep -q "^Keyring (.bpf):" "$W/keys"
'
diff --git a/testing/t1126-keys-revoke.sh b/testing/t1126-keys-revoke.sh
index 85d971d8..f9b2ee9d 100755
--- a/testing/t1126-keys-revoke.sh
+++ b/testing/t1126-keys-revoke.sh
@@ -2,11 +2,8 @@
# SPDX-License-Identifier: BSD-2-Clause
# Copyright (c) 2026 Authors of shirudo
#
-# t1126 -- revoking the second enrolled key on a live target: its key
-# leaves the bpf keyring, the upatch it signed is unloaded and purged
-# with a measured record, the revocation itself is measured, a load it
-# signed is refused from then on, and the set on disk is without it.
-# Runs after t1123 and t1124, which need the key enrolled.
+# t1126 -- a signed CONFIG owns signer revocation. A live revoke is
+# refused without changing the boot-enrolled keyring or loaded upatch.
cd "$(dirname "$0")"
. ./integration-lib.sh
@@ -25,7 +22,6 @@ OWN_FP=$("$SHIRUDO_BIN" bpm key fingerprint "$OWN_CERT" 2>/dev/null)
PRIMARY_FP=$("$SHIRUDO_BIN" bpm key fingerprint /var/lib/shirudo/keys/cert.der 2>/dev/null)
[ -e "/var/lib/shirudo/keys/trusted/$OWN_FP.der" ] ||
test_skip_all "the own-keyring certificate is not a trusted member"
-RING=$("$SHIRUDO_BIN" status --json 2>/dev/null | report_field keyring_serial)
W=$(mktemp -d)
trap 'rm -rf "$W"' EXIT
@@ -37,7 +33,7 @@ v = d[\"$1\"]
print(len(v) if isinstance(v, list) else v)
"
}
-# grep -c exits 1 for a count of zero, which the first revocation is.
+
events_of_type() {
grep -c "\"type\":\"$1\"" /var/lib/shirudo/eventlog || :
}
@@ -49,67 +45,40 @@ test_expect_success 'the upatch signed by the second key is loaded' '
[ -e "$OWN_PIN" ] && [ -s "$ARCHIVE" ]
'
-test_expect_success 'the primary cannot go without an heir' '
- ! "$SHIRUDO_BIN" keys revoke "$PRIMARY_FP" >/dev/null 2>&1 &&
- [ "$(status_field certs_enrolled)" = 2 ]
-'
-
-revoke_debug() {
- echo "--- keys revoke exit $1" >&2
- cat "$W/out" "$W/err" >&2
- grep -E "keyring +\.bpf" /proc/keys >&2
-}
-
-test_expect_success 'revoking the second key unlinks it and purges what it signed' '
+test_expect_success 'live revocation is refused without changing the signer or upatch' '
before_rev=$(events_of_type key_revoke) &&
- before_unl=$(events_of_type upatch_unload) &&
- { "$SHIRUDO_BIN" keys revoke "$OWN_FP" >"$W/out" 2>"$W/err"; rc=$?; revoke_debug "$rc"; [ "$rc" = 0 ]; } &&
- grep -q "^revoked $OWN_FP" "$W/out" &&
- grep -q "^purged 1 upatch it signed, 1 of them loaded" "$W/out" &&
- ! [ -e "$OWN_PIN" ] && ! [ -e "$ARCHIVE" ] &&
- [ "$(events_of_type key_revoke)" = $((before_rev + 1)) ] &&
- [ "$(events_of_type upatch_unload)" = $((before_unl + 1)) ] &&
- grep "\"type\":\"upatch_unload\"" /var/lib/shirudo/eventlog | tail -1 |
- grep -q "\"reason\":\"key_revoke\""
+ ! "$SHIRUDO_BIN" keys revoke "$OWN_FP" >"$W/out" 2>"$W/err" &&
+ grep -q "signed config image" "$W/err" &&
+ [ -e "$OWN_PIN" ] && [ -s "$ARCHIVE" ] &&
+ [ "$(events_of_type key_revoke)" = "$before_rev" ] &&
+ grep -qE "keyring +\.bpf: 2" /proc/keys
'
-test_expect_success 'the bpf keyring holds one key and the set on disk is without it' '
- grep -qE "keyring +\.bpf: 1" /proc/keys &&
- [ "$(status_field certs_enrolled)" = 1 ] &&
- [ "$(status_field certs_revoked)" -ge 1 ] &&
- ! [ -e "/var/lib/shirudo/keys/trusted/$OWN_FP.der" ] &&
- ! [ -e "/var/lib/shirudo/keys/trusted/$OWN_FP.vouch" ] &&
- [ -s "/var/lib/shirudo/keys/revoked/$OWN_FP.der" ] &&
+test_expect_success 'the bpf keyring and signed trusted set still contain both keys' '
+ [ "$(status_field certs_enrolled)" = 2 ] &&
+ [ "$(status_field certs_revoked)" = 0 ] &&
+ [ -s "/var/lib/shirudo/keys/trusted/$OWN_FP.der" ] &&
+ [ -s "/var/lib/shirudo/keys/trusted/$OWN_FP.vouch" ] &&
"$SHIRUDO_BIN" status --json | python3 -c "
import json, sys
d = json.load(sys.stdin)
-assert all(c[\"fingerprint\"] != \"$OWN_FP\" for c in d[\"certs\"]), d
+assert any(c[\"fingerprint\"] == \"$OWN_FP\" for c in d[\"certs\"]), d
"
'
-test_expect_success 'a load signed by the revoked key is refused' '
- ! "$SHIRUDO_BIN" upatch load "$OWN" --no-precheck >/dev/null 2>&1 &&
- ! [ -e "$OWN_PIN" ]
-'
-
-test_expect_success 'the eventlog with the revocation replays to the register' '
- "$SHIRUDO_BIN" status --json | python3 -c "
-import json, sys
-d = json.load(sys.stdin)
-assert d[\"tpm\"][\"chain_matches_eventlog\"] is True, d[\"tpm\"]
-" &&
- grep "\"type\":\"key_revoke\"" /var/lib/shirudo/eventlog | tail -1 |
- grep -q "\"fingerprint\":\"$OWN_FP\""
+test_expect_success 'the signed upatch remains loaded and archived' '
+ [ -e "$OWN_PIN" ] && [ -s "$ARCHIVE" ]
'
-test_expect_success 'revoking it again is a no-op and adding it back is refused' '
- "$SHIRUDO_BIN" keys revoke "$OWN_FP" >/dev/null 2>&1 &&
- ! "$SHIRUDO_BIN" keys add "$OWN_CERT" --vouch "$FIXTURES/own.vouch" >/dev/null 2>&1
+test_expect_success 'repeated live revocation and live signer addition are refused' '
+ ! "$SHIRUDO_BIN" keys revoke "$OWN_FP" >/dev/null 2>&1 &&
+ ! "$SHIRUDO_BIN" keys add "$OWN_CERT" --vouch "$FIXTURES/own.vouch" >/dev/null 2>&1 &&
+ [ "$(status_field certs_enrolled)" = 2 ]
'
-test_expect_success 'the last key cannot go without --force' '
+test_expect_success 'live revocation of the primary is refused too' '
! "$SHIRUDO_BIN" keys revoke "$PRIMARY_FP" >/dev/null 2>&1 &&
- grep -qE "keyring +\.bpf: 1" /proc/keys
+ grep -qE "keyring +\.bpf: 2" /proc/keys
'
test_done
diff --git a/testing/tamperproof/t1156-verity-revocation.py b/testing/tamperproof/t1156-verity-revocation.py
index 7c099127..12c17c51 100644
--- a/testing/tamperproof/t1156-verity-revocation.py
+++ b/testing/tamperproof/t1156-verity-revocation.py
@@ -37,13 +37,48 @@ def extension(before, after, kind, payload):
require(after["chain"] == expected, "unexpected upatch NV extension")
+def revocation_extensions(before, after):
+ lines = Path("/var/lib/shirudo/eventlog").read_text().splitlines()
+ events = [json.loads(line) for line in lines[before["nv_events"]:]]
+ require(events and events[0]["type"] == "key_revoke",
+ f"revocation is not the first new NV event: {events}")
+ cert_digest = hashlib.sha256((signer.FIXTURES / "boot.der").read_bytes()).digest()
+ expected_revoke = hashlib.sha256(
+ b"shirudo-key-revoke\0" + cert_digest).digest()
+ require(events[0]["digest"] == expected_revoke.hex(),
+ "wrong signer revocation event")
+ chain = bytes.fromhex(before["chain"])
+ unloaded = set()
+ for event in events:
+ if event["type"] == "key_revoke":
+ digest = bytes.fromhex(event["digest"])
+ else:
+ require(event["type"] == "upatch_unload",
+ f"unexpected event during signer revocation: {event}")
+ patch = event["upatch"]
+ name = patch["name"]
+ digest = hashlib.sha256(
+ b"shirudo-unload\0" + bytes.fromhex(patch["payload_sha256"]) +
+ name.encode()).digest()
+ require(event["digest"] == digest.hex(),
+ f"wrong unload event digest: {event}")
+ unloaded.add(name)
+ chain = hashlib.sha256(chain + digest).digest()
+ require(NAME in unloaded, "revoked signer upatch has no measured unload")
+ require(after["chain"] == chain.hex(),
+ f"NV chain does not replay added revocation events: {events}")
+
+
def main():
mode = sys.argv[1]
if mode == "initial":
require(UPATCH.is_file(), "missing boot-signed upatch fixture")
signer.check_members(signer.keyring())
require(not PIN.exists() and not ARCHIVE.exists(), "stale revoked upatch")
- snapshot("before", 2)
+ before = snapshot("before", 2)
+ before["nv_events"] = len(
+ Path("/var/lib/shirudo/eventlog").read_text().splitlines())
+ config.save("before", before)
elif mode == "load":
before = config.load("before")
info = json.loads(config.run("upatch-info", "upatch", "info", UPATCH, "--json"))
@@ -53,6 +88,9 @@ def main():
after = snapshot("loaded", 2)
require(before["config"] == after["config"], "load changed CONFIG")
extension(before, after, b"upatch", info["payload_sha256"])
+ after["nv_events"] = len(
+ Path("/var/lib/shirudo/eventlog").read_text().splitlines())
+ config.save("loaded", after)
elif mode == "revoke":
before = config.load("loaded")
config.run("revoke-config", "image", "update", signer.FIXTURES / "config-revoke")
@@ -66,11 +104,7 @@ def main():
expected = signer.certificate_description(signer.FIXTURES / "primary.der")
require({value[4] for value in after["keys"].values()} == {expected},
"revocation removed the wrong signer")
- cert_digest = hashlib.sha256((signer.FIXTURES / "boot.der").read_bytes()).digest()
- revoke = hashlib.sha256(b"shirudo-key-revoke\0" + cert_digest).digest()
- intermediate = dict(before)
- intermediate["chain"] = hashlib.sha256(bytes.fromhex(before["chain"]) + revoke).hexdigest()
- extension(intermediate, after, b"unload", config.load("upatch")["payload_sha256"])
+ revocation_extensions(before, after)
config.run("revoked-load", "upatch", "load", UPATCH,
"--no-precheck", success=False)
repeat = snapshot("refused-load", 1)
diff --git a/util/image_runtime.c b/util/image_runtime.c
index e580e07f..67c93623 100644
--- a/util/image_runtime.c
+++ b/util/image_runtime.c
@@ -316,6 +316,7 @@ static int load_runtime_config(bool trusted_boot)
/* The initrd checks the runtime against its authenticated UKI root. */
static int mount_runtime(bool trusted_boot)
{
+ const char *step = "open runtime image";
struct shirudo_config_image_open opened = {
.data_fd = -1,
.hash_fd = -1,
@@ -337,22 +338,30 @@ static int mount_runtime(bool trusted_boot)
rc = shirudo_config_image_open_root(image.bootstrap.runtime,
image.bootstrap.runtime_root,
&opened);
- if (rc)
- return rc;
- rc = mkdir_owned(SHIRUDO_RUNTIME_DIR);
if (!rc) {
+ step = "prepare runtime mountpoint";
+ rc = mkdir_owned(SHIRUDO_RUNTIME_DIR);
+ }
+ if (!rc) {
+ step = "create runtime dm-verity mapping";
rc = shirudo_dm_verity_create(&opened, "shirudo-runtime",
&device);
created = !rc;
}
- if (rc == -EEXIST)
+ if (rc == -EEXIST) {
+ step = "inspect runtime dm-verity mapping";
rc = shirudo_dm_verity_inspect("shirudo-runtime", &opened.image,
&device);
- if (!rc)
+ }
+ if (!rc) {
+ step = "verify runtime image";
rc = shirudo_dm_verity_verify(&device, &opened);
- if (!rc)
+ }
+ if (!rc) {
+ step = "mount runtime image";
rc = shirudo_dm_verity_mount(&device, SHIRUDO_RUNTIME_DIR,
true);
+ }
if (rc && created) {
cleanup = shirudo_dm_verity_remove(&device, false);
if (cleanup)
@@ -363,8 +372,12 @@ static int mount_runtime(bool trusted_boot)
if (!rc && trusted_boot)
image.boot_runtime = device;
shirudo_config_image_close(&opened);
- if (!rc)
+ if (!rc) {
+ step = "load runtime config";
rc = load_runtime_config(trusted_boot);
+ }
+ if (rc)
+ pr_err("image: %s: %s", step, strerror(-rc));
return rc;
}
@@ -684,6 +697,12 @@ static int boot_target(struct shirudo_config_update_target *target)
return rc;
}
+static int boot_keys_error(const char *step, int rc)
+{
+ pr_err("initrd boot keys: %s: %s", step, strerror(-rc));
+ return rc;
+}
+
static int enroll_config_key(void)
{
__u8 *der = NULL;
@@ -693,16 +712,29 @@ static int enroll_config_key(void)
rc = keys_read_der(image.bootstrap.certificate, &der, &size);
if (rc)
- return rc;
+ return boot_keys_error("read config verification certificate", rc);
ring = shirudo_keyring_dm_verity_serial();
- rc = ring < 0 ? ring : keyring_holds_cert(ring, der, size);
+ if (ring < 0) {
+ rc = (int)ring;
+ xfree(der, size);
+ return boot_keys_error("lookup dm-verity keyring", rc);
+ }
+ rc = keyring_holds_cert(ring, der, size);
+ if (rc < 0) {
+ xfree(der, size);
+ return boot_keys_error("check config certificate enrollment", rc);
+ }
if (!rc)
rc = shirudo_keyring_dm_verity_add_cert(der, size);
xfree(der, size);
if (rc < 0)
- return rc;
+ return boot_keys_error("add config verification certificate", rc);
rc = shirudo_keyring_dm_verity_seal();
- return rc == -EEXIST ? 0 : rc;
+ if (rc == -EEXIST)
+ return 0;
+ if (rc)
+ return boot_keys_error("seal dm-verity keyring", rc);
+ return 0;
}
/* The authenticated initrd validates the boot set before installing guards. */
@@ -715,25 +747,30 @@ int shirudo_image_boot_keys(struct shirudo_trusted_set *set)
/* These temporary mounts are released before loading the guards. */
image.boot_keys_open = true;
rc = mount_runtime(true);
- if (!rc)
- rc = enroll_config_key();
- if (!rc)
- rc = open_update();
- if (!rc)
- rc = boot_target(&image.boot_target);
- if (!rc)
- rc = prepare_config(&image, &image.boot_target, true);
- if (!rc)
- rc = shirudo_keys_validate_image_set(SHIRUDO_RUNTIME_CERT_PATH,
- image.candidate_fd, set);
if (rc)
- return rc;
+ return boot_keys_error("mount runtime", rc);
+ rc = enroll_config_key();
+ if (rc)
+ return boot_keys_error("enrol config certificate", rc);
+ rc = open_update();
+ if (rc)
+ return boot_keys_error("open config update state", rc);
+ rc = boot_target(&image.boot_target);
+ if (rc)
+ return boot_keys_error("select boot config", rc);
+ rc = prepare_config(&image, &image.boot_target, true);
+ if (rc)
+ return boot_keys_error("prepare boot config", rc);
+ rc = shirudo_keys_validate_image_set(SHIRUDO_RUNTIME_CERT_PATH,
+ image.candidate_fd, set);
+ if (rc)
+ return boot_keys_error("validate BPF trust set", rc);
/* Guard loaders need the initial signer until activation. */
strscpy(primary.path, SHIRUDO_RUNTIME_CERT_PATH, sizeof(primary.path));
rc = keys_digest_file(primary.path, primary.sha256,
primary.fingerprint);
if (rc)
- return rc;
+ return boot_keys_error("digest primary certificate", rc);
for (i = 0; i < set->n; i++)
if (!memcmp(set->certs[i].sha256, primary.sha256, 32))
break;