From 506473f092612aa50595fadec6cf5b30bc916bb6 Mon Sep 17 00:00:00 2001 From: Drake Date: Fri, 25 Sep 2026 06:56:53 -0500 Subject: [PATCH 1/2] feat(boot): M0 native-boot rollback qualification and trust boundary enforcement Define and verify the native-boot rollback contract for AIENOS M0: 1. Audit existing evidence in docs/M0_NATIVE_BOOT_ROLLBACK_AUDIT.md: Determine that historical M2 native boot required manual Secure Boot disablement (which tripped TPM PCR 7 and corrupted storage unsealing), leaving the Secure-Boot-enabled native rollback gate unproven on hardware. 2. Define deterministic contract in docs/NATIVE_BOOT_ROLLBACK_CONTRACT.md: Formalize finite state machine (DefaultReady -> CandidateStaged -> CandidateSelectedOnce -> CandidateRunning -> ResetOrExit -> DefaultReturned) with failure branches (fault, timeout, rejected, absent) and the core non-promotion invariant (candidate may consume exactly one boot attempt via BootNext; never promotes into permanent BootOrder). 3. QEMU rollback test harness in scripts/qemu_native_rollback_test.sh: Add mock EFI binary crates/aienos-boot/src/rollback_mock.rs. Exercise normal completion, fault/panic, watchdog timeout reset, malformed PE, absent image, and repeated reboot across disposable AAVMF variable stores. All branches pass deterministically (M0_ROLLBACK_QEMU: PASS). 4. Update docs/NATIVE_BOOT_ONE_TIME.md: Permanently retire obsolete Secure-Boot-off instructions. Enforce Secure Boot ON, establish automatic pre/post verification, and explicitly record HARDWARE_QUALIFICATION_BLOCKED_BY_TRUST_CHAIN pending enrolled platform owner keys rather than bypassing the trust boundary. 5. Host evidence verifier in scripts/verify_native_rollback.sh: Compare pre- and post-boot captures for Secure Boot parity, BootOrder preservation, BootNext consumption, and root/ESP mount/UUID integrity. 6. Integrate into scripts/verify_all.sh as Step 6d and update ROADMAP.md. Co-authored-by: Drake Stapleton --- ROADMAP.md | 5 +- crates/aienos-boot/Cargo.toml | 5 + crates/aienos-boot/src/rollback_mock.rs | 402 ++++++++++++++++++++++++ docs/M0_NATIVE_BOOT_ROLLBACK_AUDIT.md | 85 +++++ docs/NATIVE_BOOT_ONE_TIME.md | 201 ++++++------ docs/NATIVE_BOOT_ROLLBACK_CONTRACT.md | 135 ++++++++ scripts/qemu_native_rollback_test.sh | 292 +++++++++++++++++ scripts/verify_all.sh | 11 +- scripts/verify_native_rollback.sh | 268 ++++++++++++++++ 9 files changed, 1299 insertions(+), 105 deletions(-) create mode 100644 crates/aienos-boot/src/rollback_mock.rs create mode 100644 docs/M0_NATIVE_BOOT_ROLLBACK_AUDIT.md create mode 100644 docs/NATIVE_BOOT_ROLLBACK_CONTRACT.md create mode 100755 scripts/qemu_native_rollback_test.sh create mode 100755 scripts/verify_native_rollback.sh diff --git a/ROADMAP.md b/ROADMAP.md index c44ce6c1..e82a16c1 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -11,7 +11,8 @@ bar moves as issues close. This file is updated at every gate. M0 PARTIAL Reference freeze reference snapshot PASS benchmark evidence PASS 54.2 tokens/s CPU decode baseline - native-boot rollback pending (separate from recovery USB exercise) + native-boot rollback PASS (QEMU test matrix); hardware qualification + gated as BLOCKED_BY_TRUST_CHAIN (docs/NATIVE_BOOT_ONE_TIME.md) bootable recovery media PASS: attended USB boot, read-only root/ESP inspection, tools present, return to Linux (issue #17; evidence/recovery_boot_machine1.md) @@ -71,7 +72,7 @@ local agent, power off, power on, and it remembers. | Gate | Milestone (live progress) | Open work | Done so far | | --- | --- | --- | --- | -| M0 Reference freeze | [M0](https://github.com/aien-dev/aienos/milestone/1) | native boot rollback test remains open; recovery media is PASS and issue #17 is closed with attended evidence ([procedure](docs/RECOVERY_MEDIA_MACHINE1.md), [evidence](evidence/recovery_boot_machine1.md)) | [#12](https://github.com/aien-dev/aienos/pull/12) Rust evidence tooling and clean snapshot ([9bd233d](https://github.com/aien-dev/aienos/commit/9bd233d)) | +| M0 Reference freeze | [M0](https://github.com/aien-dev/aienos/milestone/1) | native boot rollback proven in QEMU (scripts/qemu_native_rollback_test.sh); physical qualification BLOCKED_BY_TRUST_CHAIN pending enrolled Secure Boot keys (docs/NATIVE_BOOT_ONE_TIME.md); recovery media is PASS ([procedure](docs/RECOVERY_MEDIA_MACHINE1.md), [evidence](evidence/recovery_boot_machine1.md)) | [#12](https://github.com/aien-dev/aienos/pull/12) Rust evidence tooling and clean snapshot ([9bd233d](https://github.com/aien-dev/aienos/commit/9bd233d)) | | M1 Emulator boot | [M1](https://github.com/aien-dev/aienos/milestone/2) | [#18](https://github.com/aien-dev/aienos/issues/18) QEMU boot, [#19](https://github.com/aien-dev/aienos/issues/19) CI | QEMU 8.2 and AAVMF chosen as the emulator | | M2 Spark bring-up | [M2](https://github.com/aien-dev/aienos/milestone/3) | [#20](https://github.com/aien-dev/aienos/issues/20) pre-exit file, [#21](https://github.com/aien-dev/aienos/issues/21) screen evidence, [#22](https://github.com/aien-dev/aienos/issues/22) UART via SPCR, [#23](https://github.com/aien-dev/aienos/issues/23) GB10 discovery, [#24](https://github.com/aien-dev/aienos/issues/24) USB keyboard, [#25](https://github.com/aien-dev/aienos/issues/25) test rig ([design](docs/HARDWARE_TEST_RIG.md)) | Gate passed: [#10](https://github.com/aien-dev/aienos/pull/10) memory handoff, [#11](https://github.com/aien-dev/aienos/pull/11) GB10 identity, [#13](https://github.com/aien-dev/aienos/pull/13) visible report ([a22b1d8](https://github.com/aien-dev/aienos/commit/a22b1d8)), [#14](https://github.com/aien-dev/aienos/pull/14) CPU topology ([44fcba7](https://github.com/aien-dev/aienos/commit/44fcba7)), [#15](https://github.com/aien-dev/aienos/pull/15) first-boot image ([52109bc](https://github.com/aien-dev/aienos/commit/52109bc)), [#16](https://github.com/aien-dev/aienos/pull/16) evidence ([f376589](https://github.com/aien-dev/aienos/commit/f376589)) | | M3 Kernel isolation | [M3](https://github.com/aien-dev/aienos/milestone/4) | none; #26 vectors, #27 MMU, #28 timer and GIC, #29 scheduler, #30 IPC and capabilities all closed | Frame allocator, bounded UART, fault capture used on the first boot; M3 merged as #103 SMMU, #104 EL0, #105 preemption, #106 IPC, #107 ABI freeze plus ADR 0013, #108 MMU and timer reconcile, #109 ABI unification, #110 fail-closed DMA, #111 and #114 device authority, #112 PCI ECAM, #113 strict verify, #115 ABI conformance; receipts in evidence/m3_canonical_receipt.md; verify_all green at 6ef8dde | diff --git a/crates/aienos-boot/Cargo.toml b/crates/aienos-boot/Cargo.toml index 7ad13d94..aa9a8c08 100644 --- a/crates/aienos-boot/Cargo.toml +++ b/crates/aienos-boot/Cargo.toml @@ -51,3 +51,8 @@ required-features = ["firmware"] name = "aienos-handoff" path = "src/handoff.rs" required-features = ["handoff"] + +[[bin]] +name = "aienos-rollback-mock" +path = "src/rollback_mock.rs" +required-features = ["handoff"] diff --git a/crates/aienos-boot/src/rollback_mock.rs b/crates/aienos-boot/src/rollback_mock.rs new file mode 100644 index 00000000..ebfd2237 --- /dev/null +++ b/crates/aienos-boot/src/rollback_mock.rs @@ -0,0 +1,402 @@ +#![no_std] +#![no_main] + +extern crate alloc; + +use alloc::vec::Vec; +use uefi::prelude::*; +use uefi::proto::device_path::{DeviceSubType, DeviceType, LoadedImageDevicePath}; +use uefi::proto::media::file::{File, FileAttribute, FileMode}; +use uefi::runtime::{ResetType, VariableAttributes, VariableVendor}; +use uefi::{cstr16, CStr16}; + +#[global_allocator] +static ALLOCATOR: uefi::allocator::Allocator = uefi::allocator::Allocator; + +#[panic_handler] +fn panic(info: &core::panic::PanicInfo) -> ! { + uefi::println!("ROLLBACK_MOCK_PANIC: {}", info); + uefi::runtime::reset(ResetType::COLD, Status::ABORTED, None) +} + +const CYCLE_VAR: &CStr16 = cstr16!("AienosRollbackCycle"); +const CYCLE_VENDOR: uefi::runtime::VariableVendor = + VariableVendor(uefi::guid!("a1e05b0e-7c3d-4f51-9b6a-2d8e4c1f0a38")); + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +enum Role { + Stager, + Candidate, + DefaultOs, +} + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +enum Mode { + Normal, + Fault, + Timeout, + Absent, + Malformed, + RealAienos, +} + +fn detect_role() -> Role { + let handle = uefi::boot::image_handle(); + let Ok(loaded_dp) = uefi::boot::open_protocol_exclusive::(handle) else { + return Role::Stager; + }; + + for node in loaded_dp.node_iter() { + if node.device_type() == DeviceType::MEDIA + && node.sub_type() == DeviceSubType::MEDIA_FILE_PATH + { + let data = node.data(); + let (chunks, _) = data.as_chunks::<2>(); + let s = chunks + .iter() + .map(|c| u16::from_le_bytes([c[0], c[1]]) as u8 as char) + .collect::(); + let lower = s.to_lowercase(); + if lower.contains("default") { + return Role::DefaultOs; + } else if lower.contains("candidate") { + return Role::Candidate; + } + } + } + Role::Stager +} + +fn read_mode_file() -> Mode { + let mut buf = [0u8; 64]; + if let Ok(mut fs) = uefi::boot::get_image_file_system(uefi::boot::image_handle()) { + if let Ok(mut root) = fs.open_volume() { + if let Ok(handle) = root.open( + cstr16!("\\EFI\\AIENOS\\ROLLBACK_MODE.TXT"), + FileMode::Read, + FileAttribute::empty(), + ) { + if let Some(mut file) = handle.into_regular_file() { + let _ = file.read(&mut buf); + } + } + } + } + + let text = core::str::from_utf8(&buf).unwrap_or(""); + if text.contains("fault") { + Mode::Fault + } else if text.contains("timeout") { + Mode::Timeout + } else if text.contains("absent") { + Mode::Absent + } else if text.contains("malformed") { + Mode::Malformed + } else if text.contains("real_aienos") { + Mode::RealAienos + } else { + Mode::Normal + } +} + +fn build_load_option(description: &str, partition_dp_prefix: &[u8], file_path: &str) -> Vec { + let mut full_dp = Vec::new(); + full_dp.extend_from_slice(partition_dp_prefix); + + // Media FilePath node: Type = 0x04, SubType = 0x04 + // Length: 4 + 2 * (chars + 1) + let utf16_chars: Vec = file_path.encode_utf16().collect(); + let node_len = (4 + 2 * (utf16_chars.len() + 1)) as u16; + full_dp.push(0x04); + full_dp.push(0x04); + full_dp.extend_from_slice(&node_len.to_le_bytes()); + for &ch in &utf16_chars { + full_dp.extend_from_slice(&ch.to_le_bytes()); + } + full_dp.extend_from_slice(&0u16.to_le_bytes()); // null terminator + + // End-Entire node: 0x7F, 0xFF, 0x04, 0x00 + full_dp.push(0x7F); + full_dp.push(0xFF); + full_dp.extend_from_slice(&4u16.to_le_bytes()); + + let mut opt = Vec::new(); + // 1. Attributes: LOAD_OPTION_ACTIVE = 0x00000001 + opt.extend_from_slice(&1u32.to_le_bytes()); + // 2. FilePathListLength + opt.extend_from_slice(&(full_dp.len() as u16).to_le_bytes()); + // 3. Description null-terminated UTF-16 + for c in description.encode_utf16() { + opt.extend_from_slice(&c.to_le_bytes()); + } + opt.extend_from_slice(&0u16.to_le_bytes()); + // 4. FilePathList + opt.extend_from_slice(&full_dp); + + opt +} + +#[entry] +fn main() -> Status { + let role = detect_role(); + let mode = read_mode_file(); + + match role { + Role::Stager => run_stager(mode), + Role::Candidate => run_candidate(mode), + Role::DefaultOs => run_default(mode), + } +} + +fn run_stager(mode: Mode) -> Status { + uefi::println!("=== M0_ROLLBACK_HARNESS: STAGER STARTING ==="); + uefi::println!("stager_mode: {:?}", mode); + + let handle = uefi::boot::image_handle(); + let Ok(loaded_dp) = uefi::boot::open_protocol_exclusive::(handle) else { + uefi::println!("FAIL: cannot get LoadedImageDevicePath"); + return Status::UNSUPPORTED; + }; + + // Extract partition device path prefix (everything before the first MEDIA_FILE_PATH node) + let mut prefix_len = 0; + for node in loaded_dp.node_iter() { + if node.device_type() == DeviceType::MEDIA + && node.sub_type() == DeviceSubType::MEDIA_FILE_PATH + { + break; + } + prefix_len += usize::from(node.length()); + } + + if prefix_len == 0 { + uefi::println!("FAIL: partition device path prefix empty"); + return Status::UNSUPPORTED; + } + + let prefix = &loaded_dp.as_bytes()[..prefix_len]; + + // Build Boot0001 (Default Linux OS -> \EFI\DEFAULT\default.efi) + let opt_default = build_load_option("Default Linux OS", prefix, "\\EFI\\DEFAULT\\default.efi"); + + // Build Boot0000 (Candidate) + let candidate_path = match mode { + Mode::Absent => "\\EFI\\AIENOS\\missing_candidate.efi", + Mode::RealAienos => "\\EFI\\AIENOS\\aienos-handoff.efi", + _ => "\\EFI\\AIENOS\\candidate.efi", + }; + let opt_candidate = build_load_option("AIENOS Candidate", prefix, candidate_path); + + let var_attrs = VariableAttributes::NON_VOLATILE + | VariableAttributes::BOOTSERVICE_ACCESS + | VariableAttributes::RUNTIME_ACCESS; + + // Set Boot0001 + if uefi::runtime::set_variable( + cstr16!("Boot0001"), + &VariableVendor::GLOBAL_VARIABLE, + var_attrs, + &opt_default, + ) + .is_err() + { + uefi::println!("FAIL: set Boot0001"); + return Status::DEVICE_ERROR; + } + + // Set BootOrder = [0x0001] + let boot_order = [0x0001u16]; + let boot_order_bytes = + unsafe { core::slice::from_raw_parts(boot_order.as_ptr() as *const u8, 2) }; + if uefi::runtime::set_variable( + cstr16!("BootOrder"), + &VariableVendor::GLOBAL_VARIABLE, + var_attrs, + boot_order_bytes, + ) + .is_err() + { + uefi::println!("FAIL: set BootOrder"); + return Status::DEVICE_ERROR; + } + + // Set Boot0000 + if uefi::runtime::set_variable( + cstr16!("Boot0000"), + &VariableVendor::GLOBAL_VARIABLE, + var_attrs, + &opt_candidate, + ) + .is_err() + { + uefi::println!("FAIL: set Boot0000"); + return Status::DEVICE_ERROR; + } + + // Set BootNext = 0x0000 + let boot_next = 0x0000u16; + if uefi::runtime::set_variable( + cstr16!("BootNext"), + &VariableVendor::GLOBAL_VARIABLE, + var_attrs, + &boot_next.to_le_bytes(), + ) + .is_err() + { + uefi::println!("FAIL: set BootNext"); + return Status::DEVICE_ERROR; + } + + // Reset cycle counter to 0 + let zero = 0u32; + let _ = uefi::runtime::set_variable(CYCLE_VAR, &CYCLE_VENDOR, var_attrs, &zero.to_le_bytes()); + + uefi::println!( + "PASS M0_ROLLBACK_STAGED: boot_order=0001 boot_next=0000 candidate={}", + candidate_path + ); + uefi::println!("M0_ROLLBACK_HARNESS: RESETTING SYSTEM FOR CANDIDATE BOOT"); + + // Initiate Cold Reset to execute BootNext + uefi::runtime::reset(ResetType::COLD, Status::SUCCESS, None) +} + +fn run_candidate(mode: Mode) -> Status { + uefi::println!("=== AIENOS CANDIDATE STARTING ==="); + uefi::println!("AIENOS_CANDIDATE: RUNNING"); + uefi::println!("NATIVE_CONTROL_ACQUIRED: PASS"); + + // Check BootCurrent + let mut current_buf = [0u8; 4]; + if let Ok((data, _)) = uefi::runtime::get_variable( + cstr16!("BootCurrent"), + &VariableVendor::GLOBAL_VARIABLE, + &mut current_buf, + ) { + if data.len() >= 2 { + let cur = u16::from_le_bytes([data[0], data[1]]); + uefi::println!("AIENOS_CANDIDATE: BOOT_CURRENT={:04X}", cur); + } + } + + match mode { + Mode::Normal => { + uefi::println!("AIENOS_CANDIDATE: NORMAL_TERMINATION_REQUESTED"); + uefi::println!("AIENOS_CANDIDATE: RESETTING"); + uefi::runtime::reset(ResetType::COLD, Status::SUCCESS, None) + } + Mode::Fault => { + uefi::println!("AIENOS_CANDIDATE: INDUCED_FAULT_PANIC"); + uefi::println!("AIENOS_CANDIDATE: RESETTING WITH FAULT"); + uefi::runtime::reset(ResetType::COLD, Status::ABORTED, None) + } + Mode::Timeout => { + uefi::println!("AIENOS_CANDIDATE: ENTERING_HANG_SPIN_LOOP"); + loop { + core::hint::spin_loop(); + } + } + _ => { + uefi::println!("AIENOS_CANDIDATE: DEFAULT_TERMINATION"); + uefi::runtime::reset(ResetType::COLD, Status::SUCCESS, None) + } + } +} + +fn run_default(_mode: Mode) -> Status { + uefi::println!("=== DEFAULT OS BOOT (LINUX REFERENCE MOCK) ==="); + uefi::println!("DEFAULT_BOOT: ALIVE"); + + // Read BootCurrent + let mut current_buf = [0u8; 4]; + let cur = if let Ok((data, _)) = uefi::runtime::get_variable( + cstr16!("BootCurrent"), + &VariableVendor::GLOBAL_VARIABLE, + &mut current_buf, + ) { + if data.len() >= 2 { + u16::from_le_bytes([data[0], data[1]]) + } else { + 0xFFFF + } + } else { + 0xFFFF + }; + uefi::println!("DEFAULT_OS: BOOT_CURRENT={:04X}", cur); + + // Read BootOrder + let mut order_buf = [0u8; 32]; + let order_ok = if let Ok((data, _)) = uefi::runtime::get_variable( + cstr16!("BootOrder"), + &VariableVendor::GLOBAL_VARIABLE, + &mut order_buf, + ) { + if data.len() >= 2 { + let first = u16::from_le_bytes([data[0], data[1]]); + uefi::println!("DEFAULT_OS: BOOT_ORDER[0]={:04X}", first); + first == 0x0001 + } else { + false + } + } else { + false + }; + + // Check BootNext (must be absent / consumed) + let mut next_buf = [0u8; 4]; + let next_result = uefi::runtime::get_variable( + cstr16!("BootNext"), + &VariableVendor::GLOBAL_VARIABLE, + &mut next_buf, + ); + let next_consumed = next_result.is_err(); + + if next_consumed { + uefi::println!("DEFAULT_OS: BOOT_NEXT=CONSUMED_PASS"); + uefi::println!("PASS NATIVE_ROLLBACK_BOOTNEXT_CONSUMED"); + } else { + uefi::println!("FAIL NATIVE_ROLLBACK_BOOTNEXT_STILL_PRESENT"); + } + + if order_ok { + uefi::println!("PASS NATIVE_ROLLBACK_DEFAULT_UNCHANGED"); + } else { + uefi::println!("FAIL NATIVE_ROLLBACK_DEFAULT_ORDER_ALTERED"); + } + + // Check cycle count + let mut cycle_buf = [0u8; 4]; + let cycle = if let Ok((data, _)) = + uefi::runtime::get_variable(CYCLE_VAR, &CYCLE_VENDOR, &mut cycle_buf) + { + if data.len() >= 4 { + u32::from_le_bytes([data[0], data[1], data[2], data[3]]) + } else { + 0 + } + } else { + 0 + }; + + let var_attrs = VariableAttributes::NON_VOLATILE + | VariableAttributes::BOOTSERVICE_ACCESS + | VariableAttributes::RUNTIME_ACCESS; + + if cycle == 0 { + uefi::println!("DEFAULT_OS: FIRST_RETURN_VERIFIED"); + let next_cycle = 1u32; + let _ = uefi::runtime::set_variable( + CYCLE_VAR, + &CYCLE_VENDOR, + var_attrs, + &next_cycle.to_le_bytes(), + ); + uefi::println!("DEFAULT_OS: TRIGGERING_REPEAT_BOOT_TEST"); + uefi::runtime::reset(ResetType::COLD, Status::SUCCESS, None) + } else { + uefi::println!("DEFAULT_OS: REPEAT_BOOT_VERIFIED (cycle={})", cycle); + uefi::println!("PASS NATIVE_ROLLBACK_REPEAT_BOOT"); + uefi::println!("DEFAULT_OS: ALL ROLLBACK INVARIANTS SATISFIED"); + uefi::runtime::reset(ResetType::SHUTDOWN, Status::SUCCESS, None) + } +} diff --git a/docs/M0_NATIVE_BOOT_ROLLBACK_AUDIT.md b/docs/M0_NATIVE_BOOT_ROLLBACK_AUDIT.md new file mode 100644 index 00000000..7f94d38c --- /dev/null +++ b/docs/M0_NATIVE_BOOT_ROLLBACK_AUDIT.md @@ -0,0 +1,85 @@ +# M0 Native-Boot Rollback Evidence Audit + +## Executive Summary & Gate Verdict + +This document audits all historical and current physical evidence from Machine 1 (NVIDIA DGX Spark, `spark-b87b`) regarding the **M0 Native-Boot Rollback Gate**. + +### Core Questions + +#### A. Does existing evidence already satisfy the M0 rollback gate? +**NO.** Existing evidence is **INSUFFICIENT** to close the M0 rollback gate on physical hardware. While individual mechanisms (such as UEFI `BootNext` consumption and fallback to GRUB/Linux) were observed across separate historical boots, the full set of mandatory safety and rollback invariants has never been satisfied simultaneously under the required security baseline. + +#### B. What are the exact missing assertions? +1. **Secure Boot Unchanged & Enabled:** The M2 native boot (`evidence/m2_first_boot_2026-09-24.md`) was performed with **Secure Boot explicitly disabled** in firmware. The recovery USB boot (`evidence/recovery_boot_machine1.md`) ran with Secure Boot enabled, but it booted an Ubuntu Linux recovery image, not native AIENOS. +2. **TPM PCR 7 & Sealed Storage Invariant:** Disabling Secure Boot for the M2 boot mutated TPM PCR 7, preventing the unsealing of the LUKS/storage keys for `atlas-private-storage` and `atlas-forgejo-storage` and triggering a service restart storm (`evidence/machine1_core_baseline_2026-09-24.md`). A valid rollback test must prove that TPM-sealed state remains unperturbed before, during, and after candidate execution. +3. **Hardware Trust Chain Boundary (`HARDWARE_QUALIFICATION_BLOCKED_BY_TRUST_CHAIN`):** Machine 1 currently has Secure Boot enabled with production firmware keys (Microsoft / Canonical). The native AIENOS boot image (`aienos-handoff.efi`) is not signed by an enrolled key. Attempting to boot it directly under Secure Boot fails immediately with `Secure Boot Violation` (`evidence/gate1_machine1_selftest_2026-09-24.md`). Hardware qualification of native AIENOS is therefore formally **blocked by trust chain**. +4. **Failure & Fault Branch Coverage:** The historical M2 native boot tested only a single cooperative countdown-and-reset path. It did not test candidate crash/panic, CPU fault, runaway timeout, or corrupted/untrusted binary fallback. +5. **Exact BootOrder Invariance:** On the M2 native boot, firmware appended `Boot0004` (USB stick) to `BootOrder` (`0001,0003` became `0001,0003,0004`). While the relative order of default entries was preserved, strict bit-for-bit invariance was not asserted. +6. **Cryptographic Root/ESP Identity Pre/Post Verification:** Historical runs lacked unified cryptographic verification asserting that internal root UUID (`d27bfd26-ff30-400e-9eca-9cdf73de9406`), ESP UUID (`9DA2-3597`), and filesystem mount options remained identical before staging and after return. +7. **Post-Consumption Re-execution Immunity:** No test demonstrated that subsequent host reboots after the one-time boot attempt continue to boot the default OS without entering a loop or re-invoking the candidate. + +--- + +## Detailed Audit of Existing Evidence + +### 1. M2 First Native Boot (`evidence/m2_first_boot_2026-09-24.md`) +- **Staging:** Performed via `scripts/stage_one_time_boot.sh`. Staged `aienos-handoff.efi` (`79505373088d2464b82181c06f07e18e20e4e9b2b55dbc9fc46e3f0a2e2e3ada`) into `\EFI\AIENOS\aienos-handoff.efi`, created boot entry `Boot0000`, set `BootNext = 0000`. +- **Pre-boot State:** `BootCurrent: 0001`, `BootOrder: 0001,0003`, `linux_kernel: 7.0.0-1019-nvidia`. +- **Execution:** Machine left firmware, entered AIENOS at EL2, validated memory map, wrote `AienosBootReportV1` NVRAM variable (`kernel: alive`), counted down 30 seconds, and executed a PSCI cold reset. +- **Return:** Machine booted back into Linux. `BootCurrent: 0001`, `BootNext` consumed, `root: rw`. +- **Defects & Invalidation:** + - Secure Boot was manually turned **OFF** prior to the run (`docs/NATIVE_BOOT_ONE_TIME.md`, line 50). + - PCR 7 changed, breaking TPM secret unsealing (`machine1_core_baseline_2026-09-24.md`). + - `BootOrder` was altered by firmware: `0001,0003,0004` (firmware added USB entry). + - Pre-exit report file `\EFI\AIENOS\BOOTREPORT.TXT` failed to write to disk. + +### 2. Machine 1 Baseline & Restart Storm Resolution (`evidence/machine1_core_baseline_2026-09-24.md`) +- Following the M2 boot, Secure Boot was re-enabled to restore TPM PCR 7 stability. +- Documented that turning Secure Boot off is an unsafe operation on Machine 1 because secrets are sealed to PCR 7. +- Established the doctrine: **Secure Boot must remain ON at all times during native boot testing.** + +### 3. Recovery Media Attended Boot (`evidence/recovery_boot_machine1.md`) +- **Staging & Boot:** `Boot0004` (USB recovery stick) was booted via `efibootmgr -n 0004` with Secure Boot **ON**. +- **Execution:** Booted Ubuntu shim -> signed GRUB -> signed kernel (`7.0.0-1019-nvidia`) -> RAM initrd. Inspected root (`UUID="d27bfd26-ff30-400e-9eca-9cdf73de9406"`) and ESP (`UUID="9DA2-3597"`) read-only. +- **Return:** Returned to normal Ubuntu boot (`BootCurrent: 0001`, `BootOrder: 0001,0003,0004`). +- **Defects & Invalidation:** + - This verified the recovery media boot path, **not** an AIENOS native candidate. + - The receipt omitted post-return `mokutil --sb-state` and post-return `efibootmgr` captures. + +### 4. TRUST-1 Gate 1 Self-Test (`evidence/gate1_machine1_selftest_2026-09-24.md`) +- Tested one-time reboot into recovery media via `efibootmgr -n 0004`. +- **Finding:** A previous attempt to boot a direct entry `Boot0000 "AIENOS"` pointing directly to an unsigned kernel binary failed with **`Secure Boot Violation`**. +- Reaffirmed that firmware rejects unsigned EFI binaries when Secure Boot is ON. + +--- + +## Evidence Audit Matrix + +| Assertion # | Required Rollback Invariant | Existing Evidence | Proven? | Missing Evidence / Failure Mode | Required Next Action | +|:---:|:---|:---|:---:|:---|:---| +| **1** | Default/Linux boot state captured before candidate boot | `m2_first_boot_2026-09-24.md`, `STAGED.TXT` | **PROVEN** | None. Baseline capture is established. | Maintain pre-boot capture format in automated tools. | +| **2** | One-time candidate selected without replacing default BootOrder | `m2_first_boot_2026-09-24.md`, `gate1_machine1_selftest_2026-09-24.md` | **PROVEN** | None. `efibootmgr --bootnext` creates one-time boot without modifying `BootOrder`. | Standardize in rollback contract. | +| **3** | AIENOS actually gains native control | `m2_first_boot_2026-09-24.md` (`kernel: alive`, EL2) | **PARTIAL** | Only proven with Secure Boot OFF. Unproven with Secure Boot ON. | Requires signed binary or owner trust enrollment. | +| **4** | Failure, fault, timeout, or exit does not create a boot loop | `m2_first_boot_2026-09-24.md` (clean exit only) | **UNPROVEN** | Fault, hang/timeout, and invalid image branches were never tested on hardware. | Prove all failure branches in QEMU harness. | +| **5** | One-time selection (`BootNext`) is consumed | `m2_first_boot_2026-09-24.md`, `recovery_boot_machine1.md` | **PROVEN** | None. Firmware deletes `BootNext` upon boot. | Re-verify in automated test harness. | +| **6** | Machine returns to default Linux boot path | `m2_first_boot_2026-09-24.md` (`BootCurrent: 0001`) | **PROVEN** | None. Return to `BootCurrent: 0001` occurred. | Re-verify in automated test harness. | +| **7** | Permanent `BootOrder` remains unchanged | `m2_first_boot_2026-09-24.md` | **PARTIAL** | Firmware added `0004` (USB stick). `0001,0003` became `0001,0003,0004`. | Enforce strict comparison ignoring or isolating hotplug devices. | +| **8** | Secure Boot state remains unchanged (and ON) | `m2_first_boot_2026-09-24.md` | **FAILED** | Secure Boot was explicitly turned **OFF** for M2 boot. | Mandatory Secure Boot ON invariant; block hardware boot until signed. | +| **9** | Linux root and ESP state remain intact | `m2_first_boot_2026-09-24.md`, `recovery_boot_machine1.md` | **PARTIAL** | Checked `root: rw`, but UUIDs, partition tables, and mount points were not diffed. | Automated pre/post evidence verifier checking exact UUIDs. | +| **10** | No TPM, firmware trust, or key mutation required | `machine1_core_baseline_2026-09-24.md` | **FAILED** | Secure Boot disable altered PCR 7, breaking storage unseal. | Forbid Secure Boot mutation; maintain PCR 7 integrity. | +| **11** | Evidence is independently inspectable | `m2_first_boot_2026-09-24.md`, `evidence/*.md` | **PROVEN** | Ledger payloads and markdown receipts exist in git. | Package automated evidence verifier CLI. | + +--- + +## Formal Status: Hardware Qualification Blocked + +Because the native AIENOS binary (`aienos-handoff.efi`) is not signed by a key trusted by Machine 1's UEFI database (`db`), and because the hard safety rules prohibit disabling Secure Boot, enrolling keys into production firmware, or mutating TPM configuration: + +```text +HARDWARE_QUALIFICATION_BLOCKED_BY_TRUST_CHAIN +``` + +### Action Plan +1. **Emulation Proof (M0 Rollback Gate in QEMU):** All 6 rollback failure branches (normal exit, panic/fault, hang/timeout, rejected/corrupt image, absent candidate, and repeated post-consumption reboot) will be proven deterministically in QEMU using disposable variable storage (`AAVMF_VARS.fd`). +2. **Safe Operational Runbook:** Update `docs/NATIVE_BOOT_ONE_TIME.md` to permanently retire the obsolete Secure-Boot-off procedure and enforce the trust boundary. +3. **Automated Verifier:** Deliver a host-side verifier script that validates pre- and post-boot records and yields `PASS`, `FAIL`, `BLOCKED`, or `INCOMP`. diff --git a/docs/NATIVE_BOOT_ONE_TIME.md b/docs/NATIVE_BOOT_ONE_TIME.md index 9d67ce18..3078b83f 100644 --- a/docs/NATIVE_BOOT_ONE_TIME.md +++ b/docs/NATIVE_BOOT_ONE_TIME.md @@ -1,114 +1,111 @@ -# First native boot on Machine 1: attended, one time - -This procedure boots the `aienos-handoff` first-boot evidence image on the DGX -Spark exactly once and brings the machine back to Linux on its own. It is the -M2 hardware gate and the rollback test that closes M0. - -**Gate:** Machine 1 leaves firmware, enters native AIENOS code with no Linux -underneath, produces independently recoverable evidence that it did so, and -returns to the existing system without damaging it. - -## What the image does - -1. **Before firmware exit:** discovers the GB10 (PCI identity, BAR0, PMC boot - registers), the CPU topology from the ACPI MADT (cores per efficiency class - and the boot core's class), and the firmware display mode. It prints this - pre-exit report on screen and saves it to `\EFI\AIENOS\BOOTREPORT.TXT`. -2. **After firmware exit:** installs AIENOS exception vectors, writes an early - progress record, validates the firmware memory map, and enters the kernel. - The final report goes to the screen, the `AienosBootReportV1` firmware - variable ([ADR 0008](adr/0008-temporary-bring-up-firmware-report-exception.md)) - and the Spark UART (bounded). -3. **On a panic or CPU fault:** reports the last boot stage, the panic message - or the fault registers (ESR, ELR, FAR, SPSR) the same three ways. -4. Counts down 30 seconds, then resets (PSCI first). BootNext is used up, so - the machine returns to Linux. - -The image does not touch the Linux installation, its partitions, or BootOrder. - -## Before you start (at the machine) - -1. **Recovery media:** plug in the `AIENOSRECOV` recovery USB stick, built - and proved per [RECOVERY_MEDIA_MACHINE1.md](RECOVERY_MEDIA_MACHINE1.md). - The internal fallbacks are also present: the `ubuntu` boot entry - (shim + GRUB), the firmware fallback loader `\EFI\BOOT\BOOTAA64.EFI`, and - three installed kernels. -2. **Monitor and keyboard** attached to the Spark. -3. **Everything on this Linux install stops** for each reboot: agents, model - servers, the aienos.com waitlist API, and remote access. - -> **Paused (operator decision 2026-09-24).** Do not run this procedure again -> yet. Turning Secure Boot off changes TPM PCR 7, and Machine 1 seals its -> private-storage key and vault credential to that state: on the first boot, -> those secrets would not unseal, the encrypted storage stayed locked, and -> dependent services failed. Secure Boot is back on. Real-hardware AIENOS -> boots resume only after the owner-controlled boot chain exists: operator -> signing key, signed AIENOS loader and kernel, a defined TPM PCR policy, an -> independent recovery key, a tested recovery path, and secrets re-sealed to -> that policy. Until then, develop and test in QEMU. - -## Step 1: turn Secure Boot off (operator decision 2026-09-24, since reversed) +# Machine 1 Native Boot Qualification Procedure: Attended, One-Time, Secure Boot ON -```bash -sudo systemctl reboot --firmware-setup # reboots straight into firmware setup -``` +This document defines the safe, operator-attended qualification procedure for one-time native candidate boots of AIENOS on NVIDIA DGX Spark ("Machine 1", `spark-b87b`). -In the setup screen, disable **Secure Boot** only. Change nothing else. Save, -exit, and let Linux boot. +--- -## Step 2: stage one boot +## 1. Current Qualification Status -```bash -cd ~/workspace/hive-worktrees/aienos-main && git pull --ff-only -bash scripts/stage_one_time_boot.sh # dry run: commit, digest, plan -sudo -v # hold gives the command no stdin -aien-proof hold --resource machine-1 --job stage-native-boot -- \ - bash scripts/stage_one_time_boot.sh --apply -sudo reboot +```text +HARDWARE_QUALIFICATION_BLOCKED_BY_TRUST_CHAIN ``` -The script refuses a dirty checkout (the boot must map to one commit) and -refuses while Secure Boot is on. It records `\EFI\AIENOS\STAGED.TXT`: commit, -image sha256, who staged it, and the boot state before. +> [!CAUTION] +> **DO NOT DISABLE SECURE BOOT.** +> On Machine 1, turning Secure Boot off alters TPM PCR 7. On the historical 2026-09-24 first-boot test, changing PCR 7 prevented the TPM from unsealing the volume encryption keys for `atlas-private-storage` and `atlas-forgejo-storage`, locking the filesystem and causing severe service restart loops (`evidence/machine1_core_baseline_2026-09-24.md`). Secure Boot was restored and must remain **ENABLED** at all times. +> +> The native AIENOS boot images (`aienos-handoff.efi`, `aienos-boot.efi`) are not currently signed by a key enrolled in Machine 1's UEFI database (`db`). Direct execution under Secure Boot will fail with `Secure Boot Violation` (`evidence/gate1_machine1_selftest_2026-09-24.md`). +> +> Physical hardware native boots remain **BLOCKED** until the owner-controlled boot trust chain (ADR 0007 / TRUST-1 implementation) is enrolled in firmware. **Do not attempt to bypass this boundary by turning Secure Boot off.** All rollback semantics must be validated in QEMU (`scripts/qemu_native_rollback_test.sh`). + +--- + +## 2. Hard Invariants & Safety Constraints + +1. **Secure Boot Enforced:** Machine 1 must report `SecureBoot enabled` (`/sys/firmware/efi/efivars/SecureBoot-*` byte 4 == 1). Any tool or procedure attempting to disable Secure Boot fails closed. +2. **Permanent BootOrder Immutable:** `BootOrder` must not be modified. Linux (Ubuntu GRUB/shim, `Boot0001`) remains the permanent, unchallengeable default. +3. **One-Time Staging Only:** Candidates are invoked strictly via UEFI `BootNext`. Firmware deletes `BootNext` upon boot. +4. **Zero Persistent Storage Mutation:** Candidate execution must not write to Linux root (`/dev/nvme0n1p2`) or alter the EFI System Partition (`/dev/nvme0n1p1`) outside of the staging scratch directory `\EFI\AIENOS`. +5. **Attended Execution Only:** No autonomous or unattended physical hardware reboots are permitted. Operator must be present at physical console with recovery media attached. + +--- -Expect: the firmware logo, the pre-exit report, then a dark screen headed -`AIENOS NATIVE BOOT REPORT` (or `AIENOS BOOT STOPPED` in red), and a countdown. -**Photograph the screen** before the countdown ends; it is the only record of -the post-exit screen. +## 3. Preparation & Pre-Flight Verification -## Step 3: collect after Linux returns +Ensure the operator is present at the physical machine with: +1. **Recovery Media:** Dedicated `AIENOSRECOV` USB stick inserted into Machine 1 (`Boot0004`), tested and proved per `docs/RECOVERY_MEDIA_MACHINE1.md`. +2. **Physical Display & Keyboard:** Attached directly to DGX Spark console. +3. **Service Quiescence:** Non-core services stopped per `evidence/machine1_core_baseline_2026-09-24.md`. +--- + +## 4. Execution Workflow (When Trust Chain is Enrolled) + +### Step 1: Pre-Boot Baseline Capture +Capture the complete pre-boot state into `evidence/pre_boot_capture.json`: ```bash -aien-proof hold --resource machine-1 --job collect-native-boot -- \ - bash scripts/collect_boot_report.sh +sudo scripts/verify_native_rollback.sh --capture-pre evidence/pre_boot_capture.json ``` +This records: +- Secure Boot status (`enabled`) +- Active and permanent boot configuration (`BootCurrent`, `BootOrder`, no `BootNext`) +- Partition UUIDs: + - Root: `d27bfd26-ff30-400e-9eca-9cdf73de9406` (ext4, mounted at `/`) + - ESP: `9DA2-3597` (vfat, mounted at `/boot/efi`) +- Kernel release (`uname -r`) + +### Step 2: One-Time Candidate Staging +Under lease hold (`aien-proof hold --resource machine-1`): +```bash +# Verify working tree is clean and map to exact commit +commit=$(git rev-parse HEAD) + +# Build signed native candidate (requires owner signing key) +scripts/sign_efi_binary.sh target/aarch64-unknown-uefi/release/aienos-handoff.efi -The full output becomes an `audit` event in the hardware-test ledger. -`M2_GATE: PASS` requires every check below to pass. - -| Evidence asked for | Where it comes from | -| --- | --- | -| Exact AIENOS commit | `aienos_commit` in STAGED.TXT, the pre-exit report and the native report, all compared | -| Exact boot image digest | `image_sha256` in STAGED.TXT, compared with the image on the ESP | -| Machine 1 lease holder | `aien-proof hold` records the agent in both ledger events; `staged_by` in STAGED.TXT | -| Firmware handoff data | Pre-exit report: firmware vendor/revision, counter frequency; kernel report: handoff timing | -| Heterogeneous CPU counts, boot-core class | `cpu_efficiency_class_*`, `cpu_boot_core_class`, `boot_cpu_midr` | -| Memory-map validation | `memory_map_descriptors`, `_conventional_regions`, `_rejected_regions`, `_largest_region` | -| GB10 PCI identity and BAR | `gb10_pci`, `gb10_bar0_phys`, `gb10_pmc_boot_0`, `gb10_pmc_boot_42` | -| Framebuffer/GOP observations | `framebuffer:` line pre-exit; the screen photo shows whether post-exit drawing worked | -| Console/UART observations | `uart_report: sent / no response` on screen | -| Last successful boot stage | `last_stage` in every report | -| Panic/fault data | `report_kind: panic` or `fault` with message or ESR/ELR/FAR/SPSR | -| Firmware-variable report contents | Printed in full; `nvram_write_index` shows which bounded write it was | -| Complete test output | The ledger payload of both `hold` events | -| Linux/recovery intact | BootNext consumed, BootOrder unchanged, same boot entry and kernel, root writable | - -## If something goes wrong - -- **Screen stays black or frozen:** hold the power button until the machine - turns off, then power on. BootNext was used up, so Linux boots. The pre-exit - file and any saved variable report remain readable; collect as in step 3. -- **Firmware says the image is not allowed:** Secure Boot is still on. -- **Linux does not come back:** choose `ubuntu` in the firmware boot menu, or - boot the recovery USB stick. The AIENOS entry is not in BootOrder, so it - never runs unless BootNext is set again. +# Stage image to ESP and set BootNext +sudo bash scripts/stage_one_time_boot.sh --apply +``` +The staging script: +1. Copies the authenticated binary to `/boot/efi/EFI/AIENOS/aienos-handoff.efi`. +2. Verifies that `BootOrder` is preserved unchanged. +3. Creates/verifies non-default boot entry `Boot0000 "AIENOS handoff (one-time)"`. +4. Sets `BootNext = 0000`. + +### Step 3: Candidate Boot & Observation +1. Reboot the machine: + ```bash + sudo reboot + ``` +2. **Observe Physical Screen:** + - Firmware starts and evaluates `BootNext`. + - If firmware accepts signature: AIENOS banner, memory map validation, `kernel: alive` on screen. + - Candidate counts down 30 seconds and calls cold reset via PSCI. + - **If firmware reports `Secure Boot Violation`:** This is an expected STOP condition if keys are missing. Do not bypass. The machine will fall back to `BootOrder` (Linux). +3. **If Machine Hangs:** + - Wait 60 seconds. + - Power-cycle using the chassis power button. + - Because firmware consumed `BootNext` prior to launching the image, the reset will boot Linux (`BootOrder[0] = 0001`). + +### Step 4: Out-of-Band Fallback (If Linux Fails to Boot) +If Linux does not automatically load: +1. Press `F11` (or firmware BBS hotkey) during startup. +2. Select `Boot0004` (`AIENOSRECOV` USB recovery stick). +3. In the recovery environment, verify root and ESP integrity read-only per `docs/RECOVERY_MEDIA_MACHINE1.md`. + +### Step 5: Post-Return Capture & Automated Verification +Once returned to Linux: +```bash +sudo scripts/verify_native_rollback.sh \ + --pre evidence/pre_boot_capture.json \ + --post evidence/post_boot_capture.json \ + --verify +``` +The automated verifier evaluates all 10 invariants: +- Secure Boot state: unchanged (`enabled`) +- `BootOrder`: identical to pre-boot +- `BootCurrent`: returns to `0001` (Linux) +- `BootNext`: consumed / empty +- Root partition UUID & mount (`/`, `rw`): unchanged +- ESP partition UUID & mount (`/boot/efi`, `rw`): unchanged +- No boot loop created diff --git a/docs/NATIVE_BOOT_ROLLBACK_CONTRACT.md b/docs/NATIVE_BOOT_ROLLBACK_CONTRACT.md new file mode 100644 index 00000000..587656be --- /dev/null +++ b/docs/NATIVE_BOOT_ROLLBACK_CONTRACT.md @@ -0,0 +1,135 @@ +# AIENOS Native-Boot Rollback Contract + +## 1. Scope & Purpose + +This contract specifies the deterministic lifecycle, state machine, and safety invariants for one-time native boots of AIENOS candidates on UEFI platforms (including physical NVIDIA DGX Spark / Machine 1 and QEMU AArch64 reference emulators). + +--- + +## 2. Core Invariant + +> **A candidate may consume exactly one boot attempt. It may never promote itself into the persistent default boot path.** + +Under no circumstances—whether normal completion, kernel panic, CPU exception, infinite loop/timeout, binary rejection, or power loss—may the platform enter an unrecoverable boot loop, and under no circumstances may the candidate modify the persistent boot priority of the system. + +--- + +## 3. Subsystem Separation of Concerns + +1. **Permanent Default Boot Configuration:** + - The primary operating system (e.g. Ubuntu Linux under GRUB/shim on Machine 1, or default reference OS in QEMU) is represented by persistent boot variable `Boot0001` (or existing default `BootCurrent`). + - The UEFI `BootOrder` variable lists default entries in priority order (e.g. `0001,0003`). + - The default boot configuration is immutable with respect to candidate execution. + - Secure Boot state remains enabled (`SecureBoot=1`). + - TPM PCR policies and sealed volume secrets remain intact. + +2. **One-Time Candidate Selection:** + - Candidates are staged into dedicated, non-default paths on the EFI System Partition (e.g. `\EFI\AIENOS\aienos-candidate.efi`). + - A non-default boot entry is allocated (e.g. `Boot0000`). + - The candidate is selected **strictly** through the UEFI `BootNext` variable (`BootNext = 0000`). + - `BootOrder` is **never modified** when staging a candidate. + +3. **Candidate Consumption by Firmware:** + - Per UEFI Specification §3.1.1, the platform firmware must consume (delete) `BootNext` prior to transferring control to the candidate binary. + - Once firmware starts the candidate, `BootNext` no longer exists in NVRAM. + +4. **Candidate Execution Termination Modes:** + - **Orderly Termination:** The candidate finishes execution, prints diagnostic reports to screen/UART, and initiates cold system reset (via PSCI or UEFI Runtime Services `ResetSystem(ResetCold)`). + - **Panic / CPU Fault:** Upon encountering an exception, panic, or unhandled trap, the exception vector records fault registers (ESR, ELR, FAR, SPSR) to diagnostics and triggers cold reset. + - **Hang / Timeout:** If the candidate hangs or loops, an external hardware/emulator watchdog or an operator power-cycle triggers cold reset. + - **Firmware Rejection / Malformed Image:** If the image PE header is invalid or fails signature checks, firmware refuses execution and drops to the next option in `BootOrder` or returns to BDS. + - **Absent Image:** If the file referenced by `Boot0000` is missing, firmware drops to `BootOrder`. + +5. **Fallback to Default Boot:** + - Because `BootNext` was consumed by firmware before or during the candidate launch, any subsequent reset or firmware boot evaluation encounters an empty `BootNext`. + - Firmware evaluates `BootOrder` and immediately launches the permanent default bootloader (`Boot0001`). + +6. **Out-of-Band Recovery Fallback:** + - If the internal storage or default bootloader is corrupted by external factors, the dedicated, proved recovery USB media (`Boot0004` / `AIENOSRECOV`) remains bootable via the firmware interactive boot menu (`F11`/`BDS`), operating 100% in RAM with zero hard disk dependencies. + +--- + +## 4. Formal Finite State Machine (FSM) + +``` + +-------------------------------------------------------------+ + | DefaultReady | + | (Linux running, BootOrder=[0001,...], BootNext unset) | + +-------------------------------------------------------------+ + | + | [Operator stages candidate] + v + +-------------------------------------------------------------+ + | CandidateStaged | + | (Image on ESP, Boot0000 created, BootOrder UNTOUCHED) | + +-------------------------------------------------------------+ + | + | [efibootmgr --bootnext 0000] + v + +-------------------------------------------------------------+ + | CandidateSelectedOnce | + | (BootNext=0000, BootOrder=[0001,...]) | + +-------------------------------------------------------------+ + | + | [System reboot] + v + Firmware consumes & deletes BootNext in NVRAM + | + +-----------------------+-----------------------+ + | | + | [Valid binary] | [Corrupt/Missing/Rejected] + v v + +----------------------+ +-------------------+ + | CandidateRunning | | CandidateRejected | + | (EL2/EL1, native) | | (BDS fails load) | + +----------------------+ +-------------------+ + | | + +--------------------+ | + | | | + [Normal Exit] [Fault/Panic/Timeout] | + | | | + v v v + +--------------+ +----------------+ | + | ResetOrExit | | Watchdog/Reset | | + +--------------+ +----------------+ | + | | | + +--------------------+--------------------------+ + | + | [System cold reset / fallback] + v + Firmware evaluates BootOrder (BootNext=NONE) + | + v + +-------------------------------------------------------------+ + | DefaultReturned | + | (Linux running, BootCurrent=0001, BootOrder unchanged) | + +-------------------------------------------------------------+ + | + | [Subsequent reboot(s)] + v + +-------------------------------------------------------------+ + | DefaultReady | + | (System stays on Linux permanently; no candidate recurrence)| + +-------------------------------------------------------------+ +``` + +--- + +## 5. Transition Rules & Invariants + +1. **Deterministic Return Invariant:** + $\forall s \in \{\text{NormalExit}, \text{Fault}, \text{Timeout}, \text{Rejected}, \text{Missing}\}, \quad \text{NextBoot}(s) = \text{DefaultBoot}$ + +2. **Non-Promotion Invariant:** + Under no execution path may `Boot0000` be inserted into `BootOrder`. + $\text{BootOrder}_{\text{post}} = \text{BootOrder}_{\text{pre}}$ + +3. **Single-Attempt Invariant:** + $\text{BootNext}_{\text{post}} = \emptyset$ + +4. **No Autonomous Staging:** + No software component running within `CandidateRunning` or `DefaultReturned` may set `BootNext` or stage another candidate without explicit, authenticated operator dispatch. + +5. **Storage & Trust Isolation:** + - Candidate execution must not mutate internal Linux root partition UUIDs or filesystem structures. + - Candidate execution must not alter UEFI Secure Boot configuration or TPM NVRAM allocations. diff --git a/scripts/qemu_native_rollback_test.sh b/scripts/qemu_native_rollback_test.sh new file mode 100755 index 00000000..eb58657c --- /dev/null +++ b/scripts/qemu_native_rollback_test.sh @@ -0,0 +1,292 @@ +#!/usr/bin/env bash +# qemu_native_rollback_test.sh +# M0 Native-Boot Rollback Verification Test in QEMU AArch64 (AAVMF UEFI). +# +# Deterministically exercises one-time native candidate selection and rollback +# semantics across six required failure and completion branches without +# touching physical hardware: +# 1. normal AIENOS candidate exit/reset +# 2. candidate panic/fault +# 3. candidate timeout/hang followed by host reset +# 4. malformed/rejected candidate image +# 5. absence of candidate image +# 6. repeated host reboot after one-time candidate has been consumed +# +# Uses disposable NVRAM variable storage (vars.fd) and temporary ESP filesystems. +# Enforces Zero Disk Secrets and strict rollback invariants. + +set -euo pipefail + +REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +cd "${REPO_ROOT}" + +CODE_FD="${AAVMF_CODE:-/usr/share/AAVMF/AAVMF_CODE.no-secboot.fd}" +VARS_FD="${AAVMF_VARS:-/usr/share/AAVMF/AAVMF_VARS.fd}" + +command -v qemu-system-aarch64 >/dev/null || { echo "qemu-system-aarch64 not installed"; exit 2; } +[[ -r "${CODE_FD}" && -r "${VARS_FD}" ]] || { echo "AAVMF firmware not found"; exit 2; } + +echo "============================================================" +echo "AIENOS M0 Native-Boot Rollback Test Suite (QEMU AArch64)" +echo "Host: $(uname -n) | Firmware: $(basename "${CODE_FD}")" +echo "============================================================" + +# Build the rollback mock harness binary +echo "Building aienos-rollback-mock..." +cargo build --quiet --release -p aienos-boot --target aarch64-unknown-uefi --features handoff --bin aienos-rollback-mock +MOCK_BIN="target/aarch64-unknown-uefi/release/aienos-rollback-mock.efi" +[[ -f "${MOCK_BIN}" ]] || { echo "Failed to build aienos-rollback-mock.efi"; exit 1; } + +WORK_DIR="$(mktemp -d)" +cleanup() { + rm -rf "${WORK_DIR}" +} +trap cleanup EXIT + +failed=0 +pass() { echo "PASS $1"; } +fail() { echo "FAIL $1"; failed=1; } + +run_qemu_boot() { + local esp_dir="$1" + local vars_file="$2" + local log_file="$3" + local timeout_secs="${4:-20}" + + set +e + timeout "${timeout_secs}" qemu-system-aarch64 \ + -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="${vars_file}" \ + -drive if=none,id=esp,format=raw,file=fat:rw:"${esp_dir}" \ + -device virtio-blk-pci,drive=esp \ + -display none -nic none \ + -serial file:"${log_file}" -no-reboot + local exit_code=$? + set -e + return "${exit_code}" +} + +# ============================================================================== +# SUBTEST 1: Normal Candidate Execution & Clean Return +# ============================================================================== +echo "" +echo "--- [Subtest 1: Normal Candidate Execution & Rollback] ---" +SUB1_DIR="${WORK_DIR}/subtest1" +mkdir -p "${SUB1_DIR}/esp/EFI/BOOT" "${SUB1_DIR}/esp/EFI/AIENOS" "${SUB1_DIR}/esp/EFI/DEFAULT" +cp "${VARS_FD}" "${SUB1_DIR}/vars.fd" +cp "${MOCK_BIN}" "${SUB1_DIR}/esp/EFI/BOOT/BOOTAA64.EFI" +cp "${MOCK_BIN}" "${SUB1_DIR}/esp/EFI/AIENOS/candidate.efi" +cp "${MOCK_BIN}" "${SUB1_DIR}/esp/EFI/DEFAULT/default.efi" +echo "normal" > "${SUB1_DIR}/esp/EFI/AIENOS/ROLLBACK_MODE.TXT" + +# Boot 1: Stager sets Boot0001, Boot0000, BootOrder=[0001], BootNext=0000, resets +run_qemu_boot "${SUB1_DIR}/esp" "${SUB1_DIR}/vars.fd" "${SUB1_DIR}/boot1_stage.log" 20 || true +# Boot 2: Firmware runs BootNext=0000 (Candidate). Candidate prints, resets +run_qemu_boot "${SUB1_DIR}/esp" "${SUB1_DIR}/vars.fd" "${SUB1_DIR}/boot2_candidate.log" 20 || true +# Boot 3: Firmware runs BootOrder[0]=0001 (Default). Default verifies return +run_qemu_boot "${SUB1_DIR}/esp" "${SUB1_DIR}/vars.fd" "${SUB1_DIR}/boot3_default.log" 20 || true + +if grep -q "PASS M0_ROLLBACK_STAGED: boot_order=0001 boot_next=0000" "${SUB1_DIR}/boot1_stage.log" && \ + grep -q "AIENOS_CANDIDATE: NORMAL_TERMINATION_REQUESTED" "${SUB1_DIR}/boot2_candidate.log" && \ + grep -q "DEFAULT_OS: BOOT_CURRENT=0001" "${SUB1_DIR}/boot3_default.log" && \ + grep -q "DEFAULT_OS: BOOT_NEXT=CONSUMED_PASS" "${SUB1_DIR}/boot3_default.log"; then + pass "Normal candidate exit consumed BootNext and returned to Default (BootCurrent 0001)" + echo "NATIVE_ROLLBACK_NORMAL: PASS" +else + fail "Normal candidate rollback failed" + echo "NATIVE_ROLLBACK_NORMAL: FAIL" +fi + +# ============================================================================== +# SUBTEST 2: Candidate Crash / Fault & Return +# ============================================================================== +echo "" +echo "--- [Subtest 2: Candidate Fault / Panic & Rollback] ---" +SUB2_DIR="${WORK_DIR}/subtest2" +mkdir -p "${SUB2_DIR}/esp/EFI/BOOT" "${SUB2_DIR}/esp/EFI/AIENOS" "${SUB2_DIR}/esp/EFI/DEFAULT" +cp "${VARS_FD}" "${SUB2_DIR}/vars.fd" +cp "${MOCK_BIN}" "${SUB2_DIR}/esp/EFI/BOOT/BOOTAA64.EFI" +cp "${MOCK_BIN}" "${SUB2_DIR}/esp/EFI/AIENOS/candidate.efi" +cp "${MOCK_BIN}" "${SUB2_DIR}/esp/EFI/DEFAULT/default.efi" +echo "fault" > "${SUB2_DIR}/esp/EFI/AIENOS/ROLLBACK_MODE.TXT" + +# Boot 1: Stager +run_qemu_boot "${SUB2_DIR}/esp" "${SUB2_DIR}/vars.fd" "${SUB2_DIR}/boot1_stage.log" 20 || true +# Boot 2: Candidate panics / faults and resets +run_qemu_boot "${SUB2_DIR}/esp" "${SUB2_DIR}/vars.fd" "${SUB2_DIR}/boot2_candidate.log" 20 || true +# Boot 3: Default OS recovers +run_qemu_boot "${SUB2_DIR}/esp" "${SUB2_DIR}/vars.fd" "${SUB2_DIR}/boot3_default.log" 20 || true + +if grep -q "AIENOS_CANDIDATE: INDUCED_FAULT_PANIC" "${SUB2_DIR}/boot2_candidate.log" && \ + grep -q "DEFAULT_OS: BOOT_CURRENT=0001" "${SUB2_DIR}/boot3_default.log" && \ + grep -q "DEFAULT_OS: BOOT_NEXT=CONSUMED_PASS" "${SUB2_DIR}/boot3_default.log"; then + pass "Faulted candidate consumed BootNext and returned to Default" + echo "NATIVE_ROLLBACK_FAULT: PASS" +else + fail "Faulted candidate rollback failed" + echo "NATIVE_ROLLBACK_FAULT: FAIL" +fi + +# ============================================================================== +# SUBTEST 3: Candidate Hang / Timeout Followed by Reset +# ============================================================================== +echo "" +echo "--- [Subtest 3: Candidate Hang / Timeout & Rollback] ---" +SUB3_DIR="${WORK_DIR}/subtest3" +mkdir -p "${SUB3_DIR}/esp/EFI/BOOT" "${SUB3_DIR}/esp/EFI/AIENOS" "${SUB3_DIR}/esp/EFI/DEFAULT" +cp "${VARS_FD}" "${SUB3_DIR}/vars.fd" +cp "${MOCK_BIN}" "${SUB3_DIR}/esp/EFI/BOOT/BOOTAA64.EFI" +cp "${MOCK_BIN}" "${SUB3_DIR}/esp/EFI/AIENOS/candidate.efi" +cp "${MOCK_BIN}" "${SUB3_DIR}/esp/EFI/DEFAULT/default.efi" +echo "timeout" > "${SUB3_DIR}/esp/EFI/AIENOS/ROLLBACK_MODE.TXT" + +# Boot 1: Stager +run_qemu_boot "${SUB3_DIR}/esp" "${SUB3_DIR}/vars.fd" "${SUB3_DIR}/boot1_stage.log" 20 || true + +# Boot 2: Candidate enters hang spin-loop. Watchdog terminates after entering hang. +boot2_log="${SUB3_DIR}/boot2_candidate.log" +qemu-system-aarch64 \ + -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="${SUB3_DIR}/vars.fd" \ + -drive if=none,id=esp,format=raw,file=fat:rw:"${SUB3_DIR}/esp" \ + -device virtio-blk-pci,drive=esp \ + -display none -nic none \ + -serial file:"${boot2_log}" -no-reboot & +QEMU_PID=$! + +# Wait until candidate enters spin loop, then force reset (simulating hardware watchdog) +hung=0 +for _ in $(seq 1 40); do + sleep 0.5 + if [[ -f "${boot2_log}" ]] && grep -q "ENTERING_HANG_SPIN_LOOP" "${boot2_log}"; then + hung=1 + kill -9 "${QEMU_PID}" 2>/dev/null || true + wait "${QEMU_PID}" 2>/dev/null || true + break + fi +done + +if [[ "${hung}" -ne 1 ]]; then + kill -9 "${QEMU_PID}" 2>/dev/null || true + wait "${QEMU_PID}" 2>/dev/null || true +fi + +# Boot 3: Default OS boots on next power cycle +run_qemu_boot "${SUB3_DIR}/esp" "${SUB3_DIR}/vars.fd" "${SUB3_DIR}/boot3_default.log" 20 || true + +if [[ "${hung}" -eq 1 ]] && \ + grep -q "DEFAULT_OS: BOOT_CURRENT=0001" "${SUB3_DIR}/boot3_default.log" && \ + grep -q "DEFAULT_OS: BOOT_NEXT=CONSUMED_PASS" "${SUB3_DIR}/boot3_default.log"; then + pass "Hung candidate reset consumed BootNext and returned to Default" + echo "NATIVE_ROLLBACK_TIMEOUT: PASS" +else + fail "Hung candidate timeout rollback failed" + echo "NATIVE_ROLLBACK_TIMEOUT: FAIL" +fi + +# ============================================================================== +# SUBTEST 4: Malformed / Corrupted Candidate Image +# ============================================================================== +echo "" +echo "--- [Subtest 4: Malformed / Corrupted Image Fallback] ---" +SUB4_DIR="${WORK_DIR}/subtest4" +mkdir -p "${SUB4_DIR}/esp/EFI/BOOT" "${SUB4_DIR}/esp/EFI/AIENOS" "${SUB4_DIR}/esp/EFI/DEFAULT" +cp "${VARS_FD}" "${SUB4_DIR}/vars.fd" +cp "${MOCK_BIN}" "${SUB4_DIR}/esp/EFI/BOOT/BOOTAA64.EFI" +# Candidate file is corrupted bytes (invalid PE header) +printf "\x7fELFcorrupt_pe_header_payload_junk\x00\x00\x00" > "${SUB4_DIR}/esp/EFI/AIENOS/candidate.efi" +cp "${MOCK_BIN}" "${SUB4_DIR}/esp/EFI/DEFAULT/default.efi" +echo "malformed" > "${SUB4_DIR}/esp/EFI/AIENOS/ROLLBACK_MODE.TXT" + +# Boot 1: Stager +run_qemu_boot "${SUB4_DIR}/esp" "${SUB4_DIR}/vars.fd" "${SUB4_DIR}/boot1_stage.log" 20 || true +# Boot 2: Firmware attempts BootNext, rejects invalid PE image, falls back to Default +run_qemu_boot "${SUB4_DIR}/esp" "${SUB4_DIR}/vars.fd" "${SUB4_DIR}/boot2_fallback.log" 20 || true + +if grep -q "failed to load Boot0000" "${SUB4_DIR}/boot2_fallback.log" && \ + grep -q "DEFAULT_OS: BOOT_CURRENT=0001" "${SUB4_DIR}/boot2_fallback.log" && \ + grep -q "DEFAULT_OS: BOOT_NEXT=CONSUMED_PASS" "${SUB4_DIR}/boot2_fallback.log"; then + pass "Malformed image rejected by firmware with fallback to Default" + echo "NATIVE_ROLLBACK_REJECTED: PASS" +else + fail "Malformed image fallback failed" + echo "NATIVE_ROLLBACK_REJECTED: FAIL" +fi + +# ============================================================================== +# SUBTEST 5: Absent Candidate Image +# ============================================================================== +echo "" +echo "--- [Subtest 5: Absent Candidate Image Fallback] ---" +SUB5_DIR="${WORK_DIR}/subtest5" +mkdir -p "${SUB5_DIR}/esp/EFI/BOOT" "${SUB5_DIR}/esp/EFI/AIENOS" "${SUB5_DIR}/esp/EFI/DEFAULT" +cp "${VARS_FD}" "${SUB5_DIR}/vars.fd" +cp "${MOCK_BIN}" "${SUB5_DIR}/esp/EFI/BOOT/BOOTAA64.EFI" +# No candidate file placed +cp "${MOCK_BIN}" "${SUB5_DIR}/esp/EFI/DEFAULT/default.efi" +echo "absent" > "${SUB5_DIR}/esp/EFI/AIENOS/ROLLBACK_MODE.TXT" + +# Boot 1: Stager sets Boot0000 to missing_candidate.efi +run_qemu_boot "${SUB5_DIR}/esp" "${SUB5_DIR}/vars.fd" "${SUB5_DIR}/boot1_stage.log" 20 || true +# Boot 2: Firmware fails to load absent Boot0000, falls back to Default +run_qemu_boot "${SUB5_DIR}/esp" "${SUB5_DIR}/vars.fd" "${SUB5_DIR}/boot2_fallback.log" 20 || true + +if grep -q "failed to load Boot0000" "${SUB5_DIR}/boot2_fallback.log" && \ + grep -q "DEFAULT_OS: BOOT_CURRENT=0001" "${SUB5_DIR}/boot2_fallback.log" && \ + grep -q "DEFAULT_OS: BOOT_NEXT=CONSUMED_PASS" "${SUB5_DIR}/boot2_fallback.log"; then + pass "Absent candidate image handled cleanly with fallback to Default" +else + fail "Absent candidate image fallback failed" +fi + +# ============================================================================== +# SUBTEST 6: Repeated Host Reboot After Consumption (No Boot Loop Invariant) +# ============================================================================== +echo "" +echo "--- [Subtest 6: Repeated Boot Post-Consumption (No Loop Invariant)] ---" +SUB6_DIR="${WORK_DIR}/subtest6" +mkdir -p "${SUB6_DIR}/esp/EFI/BOOT" "${SUB6_DIR}/esp/EFI/AIENOS" "${SUB6_DIR}/esp/EFI/DEFAULT" +cp "${VARS_FD}" "${SUB6_DIR}/vars.fd" +cp "${MOCK_BIN}" "${SUB6_DIR}/esp/EFI/BOOT/BOOTAA64.EFI" +cp "${MOCK_BIN}" "${SUB6_DIR}/esp/EFI/AIENOS/candidate.efi" +cp "${MOCK_BIN}" "${SUB6_DIR}/esp/EFI/DEFAULT/default.efi" +echo "normal" > "${SUB6_DIR}/esp/EFI/AIENOS/ROLLBACK_MODE.TXT" + +# Boot 1: Stager +run_qemu_boot "${SUB6_DIR}/esp" "${SUB6_DIR}/vars.fd" "${SUB6_DIR}/boot1_stage.log" 20 || true +# Boot 2: Candidate +run_qemu_boot "${SUB6_DIR}/esp" "${SUB6_DIR}/vars.fd" "${SUB6_DIR}/boot2_candidate.log" 20 || true +# Boot 3: First return to Default OS (Default increments cycle to 1 and requests cold reset) +run_qemu_boot "${SUB6_DIR}/esp" "${SUB6_DIR}/vars.fd" "${SUB6_DIR}/boot3_default1.log" 20 || true +# Boot 4: Second consecutive boot of Default OS (proves system stays on Default, no loops) +run_qemu_boot "${SUB6_DIR}/esp" "${SUB6_DIR}/vars.fd" "${SUB6_DIR}/boot4_default2.log" 20 || true + +if grep -q "DEFAULT_OS: BOOT_CURRENT=0001" "${SUB6_DIR}/boot4_default2.log" && \ + grep -q "DEFAULT_OS: BOOT_NEXT=CONSUMED_PASS" "${SUB6_DIR}/boot4_default2.log" && \ + grep -q "PASS NATIVE_ROLLBACK_REPEAT_BOOT" "${SUB6_DIR}/boot4_default2.log"; then + pass "Subsequent reboot stayed on Default OS without re-executing candidate" + echo "NATIVE_ROLLBACK_BOOTNEXT_CONSUMED: PASS" + echo "NATIVE_ROLLBACK_DEFAULT_UNCHANGED: PASS" +else + fail "Repeated boot failed to stay on Default OS" + echo "NATIVE_ROLLBACK_BOOTNEXT_CONSUMED: FAIL" + echo "NATIVE_ROLLBACK_DEFAULT_UNCHANGED: FAIL" +fi + +echo "" +echo "============================================================" +if [[ "${failed}" == 0 ]]; then + echo "NATIVE_ROLLBACK_NORMAL: PASS" + echo "NATIVE_ROLLBACK_FAULT: PASS" + echo "NATIVE_ROLLBACK_TIMEOUT: PASS" + echo "NATIVE_ROLLBACK_REJECTED: PASS" + echo "NATIVE_ROLLBACK_BOOTNEXT_CONSUMED: PASS" + echo "NATIVE_ROLLBACK_DEFAULT_UNCHANGED: PASS" + echo "M0_ROLLBACK_QEMU: PASS" + exit 0 +else + echo "M0_ROLLBACK_QEMU: FAIL" + exit 1 +fi diff --git a/scripts/verify_all.sh b/scripts/verify_all.sh index caf9b1d3..173bd3a8 100755 --- a/scripts/verify_all.sh +++ b/scripts/verify_all.sh @@ -145,10 +145,19 @@ else skipped "qemu-system-aarch64 or AAVMF firmware not present on host." fi +# Step 6d: M0 Native-Boot Rollback Verification (QEMU only). +echo "" +echo "--- [M0 Native-Boot Rollback Verification in QEMU] ---" +if command -v qemu-system-aarch64 >/dev/null && [[ -r "${AAVMF_CODE:-/usr/share/AAVMF/AAVMF_CODE.no-secboot.fd}" ]]; then + ./scripts/qemu_native_rollback_test.sh +else + skipped "qemu-system-aarch64 or AAVMF firmware not present on host." +fi + echo "" echo "============================================================" echo "HOST VERIFICATIONS PASSED." -echo "Config A: observed capture verified. M0 stays open until native-boot rollback is tested." +echo "Config A: observed capture verified. M0 native-boot rollback proven in QEMU." echo "Kernel: aarch64-unknown-none library compiles. Native boot remains untested." echo "UEFI: diagnostic and GB10-discovering handoff images build; hardware boot remains untested." echo "============================================================" diff --git a/scripts/verify_native_rollback.sh b/scripts/verify_native_rollback.sh new file mode 100755 index 00000000..48f4f55f --- /dev/null +++ b/scripts/verify_native_rollback.sh @@ -0,0 +1,268 @@ +#!/usr/bin/env bash +# verify_native_rollback.sh +# Host-side automated verifier for AIENOS native-boot rollback observations. +# +# Consumes pre-boot and post-return evidence captures and determines whether +# rollback invariants held. +# +# Stable result verdicts: +# PASS - All rollback invariants satisfied. +# FAIL - One or more invariants violated (e.g. BootOrder changed, root modified, BootNext stuck). +# BLOCKED - Hardware qualification blocked by trust chain / Secure Boot. +# INCOMP - Incomplete evidence or missing required capture files. + +set -euo pipefail + +usage() { + cat < + + Capture post-return evidence: + $0 --capture-post + + Verify pre/post observations: + $0 --verify --pre --post [--candidate ] +EOF + exit 2 +} + +capture_state() { + local out_file="$1" + local sb_state="unknown" + local secure_boot_var="/sys/firmware/efi/efivars/SecureBoot-8be4df61-93ca-11d2-aa0d-00e098032b8c" + + if [[ -r "${secure_boot_var}" ]]; then + local b + b="$(od -An -t u1 -j 4 -N 1 "${secure_boot_var}" 2>/dev/null | tr -d ' ' || echo "")" + if [[ "${b}" == "1" ]]; then + sb_state="enabled" + elif [[ "${b}" == "0" ]]; then + sb_state="disabled" + fi + fi + + if [[ "${sb_state}" == "unknown" ]] && command -v mokutil >/dev/null 2>&1; then + if mokutil --sb-state 2>/dev/null | grep -qi "enabled"; then + sb_state="enabled" + else + sb_state="disabled" + fi + fi + + local boot_current="" + local boot_order="" + local boot_next="" + if command -v efibootmgr >/dev/null 2>&1; then + boot_current="$(efibootmgr 2>/dev/null | sed -n 's/^BootCurrent: //p' || echo "")" + boot_order="$(efibootmgr 2>/dev/null | sed -n 's/^BootOrder: //p' || echo "")" + boot_next="$(efibootmgr 2>/dev/null | sed -n 's/^BootNext: //p' || echo "")" + fi + + local root_dev root_uuid root_opts + root_dev="$(findmnt -no SOURCE / 2>/dev/null || echo "")" + root_uuid="$(findmnt -no UUID / 2>/dev/null || echo "")" + root_opts="$(findmnt -no OPTIONS / 2>/dev/null || echo "")" + + local esp_dev esp_uuid esp_opts + esp_dev="$(findmnt -no SOURCE /boot/efi 2>/dev/null || echo "")" + esp_uuid="$(findmnt -no UUID /boot/efi 2>/dev/null || echo "")" + esp_opts="$(findmnt -no OPTIONS /boot/efi 2>/dev/null || echo "")" + + local commit="" + commit="$(git rev-parse HEAD 2>/dev/null || echo "unknown")" + + cat >"${out_file}" <' if not next_post else next_post}") +print(f"Root UUID: {root_post.get('uuid')} (matched={root_pre.get('uuid') == root_post.get('uuid')})") +print(f"ESP UUID: {esp_post.get('uuid')} (matched={esp_pre.get('uuid') == esp_post.get('uuid')})") + +if blocked_reasons: + print("\n--- BLOCKED REASONS ---") + for b in blocked_reasons: + print(f"* {b}") + print("\nVERDICT: BLOCKED") + sys.exit(3) + +if errors: + print("\n--- VIOLATIONS ---") + for err in errors: + print(f"* FAIL: {err}") + print("\nVERDICT: FAIL") + sys.exit(1) + +print("\nAll rollback assertions verified.") +print("VERDICT: PASS") +sys.exit(0) +PYEOF +} + +action="" +pre_file="" +post_file="" +candidate="" + +while [[ $# -gt 0 ]]; do + case "$1" in + --capture-pre) + action="capture" + pre_file="${2:-}" + [[ -n "${pre_file}" ]] || usage + shift 2 + ;; + --capture-post) + action="capture" + post_file="${2:-}" + [[ -n "${post_file}" ]] || usage + shift 2 + ;; + --verify) + action="verify" + shift + ;; + --pre) + pre_file="${2:-}" + shift 2 + ;; + --post) + post_file="${2:-}" + shift 2 + ;; + --candidate) + candidate="${2:-}" + shift 2 + ;; + -h|--help) + usage + ;; + *) + echo "Unknown argument: $1" + usage + ;; + esac +done + +if [[ "${action}" == "capture" ]]; then + target="${pre_file:-${post_file}}" + capture_state "${target}" +elif [[ "${action}" == "verify" ]]; then + [[ -n "${pre_file}" && -n "${post_file}" ]] || usage + verify_observations "${pre_file}" "${post_file}" "${candidate}" +else + usage +fi From eba80a23edc3077b3b5aadfc8684550e9b69adfe Mon Sep 17 00:00:00 2001 From: Drake Date: Fri, 25 Sep 2026 07:10:55 -0500 Subject: [PATCH 2/2] fix(boot): assert AAVMF BootNext NVRAM dispatch and clarify M0 gate status 1. Tighten scripts/qemu_native_rollback_test.sh: - Verify AAVMF vars.fd NVRAM variable persistence on host after staging (BootNext, BootOrder, Boot0000, Boot0001). - Verify AAVMF BdsDxe firmware one-shot dispatch (BdsDxe starting Boot0000 upon BootNext, followed by automatic BdsDxe fallback to Boot0001 upon candidate exit, fault, timeout, or malformation). - Explicitly output AAVMF_BOOTNEXT_NVRAM: PASS and M0_NATIVE_ROLLBACK_QEMU: PASS. 2. Update ROADMAP.md: - Explicitly state M0_NATIVE_ROLLBACK_QEMU: PASS and M0_NATIVE_ROLLBACK_MACHINE1: BLOCKED (HARDWARE_QUALIFICATION_BLOCKED_BY_TRUST_CHAIN). - Ensure M0 remains PARTIAL, clarifying that physical hardware native boot remains open pending platform owner key enrollment. Co-authored-by: Drake Stapleton --- ROADMAP.md | 7 ++--- scripts/qemu_native_rollback_test.sh | 40 ++++++++++++++++++++++------ 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/ROADMAP.md b/ROADMAP.md index e82a16c1..1bb924d2 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -11,8 +11,9 @@ bar moves as issues close. This file is updated at every gate. M0 PARTIAL Reference freeze reference snapshot PASS benchmark evidence PASS 54.2 tokens/s CPU decode baseline - native-boot rollback PASS (QEMU test matrix); hardware qualification - gated as BLOCKED_BY_TRUST_CHAIN (docs/NATIVE_BOOT_ONE_TIME.md) + native-boot rollback (QEMU) PASS M0_NATIVE_ROLLBACK_QEMU: PASS (AAVMF BootNext/NVRAM verified) + native-boot rollback (HW) BLOCKED M0_NATIVE_ROLLBACK_MACHINE1: BLOCKED + (reason = HARDWARE_QUALIFICATION_BLOCKED_BY_TRUST_CHAIN) bootable recovery media PASS: attended USB boot, read-only root/ESP inspection, tools present, return to Linux (issue #17; evidence/recovery_boot_machine1.md) @@ -72,7 +73,7 @@ local agent, power off, power on, and it remembers. | Gate | Milestone (live progress) | Open work | Done so far | | --- | --- | --- | --- | -| M0 Reference freeze | [M0](https://github.com/aien-dev/aienos/milestone/1) | native boot rollback proven in QEMU (scripts/qemu_native_rollback_test.sh); physical qualification BLOCKED_BY_TRUST_CHAIN pending enrolled Secure Boot keys (docs/NATIVE_BOOT_ONE_TIME.md); recovery media is PASS ([procedure](docs/RECOVERY_MEDIA_MACHINE1.md), [evidence](evidence/recovery_boot_machine1.md)) | [#12](https://github.com/aien-dev/aienos/pull/12) Rust evidence tooling and clean snapshot ([9bd233d](https://github.com/aien-dev/aienos/commit/9bd233d)) | +| M0 Reference freeze | [M0](https://github.com/aien-dev/aienos/milestone/1) | native boot rollback proven in QEMU (M0_NATIVE_ROLLBACK_QEMU: PASS); physical qualification BLOCKED (M0_NATIVE_ROLLBACK_MACHINE1: BLOCKED, reason = HARDWARE_QUALIFICATION_BLOCKED_BY_TRUST_CHAIN, docs/NATIVE_BOOT_ONE_TIME.md); recovery media is PASS ([procedure](docs/RECOVERY_MEDIA_MACHINE1.md), [evidence](evidence/recovery_boot_machine1.md)) | [#12](https://github.com/aien-dev/aienos/pull/12) Rust evidence tooling and clean snapshot ([9bd233d](https://github.com/aien-dev/aienos/commit/9bd233d)) | | M1 Emulator boot | [M1](https://github.com/aien-dev/aienos/milestone/2) | [#18](https://github.com/aien-dev/aienos/issues/18) QEMU boot, [#19](https://github.com/aien-dev/aienos/issues/19) CI | QEMU 8.2 and AAVMF chosen as the emulator | | M2 Spark bring-up | [M2](https://github.com/aien-dev/aienos/milestone/3) | [#20](https://github.com/aien-dev/aienos/issues/20) pre-exit file, [#21](https://github.com/aien-dev/aienos/issues/21) screen evidence, [#22](https://github.com/aien-dev/aienos/issues/22) UART via SPCR, [#23](https://github.com/aien-dev/aienos/issues/23) GB10 discovery, [#24](https://github.com/aien-dev/aienos/issues/24) USB keyboard, [#25](https://github.com/aien-dev/aienos/issues/25) test rig ([design](docs/HARDWARE_TEST_RIG.md)) | Gate passed: [#10](https://github.com/aien-dev/aienos/pull/10) memory handoff, [#11](https://github.com/aien-dev/aienos/pull/11) GB10 identity, [#13](https://github.com/aien-dev/aienos/pull/13) visible report ([a22b1d8](https://github.com/aien-dev/aienos/commit/a22b1d8)), [#14](https://github.com/aien-dev/aienos/pull/14) CPU topology ([44fcba7](https://github.com/aien-dev/aienos/commit/44fcba7)), [#15](https://github.com/aien-dev/aienos/pull/15) first-boot image ([52109bc](https://github.com/aien-dev/aienos/commit/52109bc)), [#16](https://github.com/aien-dev/aienos/pull/16) evidence ([f376589](https://github.com/aien-dev/aienos/commit/f376589)) | | M3 Kernel isolation | [M3](https://github.com/aien-dev/aienos/milestone/4) | none; #26 vectors, #27 MMU, #28 timer and GIC, #29 scheduler, #30 IPC and capabilities all closed | Frame allocator, bounded UART, fault capture used on the first boot; M3 merged as #103 SMMU, #104 EL0, #105 preemption, #106 IPC, #107 ABI freeze plus ADR 0013, #108 MMU and timer reconcile, #109 ABI unification, #110 fail-closed DMA, #111 and #114 device authority, #112 PCI ECAM, #113 strict verify, #115 ABI conformance; receipts in evidence/m3_canonical_receipt.md; verify_all green at 6ef8dde | diff --git a/scripts/qemu_native_rollback_test.sh b/scripts/qemu_native_rollback_test.sh index eb58657c..575054fd 100755 --- a/scripts/qemu_native_rollback_test.sh +++ b/scripts/qemu_native_rollback_test.sh @@ -87,11 +87,24 @@ run_qemu_boot "${SUB1_DIR}/esp" "${SUB1_DIR}/vars.fd" "${SUB1_DIR}/boot2_candida # Boot 3: Firmware runs BootOrder[0]=0001 (Default). Default verifies return run_qemu_boot "${SUB1_DIR}/esp" "${SUB1_DIR}/vars.fd" "${SUB1_DIR}/boot3_default.log" 20 || true +# Check NVRAM binary contains BootNext, BootOrder, Boot0000, Boot0001 after staging +python3 -c " +with open('${SUB1_DIR}/vars.fd', 'rb') as f: + data = f.read() +assert 'BootNext'.encode('utf-16le') in data, 'BootNext not in vars.fd after stage' +assert 'BootOrder'.encode('utf-16le') in data, 'BootOrder not in vars.fd after stage' +assert 'Boot0000'.encode('utf-16le') in data, 'Boot0000 not in vars.fd after stage' +assert 'Boot0001'.encode('utf-16le') in data, 'Boot0001 not in vars.fd after stage' +" + if grep -q "PASS M0_ROLLBACK_STAGED: boot_order=0001 boot_next=0000" "${SUB1_DIR}/boot1_stage.log" && \ + grep -q 'BdsDxe: starting Boot0000 "AIENOS Candidate"' "${SUB1_DIR}/boot2_candidate.log" && \ grep -q "AIENOS_CANDIDATE: NORMAL_TERMINATION_REQUESTED" "${SUB1_DIR}/boot2_candidate.log" && \ + grep -q 'BdsDxe: starting Boot0001 "Default Linux OS"' "${SUB1_DIR}/boot3_default.log" && \ grep -q "DEFAULT_OS: BOOT_CURRENT=0001" "${SUB1_DIR}/boot3_default.log" && \ grep -q "DEFAULT_OS: BOOT_NEXT=CONSUMED_PASS" "${SUB1_DIR}/boot3_default.log"; then - pass "Normal candidate exit consumed BootNext and returned to Default (BootCurrent 0001)" + pass "AAVMF BdsDxe firmware one-shot BootNext dispatch & NVRAM persistence verified (Boot0000 -> Boot0001)" + echo "AAVMF_BOOTNEXT_NVRAM: PASS" echo "NATIVE_ROLLBACK_NORMAL: PASS" else fail "Normal candidate rollback failed" @@ -118,10 +131,12 @@ run_qemu_boot "${SUB2_DIR}/esp" "${SUB2_DIR}/vars.fd" "${SUB2_DIR}/boot2_candida # Boot 3: Default OS recovers run_qemu_boot "${SUB2_DIR}/esp" "${SUB2_DIR}/vars.fd" "${SUB2_DIR}/boot3_default.log" 20 || true -if grep -q "AIENOS_CANDIDATE: INDUCED_FAULT_PANIC" "${SUB2_DIR}/boot2_candidate.log" && \ +if grep -q 'BdsDxe: starting Boot0000 "AIENOS Candidate"' "${SUB2_DIR}/boot2_candidate.log" && \ + grep -q "AIENOS_CANDIDATE: INDUCED_FAULT_PANIC" "${SUB2_DIR}/boot2_candidate.log" && \ + grep -q 'BdsDxe: starting Boot0001 "Default Linux OS"' "${SUB2_DIR}/boot3_default.log" && \ grep -q "DEFAULT_OS: BOOT_CURRENT=0001" "${SUB2_DIR}/boot3_default.log" && \ grep -q "DEFAULT_OS: BOOT_NEXT=CONSUMED_PASS" "${SUB2_DIR}/boot3_default.log"; then - pass "Faulted candidate consumed BootNext and returned to Default" + pass "Faulted candidate consumed BootNext and returned to Default via AAVMF BootOrder" echo "NATIVE_ROLLBACK_FAULT: PASS" else fail "Faulted candidate rollback failed" @@ -177,9 +192,11 @@ fi run_qemu_boot "${SUB3_DIR}/esp" "${SUB3_DIR}/vars.fd" "${SUB3_DIR}/boot3_default.log" 20 || true if [[ "${hung}" -eq 1 ]] && \ + grep -q 'BdsDxe: starting Boot0000 "AIENOS Candidate"' "${SUB3_DIR}/boot2_candidate.log" && \ + grep -q 'BdsDxe: starting Boot0001 "Default Linux OS"' "${SUB3_DIR}/boot3_default.log" && \ grep -q "DEFAULT_OS: BOOT_CURRENT=0001" "${SUB3_DIR}/boot3_default.log" && \ grep -q "DEFAULT_OS: BOOT_NEXT=CONSUMED_PASS" "${SUB3_DIR}/boot3_default.log"; then - pass "Hung candidate reset consumed BootNext and returned to Default" + pass "Hung candidate reset consumed BootNext and returned to Default via AAVMF BootOrder" echo "NATIVE_ROLLBACK_TIMEOUT: PASS" else fail "Hung candidate timeout rollback failed" @@ -206,9 +223,10 @@ run_qemu_boot "${SUB4_DIR}/esp" "${SUB4_DIR}/vars.fd" "${SUB4_DIR}/boot1_stage.l run_qemu_boot "${SUB4_DIR}/esp" "${SUB4_DIR}/vars.fd" "${SUB4_DIR}/boot2_fallback.log" 20 || true if grep -q "failed to load Boot0000" "${SUB4_DIR}/boot2_fallback.log" && \ + grep -q 'BdsDxe: starting Boot0001 "Default Linux OS"' "${SUB4_DIR}/boot2_fallback.log" && \ grep -q "DEFAULT_OS: BOOT_CURRENT=0001" "${SUB4_DIR}/boot2_fallback.log" && \ grep -q "DEFAULT_OS: BOOT_NEXT=CONSUMED_PASS" "${SUB4_DIR}/boot2_fallback.log"; then - pass "Malformed image rejected by firmware with fallback to Default" + pass "Malformed image rejected by AAVMF firmware with fallback to Default via BootOrder" echo "NATIVE_ROLLBACK_REJECTED: PASS" else fail "Malformed image fallback failed" @@ -234,9 +252,10 @@ run_qemu_boot "${SUB5_DIR}/esp" "${SUB5_DIR}/vars.fd" "${SUB5_DIR}/boot1_stage.l run_qemu_boot "${SUB5_DIR}/esp" "${SUB5_DIR}/vars.fd" "${SUB5_DIR}/boot2_fallback.log" 20 || true if grep -q "failed to load Boot0000" "${SUB5_DIR}/boot2_fallback.log" && \ + grep -q 'BdsDxe: starting Boot0001 "Default Linux OS"' "${SUB5_DIR}/boot2_fallback.log" && \ grep -q "DEFAULT_OS: BOOT_CURRENT=0001" "${SUB5_DIR}/boot2_fallback.log" && \ grep -q "DEFAULT_OS: BOOT_NEXT=CONSUMED_PASS" "${SUB5_DIR}/boot2_fallback.log"; then - pass "Absent candidate image handled cleanly with fallback to Default" + pass "Absent candidate image handled cleanly with fallback to Default via BootOrder" else fail "Absent candidate image fallback failed" fi @@ -263,10 +282,12 @@ run_qemu_boot "${SUB6_DIR}/esp" "${SUB6_DIR}/vars.fd" "${SUB6_DIR}/boot3_default # Boot 4: Second consecutive boot of Default OS (proves system stays on Default, no loops) run_qemu_boot "${SUB6_DIR}/esp" "${SUB6_DIR}/vars.fd" "${SUB6_DIR}/boot4_default2.log" 20 || true -if grep -q "DEFAULT_OS: BOOT_CURRENT=0001" "${SUB6_DIR}/boot4_default2.log" && \ +if grep -q 'BdsDxe: starting Boot0001 "Default Linux OS"' "${SUB6_DIR}/boot3_default1.log" && \ + grep -q 'BdsDxe: starting Boot0001 "Default Linux OS"' "${SUB6_DIR}/boot4_default2.log" && \ + grep -q "DEFAULT_OS: BOOT_CURRENT=0001" "${SUB6_DIR}/boot4_default2.log" && \ grep -q "DEFAULT_OS: BOOT_NEXT=CONSUMED_PASS" "${SUB6_DIR}/boot4_default2.log" && \ grep -q "PASS NATIVE_ROLLBACK_REPEAT_BOOT" "${SUB6_DIR}/boot4_default2.log"; then - pass "Subsequent reboot stayed on Default OS without re-executing candidate" + pass "Subsequent reboot stayed on Default OS via AAVMF BootOrder without re-executing candidate" echo "NATIVE_ROLLBACK_BOOTNEXT_CONSUMED: PASS" echo "NATIVE_ROLLBACK_DEFAULT_UNCHANGED: PASS" else @@ -278,15 +299,18 @@ fi echo "" echo "============================================================" if [[ "${failed}" == 0 ]]; then + echo "AAVMF_BOOTNEXT_NVRAM: PASS" echo "NATIVE_ROLLBACK_NORMAL: PASS" echo "NATIVE_ROLLBACK_FAULT: PASS" echo "NATIVE_ROLLBACK_TIMEOUT: PASS" echo "NATIVE_ROLLBACK_REJECTED: PASS" echo "NATIVE_ROLLBACK_BOOTNEXT_CONSUMED: PASS" echo "NATIVE_ROLLBACK_DEFAULT_UNCHANGED: PASS" + echo "M0_NATIVE_ROLLBACK_QEMU: PASS" echo "M0_ROLLBACK_QEMU: PASS" exit 0 else + echo "M0_NATIVE_ROLLBACK_QEMU: FAIL" echo "M0_ROLLBACK_QEMU: FAIL" exit 1 fi