eBPF-based security platform
testing: verify a measuring command waits for the register lock
Daniel Borkmanncff5401f2d9c
diff --git a/testing/run-target-tests.sh b/testing/run-target-tests.shindex 6375d32f..86a7498e 100755--- a/testing/run-target-tests.sh+++ b/testing/run-target-tests.sh@@ -83,6 +83,7 @@ for t in \tamperproof/t1165-tpm-identity.sh \tamperproof/t1166-kexec.sh \tamperproof/t1168-proc-substitution.sh \+ tamperproof/t1169-register-lock.sh \tamperproof/t1150-verity-devices.sh \tamperproof/t1151-verity-process.sh \tamperproof/t1153-verity-hidden.sh \diff --git a/testing/tamperproof/t1169-register-lock.sh b/testing/tamperproof/t1169-register-lock.shnew file mode 100755index 00000000..f9779259--- /dev/null+++ b/testing/tamperproof/t1169-register-lock.sh@@ -0,0 +1,73 @@+#!/bin/sh+# SPDX-License-Identifier: BSD-2-Clause+# Copyright (c) 2026 Authors of shirudo+#+# t1169 -- the register and the eventlog advance together only while one+# process at a time extends and appends, and the lock that serialises+# whole commands is not taken by init, which adopts the initrd's record+# while a command may append. A measuring command must hold the lock+# beside the eventlog from its extend to its append: with the lock held+# elsewhere a load waits, and completes with a log that replays to the+# register. Root may hold the lock and so delay a command, but cannot+# remove it.++cd "$(dirname "$0")/.."+. ./integration-lib.sh+target_guard+command -v python3 >/dev/null 2>&1 || test_skip_all "no python3"+command -v flock >/dev/null 2>&1 || test_skip_all "no flock"+FIXTURES=${SHIRUDO_TEST_FIXTURES_DIR:?target fixture directory is not set}+NAME=shirudo-test-lifecycle+LOAD="$FIXTURES/$NAME.upatch"+UNLOAD="$FIXTURES/$NAME.unload.upatch"+PIN="/run/shirudo/bpffs/upatches/$NAME"+LOCK=/var/lib/shirudo/eventlog.lock+[ -s "$LOAD" ] && [ -s "$UNLOAD" ] || test_skip_all "missing lifecycle fixture"+[ ! -e "$PIN" ] || test_skip_all "$NAME is loaded"++cleanup() {+ if [ -e "$PIN" ]; then+ "$SHIRUDO_BIN" upatch unload "$UNLOAD" --no-precheck \+ >/dev/null 2>&1 || true+ fi+}+trap cleanup EXIT++matches() {+ "$SHIRUDO_BIN" status --json 2>/dev/null |+ python3 -c "import json,sys; sys.exit(0 if json.load(sys.stdin)[\"tpm\"][\"chain_matches_eventlog\"] else 1)"+}++lines() {+ wc -l </var/lib/shirudo/eventlog+}++test_expect_success 'a measuring command makes the lock beside the eventlog' '+ "$SHIRUDO_BIN" upatch load "$LOAD" --no-precheck >/dev/null 2>&1 &&+ "$SHIRUDO_BIN" upatch unload "$UNLOAD" --no-precheck >/dev/null 2>&1 &&+ [ -f "$LOCK" ] &&+ ! rm -f "$LOCK" 2>/dev/null &&+ [ -f "$LOCK" ]+'++test_expect_success 'a load waits while the register lock is held and then measures' '+ before=$(lines) &&+ { flock "$LOCK" sleep 4 & holder=$!; } &&+ sleep 1 &&+ { "$SHIRUDO_BIN" upatch load "$LOAD" --no-precheck >/dev/null 2>&1 &+ loader=$!; } &&+ sleep 2 &&+ [ "$(lines)" = "$before" ] &&+ wait "$holder" && wait "$loader" &&+ [ "$(lines)" -gt "$before" ] &&+ [ -e "$PIN/link" ] &&+ matches+'++test_expect_success 'the unload after it leaves the register and the log in step' '+ "$SHIRUDO_BIN" upatch unload "$UNLOAD" --no-precheck >/dev/null 2>&1 &&+ [ ! -e "$PIN" ] &&+ matches+'++test_done