Skip to content

eBPF-based security platform

testing: verify init refuses a foreign state root

Daniel Borkmann638cb538a3dc
diff --git a/testing/run-target-tests.sh b/testing/run-target-tests.sh
index dcdb5c20..ab1ac716 100755
--- a/testing/run-target-tests.sh
+++ b/testing/run-target-tests.sh
@@ -78,6 +78,7 @@ for t in \
tamperproof/t1160-umount-above.sh \
tamperproof/t1161-bpffs-entries.sh \
tamperproof/t1162-persist-undo.sh \
+ tamperproof/t1163-foreign-state-root.sh \
tamperproof/t1150-verity-devices.sh \
tamperproof/t1151-verity-process.sh \
tamperproof/t1153-verity-hidden.sh \
diff --git a/testing/tamperproof/t1142-archive-restore.sh b/testing/tamperproof/t1142-archive-restore.sh
index 60d151af..26051225 100755
--- a/testing/tamperproof/t1142-archive-restore.sh
+++ b/testing/tamperproof/t1142-archive-restore.sh
@@ -100,8 +100,8 @@ test_expect_success 'the foreign entry is root'"'"'s to remove' '
[ "$(chain)" = "$CHAIN" ]
'
-# A copy of the state less its eventlog, bound over the real one: the
-# register says the restore happened whatever the log says.
+# A copy of the state less its eventlog, bound over the real one: it
+# carries no label, so init refuses it before reading its archive.
test_expect_success 'a state directory hidden behind a mount without its eventlog restores nothing' '
mkdir -p "$STAGE/shadow" && mount -t tmpfs tmpfs "$STAGE/shadow" &&
cp -r --preserve=mode,timestamps /var/lib/shirudo/. "$STAGE/shadow/" &&
@@ -111,7 +111,7 @@ test_expect_success 'a state directory hidden behind a mount without its eventlo
rc=0; "$SHIRUDO_BIN" init >/dev/null 2>"$STAGE/shadow.err" || rc=$?;
umount /var/lib/shirudo &&
[ "$rc" != 0 ] &&
- grep -q "archived but not loaded after the register was bound" \
+ grep -q "carries no label with enforcement live" \
"$STAGE/shadow.err" &&
[ ! -e "$PIN" ] &&
[ "$(chain)" = "$CHAIN" ]
diff --git a/testing/tamperproof/t1163-foreign-state-root.sh b/testing/tamperproof/t1163-foreign-state-root.sh
new file mode 100755
index 00000000..11c839ab
--- /dev/null
+++ b/testing/tamperproof/t1163-foreign-state-root.sh
@@ -0,0 +1,49 @@
+#!/bin/sh
+# SPDX-License-Identifier: BSD-2-Clause
+# Copyright (c) 2026 Authors of shirudo
+#
+# t1163 -- init labels the state tree on the run that brings enforcement
+# up, and the label is what the seal takes for shirudo's own. A tree of
+# root's bound over /var/lib/shirudo in a mount namespace of root's own
+# carries no label, and a re-run of init there took it for a first run
+# and labelled root's files, which the eviction gap then lets root bring
+# into sealed state as shirudo's. With enforcement live, init must refuse
+# such a tree and label nothing in it; the real tree stays as it was.
+
+cd "$(dirname "$0")/.."
+. ./integration-lib.sh
+target_guard
+command -v python3 >/dev/null 2>&1 || test_skip_all "no python3"
+command -v unshare >/dev/null 2>&1 || test_skip_all "no unshare"
+FIXTURES=${SHIRUDO_TEST_FIXTURES_DIR:?target fixture directory is not set}
+FIXTURE="$FIXTURES/shirudo-test-marker.upatch"
+[ -s "$FIXTURE" ] || test_skip_all "missing marker fixture"
+W=/tmp/t1163
+rm -rf "$W"
+mkdir -p "$W/upatches"
+cp "$FIXTURE" "$W/upatches/t1163.upatch"
+cp /var/lib/shirudo/eventlog "$W/eventlog" 2>/dev/null || true
+trap 'rm -rf "$W"' EXIT
+
+labelled() {
+ python3 -c "import os,sys
+try:
+ os.getxattr(sys.argv[1], \"security.bpf.shirudo\", follow_symlinks=False)
+except OSError:
+ sys.exit(1)" "$1"
+}
+
+test_expect_success 'init refuses a state root bound over the path without the label' '
+ ! unshare -m sh -c "mount --bind $W /var/lib/shirudo && $SHIRUDO_BIN init" \
+ >/dev/null 2>&1 &&
+ ! labelled "$W" &&
+ ! labelled "$W/upatches" &&
+ ! labelled "$W/upatches/t1163.upatch"
+'
+
+test_expect_success 'init still completes on the sealed tree' '
+ "$SHIRUDO_BIN" init >/dev/null 2>&1 &&
+ labelled /var/lib/shirudo
+'
+
+test_done