eBPF-based security platform
testing: verify NV writer liveness around denied signing
Leonard Cohnenbf2a8e0afc70
diff --git a/testing/tpm/t1127-nv-writer.sh b/testing/tpm/t1127-nv-writer.shindex 981a7587..aee26736 100644--- a/testing/tpm/t1127-nv-writer.sh+++ b/testing/tpm/t1127-nv-writer.sh@@ -11,8 +11,44 @@ target_guardtest_skip_all "test-tpm-preopened not built"[ -x helper/test-nv-cphash ] ||test_skip_all "test-nv-cphash not built"+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/link"+[ -s "$LOAD" ] && [ -s "$UNLOAD" ] ||+ test_skip_all "missing lifecycle fixtures"+[ ! -e "$PIN" ] || {+ echo "NV writer test requires an unloaded lifecycle fixture" >&2+ exit 1+}W=$(mktemp -d)-trap 'rm -f "$W/status.json" "$W/preopened.log" "$W/cphash.log"; rmdir "$W"' EXIT HUP INT TERM++cleanup() {+ result=$?+ trap - EXIT+ if [ -e "$PIN" ]; then+ "$SHIRUDO_BIN" upatch unload "$UNLOAD" --no-precheck || result=1+ fi+ rm -f "$W/status.json" "$W/preopened.log" "$W/cphash.log" || result=1+ rmdir "$W" || result=1+ exit "$result"+}+trap cleanup EXIT+trap 'exit 1' HUP INT TERM++writer_chain() {+ "$SHIRUDO_BIN" status --json >"$W/status.json" &&+ python3 - "$W/status.json" <<'PY'+import json, sys+tpm = json.load(open(sys.argv[1]))["tpm"]+chain = tpm["chain"]+assert len(chain) == 64+assert len(bytes.fromhex(chain)) == 32+assert tpm["chain_matches_eventlog"] is True+print(chain)+PY+}test_expect_success 'the writer public area is available in the init record' './helper/test-nv-writer public@@ -22,9 +58,19 @@ test_expect_success 'root cannot read the kernel-held private writer key' './helper/test-nv-writer private-read'-test_expect_success 'root cannot ask the kernel-held NV writer to sign' '+test_expect_success 'root cannot sign while the trusted NV writer remains live' '+ before=$(writer_chain) &&+ "$SHIRUDO_BIN" upatch load "$LOAD" --no-precheck &&+ [ -e "$PIN" ] &&+ loaded=$(writer_chain) &&+ [ "$loaded" != "$before" ] &&./helper/test-nv-writer sign &&- ./helper/test-nv-writer sign-shared+ ./helper/test-nv-writer sign-shared &&+ [ "$(writer_chain)" = "$loaded" ] &&+ "$SHIRUDO_BIN" upatch unload "$UNLOAD" --no-precheck &&+ [ ! -e "$PIN" ] &&+ after=$(writer_chain) &&+ [ "$after" != "$loaded" ]'test_expect_success 'root cannot update, revoke or invalidate the NV signing key' '