Skip to content

eBPF-based security platform

bpf: test protection of archived upatches from replacement

John Fastabend25b7199e2169
diff --git a/testing/tamperproof/t1101-seal.sh b/testing/tamperproof/t1101-seal.sh
index cf972953..5987f3d2 100644
--- a/testing/tamperproof/t1101-seal.sh
+++ b/testing/tamperproof/t1101-seal.sh
@@ -11,8 +11,15 @@ cd "$(dirname "$0")/.."
target_guard
CERT=/var/lib/shirudo/keys/cert.der
+ARCHIVE=/var/lib/shirudo/upatches/shirudo-test-basic.upatch
+FIXTURES=$SHIRUDO_TEST_FIXTURES_DIR
[ -e "$CERT" ] || test_skip_all "no cert at $CERT"
+[ -s "$ARCHIVE" ] || test_skip_all "no archived basic upatch"
before=$(sha256sum "$CERT" | cut -d' ' -f1)
+archive_before=$(sha256sum "$ARCHIVE" | cut -d' ' -f1)
+WORK=$(mktemp -d)
+replacement=/var/lib/shirudo/upatches/.t1101-replacement.$$
+trap 'rm -f "$replacement"; rm -rf "$WORK"' EXIT
test_expect_success 'seal denies a non-shirudo write to a labelled file' '
! dd if=/dev/zero of=/var/lib/shirudo/keys/cert.der bs=1 count=1 \
@@ -25,4 +32,20 @@ test_expect_success 'seal denies a non-shirudo setxattr on a labelled file' '
/var/lib/shirudo/keys/cert.der 2>/dev/null
'
+test_expect_success 'seal denies changes to an archived upatch' '
+ ! dd if=/dev/zero of="$ARCHIVE" bs=1 count=1 conv=notrunc 2>/dev/null &&
+ ! python3 -c "import os,sys; os.setxattr(sys.argv[1], \\"user.sealprobe\\", b\\"x\\")" \
+ "$ARCHIVE" 2>/dev/null &&
+ ! python3 -c "import os,sys; os.removexattr(sys.argv[1], \\"security.bpf.shirudo\\")" \
+ "$ARCHIVE" 2>/dev/null &&
+ [ "$(sha256sum "$ARCHIVE" | cut -d" " -f1)" = "$archive_before" ]
+'
+test_expect_success 'seal denies unlink, rename-away, and replacement of an archived upatch' '
+ cp "$ARCHIVE" "$replacement" &&
+ ! rm "$ARCHIVE" 2>/dev/null &&
+ ! mv "$ARCHIVE" "$WORK/moved.upatch" 2>/dev/null &&
+ ! python3 -c "import os,sys; os.replace(sys.argv[1],sys.argv[2])" \
+ "$replacement" "$ARCHIVE" 2>/dev/null &&
+ [ "$(sha256sum "$ARCHIVE" | cut -d" " -f1)" = "$archive_before" ]
+'
test_done