Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/patches/34ee50a873b50962 # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers ## GitHub aien-dev/aienux#213 (code only) closed derived `34ee50a873b50962` #213 Imported from GitHub aien-dev/aienux#213 (code only) GitHub's metadata for this pull request is unavailable: its state is DERIVED from the commits (merged: the head is reachable from this project's main; open: GitHub kept a merge ref; else closed). Base `33927b1fb8a67eb9f2758b19add337f1c2a18bdb` · Head `11d4df608dbdf713e6aa545027c47e63051d6e65` ### Apply it ``` git checkout -b patch-34ee50a873b50962 33927b1fb8a67eb9f2758b19add337f1c2a18bdb curl -fsSL https://interplane.io/drakestapleton/aienux/patches/34ee50a873b50962.patch | git am ``` Raw patch (mbox) · Diff ### Provenance This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record: ``` github-import 1 aien-dev/aienux 213 11d4df608dbdf713e6aa545027c47e63051d6e65 ``` ``` {"kind":"github-import","owner":"aien-dev","repo":"aienux","number":213,"url":"https://github.com/aien-dev/aienux/pull/213","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:35:58Z","metadata":"unavailable","state_derived":true} ``` ### Changes ``` diff --git a/.github/workflows/native-suites.yml b/.github/workflows/native-suites.yml index 952baf87..f5aa1872 100644 --- a/.github/workflows/native-suites.yml +++ b/.github/workflows/native-suites.yml @@ -2,7 +2,8 @@ # only compiled these into the kernel image; nothing ran their own tests. # # Coverage map (what runs where): -# native/capability test, mutants ci.yml (test), not repeated here +# native/capability test ci.yml +# native/capability mutants this file # native/store test mutants ci.yml # native/kernel test sanitize + gates ck-kernel.yml (owned by another lane) # native/net test sanitize mutants this file @@ -51,6 +52,7 @@ jobs: - { suite: m5, targets: "test sanitize mutants" } - { suite: disk, targets: "test sanitize mutants" } - { suite: argus, targets: "test sanitize" } + - { suite: capability, targets: "mutants" } steps: - name: Checkout repository uses: actions/checkout@v4 @@ -77,6 +79,7 @@ jobs: m5) req='M5_NATIVE: PASS|M5_NATIVE_MUTANTS: PASS' ;; disk) req='AIENOS_DISK_NATIVE: PASS|AIENOS_DISK_SANITIZE: PASS|AIENOS_DISK_MUTANTS: PASS' ;; argus) req='GATE CONTAIN_TEST PASS|GATE CONTAIN_DETERMINISM PASS' ;; + capability) req='AIENOS_CAP_MUTANTS: PASS' ;; esac for m in $(echo "$req" | tr '|' '\n' | sed 's/ /@/g'); do m="${m//@/ }" diff --git a/native/capability/Makefile b/native/capability/Makefile index 098dabcb..5dae6300 100644 --- a/native/capability/Makefile +++ b/native/capability/Makefile @@ -3,6 +3,8 @@ # # make build out/libaienos_capability.a # make test build and run the rule tests (SEED=n picks the random-op seed) +# make mutants plant 17 known bugs one at a time; the existing tests must +# catch every one (see the table near the end of this file) # make clean CC ?= cc @@ -85,3 +87,75 @@ else endif .PHONY: test-contain contain-checks sanitize + +# ---- Mutation check: `make mutants` ------------------------------------------- +# Each line below plants one realistic bug (a dropped or weakened check) in a +# copy of the source, rebuilds the existing tests against that copy, and runs +# them. The existing tests must catch every bug ("killed"). A bug the tests +# miss ("SURVIVED"), a mutation whose target text is no longer in the source +# ("did not apply"), or a copy that will not compile all count as FAIL, so a +# source edit that moves the target text cannot silently turn this green. +# The sources themselves are never edited; mutated copies live in $(OUT)/mut/. +# +# Format: name|file|which match (1 = first line containing the text)|text|replacement +define CAP_MUTANTS +inspect_stale_generation|aienos_capability.c|1|e->generation != cap.generation) return AIENOS_CAP_ERR_STALE_GEN|0) return AIENOS_CAP_ERR_STALE_GEN +validate_stale_generation|aienos_capability.c|2|e->generation != cap.generation) return AIENOS_CAP_ERR_STALE_GEN|0) return AIENOS_CAP_ERR_STALE_GEN +validate_revoked|aienos_capability.c|1|e->state != AIENOS_CAP_STATE_LIVE) return AIENOS_CAP_ERR_REVOKED|0) return AIENOS_CAP_ERR_REVOKED +validate_epoch|aienos_capability.c|1|e->epoch != s->epoch) return AIENOS_CAP_ERR_EPOCH|0) return AIENOS_CAP_ERR_EPOCH +validate_parent_live|aienos_capability.c|1|parent->state != AIENOS_CAP_STATE_LIVE) return AIENOS_CAP_ERR_CHAIN|0) return AIENOS_CAP_ERR_CHAIN +validate_subject|aienos_capability.c|1|e->subject != subject|0 +validate_partial_rights|aienos_capability.c|1|(e->rights & rights) != rights|(e->rights & rights) == 0 +lease_expiry_off_by_one|aienos_capability.c|1|s->clock >= e->lease_expiry|s->clock > e->lease_expiry +mint_amplify|aienos_capability.c|1|r->rights & ~auth->rights) return AIENOS_CAP_ERR_AMPLIFY|0) return AIENOS_CAP_ERR_AMPLIFY +mint_child_outlives_lease|aienos_capability.c|1|child > auth->lease_expiry|0 +mint_depth_limit|aienos_capability.c|1|ancestor_hops(s, r->parent.cap_id) >= AIENOS_CAP_MAX_DEPTH|0 +revoke_no_cascade|aienos_capability.c|1|parent->state == AIENOS_CAP_STATE_REVOKED|0 +generation_not_advanced|aienos_capability.c|1|*out = generation + 1|*out = generation +authorize_epoch|aienos_capability.c|2|e->epoch != s->epoch) return AIENOS_CAP_ERR_EPOCH|0) return AIENOS_CAP_ERR_EPOCH +contain_subject_mismatch|aienos_contain.c|1|e.subject != r->principal|0 +contain_not_leaf|aienos_contain.c|1|has_live_child(g, r->target.cap_id, r->target.generation)|0 +contain_protected_subject|aienos_contain.c|1|if (is_protected_subject(r->principal)) return true|if (0) return true +endef + +MUT_DIR = $(OUT)/mut +# The mutant table lives outside MUT_DIR. GNU make expands every recipe line, +# including $(file ...), before the first shell line runs, so the table must +# target a directory that already exists ($(OUT), an order-only prerequisite) +# and must not sit inside the directory the recipe's first line wipes. +MUT_TABLE = $(OUT)/mutants.table +MUT_TIMEOUT ?= 300 + +mutants: $(TEST) $(CONTAIN_TEST) | $(OUT) + @rm -rf $(MUT_DIR); mkdir -p $(MUT_DIR) + $(file >$(MUT_TABLE),$(CAP_MUTANTS)) + @ulimit -c 0; \ + if ./$(TEST) > $(MUT_DIR)/baseline.log 2>&1 && ./$(CONTAIN_TEST) >> $(MUT_DIR)/baseline.log 2>&1; then \ + echo "baseline (no mutation): tests pass"; \ + else echo "baseline (no mutation): tests FAIL, mutants are meaningless"; \ + echo "---- baseline log ($(MUT_DIR)/baseline.log) ----"; cat $(MUT_DIR)/baseline.log; echo "---- end baseline log ----"; \ + echo "AIENOS_CAP_MUTANTS: FAIL"; exit 1; fi; \ + n=0; killed=0; fail=0; \ + while IFS='|' read -r name file k from to; do \ + [ -n "$$name" ] || continue; n=$$((n+1)); d=$(MUT_DIR)/$$name; mkdir -p $$d; \ + if ! awk -v k="$$k" -v from="$$from" -v to="$$to" \ + 'index($$0, from) { c++; if (c == k) { i = index($$0, from); $$0 = substr($$0, 1, i - 1) to substr($$0, i + length(from)); hit = 1 } } { print } END { exit hit ? 0 : 3 }' \ + $$file > $$d/$$file; then \ + echo "mutant $$name: did not apply, text not found in $$file (FAIL)"; fail=1; continue; fi; \ + if cmp -s $$file $$d/$$file; then echo "mutant $$name: no change (FAIL)"; fail=1; continue; fi; \ + if [ $$file = aienos_capability.c ]; then capsrc=$$d/aienos_capability.c; gatesrc=aienos_contain.c; \ + else capsrc=aienos_capability.c; gatesrc=$$d/aienos_contain.c; fi; \ + if ! $(CC) $(CFLAGS) -Wno-error -I. -pthread -o $$d/capability_test tests/capability_test.c $$capsrc > $$d/build.log 2>&1 || \ + ! $(CC) $(CFLAGS) -Wno-error -I. -pthread -o $$d/contain_test tests/contain_test.c $$gatesrc $$capsrc >> $$d/build.log 2>&1; then \ + echo "mutant $$name: does not compile (FAIL, see $$d/build.log)"; fail=1; continue; fi; \ + by=""; \ + timeout $(MUT_TIMEOUT) $$d/capability_test > $$d/run.log 2>&1 || by="capability_test"; \ + timeout $(MUT_TIMEOUT) $$d/contain_test >> $$d/run.log 2>&1 || by="$${by:+$$by+}contain_test"; \ + if [ -n "$$by" ]; then echo "mutant $$name: killed by $$by"; killed=$$((killed+1)); \ + else echo "mutant $$name: SURVIVED (FAIL)"; fail=1; fi; \ + done < $(MUT_TABLE); \ + if [ $$n -lt 8 ]; then echo "only $$n mutants defined, need at least 8"; fail=1; fi; \ + if [ $$fail -eq 0 ] && [ $$killed -eq $$n ]; then echo "AIENOS_CAP_MUTANTS: PASS ($$killed/$$n killed)"; \ + else echo "AIENOS_CAP_MUTANTS: FAIL ($$killed/$$n killed)"; exit 1; fi + +.PHONY: mutants diff --git a/native/capability/tests/capability_test.c b/native/capability/tests/capability_test.c index a55d98f1..4e2f06a9 100644 --- a/native/capability/tests/capability_test.c +++ b/native/capability/tests/capability_test.c @@ -6,6 +6,8 @@ */ #include "../aienos_capability.h" +#include +#include #include #include #include @@ -24,6 +26,21 @@ static int checks; #define EQ(a, b) CHECK((a) == (b)) +/* Entries are compared field by field, never with memcmp. AienosCapEntry + * has padding (after cap_id, parent_id and minted_by_id), and a struct copy + * such as `*out = *e` need not copy padding bytes, so memcmp can see stack + * garbage in the padding of two equal entries. How a compiler copies differs + * by target (the suspected cause of the x86-64 CI baseline failure). */ +static int same_entry(const AienosCapEntry *x, const AienosCapEntry *y) { + return x->cap_id == y->cap_id && x->generation == y->generation && x->state == y->state && + x->issuer == y->issuer && x->subject == y->subject && x->rights == y->rights && + x->resource == y->resource && x->epoch == y->epoch && + x->lease_expiry == y->lease_expiry && x->parent_id == y->parent_id && + x->parent_generation == y->parent_generation && + x->minted_by_id == y->minted_by_id && + x->minted_by_generation == y->minted_by_generation; +} + static const AienosCapRef NONE = {AIENOS_CAP_PARENT_NONE, 0}; typedef struct { @@ -340,7 +357,7 @@ static int matches_view(Auth *a, const Rec *r) { AienosCapEntry now; AienosCapRef ref = {r->entry.cap_id, r->entry.generation}; if (aienos_cap_inspect(a->view, ref, &now) != AIENOS_CAP_OK) return 0; - return memcmp(&now, &r->entry, sizeof now) == 0; + return same_entry(&now, &r->entry); } static void observer_sees_each_admin_operation_once(void) { @@ -621,7 +638,7 @@ static int shadow_matches(Auth *a, const Shadow *sh) { } /* The epoch and clock move without touching entries; the entry * itself must be exactly what the shadow holds. */ - if (rc != AIENOS_CAP_OK || memcmp(&now, &sh->e[i], sizeof now) != 0) return 0; + if (rc != AIENOS_CAP_OK || !same_entry(&now, &sh->e[i])) return 0; } return 1; } @@ -664,6 +681,101 @@ static void observer_shadow_matches_table_under_random_operations(uint64_t base_ } } + +/* Rights are a superset check: a reference holding READ must not pass a + * request for READ|WRITE. Kills mutant validate_partial_rights (any-overlap + * instead of all-of). */ +static void validate_needs_every_requested_right(void) { + Auth a = boot(); + AienosCapRef cap; + EQ(root_mint(&a, 1, 0x60, AIENOS_CAP_RIGHT_READ | AIENOS_CAP_RIGHT_EFFECT, &cap), + AIENOS_CAP_OK); + EQ(validate(&a, cap, 1, 0x60, AIENOS_CAP_RIGHT_READ), AIENOS_CAP_OK); + EQ(validate(&a, cap, 1, 0x60, AIENOS_CAP_RIGHT_READ | AIENOS_CAP_RIGHT_EFFECT), AIENOS_CAP_OK); + EQ(validate(&a, cap, 1, 0x60, AIENOS_CAP_RIGHT_READ | AIENOS_CAP_RIGHT_WRITE), + AIENOS_CAP_ERR_RIGHTS); + EQ(validate(&a, cap, 1, 0x60, + AIENOS_CAP_RIGHT_READ | AIENOS_CAP_RIGHT_EFFECT | AIENOS_CAP_RIGHT_DELEGATE), + AIENOS_CAP_ERR_RIGHTS); + aienos_cap_stop(a.admin, a.view); +} + +/* A lease of n ticks is good for clock values below start+n and dead at + * exactly start+n. Kills mutant lease_expiry_off_by_one (> instead of >=). */ +static void lease_ends_exactly_at_expiry_tick(void) { + Auth a = boot(); + AienosCapRef leased; + AienosCapMint m = {3, 1, 0x70, AIENOS_CAP_RIGHT_READ, 5, NONE, office(&a)}; + EQ(aienos_cap_mint(a.admin, &m, &leased), AIENOS_CAP_OK); + EQ(aienos_cap_advance_clock(a.admin, office(&a), 4), AIENOS_CAP_OK); + EQ(validate(&a, leased, 1, 0x70, AIENOS_CAP_RIGHT_READ), AIENOS_CAP_OK); + EQ(aienos_cap_advance_clock(a.admin, office(&a), 1), AIENOS_CAP_OK); + EQ(aienos_cap_clock(a.view), 5u); + EQ(validate(&a, leased, 1, 0x70, AIENOS_CAP_RIGHT_READ), AIENOS_CAP_ERR_EXPIRED); + aienos_cap_stop(a.admin, a.view); +} + +/* Fault injection for the chain walk in validate. + * + * Through the public calls a live child of a non-live parent cannot exist: + * revoke cascades to every descendant, and reclaim and force_generation + * only touch non-live slots. So the "parent must be LIVE" step in validate + * is defense in depth, and only a corrupted table can reach it. This test + * corrupts the table on purpose: it flips the parent's state with no + * cascade and checks validate still refuses the child with CHAIN. + * + * It reaches the table through a mirror of the private layout in + * aienos_capability.c (CapShared/CapState). The mirror is checked against + * the public view before anything is written; any layout drift fails this + * test loudly instead of poking the wrong bytes. Kills mutant + * validate_parent_live. */ +typedef struct { + uint64_t boot_gen; + uint64_t epoch; + uint64_t clock; + AienosCapEntry entries[AIENOS_CAP_MAX]; + bool delivered[AIENOS_CAP_MAX]; + bool writer_alive; +} MirrorCapState; + +typedef struct { + pthread_mutex_t state_lock; + MirrorCapState state; +} MirrorCapShared; + +static void validate_refuses_child_of_non_live_parent_in_corrupt_table(void) { + Auth a = boot(); + AienosCapRef parent, child; + AienosCapEntry pe, ce, oe; + EQ(root_mint(&a, 1, 0x80, AIENOS_CAP_RIGHT_READ | AIENOS_CAP_RIGHT_DELEGATE, &parent), + AIENOS_CAP_OK); + EQ(child_mint(&a, parent, 1, 2, 0x80, AIENOS_CAP_RIGHT_READ, &child), AIENOS_CAP_OK); + EQ(validate(&a, child, 2, 0x80, AIENOS_CAP_RIGHT_READ), AIENOS_CAP_OK); + EQ(aienos_cap_inspect(a.view, parent, &pe), AIENOS_CAP_OK); + EQ(aienos_cap_inspect(a.view, child, &ce), AIENOS_CAP_OK); + EQ(aienos_cap_inspect(a.view, office(&a), &oe), AIENOS_CAP_OK); + + MirrorCapShared *sh = *(MirrorCapShared *const *)a.admin; + int layout_ok = sh != NULL && sh->state.epoch == 1 && sh->state.clock == 0 && + sh->state.writer_alive && sh->state.delivered[child.cap_id] && + same_entry(&sh->state.entries[0], &oe) && + same_entry(&sh->state.entries[parent.cap_id], &pe) && + same_entry(&sh->state.entries[child.cap_id], &ce); + CHECK(layout_ok); + if (layout_ok) { + AienosCapEntry *p = &sh->state.entries[parent.cap_id]; + p->state = AIENOS_CAP_STATE_REVOKED; /* no cascade: child stays LIVE */ + EQ(aienos_cap_inspect(a.view, child, &ce), AIENOS_CAP_OK); + EQ(ce.state, AIENOS_CAP_STATE_LIVE); + EQ(validate(&a, child, 2, 0x80, AIENOS_CAP_RIGHT_READ), AIENOS_CAP_ERR_CHAIN); + p->state = AIENOS_CAP_STATE_FREE; + EQ(validate(&a, child, 2, 0x80, AIENOS_CAP_RIGHT_READ), AIENOS_CAP_ERR_CHAIN); + p->state = AIENOS_CAP_STATE_LIVE; + EQ(validate(&a, child, 2, 0x80, AIENOS_CAP_RIGHT_READ), AIENOS_CAP_OK); + } + aienos_cap_stop(a.admin, a.view); +} + int main(int argc, char **argv) { uint64_t base_seed = argc > 1 ? strtoull(argv[1], NULL, 0) : 0x5eedull; high_half_resource_is_kept(); @@ -679,6 +791,9 @@ int main(int argc, char **argv) { generation_above_32_bits_is_kept(); ordinary_capability_cannot_administer_and_depth_stops(); table_fills_then_refuses(); + validate_needs_every_requested_right(); + lease_ends_exactly_at_expiry_tick(); + validate_refuses_child_of_non_live_parent_in_corrupt_table(); observer_sees_each_admin_operation_once(); observer_sees_cascade_ancestor_first(); observer_sees_refusals_with_their_code(); diff --git a/scripts/capture_gate1_receipt.sh b/scripts/capture_gate1_receipt.sh index 1ae1312d..1480627a 100755 --- a/scripts/capture_gate1_receipt.sh +++ b/scripts/capture_gate1_receipt.sh @@ -1,76 +1,203 @@ #!/usr/bin/env bash -# capture_gate1_receipt.sh: Capture Gate 1 standalone recovery evidence receipt -# Invariant: NO PLAINTEXT SECRETS IN REPOSITORY OR BUILD ARTIFACTS. Unslop compliant. +# capture_gate1_receipt.sh: write the TRUST-1 Gate 1 (standalone RAM recovery +# media) receipt from checks that actually ran. Nothing in the receipt is +# assumed: every field is either measured here or marked NOT_RUN. +# +# What it checks: +# host The recovery image (a gzip'd cpio archive) opens, has /init, and +# carries every recovery tool the build script packages. +# QEMU Only with --boot (boots THIS image in QEMU with zero disks attached +# and requires the image's own completion line) or --serial-log FILE +# (reads the console log of an earlier zero-disk boot; the receipt +# then says the log is not bound to this image's hash). +# hardware Never checked here. Internal NVMe unmounted and the ATLAS_RECOV +# stick protected are facts about Machine 1, so they stay NOT_RUN +# until the attended exercise records them. +# +# Usage: capture_gate1_receipt.sh [--boot | --serial-log FILE] +# Env: AIENOS_GATE1_INITRD image to check (default /tmp/aienos-recovery-standalone-initrd.img, +# built if missing) +# AIENOS_GATE1_OUT_DIR where the receipt goes (default evidence/); the +# file is named by its own sha256 and never overwritten +# AIENOS_GATE1_KERNEL kernel for --boot (default newest /boot/vmlinuz-*) +# Last line: GATE1_RECEIPT: PASS | FAIL | NOT_RUN . PASS needs host +# PASS, a bound QEMU boot (--boot) and a clean tree; anything less is NOT_RUN. +# Exit: 1 on FAIL, 2 on usage or setup errors, 0 otherwise (read the marker). +# Invariant: NO PLAINTEXT SECRETS IN REPOSITORY OR BUILD ARTIFACTS. set -euo pipefail REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" cd "${REPO_ROOT}" -RECEIPT_FILE="${REPO_ROOT}/evidence/gate1_zero_disk_recovery_receipt.json" -INITRD_IMG="/tmp/aienos-recovery-standalone-initrd.img" +mode="none" +serial_log="" +case "${1:-}" in + "") ;; + --boot) mode="boot" ;; + --serial-log) mode="log"; serial_log="${2:-}"; [[ -n "${serial_log}" ]] || { echo "usage: $0 [--boot | --serial-log FILE]" >&2; exit 2; } ;; + *) echo "usage: $0 [--boot | --serial-log FILE]" >&2; exit 2 ;; +esac -if [[ ! -f "${INITRD_IMG}" ]]; then +INITRD_IMG="${AIENOS_GATE1_INITRD:-/tmp/aienos-recovery-standalone-initrd.img}" +OUT_DIR="${AIENOS_GATE1_OUT_DIR:-${REPO_ROOT}/evidence}" +WORK_DIR=$(mktemp -d) +trap 'rm -rf "${WORK_DIR}"' EXIT + +json_str() { printf '"%s"' "$(printf '%s' "$1" | sed -e 's/\\/\\\\/g' -e 's/"/\\"/g')"; } + +# ---- Source identity ------------------------------------------------------- +commit="$(git rev-parse HEAD 2>/dev/null || echo unknown)" +if [[ "${commit}" == unknown ]]; then tree_dirty="unknown" +elif [[ -n "$(git status --porcelain 2>/dev/null)" ]]; then tree_dirty="true" +else tree_dirty="false"; fi + +# ---- Host checks on the image ---------------------------------------------- +if [[ ! -f "${INITRD_IMG}" && -z "${AIENOS_GATE1_INITRD:-}" ]]; then bash "${REPO_ROOT}/scripts/build_standalone_recovery_initrd.sh" "${INITRD_IMG}" fi -INITRD_SHA256=$(sha256sum "${INITRD_IMG}" | awk '{print $1}') -INITRD_SIZE=$(stat -c%s "${INITRD_IMG}") -PROD_VMLINUZ=$(ls -1t /boot/vmlinuz-* 2>/dev/null | head -n 1 || true) -VMLINUZ_SHA256=$(sudo -n sha256sum "${PROD_VMLINUZ}" 2>/dev/null | awk '{print $1}' || sha256sum "${PROD_VMLINUZ}" 2>/dev/null | awk '{print $1}' || echo "unknown") +host_status="PASS" +host_notes=() +host_fail() { host_status="FAIL"; host_notes+=("$1"); echo "FAIL host: $1"; } + +initrd_sha="null"; initrd_size="null"; init_status="FAIL" +# Every tool build_standalone_recovery_initrd.sh copies into bin/. +EXPECTED=(busybox sh bash lsblk blkid mount umount mkdir cat grep sed sha256sum age + sbverify fusermount3 tpm2_pcrread efibootmgr findmnt cryptsetup fsck.vfat + mkfs.vfat fsck.ext4 chroot gocryptfs) +present=(); missing=() +if [[ ! -f "${INITRD_IMG}" ]]; then + host_fail "image not found: ${INITRD_IMG}" + missing=("${EXPECTED[@]}") +else + initrd_sha=$(json_str "$(sha256sum "${INITRD_IMG}" | awk '{print $1}')") + initrd_size=$(stat -c%s "${INITRD_IMG}") + if ! gzip -t "${INITRD_IMG}" 2>/dev/null; then + host_fail "image is not a valid gzip stream" + elif ! gzip -dc "${INITRD_IMG}" | cpio -t --quiet > "${WORK_DIR}/list" 2>/dev/null; then + host_fail "image is not a readable cpio archive" + fi + sed -e 's|^\./||' "${WORK_DIR}/list" 2>/dev/null > "${WORK_DIR}/names" || : > "${WORK_DIR}/names" + init_status="PASS" + grep -qx 'init' "${WORK_DIR}/names" || { init_status="FAIL"; host_fail "image has no /init (rdinit=/init would not start)"; } + for t in "${EXPECTED[@]}"; do + if grep -qx "bin/${t}" "${WORK_DIR}/names"; then present+=("/bin/${t}"); else missing+=("/bin/${t}"); fi + done + [[ ${#missing[@]} -eq 0 ]] || host_fail "image lacks ${#missing[@]} recovery tool(s): ${missing[*]}" +fi +[[ "${host_status}" == FAIL ]] || echo "PASS host: image opens, has /init and all ${#EXPECTED[@]} recovery tools" + +# ---- QEMU zero-disk boot ---------------------------------------------------- +qemu_status="NOT_RUN"; qemu_note="not requested (pass --boot or --serial-log FILE)" +qemu_bound="false"; kernel_path="null"; kernel_sha="null"; log_sha="null" +markers=("AIENOS Standalone Hardware Recovery Core" + "TEST MODE DETECTED: automated recovery verification complete") -mkdir -p "${REPO_ROOT}/evidence" +if [[ "${mode}" == boot ]]; then + quiet="${AIENOS_QUIET_FLAG:-${HOME}/workspace/.spark-quiet}" + kernel="${AIENOS_GATE1_KERNEL:-$(ls -1t /boot/vmlinuz-* 2>/dev/null | head -n 1 || true)}" + if [[ -e "${quiet}" ]]; then + qemu_note="quiet flag ${quiet} is held; boot skipped" + elif ! command -v qemu-system-aarch64 >/dev/null; then + qemu_note="qemu-system-aarch64 not installed" + elif [[ "$(uname -m)" != aarch64 && -z "${AIENOS_GATE1_KERNEL:-}" ]]; then + qemu_note="host is $(uname -m); set AIENOS_GATE1_KERNEL to an AArch64 kernel" + elif [[ "${host_status}" != PASS ]]; then + qemu_note="host checks failed; image not booted" + elif [[ -z "${kernel}" ]] || ! { cp "${kernel}" "${WORK_DIR}/vmlinuz" 2>/dev/null || sudo -n cp "${kernel}" "${WORK_DIR}/vmlinuz" 2>/dev/null; }; then + qemu_note="kernel not readable: ${kernel:-none found}" + else + kernel_path=$(json_str "${kernel}") + kernel_sha=$(json_str "$(sha256sum "${WORK_DIR}/vmlinuz" | awk '{print $1}')") + serial_log="${WORK_DIR}/serial.log" + set +e + timeout "${AIENOS_QEMU_TIMEOUT:-60}" qemu-system-aarch64 \ + -M virt -cpu max -smp 2 -m 1024 \ + -kernel "${WORK_DIR}/vmlinuz" -initrd "${INITRD_IMG}" \ + -append "rdinit=/init aienos.test=1 console=ttyAMA0 panic=1 quiet" \ + -display none -nic none -serial file:"${serial_log}" -no-reboot + set -e + qemu_bound="true" + fi +elif [[ "${mode}" == log ]]; then + [[ -f "${serial_log}" ]] || { echo "serial log not found: ${serial_log}" >&2; exit 2; } + qemu_note="console log supplied; the image that produced it is not bound to this receipt's image hash" +fi + +if [[ -n "${serial_log}" && -f "${serial_log}" ]]; then + log_sha=$(json_str "$(sha256sum "${serial_log}" | awk '{print $1}')") + tr -d '\r' < "${serial_log}" > "${WORK_DIR}/serial.txt" + qemu_status="PASS" + for m in "${markers[@]}"; do + if ! grep -qF -- "${m}" "${WORK_DIR}/serial.txt"; then + qemu_status="FAIL"; echo "FAIL QEMU: console never printed: ${m}" + fi + done + if [[ "${qemu_status}" == PASS ]]; then + echo "PASS QEMU: zero-disk boot reached the recovery completion line" + [[ "${qemu_bound}" != true ]] || qemu_note="booted this image with zero disks attached" + else + qemu_note="zero-disk boot did not reach the recovery completion line" + fi +fi +echo "${qemu_status} QEMU: ${qemu_note}" + +# ---- Verdict ---------------------------------------------------------------- +if [[ "${host_status}" == FAIL || "${qemu_status}" == FAIL ]]; then status="FAIL" +elif [[ "${qemu_status}" == PASS && "${qemu_bound}" == true && "${tree_dirty}" == false ]]; then status="PASS" +else status="NOT_RUN"; fi -cat << JSON_EOF > "${RECEIPT_FILE}" +json_list() { local first=1; printf '['; for x in "$@"; do [[ $first == 1 ]] || printf ', '; first=0; json_str "$x"; done; printf ']'; } +notes_json=$(json_list "${host_notes[@]+"${host_notes[@]}"}") + +mkdir -p "${OUT_DIR}" +tmp_receipt="${WORK_DIR}/receipt.json" +cat > "${tmp_receipt}" << JSON_EOF { "gate": "TRUST-1 Gate 1", "name": "standalone_ram_recovery_media", - "status": "PASS_EMULATOR_VERIFIED", - "physical_hardware_status": "PENDING_ATTENDED_EXERCISE", + "status": "${status}", + "status_rule": "PASS needs host PASS, a QEMU zero-disk boot of this exact image and a clean tree at a known commit; any FAIL is FAIL; otherwise NOT_RUN", + "evidence_levels": { + "host": "${host_status}", + "qemu": "${qemu_status}", + "hardware": "NOT_RUN" + }, + "commit": $(json_str "${commit}"), + "tree_dirty": $( [[ "${tree_dirty}" == unknown ]] && echo '"unknown"' || echo "${tree_dirty}"), "captured_utc": "$(date -u +"%Y-%m-%dT%H:%M:%SZ")", - "host": "$(uname -n)", + "host": $(json_str "$(uname -n)"), "arch": "$(uname -m)", - "kernel_version": "$(uname -r)", "artifacts": { - "kernel": { - "path": "${PROD_VMLINUZ}", - "sha256": "${VMLINUZ_SHA256}" - }, "standalone_initrd": { - "path": "aienos-recovery-standalone-initrd.img", - "size_bytes": ${INITRD_SIZE}, - "sha256": "${INITRD_SHA256}", - "format": "cpio_gzip_ramfs" - } + "path": $(json_str "${INITRD_IMG}"), + "size_bytes": ${initrd_size}, + "sha256": ${initrd_sha}, + "host_check_failures": ${notes_json} + }, + "qemu_kernel": { "path": ${kernel_path}, "sha256": ${kernel_sha} }, + "qemu_serial_log_sha256": ${log_sha} }, - "invariants": { - "zero_internal_storage_dependency": true, - "internal_nvme_unmounted": true, - "init_entrypoint": "rdinit=/init", - "atlas_recov_protected": true, - "qemu_zero_disk_verified": true, + "checks": { + "init_entrypoint_present": "${init_status}", + "recovery_tools_packaged": "$( [[ ${#missing[@]} -eq 0 ]] && echo PASS || echo FAIL)", + "qemu_zero_disk_boot": "${qemu_status}", + "qemu_boot_bound_to_image_hash": ${qemu_bound}, + "qemu_note": $(json_str "${qemu_note}"), + "internal_nvme_unmounted": "NOT_RUN", + "atlas_recov_protected": "NOT_RUN", + "hardware_note": "Machine 1 facts; only the attended exercise can record them", "secrets_policy": "NO PLAINTEXT SECRETS IN REPOSITORY OR BUILD ARTIFACTS" }, - "utilities_packaged": [ - "/bin/busybox", - "/bin/sh", - "/bin/bash", - "/bin/lsblk", - "/bin/blkid", - "/bin/mount", - "/bin/umount", - "/bin/mkdir", - "/bin/cat", - "/bin/grep", - "/bin/sed", - "/bin/sha256sum", - "/bin/cryptsetup", - "/bin/age", - "/bin/tpm2_pcrread", - "/bin/efibootmgr", - "/bin/gocryptfs" - ] + "utilities_packaged": $(json_list "${present[@]+"${present[@]}"}"), + "utilities_missing": $(json_list "${missing[@]+"${missing[@]}"}") } JSON_EOF -echo "Captured Gate 1 zero-disk recovery receipt at ${RECEIPT_FILE}" +receipt_sha=$(sha256sum "${tmp_receipt}" | awk '{print $1}') +RECEIPT_FILE="${OUT_DIR}/gate1_recovery_receipt_${receipt_sha}.json" +cp "${tmp_receipt}" "${RECEIPT_FILE}" +echo "GATE1_RECEIPT: ${status} ${RECEIPT_FILE}" +[[ "${status}" != FAIL ]] || exit 1 +exit 0 diff --git a/scripts/qemu_store_512b_crash_test.sh b/scripts/qemu_store_512b_crash_test.sh index 1724b24d..3cf8ec8e 100755 --- a/scripts/qemu_store_512b_crash_test.sh +++ b/scripts/qemu_store_512b_crash_test.sh @@ -29,6 +29,43 @@ set -uo pipefail repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" cd "${repo_root}" +# rows_all_ok FILE WANT: true only when FILE holds exactly WANT result rows +# (lines with " -> ") and every one ends in "-> OK". A missing file, a short +# campaign, an extra row or any BAD row is false, so a loop that never ran +# (or stopped early) cannot read as PASS. +rows_all_ok() { + local f="$1" want="$2" total=0 ok=0 + [[ -f "${f}" ]] || { echo " rows: ${f##*/} missing (want ${want})"; return 1; } + total=$(grep -c ' -> ' "${f}" || true) + ok=$(grep -c ' -> OK$' "${f}" || true) + if [[ "${want}" -gt 0 && "${total}" == "${want}" && "${ok}" == "${want}" ]]; then return 0; fi + echo " rows: ${f##*/} has ${total} rows, ${ok} OK; want exactly ${want} OK" + return 1 +} + +# --verdict-self-test: feed the verdict check broken result files (no QEMU, +# no build) and require FAIL for each, PASS only for the complete table. +if [[ "${1:-}" == --verdict-self-test ]]; then + t="$(mktemp -d)"; st=0 + want_rows() { # NAME WANT EXPECT(0 pass|1 fail) LINES... + local name="$1" want="$2" expect="$3"; shift 3 + printf '%s' "" > "${t}/r"; for l in "$@"; do printf '%s\n' "${l}" >> "${t}/r"; done + local got=0; rows_all_ok "${t}/r" "${want}" >/dev/null || got=1 + if [[ "${got}" == "${expect}" ]]; then echo "PASS ${name} -> $([ "${got}" = 0 ] && echo PASS || echo FAIL)" + else echo "FAIL ${name} gave the wrong verdict"; st=1; fi + } + want_rows "empty results (campaign never ran)" 3 1 + want_rows "one row short (campaign stopped early)" 3 1 "a -> OK" "b -> OK" + want_rows "one BAD row" 3 1 "a -> OK" "b -> BAD" "c -> OK" + want_rows "one extra row" 3 1 "a -> OK" "b -> OK" "c -> OK" "d -> OK" + want_rows "zero rows wanted is never a pass" 0 1 + want_rows "complete, all OK" 3 0 "a -> OK" "b -> OK" "c -> OK" + rm -f "${t}/r"; rows_all_ok "${t}/r" 3 >/dev/null && { echo "FAIL missing file read as PASS"; st=1; } || echo "PASS missing results file -> FAIL" + rm -rf "${t}" + [[ "${st}" == 0 ]] && { echo "STORE_CRASH_VERDICT_SELF_TEST: PASS"; exit 0; } + echo "STORE_CRASH_VERDICT_SELF_TEST: FAIL"; exit 1 +fi + code_fd="${AAVMF_CODE:-/usr/share/AAVMF/AAVMF_CODE.no-secboot.fd}" vars_fd="${AAVMF_VARS:-/usr/share/AAVMF/AAVMF_VARS.fd}" command -v qemu-system-aarch64 >/dev/null || { echo "qemu-system-aarch64 not installed"; exit 2; } @@ -45,7 +82,10 @@ target_dir="target/qemu-store-512b-crash" echo "=== Building aienos-handoff (store-qual) and aienos-store-tool ===" commit="$(git rev-parse HEAD 2>/dev/null || echo unknown)" -git diff --quiet HEAD 2>/dev/null || commit="${commit}-dirty" +tree_dirty=unknown +if [[ "${commit}" != unknown ]]; then + if [[ -n "$(git status --porcelain 2>/dev/null)" ]]; then tree_dirty=true; commit="${commit}-dirty"; else tree_dirty=false; fi +fi AIENOS_COMMIT="${commit}" AIENOS_RESTART_SECS=1 cargo build --quiet --release \ -p aienos-boot --target aarch64-unknown-uefi --features store-qual --bin aienos-handoff \ --target-dir "${target_dir}" || { echo "build failed"; exit 2; } @@ -186,8 +226,10 @@ for settle in 0 3; do done done cat "${work}/results_tier1.txt" -tier1_pass=1 -grep -q ' -> BAD' "${work}/results_tier1.txt" && tier1_pass=0 +# Exactly one OK row per (settle, checkpoint); a short or empty table is FAIL. +tier1_pass=0 +rows_all_ok "${work}/results_tier1.txt" $(( 2 * ${#checkpoints[@]} )) && tier1_pass=1 +[[ "${tier1_pass}" == 1 ]] || fail=1 [[ "${tier1_pass}" == 1 ]] && echo "STORE_512B_CRASH_OBSERVED_QEMU: PASS" || echo "STORE_512B_CRASH_OBSERVED_QEMU: FAIL" # --- Tier 2a: root tear closure on the real Tier 1 images ------------------- @@ -195,11 +237,16 @@ echo echo "=== Tier 2a: Root Tear Closure (host proof over Tier 1 images) ===" tier2a_pass=1 for settle in 0 3; do + # PASS needs exit 0 AND the tool's own PASS line (an empty run is FAIL). if ! "${tool}" tear-closure "${work}/saved/s${settle}_after_first_flush.img" \ "${work}/saved/s${settle}_after_final_flush.img" "${store_offset}" "${lba_bytes}" \ - | sed "s/^/settle=${settle} /"; then + > "${work}/tear_s${settle}.txt" 2>&1 \ + || ! grep -q "^STORE_ROOT_TEAR_CLOSURE: PASS" "${work}/tear_s${settle}.txt"; then + sed "s/^/settle=${settle} /" "${work}/tear_s${settle}.txt" tier2a_pass=0; fail=1 echo "settle=${settle} STORE_ROOT_TEAR_CLOSURE: FAIL" + else + sed "s/^/settle=${settle} /" "${work}/tear_s${settle}.txt" fi done [[ "${tier2a_pass}" == 1 ]] && echo "STORE_512B_ROOT_TEAR_CLOSURE: PASS" || echo "STORE_512B_ROOT_TEAR_CLOSURE: FAIL" @@ -259,11 +306,12 @@ for row in "${inject_cases[@]}"; do "${expect}" "$([ "${ok}" = 1 ] && echo OK || echo BAD)" >> "${work}/results_tier2b.txt" if [[ "${ok}" != 1 ]]; then tier2b_pass=0; fail=1; fi done +rows_all_ok "${work}/results_tier2b.txt" ${#inject_cases[@]} || { tier2b_pass=0; fail=1; } cat "${work}/results_tier2b.txt" [[ "${tier2b_pass}" == 1 ]] && echo "STORE_512B_INJECTED_ROOT_RECOVERY_QEMU: PASS" || echo "STORE_512B_INJECTED_ROOT_RECOVERY_QEMU: FAIL" echo -echo "=== Final Summary (commit ${commit}) ===" +echo "=== Final Summary (commit ${commit}, tree_dirty=${tree_dirty}, evidence level: QEMU only) ===" [[ "${integration_pass}" == 1 && "${reopen_pass}" == 1 ]] && echo "STORE_NVME_INTEGRATION_512B_QEMU: PASS" || echo "STORE_NVME_INTEGRATION_512B_QEMU: FAIL" [[ "${tier1_pass}" == 1 ]] && echo "STORE_512B_CRASH_OBSERVED_QEMU: PASS" || echo "STORE_512B_CRASH_OBSERVED_QEMU: FAIL" [[ "${tier2a_pass}" == 1 ]] && echo "STORE_512B_ROOT_TEAR_CLOSURE: PASS" || echo "STORE_512B_ROOT_TEAR_CLOSURE: FAIL" diff --git a/scripts/qemu_store_crash_test.sh b/scripts/qemu_store_crash_test.sh index e7dae445..707997cb 100755 --- a/scripts/qemu_store_crash_test.sh +++ b/scripts/qemu_store_crash_test.sh @@ -16,6 +16,43 @@ set -uo pipefail repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" cd "${repo_root}" +# rows_all_ok FILE WANT: true only when FILE holds exactly WANT result rows +# (lines with " -> ") and every one ends in "-> OK". A missing file, a short +# campaign, an extra row or any BAD row is false, so a loop that never ran +# (or stopped early) cannot read as PASS. +rows_all_ok() { + local f="$1" want="$2" total=0 ok=0 + [[ -f "${f}" ]] || { echo " rows: ${f##*/} missing (want ${want})"; return 1; } + total=$(grep -c ' -> ' "${f}" || true) + ok=$(grep -c ' -> OK$' "${f}" || true) + if [[ "${want}" -gt 0 && "${total}" == "${want}" && "${ok}" == "${want}" ]]; then return 0; fi + echo " rows: ${f##*/} has ${total} rows, ${ok} OK; want exactly ${want} OK" + return 1 +} + +# --verdict-self-test: feed the verdict check broken result files (no QEMU, +# no build) and require FAIL for each, PASS only for the complete table. +if [[ "${1:-}" == --verdict-self-test ]]; then + t="$(mktemp -d)"; st=0 + want_rows() { # NAME WANT EXPECT(0 pass|1 fail) LINES... + local name="$1" want="$2" expect="$3"; shift 3 + printf '%s' "" > "${t}/r"; for l in "$@"; do printf '%s\n' "${l}" >> "${t}/r"; done + local got=0; rows_all_ok "${t}/r" "${want}" >/dev/null || got=1 + if [[ "${got}" == "${expect}" ]]; then echo "PASS ${name} -> $([ "${got}" = 0 ] && echo PASS || echo FAIL)" + else echo "FAIL ${name} gave the wrong verdict"; st=1; fi + } + want_rows "empty results (campaign never ran)" 3 1 + want_rows "one row short (campaign stopped early)" 3 1 "a -> OK" "b -> OK" + want_rows "one BAD row" 3 1 "a -> OK" "b -> BAD" "c -> OK" + want_rows "one extra row" 3 1 "a -> OK" "b -> OK" "c -> OK" "d -> OK" + want_rows "zero rows wanted is never a pass" 0 1 + want_rows "complete, all OK" 3 0 "a -> OK" "b -> OK" "c -> OK" + rm -f "${t}/r"; rows_all_ok "${t}/r" 3 >/dev/null && { echo "FAIL missing file read as PASS"; st=1; } || echo "PASS missing results file -> FAIL" + rm -rf "${t}" + [[ "${st}" == 0 ]] && { echo "STORE_CRASH_VERDICT_SELF_TEST: PASS"; exit 0; } + echo "STORE_CRASH_VERDICT_SELF_TEST: FAIL"; exit 1 +fi + code_fd="${AAVMF_CODE:-/usr/share/AAVMF/AAVMF_CODE.no-secboot.fd}" vars_fd="${AAVMF_VARS:-/usr/share/AAVMF/AAVMF_VARS.fd}" command -v qemu-system-aarch64 >/dev/null || { echo "qemu-system-aarch64 not installed"; exit 2; } @@ -30,6 +67,10 @@ machine="virt,virtualization=on,gic-version=3,iommu=smmuv3" target_dir="target/qemu-store-crash" commit="$(git rev-parse HEAD 2>/dev/null || echo unknown)" +tree_dirty=unknown +if [[ "${commit}" != unknown ]]; then + if [[ -n "$(git status --porcelain 2>/dev/null)" ]]; then tree_dirty=true; commit="${commit}-dirty"; else tree_dirty=false; fi +fi AIENOS_COMMIT="${commit}" AIENOS_RESTART_SECS=1 cargo build --quiet --release \ -p aienos-boot --target aarch64-unknown-uefi --features store-qual --bin aienos-handoff \ --target-dir "${target_dir}" || { echo "build failed"; exit 2; } @@ -148,10 +189,12 @@ for settle in 0 3; do done done -crash_pass=1; reopen_pass=1; slot_pass=1 -grep -q ' -> BAD' "${work}/results.txt" && { crash_pass=0; reopen_pass=0; } -grep -qE '^settle=3 .* -> OK$' "${work}/results.txt" || slot_pass=0 -grep -q ' BAD$' "${work}/results.txt" && slot_pass=0 +# Exactly one OK row per (settle, checkpoint); a short or empty table is FAIL. +# Slot reuse is checked on the settle=3 rows: all of them must be present and OK. +crash_pass=0; reopen_pass=0; slot_pass=0 +if rows_all_ok "${work}/results.txt" $(( 2 * ${#checkpoints[@]} )); then crash_pass=1; reopen_pass=1; else fail=1; fi +grep '^settle=3 ' "${work}/results.txt" > "${work}/results_settle3.txt" 2>/dev/null || true +rows_all_ok "${work}/results_settle3.txt" ${#checkpoints[@]} && slot_pass=1 echo "---- crash campaign results ----" cat "${work}/results.txt" @@ -160,6 +203,7 @@ if [[ "${fail}" != 0 || -n "${AIENOS_QEMU_VERBOSE:-}" ]]; then fi echo +echo "=== Summary (commit ${commit}, tree_dirty=${tree_dirty}, evidence level: QEMU only) ===" [[ "${integration_pass}" == 1 ]] && echo "STORE_NVME_INTEGRATION_QEMU: PASS" || echo "STORE_NVME_INTEGRATION_QEMU: FAIL" [[ "${crash_pass}" == 1 && "${fail}" == 0 ]] && echo "STORE_CHECKPOINT_CRASH_QEMU: PASS" || echo "STORE_CHECKPOINT_CRASH_QEMU: FAIL" [[ "${reopen_pass}" == 1 && "${fail}" == 0 ]] && echo "STORE_REOPEN_QEMU: PASS" || echo "STORE_REOPEN_QEMU: FAIL" diff --git a/scripts/trust1_m5_qualify.sh b/scripts/trust1_m5_qualify.sh index 49f73d83..4ed83da4 100755 --- a/scripts/trust1_m5_qualify.sh +++ b/scripts/trust1_m5_qualify.sh @@ -4,9 +4,11 @@ # It refuses a dirty tree, records the exact commit and the machine it ran on # (read-only: no sudo, no TPM writes, no efivar or boot-entry writes, no disk # writes outside its own output folder), runs every software gate that exists -# today, lists every operator/hardware/unimplemented gate with an honest -# BLOCKED_* or MISSING_IMPLEMENTATION verdict (never PASS), and writes one -# JSON receipt named by the sha256 of its own content. +# today, lists every operator/hardware/unimplemented gate as NOT_RUN (never +# PASS) with its blocker class (BLOCKED_OPERATOR, BLOCKED_HARDWARE or +# MISSING_IMPLEMENTATION) as the reason, and writes one JSON receipt named by +# the sha256 of its own content. Verdicts are only PASS, FAIL or NOT_RUN: a +# blocker is the table's reason for not running, never a measured result. # # Usage: bash scripts/trust1_m5_qualify.sh [--with-qemu] [--out DIR] # bash scripts/trust1_m5_qualify.sh --self-test @@ -21,7 +23,7 @@ # # Overall verdict: QUALIFIED only if every canonical gate is PASS, otherwise # NOT_QUALIFIED with the list of gates that are not PASS. -# Exit: 0 no software gate FAILed (BLOCKED_*/MISSING/NOT_RUN allowed), +# Exit: 0 no software gate FAILed (NOT_RUN allowed, whatever its blocker), # 1 at least one software gate FAILed or the run dirtied the tree, # 2 usage error or dirty tree at start. set -uo pipefail @@ -34,12 +36,12 @@ set -uo pipefail # kind: # software run now; PASS needs exit 0 AND the marker line in the log # cargo like software, and the log must show N>0 passed, 0 failed -# auto like software if the runner's file exists, else -# MISSING_IMPLEMENTATION (being built in parallel) +# auto like software if the runner's file exists, else NOT_RUN +# with blocker MISSING_IMPLEMENTATION (being built in parallel) # qemu software, only with --with-qemu and no .spark-quiet; else NOT_RUN -# operator BLOCKED_OPERATOR, never run, never PASS -# hardware BLOCKED_HARDWARE, never run, never PASS -# missing MISSING_IMPLEMENTATION, never run, never PASS +# operator NOT_RUN, blocker BLOCKED_OPERATOR; never run, never PASS +# hardware NOT_RUN, blocker BLOCKED_HARDWARE; never run, never PASS +# missing NOT_RUN, blocker MISSING_IMPLEMENTATION; never run, never PASS # runner: name of a run_* function below ('-' for none). # notrun_rc: exit code that means "a tool is missing" -> NOT_RUN ('-' none). # marker: extended regex that must match a line of the log ('-' for none). @@ -62,7 +64,7 @@ qemu_secureboot_signing|qemu|run_qemu_sb|-|^TRUST-1 Gate 4 Secure Boot signing t qemu_store_512b_crash|qemu|run_qemu_store512|-|^STORE_512B_CRASH_RECOVERY_QEMU: PASS$|QEMU Store crash recovery on 512-byte blocks qemu_native_nvme|qemu|run_qemu_native_nvme|-|^AIENOS_STORE_NVME_QEMU: PASS$|C NVMe driver write/flush/reset/read-back on QEMU virtual NVMe (emulator only) ck_m1_boot_qemu|qemu|run_qemu_ck_boot|3|^AIENOS_CK_M1: PASS( .*)?$|C kernel (native/boot + native/kernel, Lane 18) UEFI boot observables on QEMU, scripts/qemu_ck_boot_test.sh (emulator only) -ck_store_kernel_qemu|qemu|run_qemu_ck_store|3|^AIENOS_CK_M4_STORE: PASS( .*)?$|sealed C Store (native/store + native/m5, TEST keys) in the C kernel boot path on QEMU virtual NVMe with the QEMU-only unsafe DMA bypass, scripts/qemu_ck_store_test.sh (emulator only; not a real device) +ck_store_kernel_qemu|qemu|run_qemu_ck_store|3|^AIENOS_CK_M4_STORE: PASS( .*)?$|sealed C Store (native/store + native/m5, TEST keys) in the C kernel boot path on QEMU virtual NVMe, DMA confined by the emulated SMMU, scripts/qemu_ck_store_test.sh (emulator only; not a real device, not real keys) ck_argus1_revoke_qemu|qemu|run_qemu_ck_argus|3|^AIENOS_CK_ARGUS1_REVOKE: PASS( .*)?$|ARGUS-1 narrow revoke inside the C kernel on QEMU, scripts/qemu_ck_store_test.sh (emulator only) t1_gate0_second_offline_location|operator|-|-|-|Gate 0: second offline backup location t1_gate0_cold_boot_pcr_stability|hardware|-|-|-|Gate 0: cold-boot PCR stability on Machine 1 @@ -76,9 +78,9 @@ t1_gate8|operator|-|-|-|Gate 8 (attended) t1_gate9|operator|-|-|-|Gate 9 (attended) m5_sealed_volume_keys_real_tpm|missing|-|-|-|M5: sealed volume keys bound to a real TPM m5_store_encrypted_objects|software|run_store_c|-|^STORE_SEALED: PASS$|M5: encrypted objects in the C sealed Store (host file-backed only; not QEMU, not Machine 1) -m5_store_kernel_binding|missing|-|-|-|M5: sealed C Store bound into the kernel/boot path on a real device +m5_store_kernel_binding|missing|-|-|-|M5: sealed C Store bound into the kernel boot path on a real device with real keys (the QEMU binding with TEST keys is row ck_store_kernel_qemu; it does not count here) m5_owner_signed_chain_machine1|missing|-|-|-|M5: owner-signed trust chain on Machine 1 -m5_production_store_512b|missing|-|-|-|M5: production Store on 512-byte geometry (C engine native/store + C NVMe driver native/disk exist, host/QEMU tested; not bound into the boot path, not qualified on Machine 1) +m5_production_store_512b|missing|-|-|-|M5: production Store on 512-byte geometry on Machine 1 (C engine native/store + C NVMe driver native/disk are host/QEMU tested and the C kernel loads the Store in QEMU with TEST keys; no real-device run, not qualified on Machine 1) t1_gate4_manifest_ab|missing|-|-|-|Gate 4: signed boot manifest + A/B slot selection in the loader (awaits the C/asm loader) m5_migration_sig_test_key|auto|run_native_m5_migsig|-|^AIENOS_M5_MIGRATION_SIG: PASS$|M5: owner-signed migration record (native/m5 + native/sig Ed25519), host test with TEST keys only m5_migration_owner_signature|operator|-|-|-|M5: migration signed by the real owner key (needs the Gate 3 offline key ceremony) @@ -219,12 +221,15 @@ evaluate_gate() { local id="$1" kind="$2" runner="$3" notrun_rc="$4" marker="$5" local verdict reason log="${work_dir}/logs/${id}.log" rc t0 t1 out case "${kind}" in - operator) results+=("${id}|${kind}|BLOCKED_OPERATOR|needs an attended operator step|-|0|0"); return ;; - hardware) results+=("${id}|${kind}|BLOCKED_HARDWARE|needs attended hardware boots on Machine 1|-|0|0"); return ;; - missing) results+=("${id}|${kind}|MISSING_IMPLEMENTATION|no implementation in the repo|-|0|0"); return ;; + # Not checked by this script, so the verdict is NOT_RUN. The reason + # starts with the blocker class from the table; that is the table's + # claim about why, not a measured result. + operator) results+=("${id}|${kind}|NOT_RUN|BLOCKED_OPERATOR: needs an attended operator step; this script cannot check it|-|0|0"); return ;; + hardware) results+=("${id}|${kind}|NOT_RUN|BLOCKED_HARDWARE: needs attended hardware boots on Machine 1; this script cannot check it|-|0|0"); return ;; + missing) results+=("${id}|${kind}|NOT_RUN|MISSING_IMPLEMENTATION: the gate table lists no implementation to run|-|0|0"); return ;; auto) if ! auto_present "${runner}"; then - results+=("${id}|${kind}|MISSING_IMPLEMENTATION|implementation not present at this commit|-|0|0"); return + results+=("${id}|${kind}|NOT_RUN|MISSING_IMPLEMENTATION: runner file not present at this commit|-|0|0"); return fi ;; qemu) if [[ "${with_qemu}" != 1 ]]; then @@ -262,16 +267,19 @@ run_table() { # count_results -> sets n_pass n_fail n_notrun n_blocked n_missing sw_fail count_results() { n_pass=0; n_fail=0; n_notrun=0; n_blocked=0; n_missing=0; sw_fail=0; n_total=0 - local r v + local r v why for r in "${results[@]}"; do - IFS='|' read -r _ _ v _ <<<"${r}" + IFS='|' read -r _ _ v why _ <<<"${r}" + if [[ "${v}" == NOT_RUN ]]; then + case "${why}" in BLOCKED_OPERATOR:*|BLOCKED_HARDWARE:*) v=BLOCKED ;; MISSING_IMPLEMENTATION:*) v=MISSING ;; esac + fi n_total=$((n_total + 1)) case "${v}" in PASS) n_pass=$((n_pass + 1)) ;; FAIL) n_fail=$((n_fail + 1)); sw_fail=1 ;; NOT_RUN) n_notrun=$((n_notrun + 1)) ;; - BLOCKED_OPERATOR|BLOCKED_HARDWARE) n_blocked=$((n_blocked + 1)) ;; - MISSING_IMPLEMENTATION) n_missing=$((n_missing + 1)) ;; + BLOCKED) n_blocked=$((n_blocked + 1)) ;; + MISSING) n_missing=$((n_missing + 1)) ;; *) n_fail=$((n_fail + 1)); sw_fail=1 ;; esac done @@ -344,15 +352,15 @@ collect_machine() { # --------------------------------------------------------------- receipt write_receipt() { - local tmp="${work_dir}/receipt.tmp" i r id kind v reason lsha lines secs first + local tmp="${work_dir}/receipt.tmp" i r id kind v reason lsha lines secs first blocker { echo "{" - echo " \"schema\": \"aienos.trust1_m5_qualification.v1\"," + echo " \"schema\": \"aienos.trust1_m5_qualification.v2\"," echo " \"started_utc\": $(json_str "${started_utc}")," echo " \"finished_utc\": $(json_str "$(date -u +%FT%TZ)")," echo " \"commit\": $(json_str "${head_sha}")," echo " \"commit_subject\": $(json_str "${head_subject}")," - echo " \"tree_clean_before\": true," + echo " \"tree_clean_before\": ${tree_clean_before}," echo " \"tree_clean_after\": ${tree_clean_after}," echo " \"with_qemu_requested\": $([[ ${with_qemu} == 1 ]] && echo true || echo false)," echo " \"quiet_flag_present\": $([[ -e ${QUIET_FLAG} ]] && echo true || echo false)," @@ -392,8 +400,9 @@ write_receipt() { echo " \"gates\": [" for i in "${!results[@]}"; do IFS='|' read -r id kind v reason lsha lines secs <<<"${results[$i]}" - printf ' {"id": %s, "kind": %s, "verdict": %s, "reason": %s, "description": %s, "log_sha256": %s, "log_lines": %s, "seconds": %s}' \ - "$(json_str "${id}")" "$(json_str "${kind}")" "$(json_str "${v}")" "$(json_str "${reason}")" \ + blocker="-"; [[ "${v}" == NOT_RUN && "${reason}" =~ ^(BLOCKED_OPERATOR|BLOCKED_HARDWARE|MISSING_IMPLEMENTATION): ]] && blocker="${BASH_REMATCH[1]}" + printf ' {"id": %s, "kind": %s, "verdict": %s, "blocker": %s, "reason": %s, "description": %s, "log_sha256": %s, "log_lines": %s, "seconds": %s}' \ + "$(json_str "${id}")" "$(json_str "${kind}")" "$(json_str "${v}")" "$(json_str "${blocker}")" "$(json_str "${reason}")" \ "$(json_str "${descs[${id}]:-}")" "$(json_str "${lsha}")" "${lines:-0}" "${secs:-0}" [[ $i -lt $((${#results[@]} - 1)) ]] && echo "," || echo "" done @@ -448,6 +457,17 @@ self_test() { done bad "$1 has no result row" } + expect_why() { # expect_why ID BLOCKER: the NOT_RUN reason names the blocker class + local r v why + for r in "${results[@]}"; do + IFS='|' read -r id _ v why _ <<<"${r}" + if [[ "${id}" == "$1" ]]; then + [[ "${why}" == "$2:"* ]] && ok "$1 reason names $2" || bad "$1 reason '${why}' does not start with $2:" + return + fi + done + bad "$1 has no result row" + } fake_fail() { echo "boom"; return 1; } fake_nomarker() { echo "all good, honest"; return 0; } fake_pass() { echo "FAKE: ALL PASS"; return 0; } @@ -479,9 +499,11 @@ self_test() { expect neg_fail FAIL; expect neg_nomarker FAIL; expect pos_pass PASS expect notrun_rc2 NOT_RUN; expect rc2_not_notrun FAIL expect cargo_zero FAIL; expect cargo_ok PASS; expect cargo_badrc FAIL - expect auto_absent MISSING_IMPLEMENTATION - expect op_never_pass BLOCKED_OPERATOR; expect hw_never_pass BLOCKED_HARDWARE - expect miss_never_pass MISSING_IMPLEMENTATION + expect auto_absent NOT_RUN + expect op_never_pass NOT_RUN; expect hw_never_pass NOT_RUN + expect miss_never_pass NOT_RUN + expect_why auto_absent MISSING_IMPLEMENTATION; expect_why miss_never_pass MISSING_IMPLEMENTATION + expect_why op_never_pass BLOCKED_OPERATOR; expect_why hw_never_pass BLOCKED_HARDWARE expect qemu_quiet NOT_RUN; expect qemu_off NOT_RUN [[ ! -e "${sentinel}" ]] && ok "blocked/missing/vetoed gates never ran their runner" || bad "a blocked/missing/vetoed runner ran" @@ -498,7 +520,7 @@ self_test() { results=("a|software|PASS|x|-|0|0" "b|cargo|PASS|x|-|0|0") summarize >/dev/null [[ "${overall}" == QUALIFIED ]] && ok "all-PASS table -> QUALIFIED" || bad "all-PASS table -> ${overall}" - results=("a|software|PASS|x|-|0|0" "b|operator|BLOCKED_OPERATOR|x|-|0|0") + results=("a|software|PASS|x|-|0|0" "b|operator|NOT_RUN|BLOCKED_OPERATOR: x|-|0|0") summarize >/dev/null count_results [[ "${overall}" == NOT_QUALIFIED && ${sw_fail} == 0 ]] && ok "PASS + BLOCKED -> NOT_QUALIFIED, exit 0" || bad "PASS + BLOCKED -> ${overall} sw_fail=${sw_fail}" @@ -562,7 +584,7 @@ self_test() { # JSON escaping and receipt naming by content hash. out_dir="${tmp}/out"; mkdir -p "${out_dir}" - started_utc=x; head_sha=x; head_subject='quote " backslash \ tab end'; tree_clean_after=true + started_utc=x; head_sha=x; head_subject='quote " backslash \ tab end'; tree_clean_before=true; tree_clean_after=true m_host=h; m_machine_id_sha=x; m_product=x; m_board=x; m_serial_sha=x; m_cpu=x; m_kernel=x m_bios_version=x; m_bios_date=x; m_sb_efivar=1; m_setup_mode=0; m_sb_mokutil=x; m_tpm_present=no m_tpm_mfr=x; m_tpm_vendor=x; m_tpm_fw=x; m_boot_disk=x; m_lbs=512; m_capture=x; pcr_lines=("0 ab" "1 cd") @@ -574,7 +596,7 @@ self_test() { bad "receipt name does not match its content hash" fi if command -v jq >/dev/null; then - jq -e '.verdict == "NOT_QUALIFIED" and .counts.blocked == 1 and .machine.pcr_sha256["1"] == "cd"' "${receipt_path}" >/dev/null \ + jq -e '.verdict == "NOT_QUALIFIED" and .counts.blocked == 1 and .gates[1].verdict == "NOT_RUN" and .gates[1].blocker == "BLOCKED_OPERATOR" and .gates[0].blocker == "-" and .tree_clean_before == true and .machine.pcr_sha256["1"] == "cd"' "${receipt_path}" >/dev/null \ && ok "receipt is valid JSON (jq) with expected fields" || bad "receipt is not valid JSON or fields wrong" else echo "SKIP jq not installed; JSON validity not machine-checked" @@ -624,7 +646,7 @@ main() { --out) [[ $# -ge 2 ]] || die "--out needs a directory"; out_arg="$2"; shift ;; --self-test) mode=self ;; --machine-only) mode=machine ;; # internal: identity + receipt, no gates - -h|--help) sed -n '2,27p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'; exit 0 ;; + -h|--help) sed -n '2,28p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'; exit 0 ;; *) die "unknown argument: $1" ;; esac shift @@ -635,6 +657,9 @@ main() { refuse_if_dirty "${repo_root}" local before; before="$(tree_state "${repo_root}")" + # Measured, not assumed: refuse_if_dirty above exits on a dirty tree, and + # this re-reads the state the receipt reports. + if [[ -z "${before}" ]]; then tree_clean_before=true; else tree_clean_before=false; fi head_sha="$(git -C "${repo_root}" rev-parse HEAD)" head_subject="$(git -C "${repo_root}" log -1 --format=%s HEAD)" started_utc="$(date -u +%FT%TZ)" ```