diff --git a/.crumb b/.crumb index 0e653aa6..32247b0d 100644 --- a/.crumb +++ b/.crumb @@ -27,33 +27,33 @@ "purpose": "Directory crates. Purpose not yet described by a human." }, { - "digest": "bf79b3f7eac22405088a596c95f8e29f02f09863be146ce4978f91aab618bda1", - "last_commit": "5e3634e", + "digest": "bd7eb99f15a1f1a63969943ca3c980811ed110709dc9b3861f5aad6fd25fa84c", + "last_commit": "f23da68", "name": "docs", "purpose": "Directory docs. Purpose not yet described by a human." }, { - "digest": "6927d3188791f1611d1451adc3998da13661a8a026a7d0b30c5d318e55fcdccd", - "last_commit": "2529de3", + "digest": "cd19d20499065a773a3cb624c5e3cb1b5ed3ddf4e4ecec2e433c0e39ac5c1088", + "last_commit": "f23da68", "name": "native", "purpose": "Directory native. Purpose not yet described by a human." }, { - "digest": "e05c9be44a099db64118bb542ef8f97041efe9642107c7007291c44b7aac1ff4", - "last_commit": "6da9d58", + "digest": "dbd714ff3e2649a9d09a4d9d6d2b188b1c054e89a0524b9af1153832a8017355", + "last_commit": "ecd12c6", "name": "scripts", "purpose": "Directory scripts. Purpose not yet described by a human." } ], - "children_root": "sha256:82e3b069f9b1f4cd48ace284b1b959fcae8086a2afea69f70feeec997e7b6376", - "compiled_at": "2026-10-06T14:54:31Z", + "children_root": "sha256:2804306afa73df8ef1d07958ce103abaea28a4a6a5812177f5601e69bdfa7029", + "compiled_at": "2026-10-06T19:43:14Z", "compiler": "crumb-compile/1", - "digest": "sha256:91071752742465e2bc2af5e46d6547f47eeae6a8b5b24a35119ce64583044294", - "evidence_files": 152, - "evidence_root": "sha256:a74ab9a4f344734b1737c5c8f029eeec57f10340cf251cf0484903f158c3f418", - "files": 2876, - "generated_at_commit": "5e3634e05d693838e15b3a414be81c1017220f79", - "source_tree": "sha256:b63b6d203b75a29440d23e80b1bfac445e3b54b9a565a2b0fe237de542fe5e14" + "digest": "sha256:73415459a0b259a8b947f9aebe22f6c9a2e90280992d893e2dd969b91b177f69", + "evidence_files": 153, + "evidence_root": "sha256:29aa8775feb12d9e0e64b41fc1fc48b97e32dc16bf9176562cbe9fe1ea934f00", + "files": 2881, + "generated_at_commit": "71bae34a73d2aaf85f4879f26a2f1b7c5ef396c4", + "source_tree": "sha256:ab58f9a8693161163a71f959f3d0245a961872721c6fbdccd0b87d577ef80376" }, "owner_lane": "", "provenance": { diff --git a/.github/workflows/ck-kernel.yml b/.github/workflows/ck-kernel.yml index ca84d56f..4ab96341 100644 --- a/.github/workflows/ck-kernel.yml +++ b/.github/workflows/ck-kernel.yml @@ -6,7 +6,9 @@ # 2. stage host tests: make stage-test, make stage-sanitize # 3. the gate runner's own self-test: scripts/ck_gates.sh --self-test # 4. the QEMU gates: scripts/ck_gates.sh (scripts/qemu_ck_boot_test.sh and -# scripts/qemu_ck_store_test.sh) with qemu-system-aarch64 and the AAVMF +# scripts/qemu_ck_store_test.sh, and the other children; M0_ROLLBACK from +# scripts/qemu_ck_rollback_test.sh also needs cargo and the Rust target +# aarch64-unknown-uefi for its stager/Default mock) with qemu-system-aarch64 and the AAVMF # UEFI firmware from Ubuntu (packages qemu-system-arm, qemu-efi-aarch64). # Every gate that has a C implementation must print PASS; a NOT_RUN for # one of them fails the job (a missing tool or firmware cannot turn into @@ -68,6 +70,14 @@ jobs: qemu-system-aarch64 --version | head -1 ls -l /usr/share/AAVMF/AAVMF_CODE.no-secboot.fd /usr/share/AAVMF/AAVMF_VARS.fd + - name: Install Rust toolchain (the M0_ROLLBACK stager and Default are the Rust aienos-rollback-mock) + # Pinned to the toolchain the M0_ROLLBACK evidence was produced with (Spark, rustc 1.98.1). + # Rust 1.99.0 stable fails to link the aarch64-unknown-uefi mock: uefi 0.41 proto::shell + # references wcslen, undefined under 1.99 (first seen 2026-10-06, aienos#273 CI). Tracked separately. + uses: dtolnay/rust-toolchain@1.98.1 + with: + targets: aarch64-unknown-uefi + - name: Host unit tests (plain and ASan + UBSan) run: make -C native/kernel test sanitize diff --git a/docs/.crumb b/docs/.crumb index fd67c5fe..786763a5 100644 --- a/docs/.crumb +++ b/docs/.crumb @@ -30,14 +30,14 @@ } ], "children_root": "sha256:25a2af14107c1c2ae96916dd5c4086195ebd4117975ea0ae458855ac21f46099", - "compiled_at": "2026-10-06T14:54:31Z", + "compiled_at": "2026-10-06T19:08:10Z", "compiler": "crumb-compile/1", - "digest": "sha256:bf79b3f7eac22405088a596c95f8e29f02f09863be146ce4978f91aab618bda1", + "digest": "sha256:bd7eb99f15a1f1a63969943ca3c980811ed110709dc9b3861f5aad6fd25fa84c", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 61, - "generated_at_commit": "5e3634e05d693838e15b3a414be81c1017220f79", - "source_tree": "sha256:402b3c5f575a0d309643621680452d5a799618907a908c24cd90d8c1ebbc4630" + "generated_at_commit": "f23da6872ed8576de162878d89c4eaaa3e065099", + "source_tree": "sha256:6f1215dca863b963793ae16c3c2ed46dadb3867c5706df912324cf09d62898b4" }, "owner_lane": "", "provenance": { diff --git a/docs/BOOT_HANDOFF_CONTRACT.md b/docs/BOOT_HANDOFF_CONTRACT.md index dc835c0a..75f95095 100644 --- a/docs/BOOT_HANDOFF_CONTRACT.md +++ b/docs/BOOT_HANDOFF_CONTRACT.md @@ -281,6 +281,25 @@ C variant as a separate labelled mode so the Rust-mock result is not replaced. All five rows stay **NOT_RUN** until a forge receipt covers them. QEMU only; Machine 1 is NOT_RUN. +**Status update (code cut, QEMU only).** Rows 42-46 are built as a separate +script, `scripts/qemu_ck_rollback_test.sh` (CK gate M0_ROLLBACK, child of +`scripts/ck_gates.sh`), so the Rust-mock script and its labels stay as they +were. Built as proposed: the normal C core image; TEST-only +`make CK_TEST_ROLLBACK=bad-magic` (row 43) and `CK_TEST_ROLLBACK=hang` +(row 44), both refused with `CK_HARDWARE_STAGING`. Added beyond the +proposal: `CK_TEST_ROLLBACK=cpu-fault` (BRK at EL1 after `kernel: alive`, +the `ck_fault_report` path), a rejected candidate made from the real C image +(cut to 4096 bytes) instead of junk bytes, an explicit absent lane, and a +host reader of the AAVMF vars file (`native/kernel/tools/ck_uefi_vars.c`) so +"BootNext consumed" and "BootOrder unchanged" come from the firmware's store +after every boot. Finding: AAVMF appends its own auto-created boot options to +BootOrder on the boot after the stager writes `BootOrder=0001`, with or +without a candidate; the script judges BootOrder against a no-candidate +control lane (`native/kernel/GATES.md` M0 section). Result: QEMU PASS for all +rows, run log `evidence/ck_rollback_qemu_5deb3971bd88b5664489d47bc273613104e1eb2c7a3e353bfe73f7729717fad8.log`; +no `ck_gates.sh` receipt yet; Machine 1 NOT_RUN. The three return-to-firmware +paths of section 7 step 3 are still NOT_RUN. + ## 8. Frozen forever vs extensible **Frozen (v3, `CHANDOF3`; v1 `CHANDOF1` and v2 `CHANDOF2` are superseded and refused):** the magic value; the 232-byte layout and every @@ -317,7 +336,7 @@ exact refusal line from section 6: QEMU (TEST-only builds, refused by `CK_HARDWARE_STAGING`): 14. Corrupted magic image prints `panic: handoff: bad magic` and resets. -15. Rows 42-46 per section 7.1. +15. Rows 42-46 per section 7.1 (DONE in QEMU: `scripts/qemu_ck_rollback_test.sh`, see the status update there). Layout: @@ -336,5 +355,5 @@ Layout: interrupts today (section 4); the PROPOSED rule needs its own small cut. - `native/boot/efi_main.c:8-9` (comment) says the Rust `aienos-boot` crate holds "A/B slots"; that contradicts ADR 0024 Q3 and the crate. A code - comment, out of scope for this docs change; the follow-up validator cut - should correct it. + comment, out of scope for this docs change. Corrected in the M0_ROLLBACK + code cut (the comment now points to section 7). diff --git a/docs/native/PREFLIGHT-AND-RECOVERY.md b/docs/native/PREFLIGHT-AND-RECOVERY.md index 0b5818a6..ebc4ca42 100644 --- a/docs/native/PREFLIGHT-AND-RECOVERY.md +++ b/docs/native/PREFLIGHT-AND-RECOVERY.md @@ -27,9 +27,16 @@ Run on any aarch64 or cross-capable Linux host, from a clean checkout: make -s -C native/kernel OUT=/tmp/ck-b AIENOS_COMMIT="$commit" full sha256sum /tmp/ck-a/BOOTAA64.EFI /tmp/ck-b/BOOTAA64.EFI -Expected: the two digests are equal for the same commit (UNVERIFIED: this was -not built when this page was written, the machine was held quiet by another -run). The digest changes with every commit because the commit hash is built +`scripts/ck_repro_build.sh [full|core] [--keep DIR]` does exactly this: it +refuses a dirty tree, builds twice into two fresh temp folders and prints +`CK_REPRO_BUILD: PASS commit= sha256=` only when the +digests are equal. Checked on the Spark host (gcc 13.3.0, GNU ld 2.42) at +commit ecd12c6: `full` both builds +`fa48c92029957e0c468b068b4196dde254f80036565b05facc240433b6fd77aa`, `core` +both builds `7bf5d58ce24ddf57de24cdf0c3240f37f0971eac2689fa63935f7c4732a69038`. +Negative control: the same tree built with a different `AIENOS_COMMIT` gives +a different digest, so the comparison can fail. Same-host only: a build on +another machine or toolchain is UNVERIFIED. The digest changes with every commit because the commit hash is built into the image, so no single digest can be written down in advance. The digest of the image that is actually staged is printed by the kernel itself on the recovery console (`recovery_console: identity build_sha256=<64 hex> @@ -48,6 +55,14 @@ every command it would run and touches nothing. All of these are read-only checks. Stop at the first one that fails. +`scripts/native_boot_preflight.sh [--image EFI --expect-sha256 HEX]` runs +items 2, 3, 4, 5 and 8 below. It only reads (`efibootmgr` with no arguments, +the SecureBoot variable file, `findmnt`, `git status`, the image file, the +quiet flag), needs no sudo and never stages or reboots; its `--self-test` +also fails if the script ever gains a writing command. Last line: +`NATIVE_PREFLIGHT: READY` or `NOT_READY ( STOP)`. Items 1, 6 and 7 are +printed as ASK lines: they are Drake's, a script cannot see them. + 1. Drake is at the machine, with a display and keyboard attached. (Drake's physical presence and fresh go-ahead are required; see section 5.) 2. The recovery stick `AIENOSRECOV` is plugged in and listed as `Boot0004` @@ -68,6 +83,15 @@ All of these are read-only checks. Stop at the first one that fails. ## 3. Getting back to Linux +In plain words: the AIENOS test gets one try. Whatever it does (finishes, +crashes, freezes, or the computer refuses to start it), the next start of the +machine goes back to Linux by itself. If the screen stops changing for a full +minute, hold the power button until the machine turns off, wait ten seconds, +and press it again; Linux should come up. If Linux does not come up, use the +recovery stick (section 4). Each of these outcomes was rehearsed with the real +C image in QEMU (`scripts/qemu_ck_rollback_test.sh`, CK gate M0_ROLLBACK); +not yet on the Spark itself. + Normal return: do nothing. Firmware deletes BootNext before it starts the candidate, so any reset or power-cycle (hold the chassis power button, wait, press again) boots the next BootOrder entry, which is Linux. If the candidate @@ -108,5 +132,6 @@ implemented and not specified here. The accepted spec forbids slots in this loader (Q3, ADR 0024; `docs/BOOT_HANDOFF_CONTRACT.md` section 7: "the handoff record carries no rollback state, and never will"). Doing it needs Drake to reopen Q3 first. The existing one-time BootNext rollback is proven in QEMU -(M0_NATIVE_ROLLBACK_QEMU), and M0_ROLLBACK for the C image is -MISSING_IMPLEMENTATION until the rows in section 7.1 of that contract are built. +(M0_NATIVE_ROLLBACK_QEMU, Rust mock candidate), and with the C image as the +candidate in QEMU (CK gate M0_ROLLBACK, `scripts/qemu_ck_rollback_test.sh`, +rows 42-46 of `native/kernel/GATES.md`). Neither is a physical result. diff --git a/evidence/ck_rollback_qemu_5deb3971bd88b5664489d47bc273613104e1eb2c7a3e353bfe73f7729717fad8.log b/evidence/ck_rollback_qemu_5deb3971bd88b5664489d47bc273613104e1eb2c7a3e353bfe73f7729717fad8.log new file mode 100644 index 00000000..06db3bae --- /dev/null +++ b/evidence/ck_rollback_qemu_5deb3971bd88b5664489d47bc273613104e1eb2c7a3e353bfe73f7729717fad8.log @@ -0,0 +1,436 @@ +# CK M0_ROLLBACK QEMU run (C-image evidence; Rust-mock evidence is scripts/qemu_native_rollback_test.sh, separate) +# command: bash scripts/qemu_ck_rollback_test.sh (AIENOS_ROLLBACK_KEEP set to keep lane files) +# code commit: ecd12c685bcc76b0967925488c96e70b7d9c57b0 (clean tree), host aarch64 QEMU emulator version 8.2.2 (Debian 1:8.2.2+ds-0ubuntu1.18), date 2026-10-06T19:06Z +# QEMU only. Physical: NOT_RUN. + +## script output +============================================================ +AIENOS CK M0_ROLLBACK: C kernel image as the one-time BootNext candidate (QEMU) +commit: ecd12c685bcc76b0967925488c96e70b7d9c57b0 +firmware: AAVMF_CODE.no-secboot.fd vars template sha256 b3b855c5a80310168051164986855692d1bdb06e67619856177965cd87c6774f +============================================================ +building aienos-rollback-mock (stager and Default, unchanged Rust mock) ... +building the C kernel images ... +candidate normal: sha256 7bf5d58ce24ddf57de24cdf0c3240f37f0971eac2689fa63935f7c4732a69038 bytes 135168 +candidate panic: sha256 2d172eda122198e9dde34c61ff401ffcc7ad7bf8cdf79a1dae061b2384d7dd85 bytes 135168 +candidate cpu-fault: sha256 ba93e92ca809f3151e58d126837b340ef0fcdfcf0daf9d6ec5118068575b6fa9 bytes 131072 +candidate hang: sha256 cd5edce9fce32756c6949ba86b2d52a6d8691f97497bd6ab8ab2b825d7e4fc7e bytes 131072 +candidate rejected: sha256 689288ac853a3c40d374f5c3750668f02ad2f8eb64f2b636ba34a36b03731b24 bytes 4096 +PASS ck_uefi_vars self-test (18 cases) + +--- [lane absent] --- +qemu exits: stage=0 attempt=0 next=0 repeat=0 +store after boot 1: BootOrder=0001 BootNext=0000 +store after boot 2: BootOrder=0001,0002,0003,0004 BootNext=absent +store after boot 4: BootOrder=0001,0002,0003,0004 BootNext=absent +PASS absent: staged (BootNext=0000, BootOrder=0001, Boot0000 "AIENOS Candidate", read from the store) +PASS absent: attempt evidence in boot 2 +PASS absent: next boot is Boot0001 Default (BOOT_CURRENT=0001) +PASS absent: repeat boot is still Default +PASS absent: BootNext consumed once (absent in the store after boots 2-4; Boot0000 dispatched never, load refused once) +PASS absent: BootOrder 0001 first, no 0000, same after boots 2-4 and equal to the no-candidate control +observation: AAVMF rewrote BootOrder 0001 -> 0001,0002,0003,0004 in boot 2 (firmware auto-created options; the control lane shows the same) + +--- [lane normal] --- +qemu exits: stage=0 attempt=0 next=0 repeat=0 +store after boot 1: BootOrder=0001 BootNext=0000 +store after boot 2: BootOrder=0001,0002,0003,0004 BootNext=absent +store after boot 4: BootOrder=0001,0002,0003,0004 BootNext=absent +PASS normal: staged (BootNext=0000, BootOrder=0001, Boot0000 "AIENOS Candidate", read from the store) +PASS normal: attempt evidence in boot 2 +PASS normal: next boot is Boot0001 Default (BOOT_CURRENT=0001) +PASS normal: repeat boot is still Default +PASS normal: BootNext consumed once (absent in the store after boots 2-4; Boot0000 dispatched in boot 2 only) +PASS normal: BootOrder 0001 first, no 0000, same after boots 2-4 and equal to the no-candidate control +observation: AAVMF rewrote BootOrder 0001 -> 0001,0002,0003,0004 in boot 2 (firmware auto-created options; the control lane shows the same) + +--- [lane panic] --- +qemu exits: stage=0 attempt=0 next=0 repeat=0 +store after boot 1: BootOrder=0001 BootNext=0000 +store after boot 2: BootOrder=0001,0002,0003,0004 BootNext=absent +store after boot 4: BootOrder=0001,0002,0003,0004 BootNext=absent +PASS panic: staged (BootNext=0000, BootOrder=0001, Boot0000 "AIENOS Candidate", read from the store) +PASS panic: attempt evidence in boot 2 +PASS panic: next boot is Boot0001 Default (BOOT_CURRENT=0001) +PASS panic: repeat boot is still Default +PASS panic: BootNext consumed once (absent in the store after boots 2-4; Boot0000 dispatched in boot 2 only) +PASS panic: BootOrder 0001 first, no 0000, same after boots 2-4 and equal to the no-candidate control +observation: AAVMF rewrote BootOrder 0001 -> 0001,0002,0003,0004 in boot 2 (firmware auto-created options; the control lane shows the same) + +--- [lane cpu-fault] --- +qemu exits: stage=0 attempt=0 next=0 repeat=0 +store after boot 1: BootOrder=0001 BootNext=0000 +store after boot 2: BootOrder=0001,0002,0003,0004 BootNext=absent +store after boot 4: BootOrder=0001,0002,0003,0004 BootNext=absent +PASS cpu-fault: staged (BootNext=0000, BootOrder=0001, Boot0000 "AIENOS Candidate", read from the store) +PASS cpu-fault: attempt evidence in boot 2 +PASS cpu-fault: next boot is Boot0001 Default (BOOT_CURRENT=0001) +PASS cpu-fault: repeat boot is still Default +PASS cpu-fault: BootNext consumed once (absent in the store after boots 2-4; Boot0000 dispatched in boot 2 only) +PASS cpu-fault: BootOrder 0001 first, no 0000, same after boots 2-4 and equal to the no-candidate control +observation: AAVMF rewrote BootOrder 0001 -> 0001,0002,0003,0004 in boot 2 (firmware auto-created options; the control lane shows the same) + +--- [lane hang] --- +hang: QEMU still running 10 s after the hang marker, no end report; host forces the reset +qemu exits: stage=0 attempt=137 next=0 repeat=0 +store after boot 1: BootOrder=0001 BootNext=0000 +store after boot 2: BootOrder=0001,0002,0003,0004 BootNext=absent +store after boot 4: BootOrder=0001,0002,0003,0004 BootNext=absent +PASS hang: staged (BootNext=0000, BootOrder=0001, Boot0000 "AIENOS Candidate", read from the store) +PASS hang: attempt evidence in boot 2 +PASS hang: next boot is Boot0001 Default (BOOT_CURRENT=0001) +PASS hang: repeat boot is still Default +PASS hang: BootNext consumed once (absent in the store after boots 2-4; Boot0000 dispatched in boot 2 only) +PASS hang: BootOrder 0001 first, no 0000, same after boots 2-4 and equal to the no-candidate control +observation: AAVMF rewrote BootOrder 0001 -> 0001,0002,0003,0004 in boot 2 (firmware auto-created options; the control lane shows the same) + +--- [lane rejected] --- +qemu exits: stage=0 attempt=0 next=0 repeat=0 +store after boot 1: BootOrder=0001 BootNext=0000 +store after boot 2: BootOrder=0001,0002,0003,0004 BootNext=absent +store after boot 4: BootOrder=0001,0002,0003,0004 BootNext=absent +PASS rejected: staged (BootNext=0000, BootOrder=0001, Boot0000 "AIENOS Candidate", read from the store) +PASS rejected: attempt evidence in boot 2 +PASS rejected: next boot is Boot0001 Default (BOOT_CURRENT=0001) +PASS rejected: repeat boot is still Default +PASS rejected: BootNext consumed once (absent in the store after boots 2-4; Boot0000 dispatched never, load refused once) +PASS rejected: BootOrder 0001 first, no 0000, same after boots 2-4 and equal to the no-candidate control +observation: AAVMF rewrote BootOrder 0001 -> 0001,0002,0003,0004 in boot 2 (firmware auto-created options; the control lane shows the same) + +============================================================ +Evidence kind: C-image, QEMU (AAVMF). Physical: NOT_RUN. +CK_ROLLBACK_NORMAL: PASS +CK_ROLLBACK_FAULT_PANIC: PASS +CK_ROLLBACK_FAULT_CPU: PASS +CK_ROLLBACK_TIMEOUT: PASS +CK_ROLLBACK_REJECTED: PASS +CK_ROLLBACK_ABSENT: PASS +CK_ROLLBACK_BOOTNEXT_CONSUMED: PASS +CK_ROLLBACK_DEFAULT_UNCHANGED: PASS +AIENOS_CK_M0_ROLLBACK: PASS (QEMU only, C kernel image as candidate; physical NOT_RUN) + +## lane absent: store read by ck_uefi_vars after each boot (v0 = fresh template) +### v0 +uefi_vars: store=authenticated live=0 obsolete=0 +BootOrder=absent +BootNext=absent +### v1 +uefi_vars: store=authenticated live=17 obsolete=6 +BootOrder=0001 +BootNext=0000 +Boot0000=AIENOS Candidate +Boot0001=Default Linux OS +Boot0002=EFI Internal Shell +### v2 +uefi_vars: store=authenticated live=18 obsolete=15 +BootOrder=0001,0002,0003,0004 +BootNext=absent +Boot0000=AIENOS Candidate +Boot0001=Default Linux OS +Boot0002=UiApp +Boot0003=UEFI Misc Device +Boot0004=EFI Internal Shell +### v3 +uefi_vars: store=authenticated live=18 obsolete=16 +BootOrder=0001,0002,0003,0004 +BootNext=absent +Boot0000=AIENOS Candidate +Boot0001=Default Linux OS +Boot0002=UiApp +Boot0003=UEFI Misc Device +Boot0004=EFI Internal Shell +### v4 +uefi_vars: store=authenticated live=18 obsolete=17 +BootOrder=0001,0002,0003,0004 +BootNext=absent +Boot0000=AIENOS Candidate +Boot0001=Default Linux OS +Boot0002=UiApp +Boot0003=UEFI Misc Device +Boot0004=EFI Internal Shell +## lane absent: boot 2 serial, key lines +BdsDxe: failed to load Boot0000 "AIENOS Candidate" from PciRoot(0x0)/Pci(0x1,0x0)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\EFI\AIENOS\missing_candidate.efi: Not Found +BdsDxe: loading Boot0001 "Default Linux OS" from PciRoot(0x0)/Pci(0x1,0x0)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\EFI\DEFAULT\default.efi +BdsDxe: starting Boot0001 "Default Linux OS" from PciRoot(0x0)/Pci(0x1,0x0)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\EFI\DEFAULT\default.efi +DEFAULT_OS: BOOT_CURRENT=0001 +## lane absent: boots 3-4, BdsDxe lines +BdsDxe: loading Boot0001 "Default Linux OS" from PciRoot(0x0)/Pci(0x1,0x0)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\EFI\DEFAULT\default.efi +BdsDxe: starting Boot0001 "Default Linux OS" from PciRoot(0x0)/Pci(0x1,0x0)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\EFI\DEFAULT\default.efi +BdsDxe: loading Boot0001 "Default Linux OS" from PciRoot(0x0)/Pci(0x1,0x0)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\EFI\DEFAULT\default.efi +BdsDxe: starting Boot0001 "Default Linux OS" from PciRoot(0x0)/Pci(0x1,0x0)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\EFI\DEFAULT\default.efi + +## lane normal: store read by ck_uefi_vars after each boot (v0 = fresh template) +### v0 +uefi_vars: store=authenticated live=0 obsolete=0 +BootOrder=absent +BootNext=absent +### v1 +uefi_vars: store=authenticated live=17 obsolete=6 +BootOrder=0001 +BootNext=0000 +Boot0000=AIENOS Candidate +Boot0001=Default Linux OS +Boot0002=EFI Internal Shell +### v2 +uefi_vars: store=authenticated live=18 obsolete=14 +BootOrder=0001,0002,0003,0004 +BootNext=absent +Boot0000=AIENOS Candidate +Boot0001=Default Linux OS +Boot0002=UiApp +Boot0003=UEFI Misc Device +Boot0004=EFI Internal Shell +### v3 +uefi_vars: store=authenticated live=18 obsolete=16 +BootOrder=0001,0002,0003,0004 +BootNext=absent +Boot0000=AIENOS Candidate +Boot0001=Default Linux OS +Boot0002=UiApp +Boot0003=UEFI Misc Device +Boot0004=EFI Internal Shell +### v4 +uefi_vars: store=authenticated live=18 obsolete=17 +BootOrder=0001,0002,0003,0004 +BootNext=absent +Boot0000=AIENOS Candidate +Boot0001=Default Linux OS +Boot0002=UiApp +Boot0003=UEFI Misc Device +Boot0004=EFI Internal Shell +## lane normal: boot 2 serial, key lines +BdsDxe: loading Boot0000 "AIENOS Candidate" from PciRoot(0x0)/Pci(0x1,0x0)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\EFI\AIENOS\candidate.efi +BdsDxe: starting Boot0000 "AIENOS Candidate" from PciRoot(0x0)/Pci(0x1,0x0)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\EFI\AIENOS\candidate.efi +aienos_commit: ecd12c685bcc76b0967925488c96e70b7d9c57b0 +report_kind: pre_exit +kernel_impl: c (native/kernel, Lane 18) +aienos_commit: ecd12c685bcc76b0967925488c96e70b7d9c57b0 +report_kind: kernel +kernel: alive +aienos_commit: ecd12c685bcc76b0967925488c96e70b7d9c57b0 +report_kind: final +note: QEMU qualifies nothing physical +## lane normal: boots 3-4, BdsDxe lines +BdsDxe: loading Boot0001 "Default Linux OS" from PciRoot(0x0)/Pci(0x1,0x0)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\EFI\DEFAULT\default.efi +BdsDxe: starting Boot0001 "Default Linux OS" from PciRoot(0x0)/Pci(0x1,0x0)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\EFI\DEFAULT\default.efi +BdsDxe: loading Boot0001 "Default Linux OS" from PciRoot(0x0)/Pci(0x1,0x0)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\EFI\DEFAULT\default.efi +BdsDxe: starting Boot0001 "Default Linux OS" from PciRoot(0x0)/Pci(0x1,0x0)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\EFI\DEFAULT\default.efi + +## lane panic: store read by ck_uefi_vars after each boot (v0 = fresh template) +### v0 +uefi_vars: store=authenticated live=0 obsolete=0 +BootOrder=absent +BootNext=absent +### v1 +uefi_vars: store=authenticated live=17 obsolete=6 +BootOrder=0001 +BootNext=0000 +Boot0000=AIENOS Candidate +Boot0001=Default Linux OS +Boot0002=EFI Internal Shell +### v2 +uefi_vars: store=authenticated live=18 obsolete=14 +BootOrder=0001,0002,0003,0004 +BootNext=absent +Boot0000=AIENOS Candidate +Boot0001=Default Linux OS +Boot0002=UiApp +Boot0003=UEFI Misc Device +Boot0004=EFI Internal Shell +### v3 +uefi_vars: store=authenticated live=18 obsolete=16 +BootOrder=0001,0002,0003,0004 +BootNext=absent +Boot0000=AIENOS Candidate +Boot0001=Default Linux OS +Boot0002=UiApp +Boot0003=UEFI Misc Device +Boot0004=EFI Internal Shell +### v4 +uefi_vars: store=authenticated live=18 obsolete=17 +BootOrder=0001,0002,0003,0004 +BootNext=absent +Boot0000=AIENOS Candidate +Boot0001=Default Linux OS +Boot0002=UiApp +Boot0003=UEFI Misc Device +Boot0004=EFI Internal Shell +## lane panic: boot 2 serial, key lines +BdsDxe: loading Boot0000 "AIENOS Candidate" from PciRoot(0x0)/Pci(0x1,0x0)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\EFI\AIENOS\candidate.efi +BdsDxe: starting Boot0000 "AIENOS Candidate" from PciRoot(0x0)/Pci(0x1,0x0)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\EFI\AIENOS\candidate.efi +aienos_commit: ecd12c685bcc76b0967925488c96e70b7d9c57b0 +report_kind: pre_exit +rollback_test: TEST-ONLY rollback candidate (bad-magic): the kernel gets a corrupted handoff magic; never counts toward a PASS +kernel_impl: c (native/kernel, Lane 18) +aienos_commit: ecd12c685bcc76b0967925488c96e70b7d9c57b0 +report_kind: panic +panic: handoff: bad magic +## lane panic: boots 3-4, BdsDxe lines +BdsDxe: loading Boot0001 "Default Linux OS" from PciRoot(0x0)/Pci(0x1,0x0)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\EFI\DEFAULT\default.efi +BdsDxe: starting Boot0001 "Default Linux OS" from PciRoot(0x0)/Pci(0x1,0x0)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\EFI\DEFAULT\default.efi +BdsDxe: loading Boot0001 "Default Linux OS" from PciRoot(0x0)/Pci(0x1,0x0)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\EFI\DEFAULT\default.efi +BdsDxe: starting Boot0001 "Default Linux OS" from PciRoot(0x0)/Pci(0x1,0x0)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\EFI\DEFAULT\default.efi + +## lane cpu-fault: store read by ck_uefi_vars after each boot (v0 = fresh template) +### v0 +uefi_vars: store=authenticated live=0 obsolete=0 +BootOrder=absent +BootNext=absent +### v1 +uefi_vars: store=authenticated live=17 obsolete=6 +BootOrder=0001 +BootNext=0000 +Boot0000=AIENOS Candidate +Boot0001=Default Linux OS +Boot0002=EFI Internal Shell +### v2 +uefi_vars: store=authenticated live=18 obsolete=14 +BootOrder=0001,0002,0003,0004 +BootNext=absent +Boot0000=AIENOS Candidate +Boot0001=Default Linux OS +Boot0002=UiApp +Boot0003=UEFI Misc Device +Boot0004=EFI Internal Shell +### v3 +uefi_vars: store=authenticated live=18 obsolete=16 +BootOrder=0001,0002,0003,0004 +BootNext=absent +Boot0000=AIENOS Candidate +Boot0001=Default Linux OS +Boot0002=UiApp +Boot0003=UEFI Misc Device +Boot0004=EFI Internal Shell +### v4 +uefi_vars: store=authenticated live=18 obsolete=17 +BootOrder=0001,0002,0003,0004 +BootNext=absent +Boot0000=AIENOS Candidate +Boot0001=Default Linux OS +Boot0002=UiApp +Boot0003=UEFI Misc Device +Boot0004=EFI Internal Shell +## lane cpu-fault: boot 2 serial, key lines +BdsDxe: loading Boot0000 "AIENOS Candidate" from PciRoot(0x0)/Pci(0x1,0x0)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\EFI\AIENOS\candidate.efi +BdsDxe: starting Boot0000 "AIENOS Candidate" from PciRoot(0x0)/Pci(0x1,0x0)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\EFI\AIENOS\candidate.efi +aienos_commit: ecd12c685bcc76b0967925488c96e70b7d9c57b0 +report_kind: pre_exit +kernel_impl: c (native/kernel, Lane 18) +aienos_commit: ecd12c685bcc76b0967925488c96e70b7d9c57b0 +report_kind: kernel +kernel: alive +rollback_test: TEST-ONLY rollback candidate (cpu-fault): brk at EL1 now; never counts toward a PASS +aienos_commit: ecd12c685bcc76b0967925488c96e70b7d9c57b0 +report_kind: fault +fault: vector=sync_el_spx el=1 esr=0xf200007b ec=0x3c far=0x4c001008 elr=0x5c6f7280 +## lane cpu-fault: boots 3-4, BdsDxe lines +BdsDxe: loading Boot0001 "Default Linux OS" from PciRoot(0x0)/Pci(0x1,0x0)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\EFI\DEFAULT\default.efi +BdsDxe: starting Boot0001 "Default Linux OS" from PciRoot(0x0)/Pci(0x1,0x0)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\EFI\DEFAULT\default.efi +BdsDxe: loading Boot0001 "Default Linux OS" from PciRoot(0x0)/Pci(0x1,0x0)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\EFI\DEFAULT\default.efi +BdsDxe: starting Boot0001 "Default Linux OS" from PciRoot(0x0)/Pci(0x1,0x0)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\EFI\DEFAULT\default.efi + +## lane hang: store read by ck_uefi_vars after each boot (v0 = fresh template) +### v0 +uefi_vars: store=authenticated live=0 obsolete=0 +BootOrder=absent +BootNext=absent +### v1 +uefi_vars: store=authenticated live=17 obsolete=6 +BootOrder=0001 +BootNext=0000 +Boot0000=AIENOS Candidate +Boot0001=Default Linux OS +Boot0002=EFI Internal Shell +### v2 +uefi_vars: store=authenticated live=18 obsolete=14 +BootOrder=0001,0002,0003,0004 +BootNext=absent +Boot0000=AIENOS Candidate +Boot0001=Default Linux OS +Boot0002=UiApp +Boot0003=UEFI Misc Device +Boot0004=EFI Internal Shell +### v3 +uefi_vars: store=authenticated live=18 obsolete=16 +BootOrder=0001,0002,0003,0004 +BootNext=absent +Boot0000=AIENOS Candidate +Boot0001=Default Linux OS +Boot0002=UiApp +Boot0003=UEFI Misc Device +Boot0004=EFI Internal Shell +### v4 +uefi_vars: store=authenticated live=18 obsolete=17 +BootOrder=0001,0002,0003,0004 +BootNext=absent +Boot0000=AIENOS Candidate +Boot0001=Default Linux OS +Boot0002=UiApp +Boot0003=UEFI Misc Device +Boot0004=EFI Internal Shell +## lane hang: boot 2 serial, key lines +BdsDxe: loading Boot0000 "AIENOS Candidate" from PciRoot(0x0)/Pci(0x1,0x0)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\EFI\AIENOS\candidate.efi +BdsDxe: starting Boot0000 "AIENOS Candidate" from PciRoot(0x0)/Pci(0x1,0x0)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\EFI\AIENOS\candidate.efi +aienos_commit: ecd12c685bcc76b0967925488c96e70b7d9c57b0 +report_kind: pre_exit +kernel_impl: c (native/kernel, Lane 18) +aienos_commit: ecd12c685bcc76b0967925488c96e70b7d9c57b0 +report_kind: kernel +kernel: alive +rollback_test: TEST-ONLY rollback candidate (hang): spinning with interrupts masked, no reset follows; never counts toward a PASS +## lane hang: boots 3-4, BdsDxe lines +BdsDxe: loading Boot0001 "Default Linux OS" from PciRoot(0x0)/Pci(0x1,0x0)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\EFI\DEFAULT\default.efi +BdsDxe: starting Boot0001 "Default Linux OS" from PciRoot(0x0)/Pci(0x1,0x0)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\EFI\DEFAULT\default.efi +BdsDxe: loading Boot0001 "Default Linux OS" from PciRoot(0x0)/Pci(0x1,0x0)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\EFI\DEFAULT\default.efi +BdsDxe: starting Boot0001 "Default Linux OS" from PciRoot(0x0)/Pci(0x1,0x0)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\EFI\DEFAULT\default.efi + +## lane rejected: store read by ck_uefi_vars after each boot (v0 = fresh template) +### v0 +uefi_vars: store=authenticated live=0 obsolete=0 +BootOrder=absent +BootNext=absent +### v1 +uefi_vars: store=authenticated live=17 obsolete=6 +BootOrder=0001 +BootNext=0000 +Boot0000=AIENOS Candidate +Boot0001=Default Linux OS +Boot0002=EFI Internal Shell +### v2 +uefi_vars: store=authenticated live=18 obsolete=15 +BootOrder=0001,0002,0003,0004 +BootNext=absent +Boot0000=AIENOS Candidate +Boot0001=Default Linux OS +Boot0002=UiApp +Boot0003=UEFI Misc Device +Boot0004=EFI Internal Shell +### v3 +uefi_vars: store=authenticated live=18 obsolete=16 +BootOrder=0001,0002,0003,0004 +BootNext=absent +Boot0000=AIENOS Candidate +Boot0001=Default Linux OS +Boot0002=UiApp +Boot0003=UEFI Misc Device +Boot0004=EFI Internal Shell +### v4 +uefi_vars: store=authenticated live=18 obsolete=17 +BootOrder=0001,0002,0003,0004 +BootNext=absent +Boot0000=AIENOS Candidate +Boot0001=Default Linux OS +Boot0002=UiApp +Boot0003=UEFI Misc Device +Boot0004=EFI Internal Shell +## lane rejected: boot 2 serial, key lines +BdsDxe: loading Boot0000 "AIENOS Candidate" from PciRoot(0x0)/Pci(0x1,0x0)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\EFI\AIENOS\candidate.efi +BdsDxe: failed to load Boot0000 "AIENOS Candidate" from PciRoot(0x0)/Pci(0x1,0x0)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\EFI\AIENOS\candidate.efi: Unsupported +BdsDxe: loading Boot0001 "Default Linux OS" from PciRoot(0x0)/Pci(0x1,0x0)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\EFI\DEFAULT\default.efi +BdsDxe: starting Boot0001 "Default Linux OS" from PciRoot(0x0)/Pci(0x1,0x0)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\EFI\DEFAULT\default.efi +DEFAULT_OS: BOOT_CURRENT=0001 +## lane rejected: boots 3-4, BdsDxe lines +BdsDxe: loading Boot0001 "Default Linux OS" from PciRoot(0x0)/Pci(0x1,0x0)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\EFI\DEFAULT\default.efi +BdsDxe: starting Boot0001 "Default Linux OS" from PciRoot(0x0)/Pci(0x1,0x0)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\EFI\DEFAULT\default.efi +BdsDxe: loading Boot0001 "Default Linux OS" from PciRoot(0x0)/Pci(0x1,0x0)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\EFI\DEFAULT\default.efi +BdsDxe: starting Boot0001 "Default Linux OS" from PciRoot(0x0)/Pci(0x1,0x0)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\EFI\DEFAULT\default.efi diff --git a/native/.crumb b/native/.crumb index e869a2dd..75eb4880 100644 --- a/native/.crumb +++ b/native/.crumb @@ -55,14 +55,14 @@ "purpose": "Directory native/argus. Purpose not yet described by a human." }, { - "digest": "f181cbf296165f1d483535eafbc9d7a1056ab20aa838ea23e39ef55fb80d9b1b", - "last_commit": "46f22fe", + "digest": "294aa4136755e9ed1d27df47ace2ad8acdd0377cfdfc5cccf04a5cca971ee5aa", + "last_commit": "f23da68", "name": "boot", "purpose": "Directory native/boot. Purpose not yet described by a human." }, { "digest": "9a4836747ec6db7bfb75218df75936070c35e3a51470f366687e156dc6ba8d71", - "last_commit": "2529de3", + "last_commit": "b84c0a6", "name": "capability", "purpose": "Directory native/capability. Purpose not yet described by a human." }, @@ -79,8 +79,8 @@ "purpose": "Directory native/disk. Purpose not yet described by a human." }, { - "digest": "772d89376f67bf1c8378f072b802ea2395d608ed6482b132cfc5a56fae6e1bd3", - "last_commit": "3df181c", + "digest": "fb063189a7b59c3f9b741bf877991880d94811195eb869940fdd151ef0e266e4", + "last_commit": "f23da68", "name": "kernel", "purpose": "Directory native/kernel. Purpose not yet described by a human." }, @@ -109,15 +109,15 @@ "purpose": "Directory native/store. Purpose not yet described by a human." } ], - "children_root": "sha256:24efd66c5c96a0853fb1c8db0b5314d1d470056d3ea82af760458b41aa43b028", - "compiled_at": "2026-10-06T14:20:29Z", + "children_root": "sha256:e028962029d8b42e5943ff3fbdd2ebad25a645ff9ae020b5b9a4675fd7e1eba1", + "compiled_at": "2026-10-06T19:08:10Z", "compiler": "crumb-compile/1", - "digest": "sha256:6927d3188791f1611d1451adc3998da13661a8a026a7d0b30c5d318e55fcdccd", + "digest": "sha256:cd19d20499065a773a3cb624c5e3cb1b5ed3ddf4e4ecec2e433c0e39ac5c1088", "evidence_files": 4, "evidence_root": "sha256:e410b845507e00568e15b51a5797af32a97e0e4b8ab4e8487bb7c98e7e0cf335", - "files": 317, - "generated_at_commit": "2529de3fb99083fbf46e3b028806efd8b2789259", - "source_tree": "sha256:9f5aad72afbe6ef7bcc4cbee3504629bf387320e4d101b5348687aefad98f2a5" + "files": 318, + "generated_at_commit": "f23da6872ed8576de162878d89c4eaaa3e065099", + "source_tree": "sha256:eb6454e4090af1d8982fb6fadc8ade0148fff5152449d6331fe21c10f8db5f7c" }, "owner_lane": "", "provenance": { diff --git a/native/boot/.crumb b/native/boot/.crumb index ee88a3ba..33e400cd 100644 --- a/native/boot/.crumb +++ b/native/boot/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-04T16:44:17Z", + "compiled_at": "2026-10-06T19:08:10Z", "compiler": "crumb-compile/1", - "digest": "sha256:f181cbf296165f1d483535eafbc9d7a1056ab20aa838ea23e39ef55fb80d9b1b", + "digest": "sha256:294aa4136755e9ed1d27df47ace2ad8acdd0377cfdfc5cccf04a5cca971ee5aa", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 9, - "generated_at_commit": "f37c8b3a5d191f4e14282ae44aedd95e82581907", - "source_tree": "sha256:bb6a59836d733bce358a2d9d38d92b8de5ba05ffe94ebc598ea3e7d9df837364" + "generated_at_commit": "f23da6872ed8576de162878d89c4eaaa3e065099", + "source_tree": "sha256:97c9197c69b874543d76aff385197907cbc3e416c67379b9b31d6af379c0b82c" }, "owner_lane": "", "provenance": { diff --git a/native/boot/README.md b/native/boot/README.md index 004f04f7..14827db3 100644 --- a/native/boot/README.md +++ b/native/boot/README.md @@ -19,7 +19,10 @@ This is the C path's UEFI entry (Lane 18). It is deliberately small: boot-report file. The Rust `aienos-boot` crate has BootNext staging and a QEMU rollback test but no A/B slot selection (ADR 0024 Q3); it is frozen and parked for the C path; this stub boots the kernel linked into the same image -and nothing else. +and nothing else. Rollback needs no loader code: the firmware's one-time BootNext +starts this image once and the unchanged BootOrder brings the Default back; +`scripts/qemu_ck_rollback_test.sh` (CK gate M0_ROLLBACK) checks that in QEMU +with this image as the candidate. Build and test from `native/kernel` (see its README). QEMU qualifies nothing physical. diff --git a/native/boot/efi_main.c b/native/boot/efi_main.c index 39136eab..88d86d46 100644 --- a/native/boot/efi_main.c +++ b/native/boot/efi_main.c @@ -5,8 +5,10 @@ * kernel needs (EL, TTBR0/SCTLR of the firmware regime, RSDP, counter), takes * the final memory map, leaves boot services (retrying when the map key goes * stale) and jumps to ck_kernel_entry with a handoff in the image's BSS. - * The full loader (signature checks, A/B slots, BootNext, rollback) lives in - * the Rust aienos-boot crate and is parked for the C path; see README.md. */ + * There are no A/B slots (ADR 0024 Q3; the Rust aienos-boot crate has none + * either): rollback is the firmware's one-time BootNext with BootOrder + * unchanged (docs/BOOT_HANDOFF_CONTRACT.md section 7). Signature checks are + * parked for the C path; see README.md. */ #include "efi.h" #include "../kernel/arch/arch.h" #include "../kernel/core/ck_internal.h" @@ -18,6 +20,14 @@ #error "CK_TEST_STALE_HANDOFF is TEST-only and cannot be combined with CK_HARDWARE_STAGING" #endif +/* TEST-ONLY (CK gate M0_ROLLBACK, native/kernel/Makefile CK_TEST_ROLLBACK=bad-magic): + * flip bit 0 of the handoff magic ("CHANDOF3" -> "BHANDOF3") after + * ExitBootServices, so the kernel refuses the record with "handoff: bad magic" + * and resets. Never in a hardware staging image. */ +#if defined(CK_TEST_ROLLBACK_BAD_MAGIC) && defined(CK_HARDWARE_STAGING) +#error "CK_TEST_ROLLBACK_BAD_MAGIC is TEST-only and cannot be combined with CK_HARDWARE_STAGING" +#endif + #define MAP_BYTES (64u << 10) #define EXIT_TRIES 8 @@ -110,6 +120,9 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *st) ck_boot_gop_find(st, h); #ifdef CK_TEST_STALE_HANDOFF ck_puts("handoff: TEST-ONLY stale handoff image: the kernel gets a CHANDOF2 record; never counts toward a PASS\n"); +#endif +#ifdef CK_TEST_ROLLBACK_BAD_MAGIC + ck_puts("rollback_test: TEST-ONLY rollback candidate (bad-magic): the kernel gets a corrupted handoff magic; never counts toward a PASS\n"); #endif /* The yardstick model from the boot disk, while the firmware drivers are * still up (efi_model.c). Absent map: boot continues without a model. */ @@ -161,6 +174,9 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *st) ck_set_stage("kernel_entry"); #ifdef CK_TEST_STALE_HANDOFF h->magic = CK_HANDOFF_MAGIC_V2; +#endif +#ifdef CK_TEST_ROLLBACK_BAD_MAGIC + h->magic ^= 1ull; #endif ck_kernel_entry(h); } diff --git a/native/kernel/.crumb b/native/kernel/.crumb index e8ee4ee1..54da126a 100644 --- a/native/kernel/.crumb +++ b/native/kernel/.crumb @@ -57,8 +57,8 @@ "purpose": "Directory native/kernel/artifact. Purpose not yet described by a human." }, { - "digest": "c820e3275ce15dabd61691a8371c3fdc3a6f43b594af398fcab62ff89e0c0578", - "last_commit": "9e69692", + "digest": "e1178d16f8c4764be7222ae67ed3f2ba728acc7196975e1600fe3608801c689c", + "last_commit": "ecd12c6", "name": "core", "purpose": "Directory native/kernel/core. Purpose not yet described by a human." }, @@ -88,26 +88,26 @@ }, { "digest": "0fd32ca401eef461e59a9ac01b7879ce928c8057e8c2843d934772af8933e1c7", - "last_commit": "9e69692", + "last_commit": "3df181c", "name": "tests", "purpose": "Directory native/kernel/tests. Purpose not yet described by a human." }, { - "digest": "342735b38f7498b022914ea412e4b8e798a916786b31ad02516ef7d9e518acba", - "last_commit": "6da9d58", + "digest": "414bb61e8cc5185f66cee0e8a7a809c3c03e92770eb4229ab5e94b60a9aa055a", + "last_commit": "ecd12c6", "name": "tools", "purpose": "Directory native/kernel/tools. Purpose not yet described by a human." } ], - "children_root": "sha256:c568be64e6c0a0c52764e6443c0da5eadfdee750b4c31161886f5c13b702776c", - "compiled_at": "2026-10-06T11:55:32Z", + "children_root": "sha256:67d8eb578cc9eac202f5e94f1758233b6916299366e7f9785ae1612c3d3150e6", + "compiled_at": "2026-10-06T19:08:10Z", "compiler": "crumb-compile/1", - "digest": "sha256:772d89376f67bf1c8378f072b802ea2395d608ed6482b132cfc5a56fae6e1bd3", + "digest": "sha256:fb063189a7b59c3f9b741bf877991880d94811195eb869940fdd151ef0e266e4", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 153, - "generated_at_commit": "788425caf3125f809254efb433fd5bc036eb6a59", - "source_tree": "sha256:fe195fc19a8d83b84479281bda9eb7363f0bfce54630bc8910a2d81edf620666" + "files": 154, + "generated_at_commit": "f23da6872ed8576de162878d89c4eaaa3e065099", + "source_tree": "sha256:13b63c0d90e176a0fd8893ad2ab7aff0651dc48ff1fc127f116f1ffbe7c2f825" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/GATES.md b/native/kernel/GATES.md index 20df2ddf..01f8164d 100644 --- a/native/kernel/GATES.md +++ b/native/kernel/GATES.md @@ -24,7 +24,7 @@ C gates (one line each from `ck_gates.sh`): `M1` and `M3` (from `scripts/qemu_ck_artifact_test.sh`, rows 33-41), `NET` (C-only, from `scripts/qemu_ck_net_test.sh`; rows 102-106 and 110-112; the script now also checks the virtio-net SMMU fence (ACCESS_PLATFORM required, out-of-window device DMA refused), rows 102 and 110-112 are QEMU PASS on this branch from the committed forge log `evidence/ck_net_qemu_8bdbc2e46b85d04c422f9d2830c1c4b263e254b3cfecfe21ff0063c9e33c86e8.log`, hardware NOT_RUN), the kernel entropy rows 107-109 (M1 via `scripts/lib_ck_m1_checks.sh`, ARGUS1_REVOKE and M4_STORE via the Store gate boot 7), `DISK_LAYOUT` (C-only, from `scripts/qemu_ck_disk_layout_test.sh`, rows 118-123: QEMU PASS at 741b2b8 before the merge with main 8555049, rerun pending at the merged head; row 123 host test), and the NOT_RUN gates -`SMP` (C-only, from `scripts/qemu_ck_smp_test.sh`, rows 113-117, NOT_RUN pending forge receipt), `M0_ROLLBACK`, `M4_STORE_CRASH` (now read from `scripts/qemu_ck_store_crash_test.sh`, rows 73-80; NOT_RUN until a forge receipt exists), +`SMP` (C-only, from `scripts/qemu_ck_smp_test.sh`, rows 113-117, NOT_RUN pending forge receipt), `M0_ROLLBACK` (from `scripts/qemu_ck_rollback_test.sh`, rows 42-46; QEMU PASS in its committed run log, C-image, no `ck_gates.sh` receipt yet; hardware NOT_RUN), `M4_STORE_CRASH` (now read from `scripts/qemu_ck_store_crash_test.sh`, rows 73-80; NOT_RUN until a forge receipt exists), `M4_CONTINUITY`, `M4_RECOVERY`, `M4_ALLEN` (C-only, from `scripts/qemu_ck_allen_test.sh`, rows A1-A30; QEMU PASS, hardware NOT_RUN), `KEYBOARD` (from `scripts/qemu_ck_keyboard_test.sh`, rows 25-32 and C-only 30a-30c and 32a; QEMU PASS; C-only row 32b and all hardware NOT_RUN), `FPU` (C-only, from `scripts/qemu_ck_fpu_test.sh`, rows 124-128; QEMU PASS, hardware NOT_RUN), `INFER` (C-only, from `scripts/qemu_ck_infer_test.sh`, rows 129-139; QEMU PASS, hardware NOT_RUN), and `SCREEN` (C-only, from `scripts/qemu_ck_screen_test.sh`, rows 140-145; QEMU PASS, hardware NOT_RUN). `M4_NVME` and `SMMU` PASS in the SMMU-confined mode (default `make full` @@ -287,15 +287,17 @@ the candidate, fallback to Default after a fault, hang, malformed or absent candidate, BootNext consumed and Default unchanged. No A/B slot logic exists in the script or in crates/aienos-boot. ADR 0024 Q3 (aien-architecture) freezes loader expansion: no A/B slots will be added. Rollback is the one-time BootNext rule; under -`docs/BOOT_HANDOFF_CONTRACT.md` section 7.1 these rows run the script with the C kernel image as the candidate, after the script and TEST-build changes listed there. Until a forge receipt covers them they stay NOT_RUN. +`docs/BOOT_HANDOFF_CONTRACT.md` section 7.1 these rows run with the C kernel image as the candidate: `scripts/qemu_ck_rollback_test.sh` (child `rollback` of `scripts/ck_gates.sh`), TEST-only candidates from `make CK_TEST_ROLLBACK=bad-magic|cpu-fault|hang`. The Rust mock stays stager and Default. Its own run (`scripts/qemu_native_rollback_test.sh`, Rust-mock evidence, labels `NATIVE_ROLLBACK_*`) is unchanged and kept apart from the C-image labels `CK_ROLLBACK_*`. BootNext and BootOrder are read by the host from the vars file after every boot (`native/kernel/tools/ck_uefi_vars.c`), not from a guest print. Run log: `evidence/ck_rollback_qemu_5deb3971bd88b5664489d47bc273613104e1eb2c7a3e353bfe73f7729717fad8.log` (code commit ecd12c6, clean tree). No `ck_gates.sh` receipt includes this child yet. + +AAVMF itself appends its auto-created options (UiApp, UEFI Misc Device, EFI Internal Shell) to BootOrder on the boot after the stager wrote `BootOrder=0001`. The absent lane, where no candidate code runs, shows the identical change, so "Default unchanged" is judged as: 0001 first, Boot0000 never in BootOrder, no change after the attempt boot, and equal to that no-candidate control. | # | Rust check (marker) | CK gate | Status | | --- | --- | --- | --- | -| 42 | `AAVMF_BOOTNEXT_NVRAM` / `NATIVE_ROLLBACK_NORMAL` | M0_ROLLBACK | NOT_RUN (MISSING_IMPLEMENTATION: C image not yet wired as the BootNext candidate, docs/BOOT_HANDOFF_CONTRACT.md 7.1) | -| 43 | `NATIVE_ROLLBACK_FAULT` (faulted candidate returns to Default) | M0_ROLLBACK | NOT_RUN (MISSING_IMPLEMENTATION: needs TEST-only bad-magic C image, contract 7.1) | -| 44 | `NATIVE_ROLLBACK_TIMEOUT` (hung candidate) | M0_ROLLBACK | NOT_RUN (MISSING_IMPLEMENTATION: needs TEST-only hang C image, contract 7.1) | -| 45 | `NATIVE_ROLLBACK_REJECTED` (malformed image) and absent-image fallback | M0_ROLLBACK | NOT_RUN (MISSING_IMPLEMENTATION: C image as candidate path, contract 7.1) | -| 46 | `NATIVE_ROLLBACK_BOOTNEXT_CONSUMED` / `_DEFAULT_UNCHANGED` | M0_ROLLBACK | NOT_RUN (MISSING_IMPLEMENTATION: C image as candidate, contract 7.1) | +| 42 | `AAVMF_BOOTNEXT_NVRAM` / `NATIVE_ROLLBACK_NORMAL` | M0_ROLLBACK | QEMU PASS, C-image (`CK_ROLLBACK_NORMAL`: the default core image runs to `report_kind: final`, PSCI reset; next boot is Boot0001 Default; run log above; hardware NOT_RUN) | +| 43 | `NATIVE_ROLLBACK_FAULT` (faulted candidate returns to Default) | M0_ROLLBACK | QEMU PASS, C-image, two lanes (`CK_ROLLBACK_FAULT_PANIC`: TEST-only bad-magic image, `panic: handoff: bad magic`, reset; `CK_ROLLBACK_FAULT_CPU`: TEST-only BRK at EL1 after `kernel: alive`, `report_kind: fault` EC 0x3c, reset; both return to Default; hardware NOT_RUN) | +| 44 | `NATIVE_ROLLBACK_TIMEOUT` (hung candidate) | M0_ROLLBACK | QEMU PASS, C-image (`CK_ROLLBACK_TIMEOUT`: TEST-only hang image prints its marker after `kernel: alive`; QEMU still running 10 s later with no end report; the host kill stands in for the operator power-cycle, there is no watchdog in the guest; next boot is Default; hardware NOT_RUN) | +| 45 | `NATIVE_ROLLBACK_REJECTED` (malformed image) and absent-image fallback | M0_ROLLBACK | QEMU PASS, C-image (`CK_ROLLBACK_REJECTED`: the default C image cut to 4096 bytes, firmware `failed to load Boot0000 ... Unsupported`, Default in the same boot; `CK_ROLLBACK_ABSENT`: Boot0000 names a missing file, `failed to load`, Default; hardware NOT_RUN) | +| 46 | `NATIVE_ROLLBACK_BOOTNEXT_CONSUMED` / `_DEFAULT_UNCHANGED` | M0_ROLLBACK | QEMU PASS, C-image, every lane (`CK_ROLLBACK_BOOTNEXT_CONSUMED`: the host-read store holds BootNext=0000 after the stage boot and none after boots 2, 3 and 4; Boot0000 dispatched in boot 2 only. `CK_ROLLBACK_DEFAULT_UNCHANGED`: judged as above; hardware NOT_RUN) | ## M4 NVMe read: scripts/qemu_nvme_test.sh (SMMU=1 and SMMU=0) -> CK `M4_NVME` diff --git a/native/kernel/Makefile b/native/kernel/Makefile index f9b186d8..c42e0000 100644 --- a/native/kernel/Makefile +++ b/native/kernel/Makefile @@ -34,6 +34,13 @@ # (target/native-kernel-test-fwcfg); announces itself and # never counts toward a PASS. Default images are checked # to contain no fw_cfg artifact code. +# make CK_TEST_ROLLBACK=bad-magic|cpu-fault|hang +# TEST-ONLY M0_ROLLBACK candidates (bad handoff magic, CPU +# fault after "kernel: alive", hang with interrupts masked); +# own OUT (target/native-kernel-test-rollback-); only +# scripts/qemu_ck_rollback_test.sh; refused with CK_HARDWARE_STAGING +# make uefi-vars host tool $(OUT)/host/ck_uefi_vars: reads BootOrder, BootNext +# and Boot#### from an edk2 vars.fd (read-only, M0_ROLLBACK) # make CK_TEST_SMP_SKIP_CPU=1 # TEST-ONLY SMP mutation: CPU_ON skipped for one secondary # core (core/smp.c); own OUT (target/native-kernel-test-smp-skip); @@ -152,6 +159,30 @@ endif OUT ?= $(REPO)/target/native-kernel-test-stale-handoff SMP_TEST_FLAGS += -DCK_TEST_STALE_HANDOFF=2 endif +# TEST-ONLY rollback candidates (CK gate M0_ROLLBACK, +# scripts/qemu_ck_rollback_test.sh; docs/BOOT_HANDOFF_CONTRACT.md 7.1 rows 43-44): +# bad-magic the stub flips one bit of the handoff magic after +# ExitBootServices; the kernel must panic "handoff: bad magic" +# cpu-fault after "kernel: alive" the kernel executes BRK at EL1; the +# fault report must print and the kernel must reset +# hang after "kernel: alive" the kernel prints one marker and spins +# with interrupts masked; only an outside reset ends it +# Own OUT; announces itself; refused with CK_HARDWARE_STAGING. The default +# image is checked to carry no trace of it (rollback_check). +CK_TEST_ROLLBACK ?= +ifneq ($(strip $(CK_TEST_ROLLBACK)),) +ifeq ($(filter $(strip $(CK_TEST_ROLLBACK)),bad-magic cpu-fault hang),) +$(error CK_TEST_ROLLBACK must be empty or one of bad-magic cpu-fault hang) +endif +ifneq ($(strip $(CK_HARDWARE_STAGING)),) +$(error CK_TEST_ROLLBACK (TEST-only rollback candidate) cannot be combined with CK_HARDWARE_STAGING) +endif +ifneq ($(strip $(CK_TEST_STALE_HANDOFF)),) +$(error CK_TEST_ROLLBACK cannot be combined with CK_TEST_STALE_HANDOFF) +endif +OUT ?= $(REPO)/target/native-kernel-test-rollback-$(strip $(CK_TEST_ROLLBACK)) +SMP_TEST_FLAGS += -DCK_TEST_ROLLBACK_$(subst -,_,$(shell echo '$(strip $(CK_TEST_ROLLBACK))' | tr a-z A-Z))=1 +endif OUT ?= $(REPO)/target/native-kernel AIENOS_COMMIT ?= $(shell git -C $(REPO) rev-parse HEAD 2>/dev/null || echo unknown) @@ -561,6 +592,16 @@ define owner_check fi endef +# rollback_check(elf): only a CK_TEST_ROLLBACK image may carry a TEST-only +# rollback candidate, and it must announce itself. +define rollback_check + @if [ -n "$(strip $(CK_TEST_ROLLBACK))" ]; then \ + grep -aqF "TEST-ONLY rollback candidate ($(strip $(CK_TEST_ROLLBACK)))" $(1) || { echo "rollback test image lacks its TEST-ONLY announcement"; rm -f $(1); exit 1; }; \ + else \ + if grep -aqF "TEST-ONLY rollback candidate" $(1); then echo "default image carries a TEST-ONLY rollback candidate"; rm -f $(1); exit 1; fi; \ + fi +endef + # smp_check(elf): only a CK_TEST_SMP_SKIP_CPU image may carry the SMP mutation # announcement, and such an image must carry it. define smp_check @@ -629,6 +670,7 @@ $(ELF): $(CORE_OBJS) $(BOOT)/image.ld $(call link_image,$@,$(CORE_OBJS) $(CK_RUST_LIBS) $(CK_INFER_LIB)) @if [ -z "$(strip $(CK_TEST_STALE_HANDOFF))" ] && grep -aqF "TEST-ONLY stale handoff" $@; then \ echo "default image carries the TEST-only stale handoff"; rm -f $@; exit 1; fi + $(call rollback_check,$@) @s=$$($(KNM) $@ | grep -E ' [TtDdBbWwVv] ck_stage_(devices|security|store|quiesce)$$' || true); \ if [ -n "$$s" ]; then echo "core image defines stage symbols: $$s"; rm -f $@; exit 1; fi $(call fwcfg_check,$@) @@ -636,6 +678,7 @@ $(ELF): $(CORE_OBJS) $(BOOT)/image.ld $(FULL_ELF): $(CORE_OBJS) $(STAGE_BUILT) $(BOOT)/image.ld $(call link_image,$@,$(CORE_OBJS) $(STAGE_LINK) $(CK_RUST_LIBS) $(CK_INFER_LIB)) + $(call rollback_check,$@) @for s in ck_stage_devices ck_stage_security ck_stage_store ck_stage_quiesce ck_stage_disk_artifacts; do \ $(KNM) $@ | grep -qE " [TW] $$s$$" || { echo "full image lacks $$s"; rm -f $@; exit 1; }; done $(call fwcfg_check,$@) @@ -748,6 +791,12 @@ sanitize: $(addprefix $(OUT)/host-san/,$(TESTS)) @fail=0; for t in $^; do ASAN_OPTIONS=detect_leaks=1 UBSAN_OPTIONS=print_stacktrace=1 $$t || fail=1; done; \ if [ $$fail = 0 ]; then echo "CK_CORE_HOST: PASS (sanitize)"; else echo "CK_CORE_HOST: FAIL (sanitize)"; exit 1; fi +# ---- host tool for the M0_ROLLBACK gate (scripts/qemu_ck_rollback_test.sh) ---- +uefi-vars: $(OUT)/host/ck_uefi_vars +$(OUT)/host/ck_uefi_vars: $(KDIR)/tools/ck_uefi_vars.c + @mkdir -p $(dir $@) + $(HOSTCC) -std=gnu11 -O2 -Wall -Wextra -Werror -o $@ $< + # ---- host tool for the AIENOS_CK_NET gate (scripts/qemu_ck_net_test.sh) ---- udp-echo: $(OUT)/host/ck_udp_echo $(OUT)/host/ck_udp_echo: $(KDIR)/tools/ck_udp_echo.c @@ -1122,4 +1171,5 @@ clean: rm -rf $(OUT) FORCE: +.PHONY: uefi-vars .PHONY: all full test sanitize handoff-mutant acpi-dev-mutant iort-mutants smmu-l2-mutants acpi-scan clean print-kcflags udp-echo tool store-image gpt-image cont-tool owner-gen fb-check continuity-mutants continuity-resolve-mutants FORCE diff --git a/native/kernel/core/.crumb b/native/kernel/core/.crumb index d2446e90..64827b58 100644 --- a/native/kernel/core/.crumb +++ b/native/kernel/core/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-06T11:55:32Z", + "compiled_at": "2026-10-06T19:08:10Z", "compiler": "crumb-compile/1", - "digest": "sha256:c820e3275ce15dabd61691a8371c3fdc3a6f43b594af398fcab62ff89e0c0578", + "digest": "sha256:e1178d16f8c4764be7222ae67ed3f2ba728acc7196975e1600fe3608801c689c", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 31, - "generated_at_commit": "788425caf3125f809254efb433fd5bc036eb6a59", - "source_tree": "sha256:e72a04571cd4898c3631b3893de0133c50fa734accc4b30170e14db145e4f054" + "generated_at_commit": "f23da6872ed8576de162878d89c4eaaa3e065099", + "source_tree": "sha256:2b85c7a4c972cb5d1d56b82e5bb8694976694b5cf211964dc70d077edaf6a316" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/core/kmain.c b/native/kernel/core/kmain.c index e13001fb..652af454 100644 --- a/native/kernel/core/kmain.c +++ b/native/kernel/core/kmain.c @@ -90,6 +90,31 @@ static void screen_start(const struct ck_handoff *h, const struct ck_mm_report * (unsigned long long)h->fb_base, (unsigned long long)mm->fb_map_bytes, scale, cols, rows); } +/* TEST-ONLY rollback candidates (CK gate M0_ROLLBACK, Makefile + * CK_TEST_ROLLBACK=cpu-fault|hang, scripts/qemu_ck_rollback_test.sh). They + * end the candidate boot the two ways a real kernel can fail after + * "kernel: alive": a CPU exception (BRK at EL1 -> ck_fault_report -> reset) + * or a hang with interrupts masked (no reset; only an outside reset ends it, + * docs/BOOT_HANDOFF_CONTRACT.md 7 step 3). Never in a hardware staging image. */ +#if defined(CK_TEST_ROLLBACK_CPU_FAULT) || defined(CK_TEST_ROLLBACK_HANG) +#if defined(CK_HARDWARE_STAGING) +#error "CK_TEST_ROLLBACK is TEST-only and cannot be combined with CK_HARDWARE_STAGING" +#endif +static __attribute__((noreturn)) void rollback_test_end(void) +{ +#ifdef CK_TEST_ROLLBACK_CPU_FAULT + ck_puts("rollback_test: TEST-ONLY rollback candidate (cpu-fault): brk at EL1 now; never counts toward a PASS\n"); + __asm__ volatile("brk #0x7b" ::: "memory"); + ck_panic("rollback_test: brk returned"); +#else + ck_puts("rollback_test: TEST-ONLY rollback candidate (hang): spinning with interrupts masked, no reset follows; never counts toward a PASS\n"); + __asm__ volatile("msr daifset, #0xf" ::: "memory"); + for (;;) + __asm__ volatile("wfe" ::: "memory"); +#endif +} +#endif + static __attribute__((noreturn)) void ck_el1_main(void *arg) { struct ck_handoff *h = arg; @@ -172,6 +197,10 @@ static __attribute__((noreturn)) void ck_el1_main(void *arg) ck_puts("kernel: alive\n"); ck_printf("kernel_el: EL%u%s\n", el, (spsel & 1) ? "h" : "t"); +#if defined(CK_TEST_ROLLBACK_CPU_FAULT) || defined(CK_TEST_ROLLBACK_HANG) + rollback_test_end(); +#endif + /* Kernel entropy (arch/rndr.c): RNDR or a latched refusal, no fallback. * Probed once here, before the artifact loader and the stages. */ ck_set_stage("entropy"); diff --git a/native/kernel/tools/.crumb b/native/kernel/tools/.crumb index 24515961..e124a8df 100644 --- a/native/kernel/tools/.crumb +++ b/native/kernel/tools/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-06T02:21:10Z", + "compiled_at": "2026-10-06T19:08:10Z", "compiler": "crumb-compile/1", - "digest": "sha256:342735b38f7498b022914ea412e4b8e798a916786b31ad02516ef7d9e518acba", + "digest": "sha256:414bb61e8cc5185f66cee0e8a7a809c3c03e92770eb4229ab5e94b60a9aa055a", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 11, - "generated_at_commit": "4bbc7e66f4e28b91c523acf8f4b296dfe2141e71", - "source_tree": "sha256:aa1ee438169ab780d8defb5862895c5229695217cd120db604c96aca2a5ecb04" + "files": 12, + "generated_at_commit": "f23da6872ed8576de162878d89c4eaaa3e065099", + "source_tree": "sha256:da8ab6a70391ade803dbc658186ffaf53b88f16206ad88b184122a94eb3f8ac6" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/tools/ck_uefi_vars.c b/native/kernel/tools/ck_uefi_vars.c new file mode 100644 index 00000000..b1d9d0f5 --- /dev/null +++ b/native/kernel/tools/ck_uefi_vars.c @@ -0,0 +1,394 @@ +/* ck_uefi_vars -- host reader for an edk2 (AAVMF/OVMF) variable store file, + * used by scripts/qemu_ck_rollback_test.sh (CK gate M0_ROLLBACK). It reads + * the vars.fd a QEMU run left behind and prints the boot variables the + * firmware itself holds, so the rollback checks do not depend on what a guest + * program printed. Hosted C, test tooling only, never part of an image. + * Read-only: the file is opened "rb" and never written. + * + * ck_uefi_vars VARS.fd print the live boot variables (below) + * ck_uefi_vars --self-test parse synthetic stores; exit 0 only if every + * case gives the expected answer + * + * Output (one line each, stable order, for diffing between boots): + * uefi_vars: store=authenticated|plain live= obsolete= + * BootOrder=|absent + * BootNext=|absent + * Boot= one per live Boot#### option, ascending + * Exit 0 on success, 2 when the file is not a healthy edk2 variable store. + * + * Layout source (read, not recalled): edk2 tag edk2-stable202402 (the + * firmware here is Ubuntu qemu-efi-aarch64 2024.02-2ubuntu0.9), + * MdeModulePkg/Include/Guid/VariableFormat.h: VARIABLE_STORE_HEADER (GUID + * signature, UINT32 Size, UINT8 Format 0x5a, UINT8 State 0xfe, UINT16, UINT32 + * = 28 bytes), VARIABLE_HEADER (32 bytes) and AUTHENTICATED_VARIABLE_HEADER + * (60 bytes), StartId 0x55AA, State VAR_ADDED 0x3f / VAR_IN_DELETED_TRANSITION + * 0xfe / VAR_DELETED 0xfd / VAR_HEADER_VALID_ONLY 0x7f, HEADER_ALIGNMENT 4, + * name and data unpadded (ALIGNMENT 1). Store start: the firmware volume + * header's HeaderLength (MdePkg/Include/Pi/PiFirmwareVolume.h, UINT16 at + * offset 48, signature "_FVH" at offset 40). Which copy is live: + * MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.c FindVariableEx + * (State VAR_ADDED wins; a State VAR_ADDED & VAR_IN_DELETED_TRANSITION copy is + * used only when no VAR_ADDED copy exists). */ +#include +#include +#include +#include + +#define VARIABLE_DATA 0x55AAu +#define VAR_ADDED 0x3fu +#define VAR_IN_DELETED_TRANSITION 0xfeu +#define VAR_HEADER_VALID_ONLY 0x7fu +#define VAR_LIVE_IN_TRANSITION (VAR_ADDED & VAR_IN_DELETED_TRANSITION) /* 0x3e */ +#define STORE_FORMATTED 0x5au +#define STORE_HEALTHY 0xfeu +#define STORE_HDR 28u +#define PLAIN_HDR 32u +#define AUTH_HDR 60u +#define MAX_VARS 4096 + +/* EFI_VARIABLE_GUID ddcf3616-3275-4164-98b6-fe85707ffe7d and + * EFI_AUTHENTICATED_VARIABLE_GUID aaf32c78-947b-439a-a180-2e144ec37792, as + * the bytes stored on flash (first three fields little-endian). */ +static const uint8_t plain_sig[16] = {0x16, 0x36, 0xcf, 0xdd, 0x75, 0x32, 0x64, 0x41, + 0x98, 0xb6, 0xfe, 0x85, 0x70, 0x7f, 0xfe, 0x7d}; +static const uint8_t auth_sig[16] = {0x78, 0x2c, 0xf3, 0xaa, 0x7b, 0x94, 0x9a, 0x43, + 0xa1, 0x80, 0x2e, 0x14, 0x4e, 0xc3, 0x77, 0x92}; +/* EFI_GLOBAL_VARIABLE 8be4df61-93ca-11d2-aa0d-00e098032b8c (UEFI spec 3.3). */ +static const uint8_t global_guid[16] = {0x61, 0xdf, 0xe4, 0x8b, 0xca, 0x93, 0xd2, 0x11, + 0xaa, 0x0d, 0x00, 0xe0, 0x98, 0x03, 0x2b, 0x8c}; + +struct var { + uint8_t state; + uint8_t guid[16]; + char name[64]; /* ASCII copy of the UCS-2 name; '?' for non-ASCII */ + const uint8_t *data; + uint32_t data_size; + int superseded; +}; + +struct store { + int authenticated; + unsigned live, obsolete, nvars; + struct var v[MAX_VARS]; +}; + +static uint16_t rd16(const uint8_t *p) { return (uint16_t)(p[0] | p[1] << 8); } +static uint32_t rd32(const uint8_t *p) { return (uint32_t)rd16(p) | (uint32_t)rd16(p + 2) << 16; } + +/* Returns 0 and fills *s, or -1 with a reason on stderr. */ +static int parse(const uint8_t *img, size_t len, struct store *s) +{ + memset(s, 0, sizeof *s); + if (len < 64 || memcmp(img + 40, "_FVH", 4) != 0) { + fprintf(stderr, "ck_uefi_vars: no firmware volume header (_FVH at offset 40)\n"); + return -1; + } + size_t base = rd16(img + 48); + if (base < 56 || base + STORE_HDR > len) { + fprintf(stderr, "ck_uefi_vars: bad FV HeaderLength %zu\n", base); + return -1; + } + const uint8_t *sh = img + base; + if (memcmp(sh, auth_sig, 16) == 0) + s->authenticated = 1; + else if (memcmp(sh, plain_sig, 16) != 0) { + fprintf(stderr, "ck_uefi_vars: unknown variable store signature\n"); + return -1; + } + uint32_t size = rd32(sh + 16); + if (sh[20] != STORE_FORMATTED || sh[21] != STORE_HEALTHY) { + fprintf(stderr, "ck_uefi_vars: store not formatted/healthy (format=0x%02x state=0x%02x)\n", + sh[20], sh[21]); + return -1; + } + if (size < STORE_HDR || base + size > len) { + fprintf(stderr, "ck_uefi_vars: store size %u exceeds file\n", size); + return -1; + } + size_t end = base + size, hdr = s->authenticated ? AUTH_HDR : PLAIN_HDR; + size_t off = (base + STORE_HDR + 3) & ~(size_t)3; + while (off + hdr <= end && rd16(img + off) == VARIABLE_DATA) { + const uint8_t *h = img + off; + uint32_t name_size = rd32(h + hdr - 24), data_size = rd32(h + hdr - 20); + const uint8_t *guid = h + hdr - 16; + if (name_size > end - off - hdr || data_size > end - off - hdr - name_size) { + fprintf(stderr, "ck_uefi_vars: variable at 0x%zx runs past the store\n", off); + return -1; + } + if (s->nvars == MAX_VARS) { + fprintf(stderr, "ck_uefi_vars: more than %d variables\n", MAX_VARS); + return -1; + } + struct var *v = &s->v[s->nvars++]; + v->state = h[2]; + memcpy(v->guid, guid, 16); + size_t n = 0; + for (uint32_t i = 0; i + 1 < name_size && n < sizeof v->name - 1; i += 2) { + uint16_t c = rd16(h + hdr + i); + if (!c) + break; + v->name[n++] = c < 0x80 ? (char)c : '?'; + } + v->name[n] = 0; + v->data = h + hdr + name_size; + v->data_size = data_size; + off = (off + hdr + name_size + data_size + 3) & ~(size_t)3; + } + /* FindVariableEx: VAR_ADDED wins over an in-deleted-transition copy. */ + for (unsigned i = 0; i < s->nvars; i++) { + struct var *a = &s->v[i]; + if (a->state != VAR_LIVE_IN_TRANSITION) + continue; + for (unsigned j = 0; j < s->nvars; j++) + if (s->v[j].state == VAR_ADDED && !strcmp(s->v[j].name, a->name) && + !memcmp(s->v[j].guid, a->guid, 16)) + a->superseded = 1; + } + for (unsigned i = 0; i < s->nvars; i++) { + struct var *a = &s->v[i]; + int live = a->state == VAR_ADDED || (a->state == VAR_LIVE_IN_TRANSITION && !a->superseded); + if (live) + s->live++; + else + s->obsolete++; + a->superseded = !live; /* reuse: 1 = not live */ + } + return 0; +} + +static const struct var *find_global(const struct store *s, const char *name) +{ + for (unsigned i = 0; i < s->nvars; i++) + if (!s->v[i].superseded && !memcmp(s->v[i].guid, global_guid, 16) && + !strcmp(s->v[i].name, name)) + return &s->v[i]; + return NULL; +} + +static int is_boot_option(const char *n) +{ + if (strncmp(n, "Boot", 4) || strlen(n) != 8) + return 0; + for (int i = 4; i < 8; i++) + if (!((n[i] >= '0' && n[i] <= '9') || (n[i] >= 'A' && n[i] <= 'F'))) + return 0; + return 1; +} + +static void report(const struct store *s, FILE *o) +{ + fprintf(o, "uefi_vars: store=%s live=%u obsolete=%u\n", s->authenticated ? "authenticated" : "plain", + s->live, s->obsolete); + const struct var *bo = find_global(s, "BootOrder"); + if (!bo) + fprintf(o, "BootOrder=absent\n"); + else { + fprintf(o, "BootOrder="); + for (uint32_t i = 0; i + 1 < bo->data_size; i += 2) + fprintf(o, "%s%04X", i ? "," : "", rd16(bo->data + i)); + fprintf(o, "%s\n", bo->data_size % 2 ? " (odd size)" : ""); + } + const struct var *bn = find_global(s, "BootNext"); + if (!bn) + fprintf(o, "BootNext=absent\n"); + else if (bn->data_size != 2) + fprintf(o, "BootNext=bad-size-%u\n", bn->data_size); + else + fprintf(o, "BootNext=%04X\n", rd16(bn->data)); + /* Boot#### options in ascending name order. EFI_LOAD_OPTION: UINT32 + * Attributes, UINT16 FilePathListLength, CHAR16 Description[] (UEFI 3.1.3). */ + const char *prev = ""; + for (;;) { + const struct var *next = NULL; + for (unsigned i = 0; i < s->nvars; i++) { + const struct var *v = &s->v[i]; + if (v->superseded || memcmp(v->guid, global_guid, 16) || !is_boot_option(v->name)) + continue; + if (strcmp(v->name, prev) > 0 && (!next || strcmp(v->name, next->name) < 0)) + next = v; + } + if (!next) + break; + char desc[80]; + size_t n = 0; + for (uint32_t i = 6; i + 1 < next->data_size && n < sizeof desc - 1; i += 2) { + uint16_t c = rd16(next->data + i); + if (!c) + break; + desc[n++] = c >= 0x20 && c < 0x7f ? (char)c : '?'; + } + desc[n] = 0; + fprintf(o, "%s=%s\n", next->name, desc); + prev = next->name; + } +} + +/* ---- self-test: synthetic stores ---- */ + +static uint8_t *t_img; +static size_t t_off; + +static void t_begin(int auth) +{ + memset(t_img, 0xff, 8192); + memset(t_img, 0, 72); + memcpy(t_img + 40, "_FVH", 4); + t_img[48] = 72; + memcpy(t_img + 72, auth ? auth_sig : plain_sig, 16); + uint32_t size = 8192 - 72; + memcpy(t_img + 88, &size, 4); + t_img[92] = STORE_FORMATTED; + t_img[93] = STORE_HEALTHY; + memset(t_img + 94, 0, 6); + t_off = 100; +} + +static void t_var(int auth, uint8_t state, const char *name, const void *data, uint32_t dsize) +{ + size_t hdr = auth ? AUTH_HDR : PLAIN_HDR; + uint8_t *h = t_img + t_off; + memset(h, 0, hdr); + h[0] = 0xaa; + h[1] = 0x55; + h[2] = state; + h[4] = 7; + uint32_t nsize = (uint32_t)(strlen(name) + 1) * 2; + memcpy(h + hdr - 24, &nsize, 4); + memcpy(h + hdr - 20, &dsize, 4); + memcpy(h + hdr - 16, global_guid, 16); + for (size_t i = 0; i <= strlen(name); i++) { + h[hdr + 2 * i] = (uint8_t)name[i]; + h[hdr + 2 * i + 1] = 0; + } + memcpy(h + hdr + nsize, data, dsize); + t_off = (t_off + hdr + nsize + dsize + 3) & ~(size_t)3; +} + +static int t_expect(const char *label, const char *want_line, int want_present) +{ + static struct store s; + char buf[4096]; + FILE *m = fmemopen(buf, sizeof buf, "w"); + int rc = parse(t_img, 8192, &s); + if (rc == 0) + report(&s, m); + fclose(m); + if (rc != 0) { + printf("%s %s (parse refused)\n", want_line ? "FAIL" : "PASS", label); + return want_line ? 1 : 0; + } + if (!want_line) { + printf("FAIL %s (parse accepted a bad store)\n", label); + return 1; + } + char needle[128]; + snprintf(needle, sizeof needle, "%s\n", want_line); + int got = strstr(buf, needle) != NULL; + printf("%s %s\n", got == want_present ? "PASS" : "FAIL", label); + return got != want_present; +} + +static int self_test(void) +{ + static uint8_t img[8192]; + t_img = img; + int bad = 0; + const uint8_t order1[2] = {0x01, 0x00}, next0[2] = {0x00, 0x00}, order21[4] = {2, 0, 1, 0}; + uint8_t opt[6 + 2 * 17] = {1, 0, 0, 0, 0, 0}; + const char *d = "AIENOS Candidate"; + for (size_t i = 0; i <= strlen(d); i++) + opt[6 + 2 * i] = (uint8_t)d[i]; + + for (int auth = 0; auth <= 1; auth++) { + t_begin(auth); + t_var(auth, VAR_ADDED, "BootOrder", order1, 2); + t_var(auth, VAR_ADDED, "BootNext", next0, 2); + t_var(auth, VAR_ADDED, "Boot0000", opt, sizeof opt); + bad |= t_expect(auth ? "auth: staged BootNext read" : "plain: staged BootNext read", "BootNext=0000", 1); + bad |= t_expect("staged BootOrder read", "BootOrder=0001", 1); + bad |= t_expect("Boot0000 description read", "Boot0000=AIENOS Candidate", 1); + } + /* The firmware deletes BootNext: the old header goes to VAR_DELETED. */ + t_begin(1); + t_var(1, VAR_ADDED, "BootOrder", order1, 2); + t_var(1, 0xfd, "BootNext", next0, 2); + bad |= t_expect("deleted BootNext is absent", "BootNext=absent", 1); + bad |= t_expect("deleted BootNext is not reported present", "BootNext=0000", 0); + /* A header-only (interrupted add) BootNext is not live. */ + t_begin(1); + t_var(1, VAR_HEADER_VALID_ONLY, "BootNext", next0, 2); + bad |= t_expect("header-valid-only BootNext is absent", "BootNext=absent", 1); + /* An in-deleted-transition copy is live while no newer copy exists. */ + t_begin(1); + t_var(1, VAR_LIVE_IN_TRANSITION, "BootNext", next0, 2); + bad |= t_expect("in-transition BootNext with no newer copy is live", "BootNext=0000", 1); + /* BootOrder rewritten: the old copy in transition, the new one added. */ + t_begin(1); + t_var(1, VAR_LIVE_IN_TRANSITION, "BootOrder", order1, 2); + t_var(1, VAR_ADDED, "BootOrder", order21, 4); + bad |= t_expect("newer BootOrder wins over the in-transition copy", "BootOrder=0002,0001", 1); + bad |= t_expect("old BootOrder copy is not reported", "BootOrder=0001", 0); + /* Nothing written yet. */ + t_begin(1); + bad |= t_expect("empty store: BootOrder absent", "BootOrder=absent", 1); + bad |= t_expect("empty store: BootNext absent", "BootNext=absent", 1); + /* Refusals. */ + t_begin(1); + t_img[93] = 0x00; + bad |= t_expect("unhealthy store refused", NULL, 0); + t_begin(1); + t_img[72] ^= 1; + bad |= t_expect("unknown store signature refused", NULL, 0); + t_begin(1); + memcpy(t_img + 40, "_FVX", 4); + bad |= t_expect("missing _FVH refused", NULL, 0); + t_begin(1); + t_var(1, VAR_ADDED, "BootNext", next0, 2); + uint32_t huge = 0x10000; + memcpy(t_img + 100 + AUTH_HDR - 20, &huge, 4); + bad |= t_expect("variable running past the store refused", NULL, 0); + printf("CK_UEFI_VARS_SELF_TEST: %s\n", bad ? "FAIL" : "PASS"); + return bad ? 1 : 0; +} + +int main(int argc, char **argv) +{ + if (argc == 2 && !strcmp(argv[1], "--self-test")) + return self_test(); + if (argc != 2 || argv[1][0] == '-') { + fprintf(stderr, "usage: ck_uefi_vars VARS.fd | --self-test\n"); + return 2; + } + FILE *f = fopen(argv[1], "rb"); + if (!f) { + perror(argv[1]); + return 2; + } + size_t cap = 1u << 20, len = 0; + uint8_t *img = malloc(cap); + size_t n; + while (img && (n = fread(img + len, 1, cap - len, f)) > 0) { + len += n; + if (len == cap) { + uint8_t *bigger = realloc(img, cap * 2); + if (!bigger) { + free(img); + img = NULL; + break; + } + img = bigger; + cap *= 2; + } + } + fclose(f); + if (!img) { + fprintf(stderr, "ck_uefi_vars: out of memory\n"); + return 2; + } + static struct store s; + int rc = parse(img, len, &s); + if (rc == 0) + report(&s, stdout); + free(img); + return rc == 0 ? 0 : 2; +} diff --git a/scripts/.crumb b/scripts/.crumb index f8c6817f..5cf90363 100644 --- a/scripts/.crumb +++ b/scripts/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-06T03:00:56Z", + "compiled_at": "2026-10-06T19:08:10Z", "compiler": "crumb-compile/1", - "digest": "sha256:e05c9be44a099db64118bb542ef8f97041efe9642107c7007291c44b7aac1ff4", + "digest": "sha256:dbd714ff3e2649a9d09a4d9d6d2b188b1c054e89a0524b9af1153832a8017355", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 66, - "generated_at_commit": "b79954c7278df871a8226d51c6a594918676aba3", - "source_tree": "sha256:99777fce9b13056d307ffa853656a83a7cd72d5ec5e2e6da1ba6fe5ac8925e53" + "files": 69, + "generated_at_commit": "f23da6872ed8576de162878d89c4eaaa3e065099", + "source_tree": "sha256:352cd0d4ab1914a8e3cc22360233cb7e5ee4d32b322e9b515d1cc86b30cfbf22" }, "owner_lane": "", "provenance": { diff --git a/scripts/ck_gates.sh b/scripts/ck_gates.sh index a550d4f3..312c1daf 100755 --- a/scripts/ck_gates.sh +++ b/scripts/ck_gates.sh @@ -9,7 +9,8 @@ # scripts/qemu_ck_disk_layout_test.sh, scripts/qemu_ck_continuity_test.sh, # scripts/qemu_ck_recovery_test.sh, scripts/qemu_ck_allen_test.sh, # scripts/qemu_ck_keyboard_test.sh, scripts/qemu_ck_fpu_test.sh, -# scripts/qemu_ck_infer_test.sh, scripts/qemu_ck_screen_test.sh), and prints +# scripts/qemu_ck_infer_test.sh, scripts/qemu_ck_screen_test.sh, +# scripts/qemu_ck_rollback_test.sh), and prints # one line per gate: # AIENOS_CK_: PASS|FAIL|NOT_RUN [(reason)] # for M1 M3 SMMU NVME_SHUTDOWN P2_ARTIFACT M0_ROLLBACK M4_NVME M4_STORE M4_STORE_CRASH @@ -59,6 +60,7 @@ set -uo pipefail # fpu -> verdict line from scripts/qemu_ck_fpu_test.sh (NOT_RUN without the Rust target) # infer -> verdict line from scripts/qemu_ck_infer_test.sh (NOT_RUN without the model file or the Rust target) # screen -> verdict line from scripts/qemu_ck_screen_test.sh (GOP framebuffer console vs a QMP screendump) +# rollback -> verdict line from scripts/qemu_ck_rollback_test.sh (C image as the one-time BootNext candidate, AAVMF) # missing -> NOT_RUN (MISSING_IMPLEMENTATION), never run, never PASS # =========================================================================== CK_GATE_TABLE=' @@ -67,7 +69,7 @@ M3|boot|- SMMU|store|- NVME_SHUTDOWN|store|- P2_ARTIFACT|artifact|- -M0_ROLLBACK|missing|C loader signatures, A/B, BootNext and rollback are parked (native/boot/README.md) +M0_ROLLBACK|rollback|- M4_NVME|store|- M4_STORE|store|- M4_STORE_CRASH|crash|- @@ -83,7 +85,7 @@ FPU|fpu|- INFER|infer|- SCREEN|screen|- ' -CHILDREN=(boot store net artifact smp crash disk cont recov allen kbd fpu infer screen) +CHILDREN=(boot store net artifact smp crash disk cont recov allen kbd fpu infer screen rollback) # =========================================================================== repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" @@ -135,6 +137,7 @@ set_default_children() { [fpu]="${repo_root}/scripts/qemu_ck_fpu_test.sh" [infer]="${repo_root}/scripts/qemu_ck_infer_test.sh" [screen]="${repo_root}/scripts/qemu_ck_screen_test.sh" + [rollback]="${repo_root}/scripts/qemu_ck_rollback_test.sh" ) } @@ -368,7 +371,7 @@ self_test() { } scenario() { # NAME BOOT_SCRIPT STORE_SCRIPT [NET_SCRIPT] [ARTIFACT_SCRIPT] [SMP_SCRIPT] [CRASH_SCRIPT] [DISK_SCRIPT] (absent: missing) scen="$1" - declare -gA child_script=([boot]="$2" [store]="$3" [net]="${4:-${tmp}/kids/net_not_present.sh}" [artifact]="${5:-${tmp}/kids/no_artifact_child.sh}" [smp]="${6:-${tmp}/kids/no_smp_child.sh}" [crash]="${7:-${tmp}/kids/no_crash_child.sh}" [disk]="${8:-${tmp}/kids/no_disk_child.sh}" [cont]="${tmp}/kids/no_cont_child.sh" [recov]="${tmp}/kids/no_recov_child.sh" [allen]="${tmp}/kids/no_allen_child.sh" [kbd]="${kbd_kid:-${tmp}/kids/no_kbd_child.sh}" [fpu]="${tmp}/kids/no_fpu_child.sh" [infer]="${tmp}/kids/no_infer_child.sh" [screen]="${tmp}/kids/no_screen_child.sh") + declare -gA child_script=([boot]="$2" [store]="$3" [net]="${4:-${tmp}/kids/net_not_present.sh}" [artifact]="${5:-${tmp}/kids/no_artifact_child.sh}" [smp]="${6:-${tmp}/kids/no_smp_child.sh}" [crash]="${7:-${tmp}/kids/no_crash_child.sh}" [disk]="${8:-${tmp}/kids/no_disk_child.sh}" [cont]="${tmp}/kids/no_cont_child.sh" [recov]="${tmp}/kids/no_recov_child.sh" [allen]="${tmp}/kids/no_allen_child.sh" [kbd]="${kbd_kid:-${tmp}/kids/no_kbd_child.sh}" [fpu]="${tmp}/kids/no_fpu_child.sh" [infer]="${tmp}/kids/no_infer_child.sh" [screen]="${tmp}/kids/no_screen_child.sh" [rollback]="${rollback_kid:-${tmp}/kids/no_rollback_child.sh}") run_children 2>/dev/null evaluate_table >"${tmp}/${scen}.out" } @@ -391,8 +394,10 @@ self_test() { && ok "A: M4_NVME PASS line carries the confined-mode note" || bad "A: M4_NVME PASS line lacks the note" grep -qxF "AIENOS_CK_NET: PASS (${NET_PASS_NOTE})" "${tmp}/A.out" \ && ok "A: NET PASS line carries the QEMU slirp / SMMU fence note" || bad "A: NET PASS line lacks the note" - grep -qxF 'AIENOS_CK_M0_ROLLBACK: NOT_RUN (MISSING_IMPLEMENTATION: C loader signatures, A/B, BootNext and rollback are parked (native/boot/README.md))' "${tmp}/A.out" \ - && ok "A: missing gate prints NOT_RUN (MISSING_IMPLEMENTATION: reason)" || bad "A: M0_ROLLBACK line wrong" + grep -qxF 'AIENOS_CK_M0_ROLLBACK: NOT_RUN (child script no_rollback_child.sh not present at this commit)' "${tmp}/A.out" \ + && ok "A: M0_ROLLBACK without its child prints NOT_RUN (child script not present)" || bad "A: M0_ROLLBACK line wrong" + [[ "$(classify_gate X missing 'parked')" == "NOT_RUN|MISSING_IMPLEMENTATION: parked" ]] \ + && ok "a missing-source row is NOT_RUN (MISSING_IMPLEMENTATION: reason)" || bad "missing-source row not NOT_RUN" grep -q '^AIENOS_CK_KEYBOARD: NOT_RUN' "${tmp}/A.out" \ && ok "A: KEYBOARD claimed PASS by the store child stays NOT_RUN without its own child" || bad "A: KEYBOARD line wrong" [[ "$(grep -c '^AIENOS_CK_[A-Z0-9_]*: ' "${tmp}/A.out")" == 20 ]] && ok "A: exactly 20 verdict lines" || bad "A: verdict line count" @@ -498,6 +503,17 @@ self_test() { scenario Y "$(fake bootY 0 'AIENOS_CK_M1: PASS')" "$(fake storeY 0 'AIENOS_CK_M4_NVME: PASS')" expect KEYBOARD NOT_RUN unset kbd_kid + # RA, RB, RC: M0_ROLLBACK comes only from its own child (scripts/qemu_ck_rollback_test.sh). + rollback_kid="$(fake rbA 0 'PASS normal: attempt evidence in boot 2' 'AIENOS_CK_M0_ROLLBACK: PASS (QEMU only, C kernel image as candidate; physical NOT_RUN)')" + scenario RA "$(fake bootRA 0 'AIENOS_CK_M1: PASS')" "$(fake storeRA 0 'AIENOS_CK_M0_ROLLBACK: FAIL')" + expect M0_ROLLBACK PASS + rollback_kid="$(fake rbB 1 'FAIL hang: attempt evidence in boot 2' 'AIENOS_CK_M0_ROLLBACK: FAIL')" + scenario RB "$(fake bootRB 0 'AIENOS_CK_M1: PASS')" "$(fake storeRB 0 'AIENOS_CK_M0_ROLLBACK: PASS')" + expect M0_ROLLBACK FAIL + rollback_kid="$(fake rbC 3 'NOT_RUN QEMU gate lock held' 'AIENOS_CK_M0_ROLLBACK: NOT_RUN')" + scenario RC "$(fake bootRC 0 'AIENOS_CK_M1: PASS')" "$(fake storeRC 0 'AIENOS_CK_M4_NVME: PASS')" + expect M0_ROLLBACK NOT_RUN + unset rollback_kid # Receipt: named by its content hash, valid JSON, physical NOT_RUN, never overwritten. scenario R "$(fake bootR 0 'AIENOS_CK_M1: PASS')" "$(fake storeR 0 'AIENOS_CK_M4_NVME: PASS')" @@ -523,7 +539,7 @@ self_test() { jq -e '.physical == "NOT_RUN" and (.gates | length) == 20 and .verdict == "NOT_ALL_GATES_PASS" and ([.gates[] | select(.id == "M1")][0].verdict == "PASS") and ([.gates[] | select(.id == "ARGUS1_REVOKE")][0].verdict == "FAIL") - and (.children | length) == 14 and .commit_subject == "quote \" backslash \\ tab\tend"' "${receipt_path}" >/dev/null \ + and (.children | length) == 15 and .commit_subject == "quote \" backslash \\ tab\tend"' "${receipt_path}" >/dev/null \ && ok "receipt is valid JSON (jq) with expected fields" || bad "receipt JSON invalid or fields wrong" else echo "NOT_RUN jq not installed; JSON validity not machine-checked"; jq_skipped=1 @@ -542,7 +558,7 @@ self_test() { [[ -n "${g}" ]] || continue rows=$((rows + 1)) case "${s}" in - boot|store|net|artifact|smp|crash|disk|cont|recov|allen|kbd|fpu|infer|screen) [[ "${w}" == - ]] || tbad=1 ;; + boot|store|net|artifact|smp|crash|disk|cont|recov|allen|kbd|fpu|infer|screen|rollback) [[ "${w}" == - ]] || tbad=1 ;; missing) [[ -n "${w}" && "${w}" != - ]] || tbad=1 ;; *) tbad=1 ;; esac diff --git a/scripts/ck_repro_build.sh b/scripts/ck_repro_build.sh new file mode 100755 index 00000000..5d162476 --- /dev/null +++ b/scripts/ck_repro_build.sh @@ -0,0 +1,73 @@ +#!/usr/bin/env bash +# ck_repro_build.sh -- build the AIENOS C kernel UEFI image twice from the same +# clean commit, in two fresh output folders, and compare the sha256 digests +# (docs/native/PREFLIGHT-AND-RECOVERY.md section 1). Host only: builds files +# under a temp folder, never touches the ESP, NVRAM, firmware, keys or any disk. +# +# Usage: bash scripts/ck_repro_build.sh [full|core] [--keep DIR] +# full (default) make full: the image with the boot stages +# core make: the core-only image (the M1 / M0_ROLLBACK candidate) +# --keep DIR copy build A's BOOTAA64.EFI to DIR (for staging later) +# The hardware staging image (CK_HARDWARE_STAGING=1) needs the owner's files +# and is built by the stage scripts; this script does not build it. +# +# Prints both digests and, last, one line: +# CK_REPRO_BUILD: PASS commit= sha256= +# CK_REPRO_BUILD: FAIL (digests differ: ) +# Exit 0 PASS, 1 FAIL, 2 usage error, dirty tree or build failure. +# The digest changes with every commit (the commit hash is built into the +# image), so it is recorded per commit, never written down in advance. +set -euo pipefail + +repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +cd "${repo_root}" + +kind=full keep="" +while [[ $# -gt 0 ]]; do + case "$1" in + full|core) kind="$1"; shift ;; + --keep) [[ $# -ge 2 ]] || { echo "--keep needs a folder"; exit 2; }; keep="$2"; shift 2 ;; + *) echo "usage: $0 [full|core] [--keep DIR]"; exit 2 ;; + esac +done + +if [[ -n "$(git status --porcelain --untracked-files=normal)" ]]; then + echo "refused: the working tree is not clean (a digest must map to one commit)" + git status --short | head -20 + exit 2 +fi +commit="$(git rev-parse HEAD)" +cross="" +if [ "$(uname -m)" != "aarch64" ]; then cross="aarch64-linux-gnu-"; fi +target=""; [[ "${kind}" == full ]] && target=full + +work="$(mktemp -d)" +trap 'rm -rf "${work}"' EXIT +declare -A digest=() +for b in a b; do + out="${work}/ck-${b}" + if ! make -s -C native/kernel CROSS="${cross}" OUT="${out}" AIENOS_COMMIT="${commit}" ${target} >"${work}/build-${b}.log" 2>&1; then + tail -20 "${work}/build-${b}.log" + echo "CK_REPRO_BUILD: FAIL ${kind} (build ${b} failed)" + exit 2 + fi + img="${out}/BOOTAA64.EFI" + [[ "${kind}" == full ]] && img="${out}/full/BOOTAA64.EFI" + [[ -f "${img}" ]] || { echo "CK_REPRO_BUILD: FAIL ${kind} (build ${b} produced no ${img#"${work}"/})"; exit 2; } + digest[${b}]="$(sha256sum "${img}" | cut -c1-64)" + echo "build ${b}: ${digest[${b}]} $(stat -c %s "${img}") bytes (OUT=${out})" + [[ "${b}" == a ]] && img_a="${img}" +done +echo "commit: ${commit}" +echo "toolchain: $(${cross}gcc --version | head -1); $(${cross}ld --version | head -1)" +if [[ -n "${keep}" ]]; then + mkdir -p "${keep}" + cp "${img_a}" "${keep}/BOOTAA64.EFI" + echo "kept: ${keep}/BOOTAA64.EFI" +fi +if [[ "${digest[a]}" == "${digest[b]}" ]]; then + echo "CK_REPRO_BUILD: PASS ${kind} commit=${commit} sha256=${digest[a]}" + exit 0 +fi +echo "CK_REPRO_BUILD: FAIL ${kind} (digests differ: ${digest[a]} ${digest[b]})" +exit 1 diff --git a/scripts/native_boot_preflight.sh b/scripts/native_boot_preflight.sh new file mode 100755 index 00000000..068fe014 --- /dev/null +++ b/scripts/native_boot_preflight.sh @@ -0,0 +1,138 @@ +#!/usr/bin/env bash +# native_boot_preflight.sh -- READ-ONLY preflight before an attended one-time +# native AIENOS boot on the Spark (docs/native/PREFLIGHT-AND-RECOVERY.md +# section 2). It only reads: `efibootmgr` with no arguments, the SecureBoot +# EFI variable file, findmnt, git status, the image file and the quiet flag. +# It never writes a variable, never stages, never reboots, needs no sudo. +# +# Usage: bash scripts/native_boot_preflight.sh [--image EFI [--expect-sha256 HEX]] +# bash scripts/native_boot_preflight.sh --self-test (canned inputs, no machine state) +# +# Checks, one line each (PASS / STOP / INFO); the last line is +# NATIVE_PREFLIGHT: READY every STOP-class check passed +# NATIVE_PREFLIGHT: NOT_READY at least one STOP line (exit 1) +# Items Drake does in person (at the machine, display and keyboard attached, +# fresh go-ahead for this boot) cannot be read by a script: they are printed +# as ASK lines and never counted as passed. +# +# Environment (for the self-test and for reading a saved capture): +# AIENOS_PREFLIGHT_EFIBOOTMGR file holding saved `efibootmgr` output +# AIENOS_PREFLIGHT_SECUREBOOT path of the SecureBoot variable file +# AIENOS_PREFLIGHT_ESP ESP mount point (default /boot/efi) +# AIENOS_QUIET_FLAG quiet flag path (default ~/workspace/.spark-quiet) +set -uo pipefail + +repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +default_entry="0001" +recov_entry="0004" +recov_label="AIENOSRECOV" +sb_default="/sys/firmware/efi/efivars/SecureBoot-8be4df61-93ca-11d2-aa0d-00e098032b8c" + +# preflight EFIBOOTMGR_TEXT SB_FILE ESP QUIET_FLAG TREE_STATUS IMAGE EXPECT +# Prints the check lines; returns 0 READY, 1 NOT_READY. +preflight() { + local boot="$1" sb="$2" esp="$3" quiet="$4" tree="$5" image="$6" expect="$7" stops=0 + stop() { echo "STOP $*"; stops=$((stops + 1)); } + ok() { echo "PASS $*"; } + echo "ASK Drake is at the machine with a display and keyboard attached, and gave a fresh go-ahead for this boot" + if [[ -z "${boot}" ]]; then + stop "efibootmgr gave no output (not a UEFI Linux host, or efibootmgr missing)" + else + local order next current recov + order="$(sed -n 's/^BootOrder: //p' <<<"${boot}")" + next="$(sed -n 's/^BootNext: //p' <<<"${boot}")" + current="$(sed -n 's/^BootCurrent: //p' <<<"${boot}")" + recov="$(grep -E "^Boot${recov_entry}\*? " <<<"${boot}" || true)" + echo "INFO BootCurrent=${current:-?} BootOrder=${order:-?}" + [[ "${recov}" == *"${recov_label}"* ]] && ok "recovery stick: Boot${recov_entry} ${recov_label} listed" \ + || stop "recovery stick: Boot${recov_entry} ${recov_label} not listed (got '${recov:-none}'); plug it in, see docs/RECOVERY_MEDIA_MACHINE1.md" + [[ "${order%%,*}" == "${default_entry}" ]] && ok "BootOrder starts with ${default_entry} (Linux, the permanent default)" \ + || stop "BootOrder does not start with ${default_entry} (got '${order:-none}')" + [[ -z "${next}" ]] && ok "BootNext is not set (no other one-time boot pending)" \ + || stop "BootNext is already set (${next}); another staging is pending" + [[ "${current}" == "${default_entry}" ]] && ok "running from Boot${default_entry} (Linux)" \ + || stop "BootCurrent is '${current:-?}', not ${default_entry}: not booted from the default entry" + fi + if [[ -r "${sb}" ]]; then + local b; b="$(od -An -t u1 -j 4 -N 1 "${sb}" | tr -d ' ')" + case "${b}" in + 0) echo "INFO Secure Boot: off (recorded only; development decision 2026-10-01; a release needs it on; never flip it here)" ;; + 1) stop "Secure Boot: on; the unsigned C image would be refused (Secure Boot Violation); do not turn it off as part of this procedure" ;; + *) stop "Secure Boot variable unreadable (byte 4 = '${b}')" ;; + esac + else + stop "Secure Boot variable ${sb} not readable" + fi + if [[ -n "$(findmnt -no SOURCE "${esp}" 2>/dev/null)" ]]; then ok "ESP mounted at ${esp}"; else stop "ESP not mounted at ${esp}"; fi + if [[ -e "${quiet}" ]]; then stop "quiet flag ${quiet} is held: $(head -c 120 "${quiet}" 2>/dev/null)"; else ok "no quiet flag held (no other hardware run)"; fi + if [[ -z "${tree}" ]]; then ok "working tree clean"; else stop "working tree not clean ($(wc -l <<<"${tree}") entries): the image must map to one commit"; fi + if [[ -n "${image}" ]]; then + if [[ -r "${image}" ]]; then + local d; d="$(sha256sum "${image}" | cut -c1-64)" + echo "INFO image ${image} sha256=${d}" + if [[ -n "${expect}" ]]; then + [[ "${d}" == "${expect,,}" ]] && ok "image digest equals the expected digest (from scripts/ck_repro_build.sh)" \ + || stop "image digest ${d} differs from the expected ${expect}" + else + echo "ASK compare this digest with the CK_REPRO_BUILD line for this commit (--expect-sha256 checks it)" + fi + else + stop "image ${image} not readable" + fi + fi + echo "ASK the candidate is the one-time BootNext entry; Linux (Boot${default_entry}) stays first in BootOrder; the stage script makes the pre-boot capture itself" + if [[ ${stops} == 0 ]]; then echo "NATIVE_PREFLIGHT: READY (read-only checks only; the ASK lines are Drake's)"; return 0; fi + echo "NATIVE_PREFLIGHT: NOT_READY (${stops} STOP)" + return 1 +} + +if [[ "${1:-}" == --self-test ]]; then + st=0; t="$(mktemp -d)"; trap 'rm -rf "${t}"' EXIT + good=$'BootCurrent: 0001\nTimeout: 5 seconds\nBootOrder: 0001,0003\nBoot0001* ubuntu\nBoot0003* UEFI PXE\nBoot0004* AIENOSRECOV' + printf '\0\0\0\0\0' >"${t}/sb_off"; printf '\0\0\0\0\1' >"${t}/sb_on" + esp="/" # any mounted path stands in for the ESP in the self-test + printf 'img' >"${t}/img"; dig="$(sha256sum "${t}/img" | cut -c1-64)" + case_() { # label want(0|1) boot sb quiet tree image expect + local rc=0; preflight "$3" "$4" "${esp}" "$5" "$6" "$7" "$8" >"${t}/out" 2>&1 || rc=1 + if [[ "${rc}" == "$2" ]]; then echo "PASS $1"; else echo "FAIL $1 (wanted $2, got ${rc})"; cat "${t}/out"; st=1; fi + } + case_ "good state is READY" 0 "${good}" "${t}/sb_off" "${t}/noflag" "" "${t}/img" "${dig}" + case_ "BootNext pending -> NOT_READY" 1 "${good}"$'\nBootNext: 0000' "${t}/sb_off" "${t}/noflag" "" "" "" + case_ "recovery stick absent -> NOT_READY" 1 "${good/Boot0004\* AIENOSRECOV/}" "${t}/sb_off" "${t}/noflag" "" "" "" + case_ "BootOrder not Linux first -> NOT_READY" 1 "${good/BootOrder: 0001,0003/BootOrder: 0000,0001}" "${t}/sb_off" "${t}/noflag" "" "" "" + case_ "booted from another entry -> NOT_READY" 1 "${good/BootCurrent: 0001/BootCurrent: 0004}" "${t}/sb_off" "${t}/noflag" "" "" "" + case_ "Secure Boot on -> NOT_READY" 1 "${good}" "${t}/sb_on" "${t}/noflag" "" "" "" + case_ "Secure Boot variable missing -> NOT_READY" 1 "${good}" "${t}/nosb" "${t}/noflag" "" "" "" + touch "${t}/flag" + case_ "quiet flag held -> NOT_READY" 1 "${good}" "${t}/sb_off" "${t}/flag" "" "" "" + case_ "dirty tree -> NOT_READY" 1 "${good}" "${t}/sb_off" "${t}/noflag" " M x" "" "" + case_ "image digest mismatch -> NOT_READY" 1 "${good}" "${t}/sb_off" "${t}/noflag" "" "${t}/img" "00${dig:2}" + case_ "no efibootmgr output -> NOT_READY" 1 "" "${t}/sb_off" "${t}/noflag" "" "" "" + # The script must stay read-only: no variable-writing efibootmgr flag, no sudo, no reboot. + if grep -nE '(^|[^#]*)(efibootmgr +-[a-zA-Z]|--bootnext|--bootorder|--create|sudo |reboot|systemctl|chattr|dd |mkfs)' "${BASH_SOURCE[0]}" \ + | grep -vE "^[0-9]+: *#|grep -nE|^[0-9]+: *echo " >/dev/null; then + echo "FAIL script contains a writing command"; st=1 + else + echo "PASS script contains no writing command (efibootmgr flags, sudo, reboot, chattr, dd, mkfs)" + fi + if [[ ${st} == 0 ]]; then echo "NATIVE_PREFLIGHT_SELF_TEST: PASS"; exit 0; fi + echo "NATIVE_PREFLIGHT_SELF_TEST: FAIL"; exit 1 +fi + +image="" expect="" +while [[ $# -gt 0 ]]; do + case "$1" in + --image) image="${2:-}"; shift 2 ;; + --expect-sha256) expect="${2:-}"; shift 2 ;; + *) echo "usage: $0 [--image EFI [--expect-sha256 HEX]] | --self-test"; exit 2 ;; + esac +done +if [[ -n "${AIENOS_PREFLIGHT_EFIBOOTMGR:-}" ]]; then + boot="$(cat "${AIENOS_PREFLIGHT_EFIBOOTMGR}" 2>/dev/null || true)" +else + boot="$(efibootmgr 2>/dev/null || true)" +fi +tree="$(git -C "${repo_root}" status --porcelain --untracked-files=normal 2>/dev/null || echo '?? not a git checkout')" +echo "commit: $(git -C "${repo_root}" rev-parse HEAD 2>/dev/null || echo unknown)" +preflight "${boot}" "${AIENOS_PREFLIGHT_SECUREBOOT:-${sb_default}}" "${AIENOS_PREFLIGHT_ESP:-/boot/efi}" \ + "${AIENOS_QUIET_FLAG:-${HOME}/workspace/.spark-quiet}" "${tree}" "${image}" "${expect}" diff --git a/scripts/qemu_ck_rollback_test.sh b/scripts/qemu_ck_rollback_test.sh new file mode 100755 index 00000000..62e65271 --- /dev/null +++ b/scripts/qemu_ck_rollback_test.sh @@ -0,0 +1,399 @@ +#!/usr/bin/env bash +# qemu_ck_rollback_test.sh -- CK gate M0_ROLLBACK: one-time BootNext rollback +# with the AIENOS C kernel image as the candidate, in QEMU AArch64 with AAVMF. +# +# Design (ACCEPTED, no A/B slots, ADR 0024 Q3): docs/BOOT_HANDOFF_CONTRACT.md +# section 7 and 7.1, docs/NATIVE_BOOT_ROLLBACK_CONTRACT.md. The Rust +# aienos-rollback-mock stays the stager (\EFI\BOOT\BOOTAA64.EFI: writes +# Boot0001 "Default Linux OS", Boot0000 "AIENOS Candidate", BootOrder=0001, +# BootNext=0000, resets) and the Default entry (\EFI\DEFAULT\default.efi). +# Only the candidate changes: \EFI\AIENOS\candidate.efi is a C kernel image +# built here with make. The Rust-mock run (scripts/qemu_native_rollback_test.sh) +# is untouched and keeps its own labels; this script prints CK_ROLLBACK_* and +# AIENOS_CK_M0_ROLLBACK lines only. +# +# Each case is a lane with its own fresh copy of AAVMF_VARS.fd (the emulated +# UEFI variable store) and its own ESP folder, four boots: +# boot 1 stage the mock stager sets BootNext=0000 and resets +# boot 2 attempt firmware consumes BootNext and starts (or fails to load) +# Boot0000 +# boot 3 default the next boot (for rejected/absent the Default already ran +# in boot 2, so boot 3 is its first repeat) +# boot 4 default one more boot: still Default, no second candidate attempt +# After every boot the host reads the variable store file itself +# (native/kernel/tools/ck_uefi_vars.c, read-only), so the BootNext and +# BootOrder verdicts come from the firmware's own store, not from a guest print. +# +# Cases (lane -> candidate.efi): +# normal the default C core image: runs to "report_kind: final", PSCI reset +# panic TEST-only CK_TEST_ROLLBACK=bad-magic: the kernel refuses its +# handoff ("panic: handoff: bad magic") and resets +# cpu-fault TEST-only CK_TEST_ROLLBACK=cpu-fault: BRK at EL1 after +# "kernel: alive"; fault report ("report_kind: fault", EC 0x3c), reset +# hang TEST-only CK_TEST_ROLLBACK=hang: marker, then spins with +# interrupts masked; the host checks it is still running +# AIENOS_HANG_HOLD seconds later with no reset, then kills QEMU +# (stands in for the operator power-cycle or an outside watchdog; +# the stub disables the UEFI watchdog, there is none in the guest) +# rejected the default C image cut to its first 4096 bytes (PE headers +# intact, sections missing): the firmware must refuse to load it +# absent Boot0000 names a file that does not exist (stager mode absent) +# +# Checks per lane (each its own PASS/FAIL line): +# staged after boot 1 the store holds BootNext=0000, BootOrder=0001, +# Boot0000="AIENOS Candidate" +# attempt boot 2 shows the case's own evidence (above) and the firmware +# line for Boot0000; QEMU ended by reset (exit 0), except hang +# returned the first boot after the attempt runs Boot0001 "Default Linux +# OS" (BdsDxe line and the mock's BOOT_CURRENT=0001) +# once BootNext is absent in the store after boots 2, 3 and 4, and +# the firmware dispatched Boot0000 in boot 2 only +# order BootOrder: 0001 first and Boot0000 never in it after any boot; +# identical after boots 2, 3 and 4 (no later change); and equal +# after boot 2 to the absent lane, where no candidate code ran +# at all (the control). AAVMF itself appends its own +# auto-created options (UiApp, UEFI Misc Device, EFI Internal +# Shell) to BootOrder on the boot after the stager wrote +# BootOrder=0001; the control lane shows that this is the +# firmware, not the candidate. That firmware append is printed +# as an observation (same class as the Machine 1 note in +# docs/M0_NATIVE_BOOT_ROLLBACK_AUDIT.md row 7). +# +# Rows: native/kernel/GATES.md 42-46. QEMU only: a PASS here qualifies +# nothing physical. Never touches a real disk, NVRAM, firmware or key: every +# variable store is a temp copy of AAVMF_VARS.fd, every ESP a temp folder. +# +# Usage: bash scripts/qemu_ck_rollback_test.sh (full run) +# bash scripts/qemu_ck_rollback_test.sh --self-test (judges on canned +# logs and store dumps, no QEMU) +# Environment: AAVMF_CODE, AAVMF_VARS, AIENOS_QEMU_TIMEOUT (per boot, 120 s), +# AIENOS_HANG_HOLD (10 s), AIENOS_QUIET_FLAG (read only), AIENOS_GATE_LOCK / +# AIENOS_GATE_TAG (exclusive QEMU gate lock), AIENOS_ROLLBACK_KEEP=DIR (copy +# the lane logs and store dumps there). +# Exit: 0 PASS, 1 FAIL, 2 missing tool, 3 NOT_RUN (quiet flag or lock held). +set -euo pipefail + +repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +cd "${repo_root}" +verdict_name="AIENOS_CK_M0_ROLLBACK" + +failed=0 +pass() { echo "PASS $1"; } +fail() { echo "FAIL $1"; failed=1; } + +# --------------------------------------------------------------------------- +# Judges. Arguments are file paths; each returns 0 only on its own evidence. +# --------------------------------------------------------------------------- +# vget DUMP KEY -> value of "KEY=value" in a ck_uefi_vars dump, or "missing" +vget() { local v; v="$(sed -n "s/^$2=//p" "$1" 2>/dev/null | head -n1)"; echo "${v:-missing}"; } +# order_ok DUMP: BootOrder present, 0001 first, 0000 nowhere in it +order_ok() { + local o; o="$(vget "$1" BootOrder)" + [[ "${o}" =~ ^0001(,[0-9A-F]{4})*$ ]] && [[ ",${o}," != *",0000,"* ]] +} +staged_ok() { # DUMP after boot 1 + [[ "$(vget "$1" BootNext)" == 0000 && "$(vget "$1" BootOrder)" == 0001 && \ + "$(vget "$1" Boot0000)" == "AIENOS Candidate" && "$(vget "$1" Boot0001)" == "Default Linux OS" ]] +} +starts0() { grep -ac 'BdsDxe: starting Boot0000 "AIENOS Candidate"' "$1" 2>/dev/null || true; } +has() { grep -aqF -- "$2" "$1" 2>/dev/null; } +# no_c_report LOG: no kernel end report of any kind +no_c_end() { ! grep -aqE '^report_kind: (final|panic|fault)' "$1" 2>/dev/null; } + +# attempt_ok CASE LOG RC [HELD] +attempt_ok() { + local case="$1" log="$2" rc="$3" held="${4:-0}" + case "${case}" in + normal) + [[ "${rc}" == 0 && "$(starts0 "${log}")" == 1 ]] && has "${log}" "kernel_impl: c (native/kernel, Lane 18)" && \ + has "${log}" "kernel: alive" && has "${log}" "report_kind: final" && \ + has "${log}" "note: QEMU qualifies nothing physical" && \ + ! grep -aqE '^report_kind: (panic|fault)' "${log}" && ! has "${log}" "TEST-ONLY rollback candidate" ;; + panic) + [[ "${rc}" == 0 && "$(starts0 "${log}")" == 1 ]] && \ + has "${log}" "rollback_test: TEST-ONLY rollback candidate (bad-magic)" && \ + has "${log}" "report_kind: panic" && grep -aqx 'panic: handoff: bad magic' <(tr -d '\r' <"${log}") && \ + ! has "${log}" "kernel: alive" && ! has "${log}" "report_kind: final" ;; + cpu-fault) + [[ "${rc}" == 0 && "$(starts0 "${log}")" == 1 ]] && has "${log}" "kernel: alive" && \ + has "${log}" "rollback_test: TEST-ONLY rollback candidate (cpu-fault)" && \ + has "${log}" "report_kind: fault" && grep -aqE '^fault: vector=sync_el_spx el=1 .* ec=0x3c ' "${log}" && \ + ! has "${log}" "report_kind: final" ;; + hang) + [[ "${held}" == 1 && "$(starts0 "${log}")" == 1 ]] && has "${log}" "kernel: alive" && \ + has "${log}" "rollback_test: TEST-ONLY rollback candidate (hang)" && no_c_end "${log}" ;; + rejected|absent) + [[ "${rc}" == 0 && "$(starts0 "${log}")" == 0 ]] && has "${log}" "failed to load Boot0000" && \ + ! has "${log}" "kernel_impl: c" && has "${log}" 'BdsDxe: starting Boot0001 "Default Linux OS"' ;; + *) return 1 ;; + esac +} +returned_ok() { # LOG of the first boot that must be the Default + has "$1" 'BdsDxe: starting Boot0001 "Default Linux OS"' && has "$1" "DEFAULT_OS: BOOT_CURRENT=0001" +} +# once_ok CASE V2 V3 V4 LOG2 LOG3 LOG4 +once_ok() { + local case="$1" want=1 + [[ "${case}" == rejected || "${case}" == absent ]] && want=0 + [[ "$(vget "$2" BootNext)" == absent && "$(vget "$3" BootNext)" == absent && "$(vget "$4" BootNext)" == absent ]] && \ + [[ "$(starts0 "$5")" == "${want}" && "$(starts0 "$6")" == 0 && "$(starts0 "$7")" == 0 ]] && \ + ! has "$6" "loading Boot0000" && ! has "$7" "loading Boot0000" +} +# order_lane_ok V1 V2 V3 V4 CONTROL_V2 +order_lane_ok() { + local o2; o2="$(vget "$2" BootOrder)" + order_ok "$1" && order_ok "$2" && order_ok "$3" && order_ok "$4" && \ + [[ "$(vget "$3" BootOrder)" == "${o2}" && "$(vget "$4" BootOrder)" == "${o2}" ]] && \ + [[ -f "$5" && "$(vget "$5" BootOrder)" == "${o2}" ]] +} + +if [[ "${1:-}" == --self-test ]]; then + st=0; t="$(mktemp -d)"; trap 'rm -rf "${t}"' EXIT + expect() { # label want(0|1) cmd... + local label="$1" want="$2" rc=0; shift 2 + "$@" || rc=$?; [[ "${rc}" != 0 ]] && rc=1 + if [[ "${rc}" == "${want}" ]]; then echo "PASS ${label}"; else echo "FAIL ${label} (wanted ${want}, got ${rc})"; st=1; fi + } + printf 'uefi_vars: store=authenticated live=17 obsolete=6\nBootOrder=0001\nBootNext=0000\nBoot0000=AIENOS Candidate\nBoot0001=Default Linux OS\n' >"${t}/v1" + printf 'uefi_vars: store=authenticated live=18 obsolete=14\nBootOrder=0001,0002,0003,0004\nBootNext=absent\nBoot0000=AIENOS Candidate\nBoot0001=Default Linux OS\n' >"${t}/v2" + cp "${t}/v2" "${t}/ctl" + expect "staged store accepted" 0 staged_ok "${t}/v1" + expect "unstaged store (BootNext absent) refused as staged" 1 staged_ok "${t}/v2" + sed 's/^BootOrder=0001$/BootOrder=0000,0001/' "${t}/v1" >"${t}/v1p" + expect "stager that promoted Boot0000 refused as staged" 1 staged_ok "${t}/v1p" + expect "order: settled lane equal to control accepted" 0 order_lane_ok "${t}/v1" "${t}/v2" "${t}/v2" "${t}/v2" "${t}/ctl" + sed 's/^BootOrder=.*/BootOrder=0000,0001,0002,0003,0004/' "${t}/v2" >"${t}/vprom" + expect "order: Boot0000 promoted into BootOrder refused" 1 order_lane_ok "${t}/v1" "${t}/vprom" "${t}/vprom" "${t}/vprom" "${t}/vprom" + sed 's/^BootOrder=.*/BootOrder=0002,0001,0003,0004/' "${t}/v2" >"${t}/vfirst" + expect "order: Default no longer first refused" 1 order_lane_ok "${t}/v1" "${t}/v2" "${t}/vfirst" "${t}/v2" "${t}/ctl" + sed 's/^BootOrder=.*/BootOrder=0001,0003/' "${t}/v2" >"${t}/vdiff" + expect "order: lane differs from the control refused" 1 order_lane_ok "${t}/v1" "${t}/vdiff" "${t}/vdiff" "${t}/vdiff" "${t}/ctl" + expect "order: later boot changed BootOrder refused" 1 order_lane_ok "${t}/v1" "${t}/v2" "${t}/v2" "${t}/vdiff" "${t}/ctl" + expect "order: missing control refused" 1 order_lane_ok "${t}/v1" "${t}/v2" "${t}/v2" "${t}/v2" "${t}/nocontrol" + sed 's/^BootNext=absent$/BootNext=0000/' "${t}/v2" >"${t}/vnext" + good2='BdsDxe: starting Boot0000 "AIENOS Candidate" from x' + printf '%s\n' "${good2}" >"${t}/l2"; printf 'BdsDxe: starting Boot0001 "Default Linux OS" from x\n' >"${t}/l3" + expect "once: BootNext gone after boots 2-4, one dispatch accepted" 0 once_ok normal "${t}/v2" "${t}/v2" "${t}/v2" "${t}/l2" "${t}/l3" "${t}/l3" + expect "once: BootNext still set after boot 2 refused" 1 once_ok normal "${t}/vnext" "${t}/v2" "${t}/v2" "${t}/l2" "${t}/l3" "${t}/l3" + expect "once: BootNext back after boot 4 refused" 1 once_ok normal "${t}/v2" "${t}/v2" "${t}/vnext" "${t}/l2" "${t}/l3" "${t}/l3" + expect "once: second dispatch in boot 3 refused" 1 once_ok normal "${t}/v2" "${t}/v2" "${t}/v2" "${t}/l2" "${t}/l2" "${t}/l3" + expect "once: rejected lane must show no dispatch" 1 once_ok rejected "${t}/v2" "${t}/v2" "${t}/v2" "${t}/l2" "${t}/l3" "${t}/l3" + # attempt judges on canned serial logs + { echo "${good2}"; echo "kernel_impl: c (native/kernel, Lane 18)"; echo "kernel: alive"; echo "report_kind: final"; echo "note: QEMU qualifies nothing physical"; } >"${t}/normal" + expect "attempt normal: final report accepted" 0 attempt_ok normal "${t}/normal" 0 + expect "attempt normal: QEMU timeout (exit 124) refused" 1 attempt_ok normal "${t}/normal" 124 + { cat "${t}/normal"; echo "report_kind: panic"; } >"${t}/normalp" + expect "attempt normal: a panic in the log refused" 1 attempt_ok normal "${t}/normalp" 0 + grep -v 'report_kind: final' "${t}/normal" >"${t}/nofinal" + expect "attempt normal: no final report refused" 1 attempt_ok normal "${t}/nofinal" 0 + { echo "${good2}"; echo "rollback_test: TEST-ONLY rollback candidate (bad-magic): x"; echo "report_kind: panic"; printf 'panic: handoff: bad magic\r\n'; } >"${t}/panic" + expect "attempt panic: bad magic refusal accepted" 0 attempt_ok panic "${t}/panic" 0 + sed 's/bad magic/unsupported version 2 (kernel reads CHANDOF3 only)/' "${t}/panic" >"${t}/panicv" + expect "attempt panic: a different refusal reason refused" 1 attempt_ok panic "${t}/panicv" 0 + { echo "${good2}"; echo "kernel: alive"; echo "rollback_test: TEST-ONLY rollback candidate (cpu-fault): x"; echo "report_kind: fault"; echo "fault: vector=sync_el_spx el=1 esr=0xf200007b ec=0x3c far=0x0 elr=0x1"; } >"${t}/fault" + expect "attempt cpu-fault: BRK fault report accepted" 0 attempt_ok cpu-fault "${t}/fault" 0 + sed 's/ec=0x3c/ec=0x25/' "${t}/fault" >"${t}/faultdab" + expect "attempt cpu-fault: another exception class refused" 1 attempt_ok cpu-fault "${t}/faultdab" 0 + { echo "${good2}"; echo "kernel: alive"; echo "rollback_test: TEST-ONLY rollback candidate (hang): x"; } >"${t}/hang" + expect "attempt hang: held and silent accepted" 0 attempt_ok hang "${t}/hang" 137 1 + expect "attempt hang: QEMU ended by itself refused" 1 attempt_ok hang "${t}/hang" 0 0 + { cat "${t}/hang"; echo "report_kind: final"; } >"${t}/hangend" + expect "attempt hang: an end report after the marker refused" 1 attempt_ok hang "${t}/hangend" 137 1 + { echo 'BdsDxe: failed to load Boot0000 "AIENOS Candidate" from x: Not Found'; echo 'BdsDxe: starting Boot0001 "Default Linux OS" from x'; } >"${t}/absent" + expect "attempt absent: load failure then Default accepted" 0 attempt_ok absent "${t}/absent" 0 + { cat "${t}/absent"; echo "${good2}"; } >"${t}/absentran" + expect "attempt absent: a dispatched Boot0000 refused" 1 attempt_ok absent "${t}/absentran" 0 + printf 'BdsDxe: starting Boot0001 "Default Linux OS" from x\nDEFAULT_OS: BOOT_CURRENT=0001\n' >"${t}/l3d" + expect "returned: Default boot accepted" 0 returned_ok "${t}/l3d" + expect "returned: candidate boot again refused" 1 returned_ok "${t}/l2" + if [[ ${st} == 0 ]]; then echo "CK_ROLLBACK_SELF_TEST: PASS"; exit 0; fi + echo "CK_ROLLBACK_SELF_TEST: FAIL"; exit 1 +fi + +# --------------------------------------------------------------------------- +# Full run +# --------------------------------------------------------------------------- +code_fd="${AAVMF_CODE:-/usr/share/AAVMF/AAVMF_CODE.no-secboot.fd}" +vars_fd="${AAVMF_VARS:-/usr/share/AAVMF/AAVMF_VARS.fd}" +qemu_timeout="${AIENOS_QEMU_TIMEOUT:-120}" +hang_hold="${AIENOS_HANG_HOLD:-10}" +command -v qemu-system-aarch64 >/dev/null || { echo "qemu-system-aarch64 not installed"; echo "${verdict_name}: NOT_RUN"; exit 2; } +[[ -r "${code_fd}" && -r "${vars_fd}" ]] || { echo "AAVMF firmware not found"; echo "${verdict_name}: NOT_RUN"; exit 2; } +command -v cargo >/dev/null || { echo "cargo not installed (the stager/Default mock is Rust)"; echo "${verdict_name}: NOT_RUN"; exit 2; } + +quiet_flag="${AIENOS_QUIET_FLAG:-${HOME}/workspace/.spark-quiet}" +if [[ -e "${quiet_flag}" ]]; then + echo "NOT_RUN quiet flag ${quiet_flag} is held: $(head -c 200 "${quiet_flag}" 2>/dev/null || true)" + echo "${verdict_name}: NOT_RUN" + exit 3 +fi +gate_lock="${AIENOS_GATE_LOCK:-${HOME}/workspace/.qemu-gate-lock}" +gate_tag="${AIENOS_GATE_TAG:-qemu_ck_rollback_test $$}" +if ! ( set -C; echo "${gate_tag}" > "${gate_lock}" ) 2>/dev/null; then + echo "NOT_RUN QEMU gate lock ${gate_lock} is held: $(head -c 200 "${gate_lock}" 2>/dev/null || true)" + echo "${verdict_name}: NOT_RUN" + exit 3 +fi +own_lock=1 +release_lock() { + if [[ "${own_lock}" == 1 ]]; then + own_lock=0 + if [[ -f "${gate_lock}" ]] && grep -qxF -- "${gate_tag}" "${gate_lock}"; then rm -f "${gate_lock}"; fi + fi +} +work="$(mktemp -d)" +qemu_pid="" +cleanup() { + if [[ -n "${qemu_pid}" ]]; then kill -9 "${qemu_pid}" 2>/dev/null || true; fi + if [[ -n "${AIENOS_ROLLBACK_KEEP:-}" ]]; then mkdir -p "${AIENOS_ROLLBACK_KEEP}" && cp -r "${work}/lanes" "${AIENOS_ROLLBACK_KEEP}/" 2>/dev/null || true; fi + rm -rf "${work}"; release_lock +} +trap cleanup EXIT + +cross="" +if [ "$(uname -m)" != "aarch64" ]; then cross="aarch64-linux-gnu-"; fi +commit="$(git rev-parse HEAD 2>/dev/null || echo unknown)" +echo "============================================================" +echo "AIENOS CK M0_ROLLBACK: C kernel image as the one-time BootNext candidate (QEMU)" +echo "commit: ${commit}$( [[ -z "$(git status --porcelain 2>/dev/null)" ]] || echo ' (dirty tree)')" +echo "firmware: $(basename "${code_fd}") vars template sha256 $(sha256sum "${vars_fd}" | cut -c1-64)" +echo "============================================================" + +echo "building aienos-rollback-mock (stager and Default, unchanged Rust mock) ..." +cargo build --quiet --release -p aienos-boot --target aarch64-unknown-uefi --features handoff --bin aienos-rollback-mock +mock="target/aarch64-unknown-uefi/release/aienos-rollback-mock.efi" +[[ -f "${mock}" ]] || { echo "mock build failed"; echo "${verdict_name}: FAIL"; exit 1; } + +echo "building the C kernel images ..." +out_def="${repo_root}/target/native-kernel" +make -s -C native/kernel CROSS="${cross}" OUT="${out_def}" AIENOS_COMMIT="${commit}" >/dev/null +make -s -C native/kernel OUT="${out_def}" uefi-vars >/dev/null +vars_tool="${out_def}/host/ck_uefi_vars" +declare -A img=([normal]="${out_def}/BOOTAA64.EFI") +for m in bad-magic cpu-fault hang; do + o="${repo_root}/target/native-kernel-test-rollback-${m}" + make -s -C native/kernel CROSS="${cross}" OUT="${o}" AIENOS_COMMIT="${commit}" CK_TEST_ROLLBACK="${m}" >/dev/null + img[${m}]="${o}/BOOTAA64.EFI" +done +img[panic]="${img[bad-magic]}" +head -c 4096 "${img[normal]}" >"${work}/truncated.efi" +img[rejected]="${work}/truncated.efi" +for k in normal panic cpu-fault hang rejected; do + echo "candidate ${k}: sha256 $(sha256sum "${img[${k}]}" | cut -c1-64) bytes $(stat -c %s "${img[${k}]}")" +done +if grep -aqF "TEST-ONLY rollback candidate" "${img[normal]}"; then + fail "the default C image carries a TEST-only rollback candidate" +fi +if "${vars_tool}" --self-test >"${work}/vars_selftest.log" 2>&1; then + pass "ck_uefi_vars self-test ($(grep -c '^PASS' "${work}/vars_selftest.log") cases)" +else + cat "${work}/vars_selftest.log"; fail "ck_uefi_vars self-test" +fi + +qemu_args() { # VARS ESP LOG + echo -M virt,virtualization=on,gic-version=3 -accel tcg,thread=single -cpu max -smp 2 -m 512 \ + -drive "if=pflash,format=raw,readonly=on,file=${code_fd}" \ + -drive "if=pflash,format=raw,file=$1" \ + -drive "if=none,id=esp,format=raw,file=fat:rw:$2" \ + -device virtio-blk-pci,drive=esp -display none -nic none -serial "file:$3" -no-reboot +} +boot() { # LANE N -> sets boot_rc; dumps the store to LANE/vN + local d="$1" n="$2" + set +e + # shellcheck disable=SC2046 + timeout "${qemu_timeout}" qemu-system-aarch64 $(qemu_args "${d}/vars.fd" "${d}/esp" "${d}/boot${n}.log") "${d}/qemu${n}.out" 2>&1 + boot_rc=$? + set -e + "${vars_tool}" "${d}/vars.fd" >"${d}/v${n}" 2>&1 || true +} +hang_held=0 +boot_hang() { # LANE N: start, wait for the marker, hold, then force the reset + local d="$1" n="$2" log="$1/boot$2.log" waited=0 i + hang_held=0 + # shellcheck disable=SC2046 + qemu-system-aarch64 $(qemu_args "${d}/vars.fd" "${d}/esp" "${log}") "${d}/qemu${n}.out" 2>&1 & + qemu_pid=$! + for ((i = 0; i < qemu_timeout * 2; i++)); do + sleep 0.5 + if grep -aqF "rollback_test: TEST-ONLY rollback candidate (hang)" "${log}" 2>/dev/null; then waited=1; break; fi + kill -0 "${qemu_pid}" 2>/dev/null || break + done + if [[ "${waited}" == 1 ]]; then + sleep "${hang_hold}" + if kill -0 "${qemu_pid}" 2>/dev/null && no_c_end "${log}"; then + hang_held=1 + echo "hang: QEMU still running ${hang_hold} s after the hang marker, no end report; host forces the reset" + fi + fi + kill -9 "${qemu_pid}" 2>/dev/null || true + wait "${qemu_pid}" 2>/dev/null || true + qemu_pid="" + boot_rc=137 + "${vars_tool}" "${d}/vars.fd" >"${d}/v${n}" 2>&1 || true +} + +lanes=(absent normal panic cpu-fault hang rejected) # absent first: it is the control +declare -A verdict=() +all_once=PASS; all_order=PASS +for lane in "${lanes[@]}"; do + d="${work}/lanes/${lane}" + mkdir -p "${d}/esp/EFI/BOOT" "${d}/esp/EFI/AIENOS" "${d}/esp/EFI/DEFAULT" + cp "${vars_fd}" "${d}/vars.fd" + cp "${mock}" "${d}/esp/EFI/BOOT/BOOTAA64.EFI" + cp "${mock}" "${d}/esp/EFI/DEFAULT/default.efi" + if [[ "${lane}" == absent ]]; then + echo absent >"${d}/esp/EFI/AIENOS/ROLLBACK_MODE.TXT" + else + echo normal >"${d}/esp/EFI/AIENOS/ROLLBACK_MODE.TXT" + cp "${img[${lane}]}" "${d}/esp/EFI/AIENOS/candidate.efi" + fi + echo "" + echo "--- [lane ${lane}] ---" + "${vars_tool}" "${d}/vars.fd" >"${d}/v0" 2>&1 || true + boot "${d}" 1; rc1=${boot_rc} + if [[ "${lane}" == hang ]]; then boot_hang "${d}" 2; else boot "${d}" 2; fi + rc2=${boot_rc} + boot "${d}" 3; rc3=${boot_rc} + boot "${d}" 4; rc4=${boot_rc} + echo "qemu exits: stage=${rc1} attempt=${rc2} next=${rc3} repeat=${rc4}" + echo "store after boot 1: $(grep -E '^Boot(Order|Next)=' "${d}/v1" | paste -sd' ')" + echo "store after boot 2: $(grep -E '^Boot(Order|Next)=' "${d}/v2" | paste -sd' ')" + echo "store after boot 4: $(grep -E '^Boot(Order|Next)=' "${d}/v4" | paste -sd' ')" + first_default="${d}/boot3.log" + [[ "${lane}" == rejected || "${lane}" == absent ]] && first_default="${d}/boot2.log" + ok=1 + staged_ok "${d}/v1" && pass "${lane}: staged (BootNext=0000, BootOrder=0001, Boot0000 \"AIENOS Candidate\", read from the store)" \ + || { fail "${lane}: staged"; ok=0; } + attempt_ok "${lane}" "${d}/boot2.log" "${rc2}" "${hang_held}" && pass "${lane}: attempt evidence in boot 2" \ + || { fail "${lane}: attempt evidence in boot 2 (exit ${rc2})"; ok=0; } + returned_ok "${first_default}" && pass "${lane}: next boot is Boot0001 Default (BOOT_CURRENT=0001)" \ + || { fail "${lane}: return to Default"; ok=0; } + returned_ok "${d}/boot4.log" && pass "${lane}: repeat boot is still Default" || { fail "${lane}: repeat boot"; ok=0; } + once_ok "${lane}" "${d}/v2" "${d}/v3" "${d}/v4" "${d}/boot2.log" "${d}/boot3.log" "${d}/boot4.log" && \ + pass "${lane}: BootNext consumed once (absent in the store after boots 2-4; Boot0000 dispatched $( [[ ${lane} == rejected || ${lane} == absent ]] && echo 'never, load refused once' || echo 'in boot 2 only'))" \ + || { fail "${lane}: BootNext consumed exactly once"; ok=0; all_once=FAIL; } + order_lane_ok "${d}/v1" "${d}/v2" "${d}/v3" "${d}/v4" "${work}/lanes/absent/v2" && \ + pass "${lane}: BootOrder 0001 first, no 0000, same after boots 2-4 and equal to the no-candidate control" \ + || { fail "${lane}: BootOrder"; ok=0; all_order=FAIL; } + [[ "$(vget "${d}/v1" BootOrder)" != "$(vget "${d}/v2" BootOrder)" ]] && \ + echo "observation: AAVMF rewrote BootOrder $(vget "${d}/v1" BootOrder) -> $(vget "${d}/v2" BootOrder) in boot 2 (firmware auto-created options; the control lane shows the same)" + verdict[${lane}]=$([[ ${ok} == 1 ]] && echo PASS || echo FAIL) +done + +echo "" +echo "============================================================" +echo "Evidence kind: C-image, QEMU (AAVMF). Physical: NOT_RUN." +echo "CK_ROLLBACK_NORMAL: ${verdict[normal]}" +echo "CK_ROLLBACK_FAULT_PANIC: ${verdict[panic]}" +echo "CK_ROLLBACK_FAULT_CPU: ${verdict[cpu-fault]}" +echo "CK_ROLLBACK_TIMEOUT: ${verdict[hang]}" +echo "CK_ROLLBACK_REJECTED: ${verdict[rejected]}" +echo "CK_ROLLBACK_ABSENT: ${verdict[absent]}" +echo "CK_ROLLBACK_BOOTNEXT_CONSUMED: ${all_once}" +echo "CK_ROLLBACK_DEFAULT_UNCHANGED: ${all_order}" +if [[ "${failed}" == 0 ]]; then + echo "${verdict_name}: PASS (QEMU only, C kernel image as candidate; physical NOT_RUN)" + exit 0 +fi +echo "${verdict_name}: FAIL" +exit 1