physics-mv
FORGE: request-bound machine realization, providers and verification for AienOS. Host, simulated and GB10 hardware paths have separate evidence.
Brought by drakestapleton
physics-mv / tests / test_m2_host_security.sh
| 1 | #!/bin/sh |
| 2 | # Offline M2 host-verifier tests; no GPU, QEMU, receipt or historical edits. |
| 3 | set -eu |
| 4 | ROOT=$(cd "$(dirname "$0")/.." && pwd -P) |
| 5 | T=$(mktemp -d "${TMPDIR:-/tmp}/physics-host-security.XXXXXXXX") |
| 6 | trap 'rm -rf "$T"' EXIT |
| 7 | trap 'exit 1' INT TERM |
| 8 | : "${CC:=gcc}" |
| 9 | "$CC" -O1 -g -fsanitize=address,undefined -fno-omit-frame-pointer -std=c11 -Wall -Wextra -Werror \ |
| 10 | -o "$T/m2tool" "$ROOT/tools/m2tool.c" "$ROOT/sha256_clean.c" |
| 11 | export ASAN_OPTIONS=detect_leaks=0 |
| 12 | |
| 13 | audit() { |
| 14 | "$T/m2tool" audit-verify "$ROOT/physics.bin" "$ROOT/physics.sha256" \ |
| 15 | "$ROOT/physics.manifest" "$ROOT/machine_contract.json" "$ROOT/physics.audit" "$1" |
| 16 | } |
| 17 | audit "$ROOT/physics.decode" > "$T/golden.log" |
| 18 | sed 's/ldr[[:space:]]x10, 40200280/ldr\tx10, fffffffffffffffc/' \ |
| 19 | "$ROOT/physics.decode" > "$T/bad.decode" |
| 20 | grep -q fffffffffffffffc "$T/bad.decode" |
| 21 | if audit "$T/bad.decode" > "$T/bad.log" 2>&1; then |
| 22 | echo 'unexpected PASS: wrapping literal address' >&2; exit 1 |
| 23 | fi |
| 24 | grep -q 'FAIL: SP literal' "$T/bad.log" |
| 25 | if grep -q AddressSanitizer "$T/bad.log"; then |
| 26 | echo 'sanitizer abort: literal address' >&2; exit 1 |
| 27 | fi |
| 28 | |
| 29 | aarch64-linux-gnu-gcc -c -nostdlib "$ROOT/physics.s" -o "$T/physics.o" |
| 30 | "$T/m2tool" get-symbol "$T/physics.o" _physics_entry > "$T/symbol.log" |
| 31 | grep -q '^0x' "$T/symbol.log" |
| 32 | marker="$T/shell-marker" |
| 33 | if "$T/m2tool" get-symbol "missing; touch $marker; #" _physics_entry > "$T/injection.log" 2>&1; then |
| 34 | echo 'unexpected PASS: nonexistent object' >&2; exit 1 |
| 35 | fi |
| 36 | [ ! -e "$marker" ] || { echo 'shell interpreted object path' >&2; exit 1; } |
| 37 | |
| 38 | mkdir "$T/public" |
| 39 | chmod 777 "$T/public" |
| 40 | if QEMU=/bin/true "$ROOT/tools/qemu_inspect.sh" --out "$T/public" --marker READY \ |
| 41 | > "$T/inspect.log" 2>&1; then |
| 42 | echo 'inspector accepted publicly writable output' >&2; exit 1 |
| 43 | fi |
| 44 | grep -q 'output directory is not private' "$T/inspect.log" |
| 45 | ln -s "$T/public" "$T/symlink" |
| 46 | if QEMU=/bin/true "$ROOT/tools/qemu_inspect.sh" --out "$T/symlink" --marker READY \ |
| 47 | > "$T/symlink.log" 2>&1; then |
| 48 | echo 'inspector accepted output symlink' >&2; exit 1 |
| 49 | fi |
| 50 | grep -q 'output directory must not be a symlink' "$T/symlink.log" |
| 51 | |
| 52 | # The historical checksum file stays immutable; each absolute path resolves |
| 53 | # against the original source or receipt commit, not today's working tree. |
| 54 | # a2c0d7f is not on any branch, so a default clone lacks it: fetch it by sha. |
| 55 | # A pin that still cannot be read fails below as a digest mismatch. |
| 56 | for pin in a2c0d7fbc03f7ce91fcb6389312a0ee8630322cd b64753d95bacb1114ba48decde48239f0c542e12; do |
| 57 | git -C "$ROOT" cat-file -e "$pin^{commit}" 2>/dev/null || git -C "$ROOT" fetch -q origin "$pin" || true |
| 58 | done |
| 59 | n=0 |
| 60 | while read -r digest historical; do |
| 61 | case $historical in |
| 62 | /home/*/workspace/m17-physics/*) |
| 63 | relative=${historical#*/workspace/m17-physics/} |
| 64 | case $relative in |
| 65 | evidence/*) pin=b64753d95bacb1114ba48decde48239f0c542e12 ;; |
| 66 | *) pin=a2c0d7fbc03f7ce91fcb6389312a0ee8630322cd ;; |
| 67 | esac |
| 68 | actual=$(git -C "$ROOT" show "$pin:$relative" | sha256sum) |
| 69 | [ "${actual%% *}" = "$digest" ] || { echo "historical digest mismatch: $relative" >&2; exit 1; } |
| 70 | n=$((n + 1)) ;; |
| 71 | esac |
| 72 | done < "$ROOT/evidence/m16-requalification/SHA256SUMS" |
| 73 | [ "$n" -eq 8 ] || { echo "historical path count changed: $n" >&2; exit 1; } |
| 74 | printf 'PHYSICS-HOST-SECURITY PASS (sanitizer bounds, argv, private output refusal, M16 provenance)\n' |