interplane.Get Omega
Read in your language

atlas

aien-dev/atlas

Brought by drakestapleton

branch master Branches Tags History

atlas / scripts / test-host-security.sh

80 lines · 3218 bytes Raw Blame History
1#!/bin/sh
2# Offline host-only controls for m1tool and the KAT gate. No QEMU or receipt writes.
3set -eu
4ROOT=$(cd "$(dirname "$0")/.." && pwd -P)
5T=$(mktemp -d "${TMPDIR:-/tmp}/atlas-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/m1tool" "$ROOT/tools/m1tool.c" "$ROOT/sha256_clean.c"
11export ASAN_OPTIONS=detect_leaks=0
12
13audit() {
14 "$T/m1tool" audit-verify "$ROOT/atlas.bin" "$ROOT/atlas.sha256" \
15 "$ROOT/atlas.manifest" "$ROOT/machine_contract.json" "$ROOT/atlas.audit" "$1"
16}
17audit "$ROOT/atlas.decode" > "$T/golden.log"
18for operand in 'x19, 160' 'x0, 138'; do
19 case $operand in x19*) f=target ;; *) f=stack ;; esac
20 sed "s/ldr[[:space:]]$operand/ldr\t${operand%%,*}, fffffffffffffffc/" \
21 "$ROOT/atlas.decode" > "$T/$f.decode"
22 grep -q fffffffffffffffc "$T/$f.decode"
23 if audit "$T/$f.decode" > "$T/$f.log" 2>&1; then
24 echo "unexpected PASS: malformed $f offset" >&2; exit 1
25 fi
26 grep -q 'FAIL:' "$T/$f.log"
27 if grep -q AddressSanitizer "$T/$f.log"; then
28 echo "sanitizer abort: $f offset" >&2; exit 1
29 fi
30done
31marker="$T/shell-marker"
32if "$T/m1tool" gen-audit "$ROOT/atlas.bin" \
33 "missing; touch $marker; #" "$T/audit" "$T/decode" > "$T/injection.log" 2>&1; then
34 echo 'unexpected PASS: nonexistent ELF' >&2; exit 1
35fi
36[ ! -e "$marker" ] || { echo 'shell interpreted artifact path' >&2; exit 1; }
37
38# A deterministic inert QEMU stand-in exercises the complete mutation path
39# without asserting anything about an actual emulated boot.
40cat > "$T/qemu-system-aarch64" <<'EOF'
41#!/bin/sh
42case "$*" in
43 *atlas_sweep_*) echo 'ATLAS: REFUSE' ;;
44 *) echo 'ATLAS: HANDOFF'; echo 'PHYSICS-0: AUTHORIZED' ;;
45esac
46EOF
47chmod 700 "$T/qemu-system-aarch64"
48printf KEEP_ME > "$T/victim"
49PATH="$T:$PATH" sh -c '
50 printf "%s" "$$" > "$5"
51 ln -s "$1" "/tmp/atlas_sweep_$$.bin"
52 exec "$2" qemu-matrix "$3" "$4"
53' sh "$T/victim" "$T/m1tool" "$ROOT/atlas.bin" "$ROOT/physics-0.bin" "$T/pid" > "$T/matrix.log"
54rm -f "/tmp/atlas_sweep_$(cat "$T/pid").bin"
55[ "$(cat "$T/victim")" = KEEP_ME ] || { echo 'predictable temp clobbered victim' >&2; exit 1; }
56grep -q 'SEAM 2 RESULTS: ALL EXECUTION GATES PASSED' "$T/matrix.log"
57
58# Replace only the freshly built ignored KAT executable with a failing
59# surrogate; the runner must stop before printing any gate PASS summary.
60REAL_CC=$(command -v gcc)
61export REAL_CC ROOT
62cat > "$T/gcc" <<'EOF'
63#!/bin/sh
64"$REAL_CC" "$@" || exit $?
65case " $* " in
66 *test_sha256_kat*) printf '#!/bin/sh\necho "[PASS] misleading KAT output"\nexit 17\n' > "$ROOT/test_sha256_kat"; chmod 700 "$ROOT/test_sha256_kat" ;;
67esac
68EOF
69chmod 700 "$T/gcc"
70if PATH="$T:$PATH" "$ROOT/run_m1_gates.sh" > "$T/kat.log" 2>&1; then
71 echo 'unexpected PASS: failed SHA-256 KAT' >&2; exit 1
72else
73 rc=$?
74fi
75[ "$rc" -eq 17 ] || { echo "wrong KAT refusal status: $rc" >&2; exit 1; }
76grep -q 'known-answer test exited 17' "$T/kat.log"
77if grep -q 'Overall Result: MILESTONE 1 QUALIFIED' "$T/kat.log"; then
78 echo 'qualification summary printed after KAT failure' >&2; exit 1
79fi
80printf 'ATLAS-HOST-SECURITY PASS (sanitizer bounds, argv, private temp, failed KAT)\n'