interplane.Get Omega
Read in your language

physics-mv

FORGE: request-bound machine realization, providers and verification for AienOS. Host, simulated and GB10 hardware paths have separate evidence.

Brought by drakestapleton

branch main Branches Tags History

physics-mv / tests / test_m2_host_security.sh

74 lines · 3330 bytes Raw Blame History
1#!/bin/sh
2# Offline M2 host-verifier tests; no GPU, QEMU, receipt or historical edits.
3set -eu
4ROOT=$(cd "$(dirname "$0")/.." && pwd -P)
5T=$(mktemp -d "${TMPDIR:-/tmp}/physics-host-security.XXXXXXXX")
6trap 'rm -rf "$T"' EXIT
7trap '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"
11export ASAN_OPTIONS=detect_leaks=0
12
13audit() {
14 "$T/m2tool" audit-verify "$ROOT/physics.bin" "$ROOT/physics.sha256" \
15 "$ROOT/physics.manifest" "$ROOT/machine_contract.json" "$ROOT/physics.audit" "$1"
16}
17audit "$ROOT/physics.decode" > "$T/golden.log"
18sed 's/ldr[[:space:]]x10, 40200280/ldr\tx10, fffffffffffffffc/' \
19 "$ROOT/physics.decode" > "$T/bad.decode"
20grep -q fffffffffffffffc "$T/bad.decode"
21if audit "$T/bad.decode" > "$T/bad.log" 2>&1; then
22 echo 'unexpected PASS: wrapping literal address' >&2; exit 1
23fi
24grep -q 'FAIL: SP literal' "$T/bad.log"
25if grep -q AddressSanitizer "$T/bad.log"; then
26 echo 'sanitizer abort: literal address' >&2; exit 1
27fi
28
29aarch64-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"
31grep -q '^0x' "$T/symbol.log"
32marker="$T/shell-marker"
33if "$T/m2tool" get-symbol "missing; touch $marker; #" _physics_entry > "$T/injection.log" 2>&1; then
34 echo 'unexpected PASS: nonexistent object' >&2; exit 1
35fi
36[ ! -e "$marker" ] || { echo 'shell interpreted object path' >&2; exit 1; }
37
38mkdir "$T/public"
39chmod 777 "$T/public"
40if 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
43fi
44grep -q 'output directory is not private' "$T/inspect.log"
45ln -s "$T/public" "$T/symlink"
46if 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
49fi
50grep -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.
56for 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
58done
59n=0
60while 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
72done < "$ROOT/evidence/m16-requalification/SHA256SUMS"
73[ "$n" -eq 8 ] || { echo "historical path count changed: $n" >&2; exit 1; }
74printf 'PHYSICS-HOST-SECURITY PASS (sanitizer bounds, argv, private output refusal, M16 provenance)\n'