aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
GitHub aien-dev/aienux#372 (code only)
Apply it
git checkout -b patch-20a13deeea6dec2d 9404c9e51b91b3ce9997b2f254afb61508ef8699 curl -fsSL https://interplane.io/drakestapleton/aienux/patches/20a13deeea6dec2d.patch | git am
Provenance
github-import 1
aien-dev/aienux
372
4630bac502e8ad1be7f6f09da487fecf9e917c3a
{"kind":"github-import","owner":"aien-dev","repo":"aienux","number":372,"url":"https://github.com/aien-dev/aienux/pull/372","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:36:17Z","metadata":"unavailable","state_derived":true}
Changes
diff --git a/.crumb b/.crumb index 337a6b64..6f933285 100644 --- a/.crumb +++ b/.crumb @@ -21,39 +21,39 @@ "generated": { "children": [ { - "digest": "ba157598d0766ef2f9e7fbc3b0333b3fd84fcfc9799497a70d2aa6dd0ea9afb3", - "last_commit": "5429602", + "digest": "f0423e1cf49107bf21cebbb87dc6e457aab99782ce8de074b67e657b69577354", + "last_commit": "e673bfb", "name": "crates", "purpose": "Directory crates. Purpose not yet described by a human." }, { - "digest": "56d07fe5889c5254e4734f3c06056d6fdaf75e06c057952b0c4d7f076246ae43", - "last_commit": "23c8bcd", + "digest": "e972155c7fe8802cecb2d0eb0064267c2e1bc60b13be45736c1a88fa0d12bd9d", + "last_commit": "a3e9c23", "name": "docs", "purpose": "Directory docs. Purpose not yet described by a human." }, { - "digest": "e2a3164c1405eca5c2ce65baa8d0acae588e8d3c3f00f788af0a4f90746f593a", - "last_commit": "cb3bba7", + "digest": "dc8479ff588f0d10dbfd65003c236db4cdeb9718a60d4fbf98822da677d908ff", + "last_commit": "e673bfb", "name": "native", "purpose": "Directory native. Purpose not yet described by a human." }, { - "digest": "48c4fa69e56fcade3e5fa0d959501d89269856026f10eec71fe9818e6ca9a9de", - "last_commit": "cb3bba7", + "digest": "f573c48fba3478c69f1daac51db9427a959b611059ca020cd5eaa8c94685d883", + "last_commit": "e673bfb", "name": "scripts", "purpose": "Directory scripts. Purpose not yet described by a human." } ], - "children_root": "sha256:8c6cbe9eacc90d8b46a492c891dfc785e66687431d9b0cf96df3bb57b57a16c3", - "compiled_at": "2026-10-13T23:37:04Z", + "children_root": "sha256:77bca34ed477aafdcaed7d355c5617f3378552a11f1df29f0929ac83977e61ee", + "compiled_at": "2026-10-14T00:20:37Z", "compiler": "crumb-compile/1", - "digest": "sha256:45e06b1a1efe485ac6ee5ea982e629abd36109e5f86e14c731f832f87f921cf9", + "digest": "sha256:444c8e8b6863adfeae1b4a9da31d2d27693a20cd971a514749aec6926a78e4d4", "evidence_files": 156, "evidence_root": "sha256:cd53ab119be9de6ce28c4f5949b106c9622f1fe105611de3de21c3bce7932694", - "files": 3201, - "generated_at_commit": "23c8bcd5490dd2ec9ded661ffefd5ecb5533dcec", - "source_tree": "sha256:851da4029d8b603841af4f012f932469e021ba857aa3a75ac7ceb48c95e03b67" + "files": 3223, + "generated_at_commit": "a3e9c23dfc5b0ed0f9701132904b28edac14b71f", + "source_tree": "sha256:7901d2b70d100b61aaccea65d259b4c8745b45e98ee11c72330ce0354c3f121d" }, "owner_lane": "", "provenance": { diff --git a/crates/.crumb b/crates/.crumb index cbb85040..8890da24 100644 --- a/crates/.crumb +++ b/crates/.crumb @@ -89,8 +89,8 @@ "purpose": "Directory crates/aienos-artifact. Purpose not yet described by a human." }, { - "digest": "d7f3206903444c2cd06fe35beef52579a9df03838ea60149e710d3d3efc415a8", - "last_commit": "2276906", + "digest": "ff4260f8fede1182f834d89589eb4d5a6c6160032dfc570003d506411fe93aa4", + "last_commit": "e673bfb", "name": "aienos-artifact-tool", "purpose": "Directory crates/aienos-artifact-tool. Purpose not yet described by a human." }, @@ -149,15 +149,15 @@ "purpose": "Directory crates/aienos-store-tool. Purpose not yet described by a human." } ], - "children_root": "sha256:94f052910f8e65e9eca98d9c0b5d433ef2288dcd8ca1c474518e716295999644", - "compiled_at": "2026-10-13T18:08:10Z", + "children_root": "sha256:6b6f6e90674aa3c267f448fc5fcacb0b52175dc48736e7a1ada14a9a67560fa6", + "compiled_at": "2026-10-14T00:20:37Z", "compiler": "crumb-compile/1", - "digest": "sha256:ba157598d0766ef2f9e7fbc3b0333b3fd84fcfc9799497a70d2aa6dd0ea9afb3", + "digest": "sha256:f0423e1cf49107bf21cebbb87dc6e457aab99782ce8de074b67e657b69577354", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 234, - "generated_at_commit": "bbf44285da08d70877d4b5d35ec805544bf70f3d", - "source_tree": "sha256:6e05723abc5f59f3ac4e57a5dd6d9ab44a58cbd6f9d41522f7bc4e3fea69b11f" + "files": 248, + "generated_at_commit": "a3e9c23dfc5b0ed0f9701132904b28edac14b71f", + "source_tree": "sha256:89414eba01b8ce693eb6f1d4c666913e7074863c28bf5c6747b1acc08f9d717a" }, "owner_lane": "", "provenance": { diff --git a/crates/aienos-artifact-tool/.crumb b/crates/aienos-artifact-tool/.crumb index c5a1b420..e78f43b2 100644 --- a/crates/aienos-artifact-tool/.crumb +++ b/crates/aienos-artifact-tool/.crumb @@ -24,14 +24,14 @@ } ], "children_root": "sha256:9e74efbe992bdf8537913d0945f0b28487e757732babf47a95707d1203682e7b", - "compiled_at": "2026-10-04T13:47:18Z", + "compiled_at": "2026-10-14T00:20:37Z", "compiler": "crumb-compile/1", - "digest": "sha256:d7f3206903444c2cd06fe35beef52579a9df03838ea60149e710d3d3efc415a8", + "digest": "sha256:ff4260f8fede1182f834d89589eb4d5a6c6160032dfc570003d506411fe93aa4", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 25, - "generated_at_commit": "a863d5c1f5bd89c88c5f6671eecfd27b599ee512", - "source_tree": "sha256:3696f713812307854f90c24af2fb37daeae67a11dea85a601a25b14998724303" + "files": 39, + "generated_at_commit": "a3e9c23dfc5b0ed0f9701132904b28edac14b71f", + "source_tree": "sha256:89eb7ba0259498354bbb1f270b83b0a487ff86996ecb068df73ea51e473a92e2" }, "owner_lane": "", "provenance": { diff --git a/crates/aienos-artifact-tool/fixtures/p2_7/assemble.sh b/crates/aienos-artifact-tool/fixtures/p2_7/assemble.sh new file mode 100755 index 00000000..9f2af552 --- /dev/null +++ b/crates/aienos-artifact-tool/fixtures/p2_7/assemble.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash +# Reassemble every PI5-7 cut 3 probe from probe.S into OUT_DIR/<probe>/code.bin. +# The committed code.bin files are the Raspberry Pi 5 qualification inputs (kernel read at 0x210000, kernel +# write at 0x2000000, the addresses the Pi image's own mmu_switch / memory lines print); this script proves +# they are exactly what probe.S assembles to, and builds other platforms' variants (the QEMU twin gate +# passes the addresses its own kernel prints): +# KREAD_ADDR=0x40000000 KWRITE_ADDR=0x4a000000 assemble.sh OUT_DIR +# Needs an AArch64 GNU `as` and `objcopy` (native on the Spark). +set -euo pipefail + +here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +out="${1:?usage: assemble.sh OUT_DIR}" +as_bin="${AS:-as}" +objcopy_bin="${OBJCOPY:-objcopy}" +if [[ "$(uname -m)" != "aarch64" ]]; then + as_bin="${AS:-aarch64-linux-gnu-as}" + objcopy_bin="${OBJCOPY:-aarch64-linux-gnu-objcopy}" +fi +kread="${KREAD_ADDR:-0x210000}" +kwrite="${KWRITE_ADDR:-0x2000000}" +[[ "${kread}" =~ ^0x[0-9a-fA-F]{1,16}$ && "${kwrite}" =~ ^0x[0-9a-fA-F]{1,16}$ ]] || { echo "FAIL addresses must be 0x<hex>" >&2; exit 1; } + +for probe in p27kread p27kwrite p27priv; do + mkdir -p "${out}/${probe}" + "${as_bin}" --defsym "KADDR=$([[ ${probe} == p27kread ]] && echo "${kread}" || echo "${kwrite}")" \ + -o "${out}/${probe}/probe.o" "${here}/${probe}/probe.S" + # A probe must be fully resolved: no relocations, so the bytes the kernel authenticates are the bytes + # that execute, with no loader fix-ups. + if command -v readelf >/dev/null; then + if readelf -r "${out}/${probe}/probe.o" | grep -q "Relocation section"; then + echo "FAIL ${probe} has relocations" >&2 + exit 1 + fi + fi + "${objcopy_bin}" -O binary -j .text "${out}/${probe}/probe.o" "${out}/${probe}/code.bin" +done diff --git a/crates/aienos-artifact-tool/fixtures/p2_7/p27kread/code.bin b/crates/aienos-artifact-tool/fixtures/p2_7/p27kread/code.bin new file mode 100644 index 00000000..1bf4a6dc Binary files /dev/null and b/crates/aienos-artifact-tool/fixtures/p2_7/p27kread/code.bin differ diff --git a/crates/aienos-artifact-tool/fixtures/p2_7/p27kread/data.bin b/crates/aienos-artifact-tool/fixtures/p2_7/p27kread/data.bin new file mode 100644 index 00000000..b7ef6705 --- /dev/null +++ b/crates/aienos-artifact-tool/fixtures/p2_7/p27kread/data.bin @@ -0,0 +1 @@ +P27KRDAT \ No newline at end of file diff --git a/crates/aienos-artifact-tool/fixtures/p2_7/p27kread/manifest.json b/crates/aienos-artifact-tool/fixtures/p2_7/p27kread/manifest.json new file mode 100644 index 00000000..af3633c7 --- /dev/null +++ b/crates/aienos-artifact-tool/fixtures/p2_7/p27kread/manifest.json @@ -0,0 +1,15 @@ +{ + "entry_offset": 0, + "capabilities": [], + "resources": { + "code_pages": 1, + "data_pages": 1, + "stack_pages": 1, + "max_capabilities": 0, + "ipc_messages": 0, + "ipc_bytes": 0, + "cpu_ticks": 100000000, + "elapsed_ticks": 100000000, + "syscall_count": 4 + } +} diff --git a/crates/aienos-artifact-tool/fixtures/p2_7/p27kread/probe.S b/crates/aienos-artifact-tool/fixtures/p2_7/p27kread/probe.S new file mode 100644 index 00000000..d80979ef --- /dev/null +++ b/crates/aienos-artifact-tool/fixtures/p2_7/p27kread/probe.S @@ -0,0 +1,19 @@ +// PI5-7 cut 3 kernel-read probe: AArch64 EL0, position independent, no relocations. It loads one 64-bit word +// from a kernel address (KADDR: by default 0x210000, the kernel's own translation-table root on the Raspberry Pi 5 +// image, see the "mmu_switch: ... aienos_root=" line of every Pi run). The kernel maps its memory EL1-only in the +// task's table, so the load must take a permission fault from EL0 (ESR_EL1.EC 0x24, WnR 0, FAR = KADDR) and the +// kernel must terminate and reclaim the task and keep running. Reaching SYS_EXIT(0x57) would mean the load +// succeeded, i.e. kernel memory is readable from EL0. +// Assemble with: as --defsym KADDR=<address> (assemble.sh does). + .ifndef KADDR + .set KADDR, 0x210000 + .endif + .text + .global _start +_start: + ldr x9, =KADDR + ldr x0, [x9] + mov x0, #0x57 + mov x8, #2 + svc #0 +1: b 1b diff --git a/crates/aienos-artifact-tool/fixtures/p2_7/p27kwrite/code.bin b/crates/aienos-artifact-tool/fixtures/p2_7/p27kwrite/code.bin new file mode 100644 index 00000000..de216d0c Binary files /dev/null and b/crates/aienos-artifact-tool/fixtures/p2_7/p27kwrite/code.bin differ diff --git a/crates/aienos-artifact-tool/fixtures/p2_7/p27kwrite/data.bin b/crates/aienos-artifact-tool/fixtures/p2_7/p27kwrite/data.bin new file mode 100644 index 00000000..7d0136b0 --- /dev/null +++ b/crates/aienos-artifact-tool/fixtures/p2_7/p27kwrite/data.bin @@ -0,0 +1 @@ +P27KWDAT \ No newline at end of file diff --git a/crates/aienos-artifact-tool/fixtures/p2_7/p27kwrite/manifest.json b/crates/aienos-artifact-tool/fixtures/p2_7/p27kwrite/manifest.json new file mode 100644 index 00000000..af3633c7 --- /dev/null +++ b/crates/aienos-artifact-tool/fixtures/p2_7/p27kwrite/manifest.json @@ -0,0 +1,15 @@ +{ + "entry_offset": 0, + "capabilities": [], + "resources": { + "code_pages": 1, + "data_pages": 1, + "stack_pages": 1, + "max_capabilities": 0, + "ipc_messages": 0, + "ipc_bytes": 0, + "cpu_ticks": 100000000, + "elapsed_ticks": 100000000, + "syscall_count": 4 + } +} diff --git a/crates/aienos-artifact-tool/fixtures/p2_7/p27kwrite/probe.S b/crates/aienos-artifact-tool/fixtures/p2_7/p27kwrite/probe.S new file mode 100644 index 00000000..55427c0a --- /dev/null +++ b/crates/aienos-artifact-tool/fixtures/p2_7/p27kwrite/probe.S @@ -0,0 +1,20 @@ +// PI5-7 cut 3 kernel-write probe: AArch64 EL0, position independent, no relocations. It stores one 64-bit word +// to a kernel address (KADDR: by default 0x2000000, inside the kernel heap of the Raspberry Pi 5 image, which is +// 0x261000-0x4261000 and nearly all free at this point: a store that wrongly succeeded would not corrupt live +// data, it would only show). The kernel maps its memory EL1-only in the task's table, so the store must take a +// permission fault from EL0 (ESR_EL1.EC 0x24, WnR 1, FAR = KADDR), the task is terminated and reclaimed and the +// kernel keeps running. Reaching SYS_EXIT(0x57) would mean the store succeeded. +// Assemble with: as --defsym KADDR=<address> (assemble.sh does). + .ifndef KADDR + .set KADDR, 0x2000000 + .endif + .text + .global _start +_start: + ldr x9, =KADDR + movz x10, #0xdead + str x10, [x9] + mov x0, #0x57 + mov x8, #2 + svc #0 +1: b 1b diff --git a/crates/aienos-artifact-tool/fixtures/p2_7/p27priv/code.bin b/crates/aienos-artifact-tool/fixtures/p2_7/p27priv/code.bin new file mode 100644 index 00000000..2dce8159 Binary files /dev/null and b/crates/aienos-artifact-tool/fixtures/p2_7/p27priv/code.bin differ diff --git a/crates/aienos-artifact-tool/fixtures/p2_7/p27priv/data.bin b/crates/aienos-artifact-tool/fixtures/p2_7/p27priv/data.bin new file mode 100644 index 00000000..457c4ef7 --- /dev/null +++ b/crates/aienos-artifact-tool/fixtures/p2_7/p27priv/data.bin @@ -0,0 +1 @@ +P27PVDAT \ No newline at end of file diff --git a/crates/aienos-artifact-tool/fixtures/p2_7/p27priv/manifest.json b/crates/aienos-artifact-tool/fixtures/p2_7/p27priv/manifest.json new file mode 100644 index 00000000..af3633c7 --- /dev/null +++ b/crates/aienos-artifact-tool/fixtures/p2_7/p27priv/manifest.json @@ -0,0 +1,15 @@ +{ + "entry_offset": 0, + "capabilities": [], + "resources": { + "code_pages": 1, + "data_pages": 1, + "stack_pages": 1, + "max_capabilities": 0, + "ipc_messages": 0, + "ipc_bytes": 0, + "cpu_ticks": 100000000, + "elapsed_ticks": 100000000, + "syscall_count": 4 + } +} diff --git a/crates/aienos-artifact-tool/fixtures/p2_7/p27priv/probe.S b/crates/aienos-artifact-tool/fixtures/p2_7/p27priv/probe.S new file mode 100644 index 00000000..ae0e38d1 --- /dev/null +++ b/crates/aienos-artifact-tool/fixtures/p2_7/p27priv/probe.S @@ -0,0 +1,13 @@ +// PI5-7 cut 3 privileged-instruction probe: AArch64 EL0, position independent, no relocations. It reads +// SCTLR_EL1, a system register that EL0 may not access (Arm ARM DDI 0487: MRS of an EL1 register from EL0 is +// UNDEFINED, taken to EL1 with ESR_EL1.EC 0x00 unknown reason, or EC 0x18 when the access is trapped). The task +// is terminated and reclaimed and the kernel keeps running. Reaching SYS_EXIT(0x57) would mean EL0 may read +// kernel control registers. + .text + .global _start +_start: + mrs x0, sctlr_el1 + mov x0, #0x57 + mov x8, #2 + svc #0 +1: b 1b diff --git a/crates/aienos-artifact-tool/fixtures/p2_7/pack.sh b/crates/aienos-artifact-tool/fixtures/p2_7/pack.sh new file mode 100755 index 00000000..46cd6ade --- /dev/null +++ b/crates/aienos-artifact-tool/fixtures/p2_7/pack.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +# Pack and sign the PI5-7 cut 3 probes with the TEST ONLY SEED-0B identity (RFC 8032 TEST 1 key, public) into +# OUT_DIR as P27KREAD.AIEN, P27KWRITE.AIEN and P27PRIV.AIEN, and append "NAME ARTIFACT_ID" to OUT_DIR/ids.txt. +# CODE_DIR (optional) holds <probe>/code.bin variants from assemble.sh; default: the committed Pi code.bin. +# +# TOOL is the in-tree ck_artifact_tool (make -C native/kernel tool) or a debug aienos-artifact-tool built with +# --features seed0b-test-signing (release builds refuse that feature). +set -euo pipefail + +here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +tool="${1:?usage: pack.sh TOOL OUT_DIR [CODE_DIR]}" +out="${2:?usage: pack.sh TOOL OUT_DIR [CODE_DIR]}" +codes="${3:-}" +mkdir -p "${out}" +touch "${out}/ids.txt" + +pack_one() { # probe, output name + local probe="$1" name="$2" code="${here}/${1}/code.bin" + if [[ -n "${codes}" ]]; then code="${codes}/${probe}/code.bin"; fi + "${tool}" pack "${here}/${probe}/manifest.json" "${code}" \ + "${here}/${probe}/data.bin" "${out}/${probe}.unsigned.aien" >/dev/null + "${tool}" sign "${out}/${probe}.unsigned.aien" "${out}/${name}" >/dev/null + rm -f "${out}/${probe}.unsigned.aien" + "${tool}" verify "${out}/${name}" >/dev/null + echo "${name} $("${tool}" id "${out}/${name}")" >>"${out}/ids.txt" +} + +pack_one p27kread P27KREAD.AIEN +pack_one p27kwrite P27KWRITE.AIEN +pack_one p27priv P27PRIV.AIEN diff --git a/docs/.crumb b/docs/.crumb index 5da483f6..7ab6b3dc 100644 --- a/docs/.crumb +++ b/docs/.crumb @@ -30,14 +30,14 @@ } ], "children_root": "sha256:c5d7ca9ce0145309c90a439711adcb6dd8e8e40ff48b90455f545e63c05f04c8", - "compiled_at": "2026-10-13T23:37:04Z", + "compiled_at": "2026-10-14T00:20:37Z", "compiler": "crumb-compile/1", - "digest": "sha256:56d07fe5889c5254e4734f3c06056d6fdaf75e06c057952b0c4d7f076246ae43", + "digest": "sha256:e972155c7fe8802cecb2d0eb0064267c2e1bc60b13be45736c1a88fa0d12bd9d", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 81, - "generated_at_commit": "23c8bcd5490dd2ec9ded661ffefd5ecb5533dcec", - "source_tree": "sha256:c22db8af13a56be027321240ae6f619a10aec867e1b0df5516b3243aeb5dfbaf" + "files": 82, + "generated_at_commit": "a3e9c23dfc5b0ed0f9701132904b28edac14b71f", + "source_tree": "sha256:fed2f6b0afe5a7dadd36e87ab29ab36391b768f370313d55eaa8d6b94dcdddcc" }, "owner_lane": "", "provenance": { diff --git a/docs/native/PI5-7-ARTIFACT-RUNS.md b/docs/native/PI5-7-ARTIFACT-RUNS.md new file mode 100644 index 00000000..84e5044f --- /dev/null +++ b/docs/native/PI5-7-ARTIFACT-RUNS.md @@ -0,0 +1,88 @@ +# PI5-7 cut 3: EL0 artifact loader on the Raspberry Pi 5 (QUALIFICATION ONLY) + +Status: one Pi run, green first time (`pi5-artifact-a1`, 2026-10-14 00:0xZ). TEST keys only. Nothing here is a production claim. + +## What was built + +- `make pi5-artifact` (`CK_PI5_ARTIFACT=1`): the plain Pi core image (no Store, no NVMe, no unlock secret) whose signed artifact candidates + come from ONE card file, `\EFI\AIENOS\ARTIFACT.BND`, read by the UEFI stub (`native/boot/efi_artifact.c`) before ExitBootServices and handed to the + unchanged core loader (`core/artifact_loader.c`) through the hook the boot-disk Store uses. Layout of the file: the existing `AIENBND\0` bundle written + by `ck_artifact_tool bundle` (`core/artifact_card.h`), parsed strictly (`core/artifact_card.c`, host test `test_artifact_card` plus a mutant). +- Trust is the public RFC 8032 TEST 1 key only (`CK_SEED0B_TEST_ANCHOR=1`, forced; the image prints `artifact_trust: seed0b-test qualification build — TEST ONLY`). + No owner or release key was generated or touched. Store, signature and admission rules are unchanged. +- QEMU twin: `CK_ARTIFACT_CARD=1 CK_SEED0B_TEST_ANCHOR=1` (same code, no `CK_PI5`), gate `scripts/qemu_ck_artifact_card_test.sh`. +- New EL0 probes `fixtures/p2_7`: `P27KREAD` (load from a kernel address), `P27KWRITE` (store to a kernel address), `P27PRIV` (`mrs x0, sctlr_el1`). Kernel + addresses in the committed Pi `code.bin`: read 0x210000 (translation-table root, `mmu_switch ... aienos_root=` of all 27 earlier Pi runs), write 0x2000000 + (inside the kernel heap 0x261000-0x4261000). +- Only the card image classifies these faults by name (`outside-read`, `outside-write`, `privileged-insn`) and prints an `artifact_fault:` line; every other image + is byte-identical to main (checked: default, full, full with TEST anchor, pi5, pi5-store, pi5-unlock-card, pi5-pcie, pi5-net). +- Run tool (outside the repo, like its siblings): `~/workspace/pi5/pi5-run-artifact.sh`, copy in `scripts/pi5_run_artifact.sh`; `ARTIFACT_BND=<file>` places the bundle + on the card and zeroes and deletes it after the run (verified: `artifact_bnd_deleted_verified`). + +## Pi run pi5-artifact-a1 + +Image `target/native-kernel-pi5-artifact/BOOTAA64.EFI` sha256 `a074747fb866c9706e5e74bd50f19dabcc3a69a949f8de6c056d66ca14e8db5f`, built at commit `1192a687610da2290032eb7dbfd64861be83e77a`. +Bundle sha256 `0757c5c50efe5149504636e01d016d798fe55d7eeaae404b6642f8d99bb91d70` (6 entries: P25EXEC, P27KREAD, P27KWRITE, P27PRIV, P26SEED, P25TAMP). +`MODEL.MAP` is not on the card (`model_map: absent`). Command: `KLOG=1 ARTIFACT_BND=... pi5-run-artifact.sh <EFI> pi5-artifact-a1`. Evidence: `~/workspace/pi5-runs/pi5-artifact-a1/kernel.log`. + +### Exact kernel.log lines + +``` +aienos_commit: 1192a687610da2290032eb7dbfd64861be83e77a +model_map: absent (no \EFI\AIENOS\MODEL.MAP on the boot volume) +artifact_card: found a well-formed bundle (QUALIFICATION ONLY, TEST keys, 6 entries, 3263 bytes) +mmu_switch: firmware=EL2 firmware_mmu=on firmware_ttbr0=0x3f3fa000 aienos_root=0x210000 ttbr0_el1=0x210000 switched=yes +memory: ram_ranges=105 free_bytes=7370326016 stack=0x220000-0x260000 heap=0x261000-0x4261000 dma=0x4400000-0x4c00000 exit_attempts=1 +el0: ok write=granted forged=denied fault=contained exit=0 +artifact_trust: seed0b-test qualification build — TEST ONLY +artifact_card: \EFI\AIENOS\ARTIFACT.BND bytes=3263 entries=6 sha256=0757c5c50efe5149504636e01d016d798fe55d7eeaae404b6642f8d99bb91d70 (QUALIFICATION ONLY, TEST keys; untrusted until verified) +artifact_card: P25EXEC.AIEN bytes=628 sha256=49c3621c190bf3fa8ea9ee4b7cd7f7b65472edc2a790d81aa4a29b43ffa56244 +artifact_card: P27KREAD.AIEN bytes=380 sha256=5a441f1253d703647e6419c48b8e35de0e89ba9bcd7f7126e2a634f354005b2c +artifact_card: P27KWRITE.AIEN bytes=388 sha256=fa6d1989227b23fe1fbe72a241f3ae5509653da983f832fa5627366dfecf17ad +artifact_card: P27PRIV.AIEN bytes=368 sha256=90caa62fe2c4a870245222dfe9c1a733aa1d3863c93c2330516c4d36840d0e4e +artifact_card: P26SEED.AIEN bytes=748 sha256=0f560dff72cbd81c27677cb4de60a50eb6881be47aad0b8156efb1cbbba07224 +artifact_card: P25TAMP.AIEN bytes=628 sha256=069e10eda35bef104a8ff877cdb956724f0ccf8b2ecada3926bf89a61ffb3852 +artifact_source: card_file candidates=6 (read from the card by the UEFI stub; bytes untrusted until verified) +artifact_candidates: 6 +artifact_receipt_tier: SEED-0B-PI5 +artifact_frames_free_before: 1799379 +artifact: P25EXEC.AIEN admitted id=19429f616c5b5315 tier=seed0b-test exec=exited:0x0 bytes=identified=verified=admitted=mapped=executed wx=enforced caps=1 revoked=yes reclaimed=yes frames=10 syscalls=3 reads=1 denials=1 +grant: P25EXEC.AIEN[0] kind=object id=1 rights=0x1 bounds=0+32 max_ops=4 max_bytes=32 +artifact: P27KREAD.AIEN admitted id=509e5262e1de8ce1 tier=seed0b-test exec=fault:outside-read bytes=identified=verified=admitted=mapped=executed wx=enforced caps=0 revoked=yes reclaimed=yes frames=10 syscalls=0 reads=0 denials=0 +artifact_fault: P27KREAD.AIEN class=outside-read esr=0x9200000f ec=0x24 far=0x210000 elr=0x8000001004 contained=yes +artifact: P27KWRITE.AIEN admitted id=4392fbbf1c2a8b59 tier=seed0b-test exec=fault:outside-write bytes=identified=verified=admitted=mapped=executed wx=enforced caps=0 revoked=yes reclaimed=yes frames=10 syscalls=0 reads=0 denials=0 +artifact_fault: P27KWRITE.AIEN class=outside-write esr=0x9200004e ec=0x24 far=0x2000000 elr=0x8000001008 contained=yes +artifact: P27PRIV.AIEN admitted id=abb2c16cdfed9d9d tier=seed0b-test exec=fault:privileged-insn bytes=identified=verified=admitted=mapped=executed wx=enforced caps=0 revoked=yes reclaimed=yes frames=10 syscalls=0 reads=0 denials=0 +artifact_fault: P27PRIV.AIEN class=privileged-insn esr=0x2000000 ec=0x0 far=n/a elr=0x8000001000 contained=yes +artifact: P26SEED.AIEN admitted id=79e81fccae256533 tier=seed0b-test exec=exited:0x0 bytes=identified=verified=admitted=mapped=executed wx=enforced caps=1 revoked=yes reclaimed=yes frames=10 syscalls=9 reads=3 denials=5 +grant: P26SEED.AIEN[0] kind=object id=1 rights=0x1 bounds=0+32 max_ops=4 max_bytes=32 +artifact: P25TAMP.AIEN rejected stage=verified reason=BadSignature reclaimed=yes +artifact_frames_free_after: 1799379 +artifact_card: released bundle bytes=3263 entries=6 +artifacts: candidates=6 admitted=5 rejected=1 +``` + +### Reading it + +- (a) good artifacts: `P25EXEC` and `P26SEED` run at EL0 in their own address space, read their granted object through `SYS_OBJECT_READ`, are denied forged and + out-of-grant handles, and return exit 0 through `SYS_EXIT` (the exit value is recorded in the receipt). `P26SEED` runs AFTER the three faults. +- (b) `P25TAMP` (one payload byte flipped after signing) is refused at stage `verified`, reason `BadSignature`, before any execution (`syscalls=0` in its receipt, `status=NotRun`). +- (c) `P27KREAD`, `P27KWRITE`: data abort from EL0 (EC 0x24, DFSC 0x0f permission fault level 3 for the read, 0x0e for the write: ESR 0x9200000f / 0x9200004e), FAR equal to + the kernel address the probe used, WnR 0 / 1. `P27PRIV`: ESR 0x2000000 (EC 0x00, unknown reason = UNDEFINED instruction from EL0). Each was terminated and its frames + reclaimed; none reached its violation exit (0x57); the kernel then ran `P26SEED`, rejected `P25TAMP`, printed the final report and the frame count came back + (`1799379` free before and after). +- Receipts: all six decoded on the host from the log, bound to the supplied artifact, digest recomputed, TEST ONLY signature verified. + +## Gates (host and QEMU) + +`make test` (CK_CORE_HOST PASS, `test_artifact_card` 33 checks, mutant killed), `make stage-test` (839 checks), `scripts/ck_pi5_build_check.sh` (231 PASS), `scripts/qemu_ck_artifact_test.sh` +(208 PASS), `scripts/qemu_artifact_test.sh` (165 PASS), `scripts/qemu_ck_lifecycle_test.sh` PASS, `scripts/qemu_ck_artifact_card_test.sh` (new, 39 PASS). + +## Limits + +- The receipt record's `tier` field still reads `SEED-0B-QEMU` on the Pi (fixed in the loader's receipt writer, unchanged here); the separate line `artifact_receipt_tier: SEED-0B-PI5` is the Pi tier. +- Isolation was shown for the three attack classes above against the two kernel addresses used; it is not a proof for every kernel address, and the kernel does not itself + re-read the targets after the stores (the faulting stores never retire, FAR names the address). +- `contained=yes` in `artifact_fault:` means the fault handler terminated the task and returned to the kernel; it is not an independent audit. +- One Pi run, one card, TEST keys. Not a production or release claim. +- The Pi run used the image built at commit 1192a687 on top of main 15c19d4. The branch was then rebased onto main 9404c9e (PI5-NET-3, which does not touch the artifact path; one Makefile test-list conflict resolved). Host and QEMU gates were re-run after the rebase; the Pi was not re-run. diff --git a/native/.crumb b/native/.crumb index ef1f3117..9d2e20da 100644 --- a/native/.crumb +++ b/native/.crumb @@ -55,8 +55,8 @@ "purpose": "Directory native/argus. Purpose not yet described by a human." }, { - "digest": "441bb7a06c78208da659e10e8ff3c50998f4aac3fe8446bcc6259521d040b466", - "last_commit": "15c19d4", + "digest": "19d19008ffb4cfcd93c43202081a84ecd1e37d1c60b9d7c355fd8b9db4d3d77e", + "last_commit": "e673bfb", "name": "boot", "purpose": "Directory native/boot. Purpose not yet described by a human." }, @@ -79,8 +79,8 @@ "purpose": "Directory native/disk. Purpose not yet described by a human." }, { - "digest": "a055397a8db7d75eb8eeeb0e1e105b53ddb0e93ba13f9d0bb265749377bfae0b", - "last_commit": "cb3bba7", + "digest": "7df01cbf05b0e93aa9bbf47b2b862b110b001f9cce2283d181a91be5b3393507", + "last_commit": "e673bfb", "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:abb35e3d9ebfb14eba10be5460456dc15283465b14f2d7adf736c36517af9e26", - "compiled_at": "2026-10-13T23:37:04Z", + "children_root": "sha256:c8382b2f14968143480ff5b3dd2859dfb8a1671a60445d47a82204e06e8c5ba2", + "compiled_at": "2026-10-14T00:20:37Z", "compiler": "crumb-compile/1", - "digest": "sha256:e2a3164c1405eca5c2ce65baa8d0acae588e8d3c3f00f788af0a4f90746f593a", + "digest": "sha256:dc8479ff588f0d10dbfd65003c236db4cdeb9718a60d4fbf98822da677d908ff", "evidence_files": 4, "evidence_root": "sha256:e410b845507e00568e15b51a5797af32a97e0e4b8ab4e8487bb7c98e7e0cf335", - "files": 556, - "generated_at_commit": "23c8bcd5490dd2ec9ded661ffefd5ecb5533dcec", - "source_tree": "sha256:b0c6458b356dbabaf48eb5c4b5aa7ea7d3e54569bf19a18f99b0356714598001" + "files": 561, + "generated_at_commit": "a3e9c23dfc5b0ed0f9701132904b28edac14b71f", + "source_tree": "sha256:bfee5f6e8f8a64b1b0f1840dacc5dbd6659e62fa6b45b070ac27ddcfc775b666" }, "owner_lane": "", "provenance": { diff --git a/native/boot/.crumb b/native/boot/.crumb index 2fc1939f..92acaef9 100644 --- a/native/boot/.crumb +++ b/native/boot/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-13T23:07:22Z", + "compiled_at": "2026-10-14T00:20:37Z", "compiler": "crumb-compile/1", - "digest": "sha256:441bb7a06c78208da659e10e8ff3c50998f4aac3fe8446bcc6259521d040b466", + "digest": "sha256:19d19008ffb4cfcd93c43202081a84ecd1e37d1c60b9d7c355fd8b9db4d3d77e", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 21, - "generated_at_commit": "53de55c5dd3485948cd34734caf0f646e28a68c4", - "source_tree": "sha256:db3871c89065883142387967d20b51a113fbc23931d452e7c860a15669d672e3" + "files": 22, + "generated_at_commit": "a3e9c23dfc5b0ed0f9701132904b28edac14b71f", + "source_tree": "sha256:c339d82fa75763e357dba604d74f6713303f4e671dac066d455130eb7d9558ac" }, "owner_lane": "", "provenance": { diff --git a/native/boot/efi_artifact.c b/native/boot/efi_artifact.c new file mode 100644 index 00000000..08f50697 --- /dev/null +++ b/native/boot/efi_artifact.c @@ -0,0 +1,68 @@ +/* efi_artifact.c -- read \EFI\AIENOS\ARTIFACT.BND from the boot volume before ExitBootServices + * (EL0 artifact qualification image, CK_ARTIFACT_CARD: the Raspberry Pi 5 image and its QEMU twin). + * Nothing is written. The file is a bundle of signed artifacts placed by the run tool + * (native/kernel/core/artifact_card.h); it is untrusted input, parsed strictly here and verified by the + * core loader later. Result in ck_acard_boot (stub and kernel are one image): ABSENT (no file: the loader + * reports no source), REFUSED (printed why), FOUND. Same pattern as efi_agentcmd.c. */ +#include "efi.h" +#include "../kernel/core/artifact_card.h" +#include "../kernel/arch/arch.h" +#include "../kernel/core/ck_internal.h" + +static void wipe_buf(void) +{ + volatile uint8_t *b = ck_acard_buf; + for (unsigned i = 0; i < sizeof ck_acard_buf; i++) + b[i] = 0; +} + +void ck_boot_artifact_card_find(EFI_HANDLE image, EFI_SYSTEM_TABLE *st) +{ + static const EFI_GUID li_guid = EFI_LOADED_IMAGE_PROTOCOL_GUID_INIT; + static const EFI_GUID fs_guid = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID_INIT; + static CHAR16 path[] = {'\\', 'E', 'F', 'I', '\\', 'A', 'I', 'E', 'N', 'O', 'S', '\\', + 'A', 'R', 'T', 'I', 'F', 'A', 'C', 'T', '.', 'B', 'N', 'D', 0}; + EFI_BOOT_SERVICES *bs = st->BootServices; + EFI_LOADED_IMAGE_PROTOCOL *li = 0; + EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *fs = 0; + EFI_FILE_PROTOCOL *root = 0, *f = 0; + ck_acard_boot.state = CK_ACARD_ABSENT; + ck_acard_boot.why = "no card artifact bundle (boot volume not readable)"; + if (bs->HandleProtocol(image, &li_guid, (void **)&li) != EFI_SUCCESS || !li || !li->DeviceHandle || + bs->HandleProtocol(li->DeviceHandle, &fs_guid, (void **)&fs) != EFI_SUCCESS || !fs || + fs->OpenVolume(fs, &root) != EFI_SUCCESS || !root) { + ck_puts("artifact_card: absent (boot volume not readable); no artifact candidates this boot\n"); + return; + } + if (root->Open(root, &f, path, EFI_FILE_MODE_READ, 0) != EFI_SUCCESS || !f) { + root->Close(root); + ck_acard_boot.why = "no card artifact bundle (file absent)"; + ck_puts("artifact_card: absent (no " CK_ACARD_PATH "); no artifact candidates this boot\n"); + return; + } + wipe_buf(); + uint64_t n = sizeof ck_acard_buf; /* one byte more than the format allows: a longer file is refused */ + EFI_STATUS s = f->Read(f, &n, ck_acard_buf); + f->Close(f); + root->Close(root); + ck_acard_boot.state = CK_ACARD_REFUSED; + ck_acard_boot.why = "card artifact bundle refused (read failed or size out of range)"; + if (s != EFI_SUCCESS || n < 1 || n > CK_ACARD_FILE_MAX) { + ck_printf("artifact_card: refused (read status=0x%llx bytes=%llu, want 12..%u)\n", (unsigned long long)s, + (unsigned long long)n, (unsigned)CK_ACARD_FILE_MAX); + wipe_buf(); + return; + } + const char *why = 0; + if (ck_acard_parse(ck_acard_buf, (size_t)n, &ck_acard_boot.set, &why)) { + ck_acard_boot.why = "card artifact bundle refused (malformed)"; + ck_printf("artifact_card: refused (%s)\n", why ? why : "malformed"); + wipe_buf(); + return; + } + ck_acard_boot.state = CK_ACARD_FOUND; + ck_acard_boot.why = 0; + ck_acard_boot.file_len = (uint32_t)n; + ck_printf("artifact_card: found a well-formed bundle (QUALIFICATION ONLY, TEST keys, %u entries, %u bytes)\n", + (unsigned)ck_acard_boot.set.count, (unsigned)n); +} diff --git a/native/boot/efi_main.c b/native/boot/efi_main.c index ebc2c446..b47b5e5b 100644 --- a/native/boot/efi_main.c +++ b/native/boot/efi_main.c @@ -47,6 +47,9 @@ void ck_boot_fact_req_find(EFI_HANDLE image, EFI_SYSTEM_TABLE *st); #ifdef CK_PI5_LIFECYCLE void ck_boot_agent_cmd_find(EFI_HANDLE image, EFI_SYSTEM_TABLE *st); #endif +#ifdef CK_ARTIFACT_CARD +void ck_boot_artifact_card_find(EFI_HANDLE image, EFI_SYSTEM_TABLE *st); +#endif #ifdef CK_KLOG void ck_boot_klog_find(EFI_HANDLE image, EFI_SYSTEM_TABLE *st); #endif @@ -154,6 +157,10 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *st) #ifdef CK_PI5_LIFECYCLE /* PI5-7 cut 2 qualification image: the lifecycle command script (efi_agentcmd.c). */ ck_boot_agent_cmd_find(image, st); +#endif +#ifdef CK_ARTIFACT_CARD + /* PI5-7 cut 3 qualification image: the card artifact bundle (efi_artifact.c). */ + ck_boot_artifact_card_find(image, st); #endif ck_puts("kernel_impl: c (native/kernel, Lane 18)\n"); vendor_print(st->FirmwareVendor); diff --git a/native/kernel/.crumb b/native/kernel/.crumb index f6faa607..f317f3a8 100644 --- a/native/kernel/.crumb +++ b/native/kernel/.crumb @@ -57,14 +57,14 @@ "purpose": "Directory native/kernel/artifact. Purpose not yet described by a human." }, { - "digest": "4838185961eedd4d2053c8d8a6804065d1f8f450461ce74a819d5f7d4d8988f1", - "last_commit": "15c19d4", + "digest": "cb321e8501900b217910e4f33f40364fda20d2fbd9e88db637ee2d1e63da7e58", + "last_commit": "e673bfb", "name": "core", "purpose": "Directory native/kernel/core. Purpose not yet described by a human." }, { "digest": "ebdd66c0966fba664f36dc167836b98d26ffae97f9502b4409e9c22da687b473", - "last_commit": "cb3bba7", + "last_commit": "9404c9e", "name": "dev", "purpose": "Directory native/kernel/dev. Purpose not yet described by a human." }, @@ -87,8 +87,8 @@ "purpose": "Directory native/kernel/svc. Purpose not yet described by a human." }, { - "digest": "e3169d29c0846819ae597b2674f496724638f1456c3c36d7f72d736240211262", - "last_commit": "cb3bba7", + "digest": "8e39b06bf4949cf9db10b8499b7cef56c9759b9692efc859575ce502df0a0c0a", + "last_commit": "e673bfb", "name": "tests", "purpose": "Directory native/kernel/tests. Purpose not yet described by a human." }, @@ -99,15 +99,15 @@ "purpose": "Hosted (Linux-built) checkers for the native kernel, run by `make -C native/kernel test`; nothin" } ], - "children_root": "sha256:4ec0cd6a5814361000abd7e7b1e07514febd2aec9df33e53b30edf786a04b7f3", - "compiled_at": "2026-10-13T23:37:04Z", + "children_root": "sha256:23334b23583f5a82d687244697b1a5209d255715ae916f28919240d056b0dcde", + "compiled_at": "2026-10-14T00:20:37Z", "compiler": "crumb-compile/1", - "digest": "sha256:a055397a8db7d75eb8eeeb0e1e105b53ddb0e93ba13f9d0bb265749377bfae0b", + "digest": "sha256:7df01cbf05b0e93aa9bbf47b2b862b110b001f9cce2283d181a91be5b3393507", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 376, - "generated_at_commit": "23c8bcd5490dd2ec9ded661ffefd5ecb5533dcec", - "source_tree": "sha256:7f1752f64e6c6c1c4f4f12c0c02af9f1759715949356149197250479556d0065" + "files": 380, + "generated_at_commit": "a3e9c23dfc5b0ed0f9701132904b28edac14b71f", + "source_tree": "sha256:0d465662b8f38d82c5e9ffa1a9c01212302da583b30b970986accb5f03004e13" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/Makefile b/native/kernel/Makefile index 87f0f62f..9174582c 100644 --- a/native/kernel/Makefile +++ b/native/kernel/Makefile @@ -307,6 +307,40 @@ $(error CK_PI5_LIFECYCLE needs CK_INFER_LIB=<libaienos_infer_kernel.a> (use "mak endif CK_EXTRA_CFLAGS += -DCK_PI5_LIFECYCLE=1 -DCK_INFER_DISK_ONLY=1 -DCK_INFER_RESIDENT=1 endif +# EL0 artifact qualification image (CK_ARTIFACT_CARD=1, "make pi5-artifact" for the Pi, PI5-7 cut 3, QUALIFICATION ONLY, TEST keys only): +# the plain core image (no Store stage, no NVMe) whose signed artifact candidates come from ONE card file, \EFI\AIENOS\ARTIFACT.BND +# (core/artifact_card.h, read by native/boot/efi_artifact.c), and which trusts the RFC 8032 TEST 1 public key only +# (CK_SEED0B_TEST_ANCHOR=1, forced by CK_PI5_ARTIFACT=1; the image prints "artifact_trust: ... TEST ONLY"). CK_PI5_ARTIFACT=1 is the Pi +# image (CK_PI5=1); CK_ARTIFACT_CARD=1 CK_SEED0B_TEST_ANCHOR=1 alone is its QEMU twin (scripts/qemu_ck_artifact_card_test.sh). Both +# refuse every other tier flag (so the other images refuse it too) and the "full" image (its Store stage owns the same hook), and each +# has its own OUT. No other image changes: the code is behind -DCK_ARTIFACT_CARD. +CK_ARTIFACT_CARD ?= +CK_PI5_ARTIFACT ?= +ifneq ($(strip $(CK_PI5_ARTIFACT)),) +ifneq ($(strip $(CK_PI5_ARTIFACT)),1) +$(error CK_PI5_ARTIFACT must be empty or 1) +endif +CK_ARTIFACT_CARD := 1 +CK_PI5 := 1 +CK_SEED0B_TEST_ANCHOR := 1 +OUT ?= $(REPO)/target/native-kernel-pi5-artifact +endif +ifneq ($(strip $(CK_ARTIFACT_CARD)),) +ifneq ($(strip $(CK_ARTIFACT_CARD)),1) +$(error CK_ARTIFACT_CARD must be empty or 1) +endif +ifeq ($(strip $(CK_SEED0B_TEST_ANCHOR)),) +$(error CK_ARTIFACT_CARD (card artifact bundle, QUALIFICATION ONLY) needs CK_SEED0B_TEST_ANCHOR=1: it only ever trusts the public TEST key) +endif +ifneq ($(strip $(CK_PI5_STORE)$(CK_PI5_INFER)$(CK_PI5_PCIE)$(CK_PI5_NET)$(CK_PI5_UNLOCK)$(CK_PI5_UNLOCK_CARD)$(CK_PI5_FACT)$(CK_PI5_AGENT)$(CK_PI5_LIFECYCLE)$(CK_SERVICE)$(CK_SERVICE_TEST_KEYS)$(CK_HARDWARE_STAGING)$(CK_TEST_FWCFG_ARTIFACTS)$(CK_INFER_LIB)),) +$(error CK_ARTIFACT_CARD / CK_PI5_ARTIFACT cannot be combined with CK_PI5_STORE, CK_PI5_INFER, CK_PI5_PCIE, CK_PI5_NET, CK_PI5_UNLOCK, CK_PI5_UNLOCK_CARD, CK_PI5_FACT, CK_PI5_AGENT, CK_PI5_LIFECYCLE, CK_SERVICE, CK_SERVICE_TEST_KEYS, CK_HARDWARE_STAGING, CK_TEST_FWCFG_ARTIFACTS or CK_INFER_LIB) +endif +ifneq ($(filter full,$(MAKECMDGOALS)),) +$(error CK_ARTIFACT_CARD / CK_PI5_ARTIFACT build the core image only: the "full" image's Store stage owns the artifact hook) +endif +OUT ?= $(REPO)/target/native-kernel-artifact-card +CK_EXTRA_CFLAGS += -DCK_ARTIFACT_CARD=1 +endif CK_PI5 ?= ifneq ($(strip $(CK_PI5)),) ifneq ($(strip $(CK_PI5)),1) @@ -848,6 +882,10 @@ ART_C := $(KDIR)/core/artifact_loader.c $(KDIR)/core/osc_admit.c $(KDIR)/core/os $(NATIVE)/sig/ed25519.c $(NATIVE)/sig/ct.c ART_INC := -I$(KDIR)/svc/compat -I$(KDIR)/artifact -I$(NATIVE)/sig -I$(NATIVE)/argus ART_C += $(OSH_TEST_C) +ifneq ($(strip $(CK_ARTIFACT_CARD)),) +ART_C += $(KDIR)/core/artifact_card.c $(KDIR)/core/artifact_card_stage.c +CORE_C += $(BOOT)/efi_artifact.c +endif CORE_C += $(ART_C) CORE_S := $(BOOT)/efi_entry.S $(KDIR)/arch/vectors.S $(KDIR)/arch/m3.S $(KDIR)/arch/smp_entry.S HDRS := $(wildcard $(KDIR)/include/*.h $(KDIR)/*/*.h $(BOOT)/*.h) @@ -1266,10 +1304,10 @@ $(FULL_EFI): $(FULL_ELF) HOST_SRCS := $(KDIR)/core/fmt.c $(KDIR)/core/acpi.c $(KDIR)/core/smmu.c $(KDIR)/mm/frames.c \ $(KDIR)/mm/pt.c $(KDIR)/mm/heap.c $(KDIR)/core/sched.c $(KDIR)/core/ipc.c $(KDIR)/core/entropy.c \ $(KDIR)/core/handoff_check.c $(KDIR)/core/fbcon.c $(KDIR)/core/acpi_dev.c $(KDIR)/core/lifecycle_fsm.c \ - $(KDIR)/core/line_rx.c $(KDIR)/core/klog.c $(KDIR)/core/klog_slot.c $(KDIR)/core/cpufeat.c $(KDIR)/core/unlock_req.c $(KDIR)/core/agent_cmd.c + $(KDIR)/core/line_rx.c $(KDIR)/core/klog.c $(KDIR)/core/klog_slot.c $(KDIR)/core/cpufeat.c $(KDIR)/core/unlock_req.c $(KDIR)/core/agent_cmd.c $(KDIR)/core/artifact_card.c TESTS := test_fmt test_frames test_pt test_acpi test_acpi_dev test_heap test_smmu test_sched test_ipc test_artifact test_osc_unit test_osc_launch test_osc_admit test_entropy test_handoff test_fbcon test_osh_op \ test_continuity_codec test_continuity_resolve test_continuity_commit test_continuity_recovery test_continuity_geometry \ - test_continuity_subject test_continuity_subject_provision test_lifecycle test_console_rx test_klog test_klog_slot test_pi5 test_pi5_marker test_pi5_rng test_cpufeat test_dma_window test_pi5_pcie test_pi5_net test_pi5_gem test_unlock_req test_context test_agent_cmd + test_continuity_subject test_continuity_subject_provision test_lifecycle test_console_rx test_klog test_klog_slot test_pi5 test_pi5_marker test_pi5_rng test_cpufeat test_dma_window test_pi5_pcie test_pi5_net test_pi5_gem test_unlock_req test_context test_agent_cmd test_artifact_card HCFLAGS := -std=gnu11 -O1 -g -Wall -Wextra -Werror -I$(KDIR)/core -I$(KDIR)/mm -I$(KDIR)/tests -I$(BOOT) SANFLAGS := -fsanitize=address,undefined -fno-sanitize-recover=all -fno-omit-frame-pointer @@ -1333,6 +1371,16 @@ agent-cmd-mutant: $(OUT)/host/test_agent_cmd_mutant @if $< > $<.log 2>&1; then cat $<.log; echo "test_agent_cmd mutant (any verb allowed): PASSED, test does not catch it"; exit 1; \ else grep -F "test_agent_cmd: FAIL" $<.log && echo "test_agent_cmd mutant (any verb allowed): FAILS as required"; fi +# PI5-7 cut 3 card artifact bundle parser (core/artifact_card.c): the mutant accepts bytes after the last entry (a second, unchecked +# payload could ride along); test_artifact_card must FAIL against it (red before green). Host only, never part of an image. +$(OUT)/host/test_artifact_card_mutant: $(KDIR)/tests/test_artifact_card.c $(KDIR)/core/artifact_card.c $(KDIR)/core/artifact_card.h $(KDIR)/tests/ck_test.h + @mkdir -p $(dir $@) + $(HOSTCC) $(HCFLAGS) -DCK_ACARD_MUTANT_TRAILING -o $@ $< $(KDIR)/core/artifact_card.c + +artifact-card-mutant: $(OUT)/host/test_artifact_card_mutant + @if $< > $<.log 2>&1; then cat $<.log; echo "test_artifact_card mutant (trailing bytes accepted): PASSED, test does not catch it"; exit 1; \ + else grep -F "test_artifact_card: FAIL" $<.log && echo "test_artifact_card mutant (trailing bytes accepted): FAILS as required"; fi + # TEST-ONLY mutant of core/handoff_check.c (reserved0 check removed): the # handoff test must FAIL against it, so "make test" fails if the test stops # catching the mutation. Host only (handoff_check.c refuses it freestanding @@ -1411,8 +1459,8 @@ smmu-l2-mutants: $(OUT)/host/test_smmu else echo "mutant flag refused under CK_HARDWARE_STAGING"; fi; \ if [ $$fail = 0 ]; then echo "CK_SMMU_L2_MUTANTS: PASS"; else echo "CK_SMMU_L2_MUTANTS: FAIL"; exit 1; fi -test: $(addprefix $(OUT)/host/,$(TESTS)) handoff-mutant acpi-dev-mutant iort-mutants smmu-l2-mutants osh-op-mutant context-mutant agent-cmd-mutant test-continuity-subject-restart gsp-fw-inspect-test gsp-cot-test gsp-bindata-test gsp-bootargs-test gsp-rpc-test slot-test slot-free package-test slot-loader-check - @fail=0; for t in $(filter-out handoff-mutant acpi-dev-mutant iort-mutants smmu-l2-mutants osh-op-mutant context-mutant agent-cmd-mutant test-continuity-subject-restart gsp-fw-inspect-test gsp-cot-test gsp-bindata-test gsp-bootargs-test gsp-rpc-test slot-test slot-free package-test slot-loader-check,$^); do $$t || fail=1; done; \ +test: $(addprefix $(OUT)/host/,$(TESTS)) handoff-mutant acpi-dev-mutant iort-mutants smmu-l2-mutants osh-op-mutant context-mutant agent-cmd-mutant artifact-card-mutant test-continuity-subject-restart gsp-fw-inspect-test gsp-cot-test gsp-bindata-test gsp-bootargs-test gsp-rpc-test slot-test slot-free package-test slot-loader-check + @fail=0; for t in $(filter-out handoff-mutant acpi-dev-mutant iort-mutants smmu-l2-mutants osh-op-mutant context-mutant agent-cmd-mutant artifact-card-mutant test-continuity-subject-restart gsp-fw-inspect-test gsp-cot-test gsp-bindata-test gsp-bootargs-test gsp-rpc-test slot-test slot-free package-test slot-loader-check,$^); do $$t || fail=1; done; \ if [ $$fail = 0 ]; then echo "CK_CORE_HOST: PASS"; else echo "CK_CORE_HOST: FAIL"; exit 1; fi sanitize: $(addprefix $(OUT)/host-san/,$(TESTS)) @@ -2064,6 +2112,9 @@ pi5-lifecycle: CARGO_TARGET_DIR=$(REPO)/target/infer-kernel cargo build -q --release --target aarch64-unknown-none --manifest-path $(REPO)/crates/aienos-infer-kernel/Cargo.toml $(MAKE) CK_PI5_UNLOCK=1 CK_PI5_UNLOCK_CARD=1 CK_PI5_LIFECYCLE=1 CK_INFER_LIB=$(PI5_INFER_LIB) full +pi5-artifact: + $(MAKE) CK_PI5_ARTIFACT=1 all + pi5: $(MAKE) CK_PI5=1 all @@ -2122,7 +2173,7 @@ $(OUT)/host-san/test_pi5_rng: $(KDIR)/tests/test_pi5_rng.c $(PI5_RNG_SRCS) $(KDI FORCE: .PHONY: uefi-vars slot-loader slot-loader-check pi5-diag -.PHONY: all full pi5 pi5-store pi5-infer pi5-unlock pi5-unlock-card pi5-fact pi5-agent pi5-lifecycle test sanitize context-mutant agent-cmd-mutant cortex-image 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 +.PHONY: all full pi5 pi5-store pi5-infer pi5-unlock pi5-unlock-card pi5-fact pi5-agent pi5-lifecycle pi5-artifact artifact-card-mutant test sanitize context-mutant agent-cmd-mutant cortex-image 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 # AIENOS-PI5 step 3 marker + Pi card GPT test (hosted; a file stands in for the card, QEMU cannot model the Pi SD host). PI5_MARKER_SRCS := $(KDIR)/core/pi5_marker.c $(KDIR)/dev/disk_part.c $(NATIVE)/disk/disk.c $(NATIVE)/disk/disk_file.c \ diff --git a/native/kernel/core/.crumb b/native/kernel/core/.crumb index 66724f9b..251350d6 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-13T23:07:22Z", + "compiled_at": "2026-10-14T00:20:37Z", "compiler": "crumb-compile/1", - "digest": "sha256:4838185961eedd4d2053c8d8a6804065d1f8f450461ce74a819d5f7d4d8988f1", + "digest": "sha256:cb321e8501900b217910e4f33f40364fda20d2fbd9e88db637ee2d1e63da7e58", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 66, - "generated_at_commit": "53de55c5dd3485948cd34734caf0f646e28a68c4", - "source_tree": "sha256:0c79bbf69968edeb45698a019201c984931ae7b4ea457c0237c8fcca6a70a050" + "files": 69, + "generated_at_commit": "a3e9c23dfc5b0ed0f9701132904b28edac14b71f", + "source_tree": "sha256:c66ee9b515ec33e09871eb7960d1139b13d65de7a7017dfdfbac193c2562a883" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/core/artifact_card.c b/native/kernel/core/artifact_card.c new file mode 100644 index 00000000..9a5f8553 --- /dev/null +++ b/native/kernel/core/artifact_card.c @@ -0,0 +1,100 @@ +/* artifact_card.c -- see artifact_card.h. No kernel calls, no libc (host-tested by tests/test_artifact_card.c). */ +#include "artifact_card.h" + +struct ck_acard_boot ck_acard_boot; +uint8_t ck_acard_buf[CK_ACARD_FILE_MAX + 1u] __attribute__((aligned(64))); + +static void zero(struct ck_acard *o) +{ + unsigned char *p = (unsigned char *)o; + for (size_t i = 0; i < sizeof *o; i++) p[i] = 0; +} + +static uint32_t rd16(const uint8_t *p) { return (uint32_t)p[0] | (uint32_t)p[1] << 8; } +static uint32_t rd32(const uint8_t *p) { return rd16(p) | rd16(p + 2) << 16; } + +int ck_acard_parse(const uint8_t *buf, size_t n, struct ck_acard *out, const char **why) +{ + static const char magic[8] = {'A', 'I', 'E', 'N', 'B', 'N', 'D', 0}; + const char *w = 0; + size_t at = 12, i; + uint32_t count = 0, c; + if (out) zero(out); + if (!buf || !out) { + w = "no bundle"; + goto fail; + } + if (n < 12 || n > CK_ACARD_FILE_MAX) { + w = "file size must be 12..131072 bytes"; + goto fail; + } + for (i = 0; i < 8; i++) + if (buf[i] != (uint8_t)magic[i]) { + w = "bad magic (want AIENBND)"; + goto fail; + } + count = rd32(buf + 8); + if (count < 1 || count > CK_ACARD_MAX_ENTRIES) { + w = "entry count must be 1..16"; + goto fail; + } + for (c = 0; c < count; c++) { + uint32_t nl, bl; + if (n - at < 2) { + w = "truncated entry header"; + goto fail; + } + nl = rd16(buf + at); + at += 2; + if (nl < 1 || nl > CK_ACARD_NAME_MAX) { + w = "name length must be 1..32"; + goto fail; + } + if (n - at < (size_t)nl + 4u) { + w = "truncated entry"; + goto fail; + } + for (i = 0; i < nl; i++) + if (buf[at + i] < 0x21 || buf[at + i] > 0x7e) { + w = "name byte is not printable ASCII"; + goto fail; + } + for (uint32_t k = 0; k < c; k++) { + size_t j = 0; + while (j < nl && out->e[k].name[j] == (char)buf[at + j]) j++; + if (j == nl && out->e[k].name[nl] == 0) { + w = "duplicate name"; + goto fail; + } + } + for (i = 0; i < nl; i++) out->e[c].name[i] = (char)buf[at + i]; + out->e[c].name[nl] = 0; + at += nl; + bl = rd32(buf + at); + at += 4; + if (bl < 1 || bl > CK_ACARD_ENTRY_MAX) { + w = "artifact length must be 1..655360"; + goto fail; + } + if (n - at < bl) { + w = "artifact bytes run past the end of the file"; + goto fail; + } + out->e[c].len = bl; + out->e[c].bytes = buf + at; + at += bl; + } +#ifndef CK_ACARD_MUTANT_TRAILING + if (at != n) { + w = "bytes after the last entry"; + goto fail; + } +#endif + out->count = count; + if (why) *why = 0; + return 0; +fail: + if (out) zero(out); + if (why) *why = w; + return -1; +} diff --git a/native/kernel/core/artifact_card.h b/native/kernel/core/artifact_card.h new file mode 100644 index 00000000..090355a1 --- /dev/null +++ b/native/kernel/core/artifact_card.h @@ -0,0 +1,57 @@ +/* artifact_card.h -- the card artifact bundle of the Raspberry Pi 5 EL0 artifact qualification image + * (PI5-7 cut 3, build flag CK_ARTIFACT_CARD, "make pi5-artifact"; the same code boots in QEMU for the + * red-before-green run, see scripts/qemu_ck_artifact_card_test.sh). + * + * QUALIFICATION ONLY, TEST keys only. The Pi image has no Store stage and no NVMe, so the signed artifacts + * reach the loader as ONE file on the card's EFI partition, \EFI\AIENOS\ARTIFACT.BND, placed by the run + * tool before the run and deleted after it. The UEFI stub (native/boot/efi_artifact.c) reads it before + * ExitBootServices into ck_acard_buf; core/artifact_card_stage.c hands the entries to the unchanged core + * loader (core/artifact_loader.c) through the same hook the boot-disk Store uses (ck_stage_disk_artifacts). + * The loader then runs every check it always runs (format, TEST-key signature, digest, admission, W^X, + * EL0 containment, receipt): this file proves nothing about who wrote a byte, its bytes are untrusted. + * + * File layout: the existing bundle of tools/ck_artifact_tool.c (command "bundle OUT FILE...", the layout + * the QEMU gates already use), unchanged, all integers little endian: + * "AIENBND\0" u32 count (1..CK_ACARD_MAX_ENTRIES) + * count x { u16 name_len (1..32), name (printable ASCII 0x21..0x7e, unique in the file), + * u32 byte_len (1..CK_ACARD_ENTRY_MAX), byte_len bytes } + * and nothing after the last entry. The whole file is at most CK_ACARD_FILE_MAX bytes. Any deviation + * refuses the whole file: no entry of a refused file is offered to the loader. */ +#ifndef AIENOS_CK_ARTIFACT_CARD_H +#define AIENOS_CK_ARTIFACT_CARD_H +#include <stddef.h> +#include <stdint.h> + +#define CK_ACARD_PATH "\\EFI\\AIENOS\\ARTIFACT.BND" +#define CK_ACARD_FILE_MAX (128u * 1024u) +#define CK_ACARD_MAX_ENTRIES 16u +#define CK_ACARD_ENTRY_MAX (160u * 4096u) /* = the loader's MAX_BATCH pages */ +#define CK_ACARD_NAME_MAX 32u + +struct ck_acard_entry { + char name[CK_ACARD_NAME_MAX + 1]; + uint32_t len; + const uint8_t *bytes; /* inside the buffer given to ck_acard_parse */ +}; + +struct ck_acard { + uint32_t count; + struct ck_acard_entry e[CK_ACARD_MAX_ENTRIES]; +}; + +/* 0 = well formed and *out filled (entries point into buf); else -1, *out zeroed and *why names the first + * failed check. */ +int ck_acard_parse(const uint8_t *buf, size_t n, struct ck_acard *out, const char **why); + +enum { CK_ACARD_NONE = 0, CK_ACARD_ABSENT = 1, CK_ACARD_REFUSED = 2, CK_ACARD_FOUND = 3 }; + +/* What the UEFI stub found (the stub and the kernel are one image). */ +struct ck_acard_boot { + int state; /* CK_ACARD_* */ + const char *why; /* ABSENT / REFUSED: what failed */ + uint32_t file_len; /* bytes read, FOUND only */ + struct ck_acard set; /* FOUND only */ +}; +extern struct ck_acard_boot ck_acard_boot; +extern uint8_t ck_acard_buf[CK_ACARD_FILE_MAX + 1u]; +#endif diff --git a/native/kernel/core/artifact_card_stage.c b/native/kernel/core/artifact_card_stage.c new file mode 100644 index 00000000..67bde6ae --- /dev/null +++ b/native/kernel/core/artifact_card_stage.c @@ -0,0 +1,69 @@ +/* artifact_card_stage.c -- offers the card artifact bundle (core/artifact_card.h) to the core loader through + * the boot-disk hook (ck_stage_disk_artifacts, ck.h), in the images built with CK_ARTIFACT_CARD only + * (QUALIFICATION ONLY, TEST keys). Such an image links no Store stage, so the hook has exactly one + * definition. The bytes stay UNTRUSTED: core/artifact_loader.c verifies every candidate itself. */ +#include "ck_internal.h" +#include "artifact_card.h" +#include "sha256.h" + +static struct ck_disk_artifact offered[CK_ACARD_MAX_ENTRIES]; + +static void hex(char *o, const uint8_t *b, size_t n) +{ + static const char d[] = "0123456789abcdef"; + for (size_t i = 0; i < n; i++) { + o[2 * i] = d[b[i] >> 4]; + o[2 * i + 1] = d[b[i] & 15]; + } + o[2 * n] = 0; +} + +int ck_stage_disk_artifacts(struct ck_disk_artifacts *out) +{ + static int announced; + if (!out) + return -1; + memset(out, 0, sizeof *out); + if (ck_acard_boot.state == CK_ACARD_FOUND) { + uint8_t dg[32]; + char h[65]; + for (uint32_t i = 0; i < ck_acard_boot.set.count; i++) { + offered[i].name = ck_acard_boot.set.e[i].name; + offered[i].bytes = ck_acard_boot.set.e[i].bytes; + offered[i].len = ck_acard_boot.set.e[i].len; + offered[i].state = CK_DISK_ART_OK; + } + out->available = 1; + out->why = "ok"; + out->count = ck_acard_boot.set.count; + out->a = offered; + if (!announced) { + sha256_hash(ck_acard_buf, ck_acard_boot.file_len, dg); + hex(h, dg, 32); + ck_printf("artifact_card: %s bytes=%u entries=%u sha256=%s (QUALIFICATION ONLY, TEST keys; untrusted until verified)\n", + CK_ACARD_PATH, ck_acard_boot.file_len, ck_acard_boot.set.count, h); + for (uint32_t i = 0; i < ck_acard_boot.set.count; i++) { + sha256_hash(ck_acard_boot.set.e[i].bytes, ck_acard_boot.set.e[i].len, dg); + hex(h, dg, 32); + ck_printf("artifact_card: %s bytes=%u sha256=%s\n", ck_acard_boot.set.e[i].name, + ck_acard_boot.set.e[i].len, h); + } + announced = 1; + } + return 0; + } + out->why = ck_acard_boot.why ? ck_acard_boot.why : "no card artifact bundle"; + return 0; +} + +void ck_stage_disk_artifacts_free(void) +{ + volatile uint8_t *b = ck_acard_buf; + if (ck_acard_boot.state == CK_ACARD_FOUND) + ck_printf("artifact_card: released bundle bytes=%u entries=%u\n", ck_acard_boot.file_len, + ck_acard_boot.set.count); + for (size_t i = 0; i < sizeof ck_acard_buf; i++) + b[i] = 0; + memset(offered, 0, sizeof offered); + memset(&ck_acard_boot, 0, sizeof ck_acard_boot); +} diff --git a/native/kernel/core/artifact_loader.c b/native/kernel/core/artifact_loader.c index de9aa8b7..232a1c87 100644 --- a/native/kernel/core/artifact_loader.c +++ b/native/kernel/core/artifact_loader.c @@ -925,6 +925,15 @@ static const char *classify_fault(const struct report *r) return "exec-nx"; if (ec == 0x20 && status == 1) return "exec-unmapped"; +#ifdef CK_ARTIFACT_CARD + /* Arm ARM (DDI 0487) ESR_ELx.EC: 0x24 data abort from a lower exception level (bit 6 = WnR, write not read); + * 0x18 trapped MSR/MRS/system instruction; 0x00 unknown reason (an UNDEFINED instruction). Only the card + * qualification image names these: every other image keeps the two-name set above and "other". */ + if (ec == 0x24 && !WITHIN(r->code_base, r->code_end) && !in_ds) + return (esr & (1u << 6)) ? "outside-write" : "outside-read"; + if (ec == 0x18 || ec == 0x00) + return "privileged-insn"; +#endif #undef WITHIN return "other"; } @@ -1114,6 +1123,19 @@ static void finish_candidate(const char *name) else run_rejected++; print_candidate(name, &rep); +#ifdef CK_ARTIFACT_CARD + if (rep.admitted && rep.out.status == ST_FAULT) { + /* FAR_EL1 is architecturally defined only for instruction (0x20) and data (0x24) aborts from EL0. */ + uint64_t fec = (rep.out.esr >> 26) & 0x3f; + ck_printf("artifact_fault: %s class=%s esr=0x%llx ec=0x%llx ", name, classify_fault(&rep), + (unsigned long long)rep.out.esr, (unsigned long long)fec); + if (fec == 0x20 || fec == 0x24) + ck_printf("far=0x%llx ", (unsigned long long)rep.out.far); + else + ck_puts("far=n/a "); + ck_printf("elr=0x%llx contained=yes\n", (unsigned long long)rep.out.elr); + } +#endif print_grants(name, &rep); print_receipt(name, &rep); } @@ -1135,10 +1157,16 @@ static uint32_t disk_source(void) count = MAX_CANDIDATES; if (why) ck_printf("artifact_source: none (%s)\n", why); +#ifdef CK_ARTIFACT_CARD + else + ck_printf("artifact_source: card_file candidates=%u " + "(read from the card by the UEFI stub; bytes untrusted until verified)\n", count); +#else else ck_printf("artifact_source: nvme_store generation=%llu candidates=%u " "(read by the store stage; bytes untrusted until verified)\n", (unsigned long long)da.generation, count); +#endif source_preamble(count); for (uint32_t c = 0; c < count; c++) { const struct ck_disk_artifact *a = &da.a[c]; diff --git a/native/kernel/tests/.crumb b/native/kernel/tests/.crumb index 1b8b4d88..a2e359ff 100644 --- a/native/kernel/tests/.crumb +++ b/native/kernel/tests/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-13T23:37:04Z", + "compiled_at": "2026-10-14T00:20:37Z", "compiler": "crumb-compile/1", - "digest": "sha256:e3169d29c0846819ae597b2674f496724638f1456c3c36d7f72d736240211262", + "digest": "sha256:8e39b06bf4949cf9db10b8499b7cef56c9759b9692efc859575ce502df0a0c0a", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 164, - "generated_at_commit": "23c8bcd5490dd2ec9ded661ffefd5ecb5533dcec", - "source_tree": "sha256:a97fb66aea5aeb8b78d181e3220140dba721bc386f66283124e88ca1ebc1bfcd" + "files": 165, + "generated_at_commit": "a3e9c23dfc5b0ed0f9701132904b28edac14b71f", + "source_tree": "sha256:8a193e74853836c8f0d1d91b673225a9775581faf6f219065a41cfa41518a19b" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/tests/test_artifact_card.c b/native/kernel/tests/test_artifact_card.c new file mode 100644 index 00000000..eaa423fa --- /dev/null +++ b/native/kernel/tests/test_artifact_card.c @@ -0,0 +1,151 @@ +/* test_artifact_card.c -- core/artifact_card.c: the card artifact bundle of the EL0 artifact qualification image + * (CK_ARTIFACT_CARD, PI5-7 cut 3). The parser is strict (magic, count, name bytes, uniqueness, lengths, exact + * end of file) and a refused file leaves nothing behind for the loader. The layout is the one + * tools/ck_artifact_tool.c "bundle" writes: "AIENBND\0", u32 count, count x {u16 name_len, name, u32 len, bytes}. */ +#include <string.h> +#include "ck_test.h" +#include "artifact_card.h" + +static size_t put(uint8_t *b, size_t at, const char *name, uint32_t len, uint8_t fill) +{ + size_t nl = strlen(name); + b[at] = (uint8_t)nl; + b[at + 1] = (uint8_t)(nl >> 8); + memcpy(b + at + 2, name, nl); + at += 2 + nl; + b[at] = (uint8_t)len; + b[at + 1] = (uint8_t)(len >> 8); + b[at + 2] = (uint8_t)(len >> 16); + b[at + 3] = (uint8_t)(len >> 24); + memset(b + at + 4, fill, len); + return at + 4 + len; +} + +static size_t head(uint8_t *b, uint32_t count) +{ + memset(b, 0, 12); + memcpy(b, "AIENBND", 8); + b[8] = (uint8_t)count; + b[9] = (uint8_t)(count >> 8); + return 12; +} + +static int refused(const uint8_t *b, size_t n, const char *want) +{ + struct ck_acard o; + const char *why = 0; + int rc = ck_acard_parse(b, n, &o, &why); + int clean = o.count == 0 && o.e[0].name[0] == 0 && o.e[0].bytes == 0 && o.e[0].len == 0; + return rc != 0 && why && strstr(why, want) != 0 && clean; +} + +int main(void) +{ + static uint8_t b[CK_ACARD_FILE_MAX + 64]; + struct ck_acard o; + const char *why = (const char *)1; + size_t n; + + /* a well formed two-entry bundle */ + n = head(b, 2); + n = put(b, n, "P25EXEC.AIEN", 100, 0xa1); + n = put(b, n, "P25TAMP.AIEN", 7, 0xb2); + CHECK(ck_acard_parse(b, n, &o, &why) == 0); + CHECK(why == 0 && o.count == 2); + CHECK(strcmp(o.e[0].name, "P25EXEC.AIEN") == 0 && o.e[0].len == 100 && o.e[0].bytes[0] == 0xa1 && o.e[0].bytes[99] == 0xa1); + CHECK(strcmp(o.e[1].name, "P25TAMP.AIEN") == 0 && o.e[1].len == 7 && o.e[1].bytes == b + (n - 7)); + /* entry bytes are offered in place, never copied or reordered */ + CHECK(o.e[0].bytes + 100 + 2 + 12 + 4 == o.e[1].bytes); + + /* one-byte exact-end rule: a trailing byte is refused */ + b[n] = 0; + CHECK(refused(b, n + 1, "bytes after the last entry")); + /* a missing last byte is refused */ + CHECK(refused(b, n - 1, "past the end")); + + /* header */ + n = head(b, 1); + n = put(b, n, "A", 4, 1); + CHECK(ck_acard_parse(b, n, &o, &why) == 0); + CHECK(refused(b, 11, "file size")); + CHECK(refused(b, 0, "file size")); + CHECK(ck_acard_parse(0, 12, &o, &why) != 0); + CHECK(ck_acard_parse(b, n, 0, &why) != 0); + b[0] = 'X'; + CHECK(refused(b, n, "bad magic")); + b[0] = 'A'; + b[7] = 1; /* the NUL after AIENBND */ + CHECK(refused(b, n, "bad magic")); + b[7] = 0; + b[8] = 0; + CHECK(refused(b, n, "entry count")); + b[8] = 17; + CHECK(refused(b, n, "entry count")); + b[8] = 2; /* promises a second entry that is not there */ + CHECK(refused(b, n, "truncated")); + b[8] = 1; + b[11] = 1; /* count above 16 through the high bytes */ + CHECK(refused(b, n, "entry count")); + b[11] = 0; + + /* names */ + n = head(b, 1); + n = put(b, n, "", 4, 1); + CHECK(refused(b, n, "name length")); + n = head(b, 1); + n = put(b, n, "123456789012345678901234567890123", 4, 1); /* 33 */ + CHECK(refused(b, n, "name length")); + n = head(b, 1); + n = put(b, n, "123456789012345678901234567890AB", 4, 1); /* 32 is fine */ + CHECK(ck_acard_parse(b, n, &o, &why) == 0 && strlen(o.e[0].name) == 32); + n = head(b, 1); + n = put(b, n, "A B", 4, 1); + CHECK(refused(b, n, "printable")); + n = head(b, 1); + n = put(b, n, "A\x7f", 4, 1); + CHECK(refused(b, n, "printable")); + n = head(b, 2); + n = put(b, n, "SAME", 4, 1); + n = put(b, n, "SAME", 5, 2); + CHECK(refused(b, n, "duplicate")); + n = head(b, 2); + n = put(b, n, "SAME", 4, 1); + n = put(b, n, "SAMEX", 5, 2); /* a name that only starts like an earlier one is not a duplicate */ + CHECK(ck_acard_parse(b, n, &o, &why) == 0 && o.count == 2); + + /* lengths */ + n = head(b, 1); + n = put(b, n, "A", 1, 9); + CHECK(ck_acard_parse(b, n, &o, &why) == 0 && o.e[0].len == 1); + n = head(b, 1); + n = put(b, n, "A", 0, 9); + CHECK(refused(b, n, "artifact length")); + n = head(b, 1); + n = put(b, n, "A", 4, 9); + b[2 + 12 + 1] = 0xff; + b[2 + 12 + 2] = 0xff; + b[2 + 12 + 3] = 0xff; + b[2 + 12 + 4] = 0xff; /* length 0xffffffff */ + CHECK(refused(b, n, "artifact length")); + n = head(b, 1); + n = put(b, n, "A", 40, 9); + b[2 + 12 + 1] = 41; /* promises one byte more than the file holds */ + CHECK(refused(b, n, "past the end")); + + /* limits: 16 entries pass, a file of exactly the maximum size passes, one byte more is refused */ + n = head(b, 16); + for (int i = 0; i < 16; i++) { + char nm[4] = {'E', (char)('A' + i), 0, 0}; + n = put(b, n, nm, 3, (uint8_t)i); + } + CHECK(ck_acard_parse(b, n, &o, &why) == 0 && o.count == 16 && strcmp(o.e[15].name, "EP") == 0); + n = head(b, 1); + n = put(b, n, "BIG", CK_ACARD_FILE_MAX - 12 - 2 - 3 - 4, 5); + CHECK(n == CK_ACARD_FILE_MAX); + CHECK(ck_acard_parse(b, n, &o, &why) == 0 && o.e[0].len == CK_ACARD_FILE_MAX - 21); + n = head(b, 1); + n = put(b, n, "BIG", CK_ACARD_FILE_MAX - 12 - 2 - 3 - 4 + 1, 5); + CHECK(refused(b, n, "file size")); + + return ck_t_verdict("test_artifact_card"); +} diff --git a/scripts/.crumb b/scripts/.crumb index 4588979a..566e92d5 100644 --- a/scripts/.crumb +++ b/scripts/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-13T23:37:04Z", + "compiled_at": "2026-10-14T00:20:37Z", "compiler": "crumb-compile/1", - "digest": "sha256:48c4fa69e56fcade3e5fa0d959501d89269856026f10eec71fe9818e6ca9a9de", + "digest": "sha256:f573c48fba3478c69f1daac51db9427a959b611059ca020cd5eaa8c94685d883", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 96, - "generated_at_commit": "23c8bcd5490dd2ec9ded661ffefd5ecb5533dcec", - "source_tree": "sha256:4af4194f1f4a23a3ab45707c3407c3cb00b5311d33c95f530e80d90731456dc0" + "files": 98, + "generated_at_commit": "a3e9c23dfc5b0ed0f9701132904b28edac14b71f", + "source_tree": "sha256:84d3e36a84eac5bead0c5753a89a09d07e27a38dc2ea79ab5e9e91c8de1ec878" }, "owner_lane": "", "provenance": { diff --git a/scripts/ck_pi5_build_check.sh b/scripts/ck_pi5_build_check.sh index a44938b4..7d5a8b76 100755 --- a/scripts/ck_pi5_build_check.sh +++ b/scripts/ck_pi5_build_check.sh @@ -231,4 +231,33 @@ for tier in CK_PI5_INFER=1 CK_PI5_PCIE=1 CK_PI5_FACT=1 CK_PI5_AGENT=1; do if make -n -C "${root}/native/kernel" ${tier} CK_PI5_LIFECYCLE=1 CK_PI5_UNLOCK=1 CK_PI5_UNLOCK_CARD=1 CK_INFER_LIB=/x/l.a full >/dev/null 2>&1; then echo "FAIL Makefile accepts ${tier} with CK_PI5_LIFECYCLE=1"; fail=1; fi done test -s "${root}/target/native-kernel-pi5-unlock-card-lifecycle/full-pi5-unlock-card-lifecycle/BOOTAA64.EFI" || { echo "FAIL no pi5-lifecycle BOOTAA64.EFI"; fail=1; } +# PI5-7 cut 3: the EL0 artifact qualification image (make pi5-artifact): the plain Pi core image whose candidates come from the card +# bundle, trusting the public TEST key only. Only this image (and its QEMU twin) defines the card reader. +make -C "${root}/native/kernel" pi5-artifact >/dev/null +pa="${root}/target/native-kernel-pi5-artifact/aienos-ck.elf" +for s in ck_boot_artifact_card_find ck_acard_parse ck_acard_boot ck_acard_buf ck_stage_disk_artifacts ck_pi5_start ck_cpufeat_decode; do + if defined "${pa}" "${s}"; then echo "PASS pi5-artifact image defines ${s}"; else echo "FAIL pi5-artifact image lacks ${s}"; fail=1; fi +done +for s in ck_boot_artifact_card_find ck_acard_parse ck_acard_boot ck_acard_buf; do + for other in "${ul}" "${ua}" "${uf}" "${uc}" "${uo}" "${ps}" "${pi5}" "${pinf}" "${def}"; do + if defined "${other}" "${s}"; then echo "FAIL ${other} defines ${s}"; fail=1; fi + done +done +echo "PASS no other Pi image nor the default image defines the card artifact reader" +for s in ck_stage_store ck_store_test_keys ck_store_pi5_unlock_run ck_boot_unlock_req_find ck_lifecycle_run fw_dma_read fwcfg_from_dsdt; do + if defined "${pa}" "${s}"; then echo "FAIL pi5-artifact image defines ${s}"; fail=1; else echo "PASS pi5-artifact image has no ${s}"; fi +done +pa_strings="$(strings -a "${pa}")" +if grep -q "artifact_trust: seed0b-test qualification build" <<<"${pa_strings}" && grep -q "SEED-0B-PI5" <<<"${pa_strings}"; then echo "PASS pi5-artifact image carries the TEST ONLY trust label and the SEED-0B-PI5 tier"; else echo "FAIL pi5-artifact image lacks the TEST ONLY label or tier"; fail=1; fi +if grep -qE "opt/aienos/artifacts|fw_cfg" <<<"${pa_strings}"; then echo "FAIL pi5-artifact image carries fw_cfg artifact code"; fail=1; else echo "PASS pi5-artifact image has no fw_cfg artifact code"; fi +if make -n -C "${root}/native/kernel" CK_PI5_ARTIFACT=1 all >/dev/null 2>&1; then echo "PASS Makefile accepts CK_PI5_ARTIFACT=1 (positive control)"; else echo "FAIL Makefile refuses CK_PI5_ARTIFACT=1"; fail=1; fi +for combo in "CK_ARTIFACT_CARD=1" "CK_PI5_ARTIFACT=2" "CK_PI5_ARTIFACT=1 CK_SEED0B_TEST_ANCHOR=" "CK_PI5_ARTIFACT=1 CK_HARDWARE_STAGING=1" "CK_PI5_ARTIFACT=1 CK_TEST_FWCFG_ARTIFACTS=1" "CK_PI5_ARTIFACT=1 CK_SERVICE=1" "CK_PI5_ARTIFACT=1 CK_INFER_LIB=/x/l.a" "CK_PI5_ARTIFACT=1 full"; do + # shellcheck disable=SC2086 + if make -n -C "${root}/native/kernel" ${combo} >/dev/null 2>&1; then echo "FAIL Makefile accepts ${combo}"; fail=1; else echo "PASS Makefile refuses ${combo}"; fi +done +for other in CK_PI5_STORE=1 CK_PI5_INFER=1 CK_PI5_PCIE=1 CK_PI5_NET=1 CK_PI5_UNLOCK=1 CK_PI5_FACT=1 CK_PI5_AGENT=1 CK_PI5_LIFECYCLE=1; do + # shellcheck disable=SC2086 + if make -n -C "${root}/native/kernel" ${other} CK_PI5_ARTIFACT=1 all >/dev/null 2>&1; then echo "FAIL Makefile accepts ${other} with CK_PI5_ARTIFACT=1"; fail=1; else echo "PASS Makefile refuses ${other} with CK_PI5_ARTIFACT=1"; fi +done +test -s "${root}/target/native-kernel-pi5-artifact/BOOTAA64.EFI" || { echo "FAIL no pi5-artifact BOOTAA64.EFI"; fail=1; } if [[ ${fail} == 0 ]]; then echo "CK_PI5_BUILD: PASS"; else echo "CK_PI5_BUILD: FAIL"; exit 1; fi diff --git a/scripts/pi5_run_artifact.sh b/scripts/pi5_run_artifact.sh new file mode 100755 index 00000000..50891055 --- /dev/null +++ b/scripts/pi5_run_artifact.sh @@ -0,0 +1,264 @@ +#!/usr/bin/env bash +# pi5-run-artifact.sh (pi5-run.sh plus ARTIFACT_BND=<bundle file>, PI5-7 cut 3) -- one remote, one-shot AIENOS test run on the hub Raspberry Pi 5. +# +# [KLOG=1] [UNLOCK_REQ=<512-byte request file>] [MODEL_MAP=<4096-byte MODEL.MAP>] pi5-run.sh <EFI file> <tag> [wait-file] +# +# 1. Puts <EFI file> on the AIENOS test microSD (mmcblk0p1, label AIENOSPI5) as +# EFI/BOOT/BOOTAA64.EFI and removes the old report, so a report after the run +# proves this run wrote it. +# 2. Makes sure the Pi 5 UEFI firmware from the card is also on the USB stick's +# boot partition under aienos/ (the Pi bootloader reads config from the stick). +# 3. Appends a [tryboot]-only block to the stick's config.txt (backup kept on the +# hub and here) and reboots with reboot '0 tryboot'. Raspberry Pi docs +# (bootflow-eeprom.adoc): the flag "is cleared before starting the firmware, a +# crash or reset will cause the original config.txt file to be loaded on the +# next reboot". Normal boots never read the block. +# 4. Waits for the hub to come back on normal Linux (ping every 30 s, ssh only +# after ping answers; hub stick is fragile: one ssh at a time, no fast retries). +# 5. Removes the block (restores the backup, checks it), copies the card's +# EFI/AIENOS tree to ~/workspace/pi5-runs/<tag>/, unmounts. +# If the hub is not back after 15 min: notify Drake (power-cycle the Pi; it comes +# back on normal Linux because the flag is already cleared). +set -euo pipefail +efi="${1:?EFI file}"; tag="${2:?tag}" +hub=hub +runs="$HOME/workspace/pi5-runs/${tag}" +mkdir -p "${runs}" +log() { echo "[$(date -u +%H:%M:%SZ)] $*" | tee -a "${runs}/run.log"; } +hs() { ssh -o BatchMode=yes -o ConnectTimeout=15 "${hub}" "$@"; } +mark_begin='# >>> AIENOS-PI5 one-shot tryboot block (pi5-run.sh adds it before a run, removes it after)' +mark_end='# <<< AIENOS-PI5' + +[[ -r "${efi}" ]] || { echo "no EFI file ${efi}"; exit 2; } +sha=$(sha256sum "${efi}" | cut -d' ' -f1) +log "run ${tag}: efi=${efi} sha256=${sha}" + +# ---- preflight on the hub ---- +hs 'set -e +test "$(cat /proc/device-tree/chosen/bootloader/tryboot | od -An -tx1 | tr -d " ")" = 00000000 +test ! -e /boot/firmware/new || { echo "REFUSE: /boot/firmware/new exists (pending Ubuntu tryboot update)"; exit 1; } +grep -qF "AIENOS-PI5 one-shot" /boot/firmware/config.txt && { echo "REFUSE: block already in config.txt"; exit 1; } || true +lsblk -no LABEL /dev/mmcblk0p1 | grep -qx AIENOSPI5 +findmnt /dev/mmcblk0p1 >/dev/null && { echo "REFUSE: card mounted"; exit 1; } || true +echo "users: $(who | wc -l)"' 2>&1 | tee -a "${runs}/run.log" +[[ ${PIPESTATUS[0]} == 0 ]] || { log "preflight FAILED"; exit 1; } + +# ---- card: install EFI, clear old report; stick: firmware copy ---- +scp -q -o BatchMode=yes "${efi}" "${hub}:/tmp/aienos-run.efi" +hs "set -e +sudo mkdir -p /mnt/aienos +sudo mount /dev/mmcblk0p1 /mnt/aienos +trap 'sudo umount /mnt/aienos' EXIT +sudo cp /tmp/aienos-run.efi /mnt/aienos/EFI/BOOT/BOOTAA64.EFI +sudo rm -rf /mnt/aienos/EFI/AIENOS +test \"\$(sha256sum /mnt/aienos/EFI/BOOT/BOOTAA64.EFI | cut -d' ' -f1)\" = ${sha} +sudo mkdir -p /boot/firmware/aienos/overlays +for f in RPI_EFI.fd RPI_NV0.bin RPI_NV1.bin bcm2712-rpi-5-b.dtb overlays/bcm2712d0.dtbo; do + if ! cmp -s /mnt/aienos/\$f /boot/firmware/aienos/\$f; then sudo cp /mnt/aienos/\$f /boot/firmware/aienos/\$f; fi +done +test -e /boot/firmware/aienos/overlays/README || echo 'AIENOS-PI5 tryboot overlays (only bcm2712d0)' | sudo tee /boot/firmware/aienos/overlays/README >/dev/null +sync +echo card+stick ready" 2>&1 | tee -a "${runs}/run.log" + +# ---- optional: KLOG slot for a kernel run (KLOG=1) ---- +# A 2 MiB contiguous file on the card plus \EFI\AIENOS\KLOG.MAP naming its +# absolute first sector and a fresh nonce (aienos core/klog_slot.h). The raw +# card sector is read back and compared before the map is written, so the +# kernel is never told a position that is not the file. +if [[ "${KLOG:-0}" == 1 ]]; then + . "$(dirname "$0")/klog-lib.sh" + slot_secs=4096 + ext=$(hs "set -e +sudo mount /dev/mmcblk0p1 /mnt/aienos; trap 'sudo umount /mnt/aienos' EXIT +sudo mkdir -p /mnt/aienos/EFI/AIENOS +sudo dd if=/dev/zero of=/mnt/aienos/EFI/AIENOS/KLOG.BIN bs=512 count=${slot_secs} conv=fsync status=none +sync +sudo hdparm --fibmap /mnt/aienos/EFI/AIENOS/KLOG.BIN") + echo "${ext}" >> "${runs}/run.log" + # hdparm --fibmap rows: byte_offset begin_LBA end_LBA sectors (absolute card LBAs) + rows=$(echo "${ext}" | awk '$1 ~ /^[0-9]+$/ && NF==4') + nexts=$(echo -n "${rows}" | grep -c . || true) + read -r poff klog_lba pend plen <<<"${rows}" + if [[ "${nexts}" != 1 || "${poff}" != 0 || "${plen}" != "${slot_secs}" || $((pend - klog_lba + 1)) != "${slot_secs}" ]]; then + log "KLOG.BIN is not one ${slot_secs}-sector extent (rows=${nexts} lba=${klog_lba} len=${plen}); stopping"; exit 1 + fi + nonce=$(od -An -tx1 -N16 /dev/urandom | tr -d ' \n') + klog_hdr_empty "${klog_lba}" "${slot_secs}" "${nonce}" "${runs}/klog-hdr.bin" + klog_map "${klog_lba}" "${slot_secs}" "${nonce}" "${runs}/KLOG.MAP" + scp -q -o BatchMode=yes "${runs}/klog-hdr.bin" "${runs}/KLOG.MAP" "${hub}:/tmp/" + if ! hs "set -e +sudo mount /dev/mmcblk0p1 /mnt/aienos; trap 'sudo umount /mnt/aienos' EXIT +sudo dd if=/tmp/klog-hdr.bin of=/mnt/aienos/EFI/AIENOS/KLOG.BIN bs=512 count=1 conv=notrunc,fsync status=none +sync; echo 3 | sudo tee /proc/sys/vm/drop_caches >/dev/null +sudo dd if=/dev/mmcblk0 bs=512 skip=${klog_lba} count=1 iflag=direct status=none | cmp - /tmp/klog-hdr.bin +sudo cp /tmp/KLOG.MAP /mnt/aienos/EFI/AIENOS/KLOG.MAP; sync +echo klog_slot_ready" 2>&1 | tee -a "${runs}/run.log"; then :; fi + if ! grep -q klog_slot_ready "${runs}/run.log"; then log "klog slot raw read-back FAILED; stopping before any reboot"; exit 1; fi + log "klog slot lba=${klog_lba} sectors=${slot_secs} nonce=${nonce} (raw card sector matches)" +fi + +# ---- optional: unlock request for the PI5-4 qualification image (UNLOCK_REQ=<file>) ---- +# QUALIFICATION ONLY: the file holds a THROWAWAY recovery secret (aienos native/kernel/core/unlock_req.h: +# 512 bytes, magic AIENUNQ1, tier tag QUALIF-THROWAWAY). It is copied to \EFI\AIENOS\UNLOCK.REQ on the +# card before the run and zeroed + deleted from the card (and checked gone) after the run, before the +# card's EFI/AIENOS tree is copied back. Never put a real operator secret in it. +if [[ -n "${UNLOCK_REQ:-}" ]]; then + [[ -r "${UNLOCK_REQ}" && "$(stat -c %s "${UNLOCK_REQ}")" == 512 && "$(head -c 8 "${UNLOCK_REQ}")" == AIENUNQ1 && "$(dd if="${UNLOCK_REQ}" bs=1 skip=16 count=16 status=none)" == QUALIF-THROWAWAY ]] \ + || { log "UNLOCK_REQ ${UNLOCK_REQ} is not a 512-byte AIENUNQ1 QUALIF-THROWAWAY request; stopping"; exit 1; } + req_sha=$(sha256sum "${UNLOCK_REQ}" | cut -d' ' -f1) + scp -q -o BatchMode=yes "${UNLOCK_REQ}" "${hub}:/tmp/aienos-unlock.req" + hs "set -e +sudo mount /dev/mmcblk0p1 /mnt/aienos; trap 'sudo umount /mnt/aienos' EXIT +sudo mkdir -p /mnt/aienos/EFI/AIENOS +sudo cp /tmp/aienos-unlock.req /mnt/aienos/EFI/AIENOS/UNLOCK.REQ +sudo rm -f /tmp/aienos-unlock.req +sync +test \"\$(sudo sha256sum /mnt/aienos/EFI/AIENOS/UNLOCK.REQ | cut -d' ' -f1)\" = ${req_sha} +echo unlock_req_placed" 2>&1 | tee -a "${runs}/run.log" + grep -q unlock_req_placed "${runs}/run.log" || { log "UNLOCK.REQ placement FAILED; stopping before any reboot"; exit 1; } + log "UNLOCK.REQ placed on the card (QUALIFICATION ONLY, throwaway secret; sha256 of the request ${req_sha}); will be deleted after the run" +fi +# ---- optional: MODEL.MAP for the inference image (MODEL_MAP=<4096-byte map file>) ---- +# aienos native/boot/model_map.h: the UEFI stub reads \EFI\AIENOS\MODEL.MAP and then the model bytes by +# absolute LBA from the disk (here the raw card partition AIENOS-MODEL, mmcblk0p3, written once by hand, +# never touched by this script). Only the 4 KiB map goes on the ESP. The map is also left in the copied +# EFI/AIENOS tree as evidence. +if [[ -n "${MODEL_MAP:-}" ]]; then + [[ -r "${MODEL_MAP}" && "$(stat -c %s "${MODEL_MAP}")" == 4096 && "$(head -c 8 "${MODEL_MAP}")" == AIENMDL1 ]] \ + || { log "MODEL_MAP ${MODEL_MAP} is not a 4096-byte AIENMDL1 map; stopping"; exit 1; } + map_sha=$(sha256sum "${MODEL_MAP}" | cut -d' ' -f1) + scp -q -o BatchMode=yes "${MODEL_MAP}" "${hub}:/tmp/aienos-model.map" + hs "set -e +sudo mount /dev/mmcblk0p1 /mnt/aienos; trap 'sudo umount /mnt/aienos' EXIT +sudo mkdir -p /mnt/aienos/EFI/AIENOS +sudo cp /tmp/aienos-model.map /mnt/aienos/EFI/AIENOS/MODEL.MAP +sudo rm -f /tmp/aienos-model.map +sync +test \"\$(sudo sha256sum /mnt/aienos/EFI/AIENOS/MODEL.MAP | cut -d' ' -f1)\" = ${map_sha} +echo model_map_placed" 2>&1 | tee -a "${runs}/run.log" + grep -q model_map_placed "${runs}/run.log" || { log "MODEL.MAP placement FAILED; stopping before any reboot"; exit 1; } + log "MODEL.MAP placed on the card (sha256 ${map_sha})" +fi +# ---- optional: signed artifact bundle for the PI5-7 cut 3 EL0 artifact image (ARTIFACT_BND=<bundle file, "AIENBND\0" ...>) ---- +# QUALIFICATION ONLY, TEST keys (aienos native/kernel/core/artifact_card.h: at most 131072 bytes, produced by ck_artifact_tool "bundle"). +# Copied to \EFI\AIENOS\ARTIFACT.BND on the card before the run; zeroed + deleted from the card (and checked gone) after the run; +# a copy stays in the run directory as evidence. Negative runs simply leave ARTIFACT_BND unset. +if [[ -n "${ARTIFACT_BND:-}" ]]; then + [[ -r "${ARTIFACT_BND}" && "$(stat -c %s "${ARTIFACT_BND}")" -le 131072 && "$(head -c 7 "${ARTIFACT_BND}")" == "AIENBND" ]] \ + || { log "ARTIFACT_BND ${ARTIFACT_BND} is not an AIENBND bundle of at most 131072 bytes; stopping"; exit 1; } + bnd_sha=$(sha256sum "${ARTIFACT_BND}" | cut -d' ' -f1) + cp "${ARTIFACT_BND}" "${runs}/ARTIFACT.BND.sent" + scp -q -o BatchMode=yes "${ARTIFACT_BND}" "${hub}:/tmp/aienos-artifact.bnd" + hs "set -e +sudo mount /dev/mmcblk0p1 /mnt/aienos; trap 'sudo umount /mnt/aienos' EXIT +sudo mkdir -p /mnt/aienos/EFI/AIENOS +sudo cp /tmp/aienos-artifact.bnd /mnt/aienos/EFI/AIENOS/ARTIFACT.BND +sudo rm -f /tmp/aienos-artifact.bnd +sync +test \"\$(sudo sha256sum /mnt/aienos/EFI/AIENOS/ARTIFACT.BND | cut -d' ' -f1)\" = ${bnd_sha} +echo artifact_bnd_placed" 2>&1 | tee -a "${runs}/run.log" + grep -q artifact_bnd_placed "${runs}/run.log" || { log "ARTIFACT.BND placement FAILED; stopping before any reboot"; exit 1; } + log "ARTIFACT.BND placed on the card (QUALIFICATION ONLY, TEST keys; sha256 of the bundle ${bnd_sha}); will be deleted after the run" +fi +if [[ "${DRY:-0}" == 1 ]]; then log "DRY=1: card prepared, stopping before any config change or reboot"; exit 0; fi + +# ---- config.txt: backup, append the tryboot-only block, check ---- +hs "sudo cp -p /boot/firmware/config.txt /boot/firmware/config.txt.pre-aienos" +hs "cat /boot/firmware/config.txt" > "${runs}/config.txt.before" +{ +cat <<BLOCK + +${mark_begin} +[tryboot] +armstub=aienos/RPI_EFI.fd +device_tree=aienos/bcm2712-rpi-5-b.dtb +overlay_prefix=aienos/overlays/ +device_tree_address=0x1f0000 +device_tree_end=0x210000 +framebuffer_depth=32 +disable_overscan=1 +usb_max_current_enable=1 +force_turbo=1 +initramfs aienos/RPI_NV0.bin,aienos/RPI_NV1.bin 0x04000000 +[all] +${mark_end} +BLOCK +} > "${runs}/block.txt" +scp -q -o BatchMode=yes "${runs}/block.txt" "${hub}:/tmp/aienos-block.txt" +hs "set -e; sudo sh -c 'cat /tmp/aienos-block.txt >> /boot/firmware/config.txt'; sync +diff /boot/firmware/config.txt.pre-aienos /boot/firmware/config.txt | grep -c '^>' " +hs "cat /boot/firmware/config.txt" > "${runs}/config.txt.during" +if ! diff <(cat "${runs}/config.txt.before" "${runs}/block.txt") "${runs}/config.txt.during" >/dev/null; then + log "config.txt is not exactly before+block: restoring and stopping" + hs "sudo cp -p /boot/firmware/config.txt.pre-aienos /boot/firmware/config.txt; sync" + exit 1 +fi +log "block appended; rebooting the hub with tryboot" +t0=$(date +%s) +hs "sudo reboot '0 tryboot'" >/dev/null 2>&1 || true + +# ---- wait: down, then back ---- +sleep 20 +down=0; back=0 +for i in $(seq 1 30); do + if ping -c1 -W3 192.168.1.192 >/dev/null 2>&1; then + [[ ${down} == 1 ]] && { back=1; break; } + else + down=1 + fi + sleep 30 +done +if [[ ${back} != 1 ]]; then + log "hub NOT back after ~15 min (down_seen=${down})" + exit 4 +fi +log "hub answers ping again after $(( $(date +%s) - t0 )) s; waiting 60 s for ssh" +sleep 60 +for i in 1 2 3 4 5; do hs true 2>/dev/null && break; sleep 60; done + +# ---- cleanup + evidence ---- +hs "set -e +tb=\$(od -An -tx1 /proc/device-tree/chosen/bootloader/tryboot | tr -d ' ') +echo tryboot_flag_now=\$tb +sudo cp -p /boot/firmware/config.txt.pre-aienos /boot/firmware/config.txt; sync +grep -qF 'AIENOS-PI5 one-shot' /boot/firmware/config.txt && echo BLOCK_STILL_THERE || echo block_removed +uptime" 2>&1 | tee -a "${runs}/run.log" +hs "cat /boot/firmware/config.txt" > "${runs}/config.txt.after" +cmp -s "${runs}/config.txt.before" "${runs}/config.txt.after" && log "config.txt restored byte for byte" || log "WARNING config.txt differs from before" +if [[ -n "${UNLOCK_REQ:-}" ]]; then + hs "set -e; sudo mount /dev/mmcblk0p1 /mnt/aienos; trap 'sudo umount /mnt/aienos' EXIT +f=/mnt/aienos/EFI/AIENOS/UNLOCK.REQ +if [ -e \$f ]; then sudo dd if=/dev/zero of=\$f bs=512 count=1 conv=notrunc,fsync status=none; sudo rm -f \$f; fi +sync +if [ -e \$f ]; then echo unlock_req_STILL_ON_CARD; else echo unlock_req_deleted_verified; fi +sudo rm -f /tmp/aienos-unlock.req" 2>&1 | tee -a "${runs}/run.log" + if ! grep -q unlock_req_deleted_verified "${runs}/run.log"; then log "UNLOCK.REQ NOT confirmed deleted from the card: remove it by hand before any other use"; exit 6; fi + log "UNLOCK.REQ zeroed and deleted from the card (verified absent)" +fi +if [[ -n "${ARTIFACT_BND:-}" ]]; then + hs "set -e; sudo mount /dev/mmcblk0p1 /mnt/aienos; trap 'sudo umount /mnt/aienos' EXIT +f=/mnt/aienos/EFI/AIENOS/ARTIFACT.BND +if [ -e \$f ]; then sudo dd if=/dev/zero of=\$f bs=512 count=1 conv=notrunc,fsync status=none; sudo rm -f \$f; fi +sync +if [ -e \$f ]; then echo artifact_bnd_STILL_ON_CARD; else echo artifact_bnd_deleted_verified; fi +sudo rm -f /tmp/aienos-artifact.bnd" 2>&1 | tee -a "${runs}/run.log" + if ! grep -q artifact_bnd_deleted_verified "${runs}/run.log"; then log "ARTIFACT.BND NOT confirmed deleted from the card: remove it by hand before any other use"; exit 6; fi + log "ARTIFACT.BND zeroed and deleted from the card (verified absent)" +fi +hs "set -e; sudo mount -o ro /dev/mmcblk0p1 /mnt/aienos; trap 'sudo umount /mnt/aienos' EXIT +if [ -d /mnt/aienos/EFI/AIENOS ]; then sudo tar -C /mnt/aienos/EFI -cf - AIENOS; fi" > "${runs}/aienos.tar" +if [[ -s "${runs}/aienos.tar" ]]; then + tar -C "${runs}" -xf "${runs}/aienos.tar" && rm "${runs}/aienos.tar" + log "report copied: $(ls -R "${runs}/AIENOS" | tr '\n' ' ' | head -c 400)" + if [[ "${KLOG:-0}" == 1 ]]; then + if [[ -f "${runs}/AIENOS/KLOG.BIN" ]] && klog_extract "${runs}/AIENOS/KLOG.BIN" "${runs}/kernel.log" | tee -a "${runs}/run.log"; then + log "kernel log: $(wc -l < "${runs}/kernel.log") lines in ${runs}/kernel.log" + else + log "kernel log NOT written (slot still empty or missing)" + fi + fi +else + log "NO report on the card: the AIENOS image did not run or did not write" + exit 5 +fi +log "run ${tag} done" diff --git a/scripts/qemu_ck_artifact_card_test.sh b/scripts/qemu_ck_artifact_card_test.sh new file mode 100755 index 00000000..d8831f47 --- /dev/null +++ b/scripts/qemu_ck_artifact_card_test.sh @@ -0,0 +1,186 @@ +#!/usr/bin/env bash +# QEMU twin of the Raspberry Pi 5 EL0 artifact qualification image (PI5-7 cut 3, native/kernel/core/artifact_card.h). +# Builds the SAME code the Pi image runs (make CK_ARTIFACT_CARD=1 CK_SEED0B_TEST_ANCHOR=1, the core image with the card +# bundle source; the Pi image adds only CK_PI5) and boots it in QEMU AArch64 + UEFI (AAVMF) with the signed artifacts in ONE +# file on the ESP, \EFI\AIENOS\ARTIFACT.BND. QEMU is not hardware: a PASS here qualifies nothing physical; it is the red- +# before-green run that must pass before a Pi run is spent. +# +# TEST keys only: every artifact is signed by the in-tree C tool with the public RFC 8032 TEST 1 key (SEED-0B, TEST ONLY). +# Boots (all with the card image): +# 1. layout: the bundle holds P25EXEC only, to read the kernel's own layout lines; the two kernel-address probes are then +# assembled for exactly those addresses (fixtures/p2_7/assemble.sh); +# 2. qualification: P25EXEC (good, exits 0 through SYS_EXIT after a capability read), P27KREAD (EL0 load from kernel memory), +# P27KWRITE (EL0 store to kernel memory), P27PRIV (EL0 read of a kernel control register), P26SEED (good, runs AFTER the +# three faults: the kernel kept running), P25TAMP (one payload byte flipped after signing): every verdict, the fault +# class/ESR/FAR, the receipts (host-verified), frame accounting, TEST-ONLY labels; +# 3. negative controls: no ARTIFACT.BND on the card (no candidates), and a bundle with one trailing byte (refused whole). +# Last line: AIENOS_CK_ARTIFACT_CARD: PASS|FAIL|NOT_RUN. +set -euo pipefail + +repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +cd "${repo_root}" +verdict=AIENOS_CK_ARTIFACT_CARD + +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"; echo "${verdict}: NOT_RUN"; exit 2; } +[[ -r "${code_fd}" && -r "${vars_fd}" ]] || { echo "AAVMF firmware not found"; echo "${verdict}: NOT_RUN"; exit 2; } + +. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/lib_gate_hold.sh" +if ! gh_quiet_check || ! gh_lock_take "qemu_ck_artifact_card" "${AIENOS_GATE_MINUTES:-60}"; then + echo "NOT_RUN ${gh_why}" + echo "${verdict}: NOT_RUN" + exit 3 +fi +work="$(mktemp -d)" +cleanup() { rm -rf "${work}"; gh_lock_release; } +trap cleanup EXIT +failed=0 +pass() { echo "PASS $1"; } +fail() { echo "FAIL $1"; failed=1; } + +cross="" +if [ "$(uname -m)" != "aarch64" ]; then cross="aarch64-linux-gnu-"; fi +commit="$(git rev-parse HEAD 2>/dev/null || echo unknown)" +out="${repo_root}/target/native-kernel-artifact-card" +make -s -C native/kernel CROSS="${cross}" AIENOS_COMMIT="${commit}" OUT="${out}" CK_ARTIFACT_CARD=1 CK_SEED0B_TEST_ANCHOR=1 >/dev/null +make -s -C native/kernel CROSS="${cross}" OUT="${out}" tool >/dev/null +tool="${out}/host/ck_artifact_tool" +efi="${out}/BOOTAA64.EFI" +fx="crates/aienos-artifact-tool/fixtures" + +# ---- static: the image is TEST-ONLY labelled and carries no fw_cfg artifact code ---- +if grep -aqF "artifact_trust: seed0b-test qualification build" "${efi}"; then pass "card image carries the TEST ONLY trust label"; else fail "card image lacks the TEST ONLY trust label"; fi +if grep -aqE "opt/aienos/artifacts|fw_cfg|QEMU0002" "${efi}"; then fail "card image carries fw_cfg artifact code"; else pass "card image has no fw_cfg artifact code"; fi +for bad in "CK_ARTIFACT_CARD=1" "CK_ARTIFACT_CARD=1 CK_SEED0B_TEST_ANCHOR=1 CK_HARDWARE_STAGING=1" "CK_PI5_ARTIFACT=1 CK_PI5_STORE=1" "CK_ARTIFACT_CARD=1 CK_SEED0B_TEST_ANCHOR=1 full"; do + # shellcheck disable=SC2086 + if make -n -C native/kernel ${bad} >/dev/null 2>&1; then fail "Makefile accepts ${bad}"; else pass "Makefile refuses ${bad}"; fi +done + +boot() { # bundle-or-empty, serial text output + local esp="${work}/esp" log="${work}/serial.log" status + rm -rf "${esp}" + mkdir -p "${esp}/EFI/BOOT" "${esp}/EFI/AIENOS" + cp "${efi}" "${esp}/EFI/BOOT/BOOTAA64.EFI" + if [[ -n "$1" ]]; then cp "$1" "${esp}/EFI/AIENOS/ARTIFACT.BND"; fi + cp "${vars_fd}" "${work}/vars.fd" + set +e + nice -n 10 timeout "${AIENOS_QEMU_TIMEOUT:-300}" qemu-system-aarch64 \ + -M virt,virtualization=on,gic-version=3 -accel tcg,thread=single -cpu max -smp 4 -m 2048 \ + -drive if=pflash,format=raw,readonly=on,file="${code_fd}" \ + -drive if=pflash,format=raw,file="${work}/vars.fd" \ + -drive if=none,id=esp,format=raw,file=fat:rw:"${esp}" \ + -device virtio-blk-pci,drive=esp \ + -device ramfb -display none -nic none \ + -serial file:"${log}" -no-reboot 2>/dev/null + status=$? + set -e + tr -d '\r' <"${log}" >"$2" + [[ "${status}" == 0 ]] || fail "QEMU exit status ${status} (124 = timeout)" +} +has() { grep -qE -- "$2" "$1"; } +check() { if has "$1" "$3"; then pass "$2"; else fail "$2"; fi; } + +# ---- inputs: signed artifacts (TEST key) ---- +art="${work}/art" +mkdir -p "${art}" +"${fx}/p2_5/pack.sh" "${tool}" "${art}" >/dev/null +"${fx}/p2_6/pack.sh" "${tool}" "${art}" >/dev/null + +# ---- boot 1: layout ---- +"${tool}" bundle "${work}/layout.bnd" "${art}/P25EXEC.AIEN" >/dev/null +boot "${work}/layout.bnd" "${work}/layout.txt" +root=$(sed -nE 's/^mmu_switch: .* aienos_root=(0x[0-9a-f]+) .*/\1/p' "${work}/layout.txt" | head -1) +heap_lo=$(sed -nE 's/^memory: .* heap=(0x[0-9a-f]+)-(0x[0-9a-f]+) .*/\1/p' "${work}/layout.txt" | head -1) +heap_hi=$(sed -nE 's/^memory: .* heap=(0x[0-9a-f]+)-(0x[0-9a-f]+) .*/\2/p' "${work}/layout.txt" | head -1) +if [[ -n "${root}" && -n "${heap_lo}" && -n "${heap_hi}" ]]; then + kw=$(printf '0x%x' $(( (heap_lo + heap_hi) / 2 & ~0xfff ))) + pass "kernel layout read: translation root ${root}, heap ${heap_lo}-${heap_hi}; probes target ${root} (read) and ${kw} (write)" +else + fail "kernel layout lines (root='${root}' heap='${heap_lo}-${heap_hi}')"; root=0x40000000; kw=0x4a000000 +fi +KREAD_ADDR="${root}" KWRITE_ADDR="${kw}" "${fx}/p2_7/assemble.sh" "${work}/p27" >/dev/null +"${fx}/p2_7/pack.sh" "${tool}" "${art}" "${work}/p27" >/dev/null +# the committed Pi variant must still be exactly what probe.S assembles to (default addresses) +"${fx}/p2_7/assemble.sh" "${work}/p27pi" >/dev/null +pi_ok=1 +for p in p27kread p27kwrite p27priv; do cmp -s "${work}/p27pi/${p}/code.bin" "${fx}/p2_7/${p}/code.bin" || pi_ok=0; done +if [[ "${pi_ok}" == 1 ]]; then pass "committed Pi probe code.bin files equal probe.S assembled"; else fail "committed Pi probe code.bin differs from probe.S"; fi + +# ---- boot 2: qualification ---- +order=(P25EXEC P27KREAD P27KWRITE P27PRIV P26SEED P25TAMP) +files=() +for n in "${order[@]}"; do files+=("${art}/${n}.AIEN"); done +"${tool}" bundle "${work}/qual.bnd" "${files[@]}" >/dev/null +qual="${work}/qual.txt" +boot "${work}/qual.bnd" "${qual}" +check "${qual}" "kernel alive, M3 EL0 isolation proof unchanged" "el0: ok write=granted forged=denied fault=contained exit=0" +check "${qual}" "stub found a well-formed bundle on the card" "^artifact_card: found a well-formed bundle \(QUALIFICATION ONLY, TEST keys, 6 entries, $(stat -c %s "${work}/qual.bnd") bytes\)$" +check "${qual}" "TEST ONLY trust label" "^artifact_trust: seed0b-test qualification build — TEST ONLY$" +check "${qual}" "card_file source with six candidates" "^artifact_source: card_file candidates=6 " +if has "${qual}" "artifact_source: nvme_store|fw_cfg"; then fail "wrong artifact source label"; fi +check "${qual}" "bundle SHA-256 as the kernel read it equals the host file" "^artifact_card: .* sha256=$(sha256sum "${work}/qual.bnd" | cut -d' ' -f1) " +ok=1 +for n in "${order[@]}"; do + has "${qual}" "^artifact_card: ${n}\.AIEN bytes=$(stat -c %s "${art}/${n}.AIEN") sha256=$(sha256sum "${art}/${n}.AIEN" | cut -d' ' -f1)$" || { ok=0; echo " kernel-side SHA-256 differs: ${n}"; } +done +if [[ "${ok}" == 1 ]]; then pass "kernel-side SHA-256 of all six artifacts equals the host files"; else fail "kernel-side artifact SHA-256"; fi +adm() { echo "^artifact: $1\.AIEN admitted id=[0-9a-f]{16} tier=seed0b-test exec=$2 bytes=identified=verified=admitted=mapped=executed wx=enforced caps=$3 revoked=yes reclaimed=yes frames=[0-9]+ "; } +check "${qual}" "(a) P25EXEC ran at EL0 and returned exit 0 through SYS_EXIT, capability read granted, forged handle denied" "$(adm P25EXEC exited:0x0 1)syscalls=3 reads=1 denials=1$" +check "${qual}" "(a) P26SEED ran after the faults, exit 0, 3 granted reads, 5 denials" "$(adm P26SEED exited:0x0 1)syscalls=9 reads=3 denials=5$" +check "${qual}" "(b) P25TAMP (one payload byte flipped) refused before running" "^artifact: P25TAMP\.AIEN rejected stage=verified reason=BadSignature reclaimed=yes$" +check "${qual}" "(c) P27KREAD: EL0 load from kernel memory faults" "$(adm P27KREAD fault:outside-read 0)syscalls=0 reads=0 denials=0$" +check "${qual}" "(c) P27KWRITE: EL0 store to kernel memory faults" "$(adm P27KWRITE fault:outside-write 0)syscalls=0 reads=0 denials=0$" +check "${qual}" "(c) P27PRIV: EL0 read of a kernel control register faults" "$(adm P27PRIV fault:privileged-insn 0)syscalls=0 reads=0 denials=0$" +check "${qual}" "(c) P27KREAD fault: data abort from EL0 (EC 0x24), read, FAR = the kernel root" "^artifact_fault: P27KREAD\.AIEN class=outside-read esr=0x[0-9a-f]+ ec=0x24 far=${root} elr=0x[0-9a-f]+ contained=yes$" +check "${qual}" "(c) P27KWRITE fault: data abort from EL0 (EC 0x24), write, FAR = the kernel heap address" "^artifact_fault: P27KWRITE\.AIEN class=outside-write esr=0x[0-9a-f]+ ec=0x24 far=${kw} elr=0x[0-9a-f]+ contained=yes$" +check "${qual}" "(c) P27PRIV fault: unknown-reason/trapped system instruction (EC 0x00 or 0x18), FAR not claimed" "^artifact_fault: P27PRIV\.AIEN class=privileged-insn esr=0x[0-9a-f]+ ec=0x(0|18) far=n/a elr=0x[0-9a-f]+ contained=yes$" +if has "${qual}" "exec=exited:0x57"; then fail "a probe reached its violation exit 0x57 (isolation broken)"; else pass "no probe reached its violation exit"; fi +check "${qual}" "kernel kept running: final report after all candidates" "^artifacts: candidates=6 admitted=5 rejected=1$" +if has "${qual}" "report_kind: (panic|fault)"; then fail "panic or fault reported"; else pass "no kernel panic or fault report"; fi +before=$(grep -oE "artifact_frames_free_before: [0-9]+" "${qual}" | awk '{print $2}' | tail -1) +after=$(grep -oE "artifact_frames_free_after: [0-9]+" "${qual}" | awk '{print $2}' | tail -1) +if [[ -n "${before}" && "${before}" == "${after}" ]]; then pass "every frame returned after all candidates (${before} free before and after)"; else fail "frame accounting (before=${before:-?} after=${after:-?})"; fi +check "${qual}" "bundle buffer released after the loader" "^artifact_card: released bundle bytes=$(stat -c %s "${work}/qual.bnd") entries=6$" +# receipts: decoded, bound to the supplied artifact, digest recomputed on the host, TEST ONLY signature verifies +receipt_check() { # name pattern + local line record kdigest o file="${work}/$1.receipt" + line=$(grep -E "^receipt: $1\.AIEN seq=[0-9]+ digest=[0-9a-f]{64} record=[0-9a-f]{1024}$" "${qual}" | tail -1 || true) + if [[ -z "${line}" ]]; then fail "$1 receipt emitted"; return; fi + record=${line##*record=} + kdigest=$(sed -E 's/.* digest=([0-9a-f]{64}) .*/\1/' <<<"${line}") + "${tool}" receipt from-hex "${record}" "${file}" >/dev/null 2>&1 || { fail "$1 receipt decodes"; return; } + o=$("${tool}" receipt check "${file}" "${art}/$1.AIEN" 2>&1) || { fail "$1 receipt binds the artifact (${o})"; return; } + [[ "${o}" == *"digest=${kdigest} "* ]] || { fail "$1 receipt digest recomputed by the host"; return; } + grep -qE -- "$2" <<<"${o}" || { fail "$1 receipt records the observed outcome (${o})"; return; } + "${tool}" receipt sign-test "${file}" "${file}.signed" >/dev/null 2>&1 || { fail "$1 receipt TEST ONLY signing"; return; } + if "${tool}" receipt verify "${file}.signed" | grep -q "RECEIPT_VERIFY: PASS digest=${kdigest} "; then pass "$1 receipt: bound, host digest match, outcome recorded, TEST ONLY signature verifies"; else fail "$1 signed receipt verifies"; fi +} +receipt_check P25EXEC "decision=Admitted .* status=Exited exit=0 " +receipt_check P26SEED "decision=Admitted .* status=Exited exit=0 " +receipt_check P25TAMP "decision=Rejected .* stage=3 reason=0x12 status=NotRun " +for n in P27KREAD P27KWRITE P27PRIV; do receipt_check "${n}" "decision=Admitted .* status=Fault exit=0 syscalls=0 "; done + +# ---- boot 3: no bundle on the card ---- +none="${work}/none.txt" +boot "" "${none}" +check "${none}" "no bundle: loader reports no source" "^artifact_source: none \(no card artifact bundle \(file absent\)\)$" +check "${none}" "no bundle: zero candidates" "^artifacts: candidates=0 admitted=0 rejected=0$" + +# ---- boot 4: a bundle with one trailing byte is refused whole ---- +cp "${work}/qual.bnd" "${work}/trail.bnd" +printf '\000' >>"${work}/trail.bnd" +trail="${work}/trail.txt" +boot "${work}/trail.bnd" "${trail}" +check "${trail}" "trailing byte: bundle refused by the stub" "^artifact_card: refused \(bytes after the last entry\)$" +check "${trail}" "trailing byte: no artifact reaches the loader" "^artifacts: candidates=0 admitted=0 rejected=0$" +if has "${trail}" "^artifact: [A-Z0-9-]+\.AIEN "; then fail "an artifact of a refused bundle was named"; else pass "no artifact of the refused bundle was named or run"; fi + +if [[ -n "${AIENOS_LOG_DIR:-}" ]]; then + cp "${qual}" "${AIENOS_LOG_DIR}/qemu_ck_artifact_card_serial.log" +fi +if [[ "${failed}" != 0 || -n "${AIENOS_QEMU_VERBOSE:-}" ]]; then + echo "---- qualification serial (artifact lines) ----" + grep -E "^(artifact|grant|kernel|report_kind|panic|fault|exception|esr|far)" "${qual}" | head -80 || true +fi +if [[ "${failed}" == 0 ]]; then echo "${verdict}: PASS"; else echo "${verdict}: FAIL"; exit 1; fi