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#384 (code only)
Fetch it
curl -fsSL https://interplane.io/drakestapleton/aienux/patches/76be27d43450ee4c.bundle -o 76be27d43450ee4c.bundle git fetch 76be27d43450ee4c.bundle refs/pull/384/head
Provenance
github-import 1
aien-dev/aienux
384
044f6d30557f3c4ed79ad09d1505f495efff0a00
{"kind":"github-import","owner":"aien-dev","repo":"aienux","number":384,"url":"https://github.com/aien-dev/aienux/pull/384","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:36:19Z","metadata":"unavailable","state_derived":true}
Changes
diff --git a/.crumb b/.crumb index aa33946b..37bb9013 100644 --- a/.crumb +++ b/.crumb @@ -27,33 +27,33 @@ "purpose": "Directory crates. Purpose not yet described by a human." }, { - "digest": "edc9efe14efab371f4d937256d062b8e17b4387d11914fced55ccdf365ad85a2", - "last_commit": "c05a495", + "digest": "5fbbd547beb41060da78fc2045d188aa5148d64c48be02e667327947d81f6598", + "last_commit": "29a30a6", "name": "docs", "purpose": "Directory docs. Purpose not yet described by a human." }, { - "digest": "c1b648a264be3717dffa5556c2159b8bf233dfa57e05abfeb624eec3f2b4114f", - "last_commit": "7db773a", + "digest": "0d98faef5fa42de4cff8de8e8339e550c62f98cb610e81800f835d3b26a65f01", + "last_commit": "29a30a6", "name": "native", "purpose": "Directory native. Purpose not yet described by a human." }, { - "digest": "fe47cb248b0f45e1d91fe38a8787181eee2a42fcd49cc313a70323f207d48392", - "last_commit": "f5c90e7", + "digest": "45d955c9b529e601b184a680d586daffbe5efe31f98d9524bf58ace7ef3e1e22", + "last_commit": "29a30a6", "name": "scripts", "purpose": "Directory scripts. Purpose not yet described by a human." } ], - "children_root": "sha256:f35112f9cb4f20559d43534371b499841a0311f5363b7cb2f2333b8795626adb", - "compiled_at": "2026-10-14T20:41:24Z", + "children_root": "sha256:59dff4882689e2833fac819fc49efdbf9099e6d762d374fef660e72875293675", + "compiled_at": "2026-10-14T21:43:37Z", "compiler": "crumb-compile/1", - "digest": "sha256:dc25db333c7a18d72afcfb843ac6c83f3e689cf8c30a5d38b71e0382012b7569", + "digest": "sha256:8807d6073b03be165567b08420db1f1e23341ae597e9f85c55a798b66d0a527c", "evidence_files": 183, "evidence_root": "sha256:9ac286aca0d673f856463c2a1541854df773bfe792792e6b82b7cb7a47cd17cc", - "files": 3423, - "generated_at_commit": "7db773a8c3e041d4415c3c37240b26235c81b7a7", - "source_tree": "sha256:f4f9887588d76db2cd026407975a883b5874e5bb9a05515be4cdf5632da04000" + "files": 3450, + "generated_at_commit": "45d244fd724e84f32461758c513072e0c16532a0", + "source_tree": "sha256:6a03eefd34e0b886f7e0aef371cc6233b896c1d86ddd20ec23a69edd7ab1afb9" }, "owner_lane": "", "provenance": { diff --git a/.github/workflows/ck-kernel.yml b/.github/workflows/ck-kernel.yml index 585bd052..101ef0fe 100644 --- a/.github/workflows/ck-kernel.yml +++ b/.github/workflows/ck-kernel.yml @@ -198,6 +198,7 @@ jobs: - { name: screen, gates: "SCREEN" } - { name: osh_op, gates: "OSH_OP" } - { name: osc_launch, gates: "OSC_LAUNCH" } + - { name: osc_receipt, gates: "OSC_RECEIPT" } - { name: osc_unit, gates: "OSC_UNIT" } - { name: boot, gates: "M1,M3" } - { name: smp, gates: "SMP" } @@ -284,4 +285,4 @@ jobs: pattern: ck-shard-* path: ${{ runner.temp }}/shards - name: Every gate reported exactly once across the gate jobs - run: bash scripts/ck_shards_verify.sh 20 "${RUNNER_TEMP}/shards" + run: bash scripts/ck_shards_verify.sh 21 "${RUNNER_TEMP}/shards" diff --git a/docs/.crumb b/docs/.crumb index 714a284b..02284771 100644 --- a/docs/.crumb +++ b/docs/.crumb @@ -30,14 +30,14 @@ } ], "children_root": "sha256:491e93c09b6185b662afda8b29d24bb3ee81bc2aed9009757fdf4674d197be31", - "compiled_at": "2026-10-14T11:49:57Z", + "compiled_at": "2026-10-14T19:55:50Z", "compiler": "crumb-compile/1", - "digest": "sha256:edc9efe14efab371f4d937256d062b8e17b4387d11914fced55ccdf365ad85a2", + "digest": "sha256:5fbbd547beb41060da78fc2045d188aa5148d64c48be02e667327947d81f6598", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 215, - "generated_at_commit": "426c4b5170cc0bdcb7b5d8a958508bf58705fe51", - "source_tree": "sha256:242122f3539c1120054625e9814c856d66946a0758f326bac5e0210ab67abec1" + "files": 216, + "generated_at_commit": "29a30a6c135f5840b90a64031ed8f532c84ed80a", + "source_tree": "sha256:3b2f17a654c91e183e39872eb76a20bd42f9e0678cae522f1644c825cb31605a" }, "owner_lane": "", "provenance": { diff --git a/docs/osc-launch.md b/docs/osc-launch.md index 5c80b719..9f1e94db 100644 --- a/docs/osc-launch.md +++ b/docs/osc-launch.md @@ -8,7 +8,8 @@ Spark or any real machine. Contract: `OSC_UNIT_ARTIFACT.md` section 9 (aien-prot ## What runs An admitted unit (`struct osc_accept` from `osc_unit_admit`) is run as one function call in an EL0 task with -its own address space, by `ck_osc_launch` (`core/osc_task.c`): look up the function by exact name, check the +its own address space, by `ck_osc_launch` (`core/osc_task.c`): verify the unit's realization receipt (aienos#383, +`docs/osc-receipts.md`; no valid receipt, no launch), look up the function by exact name, check the arguments, copy and re-hash the code, map, enter EL0, wait, classify, tear down. One call at a time, one slot. ## The call signature (what an entry gets) diff --git a/docs/osc-receipts.md b/docs/osc-receipts.md new file mode 100644 index 00000000..14e17900 --- /dev/null +++ b/docs/osc-receipts.md @@ -0,0 +1,106 @@ +# OSC unit launch requires a realization receipt (aienos#383) + +Label for everything below: **QEMU (aarch64 virt), TEST signer, not physical.** Nothing here has run on a +Spark or any real machine. Contract: omega `spec/one-layer-receipts.md` (receipt v1, normative; section +numbers below refer to it). Gate: `scripts/qemu_ck_osc_receipt_test.sh` (`OSC_RECEIPT` row in +`scripts/ck_gates.sh`, notes in `native/kernel/GATES.md`). + +## What it does + +A receipt is a 416-byte record, signed by a key of a stated class, saying that omega's independent checker +(checker2) judged one exact program (the OSC IR) and that one executable is bound to it by hash. The kernel +now refuses to launch an admitted OSC unit unless a receipt that is valid for that exact unit comes with the +launch. + +- `artifact/osc_receipt.{h,c}`: `osc_receipt_verify(receipt, len, &accept, &policy, &info)`, a pure function + written from the spec (no checker2 code copied). It reuses the in-tree SHA-256 and Ed25519 verify and + compares keys, hashes and identities in constant time. +- `core/osc_task.c`: `ck_osc_launch` takes the receipt bytes and verifies them with the kernel's own policy + (`ck_osc_policy`, `core/osc_admit.c`) before anything else; callers cannot pass a policy. A missing receipt + is `RECEIPT_MISSING`. Nothing is mapped and nothing runs on any refusal. The code is still copied and + re-hashed before mapping. +- `osc_unit_admit` and the container signature check are unchanged. A receipt grants no capability. +- Receipts reach the kernel as Store entries (magic `OMRCPT1`), kept by name (24 slots, 512 bytes each; a + longer entry is kept truncated so it is refused `RECEIPT_SIZE`). The self-test drivers pair a unit with its + receipt by name. + +## Refusal codes + +Kernel code = 64 + the spec's stable reason number; the name is `RECEIPT_<spec name>`. Order is spec +section 6; the first failure decides. + +| code | name | when | +|---|---|---| +| 64 | RECEIPT_MISSING | no receipt (kernel only) | +| 65..71 | SIZE, MAGIC, VERSION, SIGNATURE_ALGORITHM, SIGNER_CLASS, EVIDENCE_CLASS, EPOCH_ORDER | structure | +| 73 | TEST_SIGNER_IN_PRODUCTION | release build and the receipt is not OWNER class | +| 74 | UNTRUSTED_SIGNER | fingerprint names no anchor of the receipt's class; a key in both classes; release mode and the owner key is not the owner root | +| 75 | BAD_SIGNATURE | | +| 76 | REVOKED | receipt id, then signer key fingerprint (`revoked=receipt_id` or `revoked=signer_key` on the launch line) | +| 77, 78, 79 | STALE_EPOCH, EXPIRED, NOT_YET_VALID | epoch window, inclusive at both ends | +| 86 | UNTRUSTED_CHECKER | checker identity not in the pinned list | +| 80..83 | WRONG_TARGET, WRONG_FIRMWARE, PROGRAM_MISMATCH, EXECUTABLE_MISMATCH | binding to the unit | +| 87 | WRONG_PRODUCER | the kernel's policy expects none (all zero) | +| 88 | DEPENDENCIES_MISMATCH | any dependency claimed | +| 96 | LRAT_PROOFS_REQUIRED | evidence class 2 (kernel-assigned number, see below) | +| 84 | ARGUMENT | verifier called without a unit or a policy | + +## Kernel policy (`ck_osc_policy`) + +- Target: SHA-256(`"OMEGA-TARGET-V1\0"` ‖ `aienos-ck-aarch64-el0`). Program = the unit's IR hash (section 1). + Executable = the unit's code hash. Firmware: none (all zero). Dependencies: the empty list. Producer: none (all zero). +- Checker identity: one pinned identity, checker2 at omega 265ce82a (`artifact/osc_receipt_anchor.h`). +- Epoch floor 10, current epoch 20 (compile-time constants: there is no epoch authority yet). +- Qualification build (`CK_SEED0B_TEST_ANCHOR=1`): checker2's TEST key is the only receipt anchor + (`artifact/osc_receipt_test_anchor.h`, separate from the unit TEST key) and one fixture receipt id is revoked. +- Release build: release mode, no receipt anchor at all, so every receipt is refused. The owner root + `578ada3c…` is listed in `osc_receipt_anchor.h` but is not trusted for receipts: it is in no anchor set + until `docs/OWNER_KEY_CEREMONY.md` says it may sign receipts. + +## Ambiguities in the spec, written down (no guess taken) + +1. **Revoked id and revoked key share one code.** The brief asked for a reason of its own per case; the spec + gives both `REVOKED` (12). The kernel returns the spec code and says which list matched in a separate + field (`revoked=receipt_id|signer_key`). +2. **Evidence class 2.** Section 6 accepts class 2 as well formed; section 10 says a class 2 receipt is valid + only when the same LRAT proofs are given and replayed, and names `LRAT-PROOFS-REQUIRED` without a number. + The kernel is given no proofs and has no LRAT checker, so it refuses class 2 (fail closed) with the + kernel-assigned code 96, after every section 6 step has passed (the spec does not place this check in the + section 6 order). +3. **The "current epoch" and the floor** have no source in the spec beyond "the verifier's". The kernel uses + compile-time constants. +4. **Producer.** The unit carries no producer identity, so the kernel policy names none (`NULL`), which + expects an all-zero producer field (`"none"`), matching `checker2 receipt verify` when no `--producer` + is given. The kernel and `checker2` agree on all 22 rows of `expected.txt`. + +## UNVERIFIED (not done, not claimed) + +- **Physical Spark: NOT_RUN.** Only QEMU. No hardware, no GPU, no reboot. +- **OWNER receipts:** none exist; the owner root is not trusted for receipts; a positive OWNER acceptance is + untested (refusals only). +- **Translation validation:** the executable is bound to the program by hash only (evidence class 1 says + so). Nothing shows the code implements the IR. +- **LRAT proofs** are not replayed in the kernel; class 2 is refused instead. +- **Requirements and input digests:** NOT CHECKED. +- **Dependency receipts:** not resolved; any claimed dependency is refused. +- **Container manifest** (entry table, capabilities, stack and tick budgets) is not bound by a receipt; it + stays bound by the unit signature only. +- **Epoch and revocation** are compile-time; there is no live revocation feed or epoch authority. +- **Name pairing** of unit and receipt in the self-test drivers is a test convenience; no Store-driven or + shell-driven launch exists yet. +- **Pre-existing non-OSC EL0 entry paths:** two pre-existing EL0 entry paths remain receipt-free: the + legacy P2 artifact `run_task` (`artifact_loader.c:810`) and the M3 self-test. Neither takes OSC units; + this change does not gate them. + +## Tests + +- Host: `tests/test_osc_receipt.c` (in `make test` and `make sanitize`, qualification and release builds): + every case of `tests/fixtures/osc_receipt/expected.txt` (checker2's own verdict recorded beside the kernel's), + trust inputs against the fixtures, each structure reason and the order of the checks, epoch window edges, + all 3328 single-bit flips of a valid receipt refused, in-memory receipts re-signed with the published TEST + seed (reproducing checker2's signature byte for byte), the Store receipt table. +- Mutants: `make osc-receipt-mutants` removes each of the 25 guards in `osc_receipt.c` one at a time; the + test must fail for every one. +- QEMU: `scripts/qemu_ck_osc_receipt_test.sh`, 17 launches of one unit: the valid receipt runs it (first and + last launch); every other launch is refused with its own named reason and maps nothing. +- Fixtures: `tests/fixtures/osc_receipt/make-receipts.sh` (provenance in `PROVENANCE.txt`). diff --git a/native/.crumb b/native/.crumb index 419f39ad..eacc1a7a 100644 --- a/native/.crumb +++ b/native/.crumb @@ -79,8 +79,8 @@ "purpose": "Directory native/disk. Purpose not yet described by a human." }, { - "digest": "31737455b2245028f473bf7d18f3c5e45f3f5e89d948d55d480c90f6b8b87f32", - "last_commit": "f5c90e7", + "digest": "7a268645098ae3e09b56d39274d2ac6f720eceb00164b1ad9e642aeec116f07e", + "last_commit": "29a30a6", "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:1cd19656d92368f42ada2464304c7c5e09f4304f10b09744d5b7b1834099794e", - "compiled_at": "2026-10-14T20:37:20Z", + "children_root": "sha256:1c4a5de9ee4c194ac445c6bada2ef26f53a7857bcce00f6c5878a61ea6b25fcf", + "compiled_at": "2026-10-14T21:43:37Z", "compiler": "crumb-compile/1", - "digest": "sha256:c1b648a264be3717dffa5556c2159b8bf233dfa57e05abfeb624eec3f2b4114f", + "digest": "sha256:0d98faef5fa42de4cff8de8e8339e550c62f98cb610e81800f835d3b26a65f01", "evidence_files": 4, "evidence_root": "sha256:e410b845507e00568e15b51a5797af32a97e0e4b8ab4e8487bb7c98e7e0cf335", - "files": 562, - "generated_at_commit": "7db773a8c3e041d4415c3c37240b26235c81b7a7", - "source_tree": "sha256:d039c7a37001af4bb4027d66bf0d8a185615ed02a881cdd3c07b66c544c203df" + "files": 587, + "generated_at_commit": "45d244fd724e84f32461758c513072e0c16532a0", + "source_tree": "sha256:c72ef0f69a2cf87489567a24666305d481363a9eb24ca61a4d05abf25279c246" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/.crumb b/native/kernel/.crumb index b29837ee..6c21820c 100644 --- a/native/kernel/.crumb +++ b/native/kernel/.crumb @@ -51,14 +51,14 @@ "purpose": "Directory native/kernel/arch. Purpose not yet described by a human." }, { - "digest": "29a3372d4ab6170718cb870e8d586c94f9828a20755277bf052588376e47333e", - "last_commit": "e12e6f6", + "digest": "243ae0c0be907222d5ae7105f655ee87020e18f47023ee53ca71d914e0ff4676", + "last_commit": "29a30a6", "name": "artifact", "purpose": "Directory native/kernel/artifact. Purpose not yet described by a human." }, { - "digest": "9333ad224a18c87c3e0e241c69209b761a27f72d7f2067354f0658b917cd77ef", - "last_commit": "e12e6f6", + "digest": "b9bbf4b8af5e31c209a7e31e2ceaab640969dd762058218763857c73aef02d38", + "last_commit": "29a30a6", "name": "core", "purpose": "Directory native/kernel/core. Purpose not yet described by a human." }, @@ -87,8 +87,8 @@ "purpose": "Directory native/kernel/svc. Purpose not yet described by a human." }, { - "digest": "67f43d00adce9780c2ae75ece209ac453a1b9debc74d735d9acdb72f36e6df77", - "last_commit": "e12e6f6", + "digest": "b9bfdf2069bf98725e1dc3b8088c19f4cb7a5ff6acbb2a7a2bb7beb23b787dee", + "last_commit": "29a30a6", "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:07df85f4c5f2c7c519b2d0c0e9a94cdabf029ba6935c68d7af30c1076a8dcbec", - "compiled_at": "2026-10-14T13:28:10Z", + "children_root": "sha256:fb0d678391e882db3960b067263af48e2f6027f23dc92a684e7d9c4b98a30ed8", + "compiled_at": "2026-10-14T19:58:14Z", "compiler": "crumb-compile/1", - "digest": "sha256:31737455b2245028f473bf7d18f3c5e45f3f5e89d948d55d480c90f6b8b87f32", + "digest": "sha256:7a268645098ae3e09b56d39274d2ac6f720eceb00164b1ad9e642aeec116f07e", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 381, - "generated_at_commit": "a0fa796235409ce465c467e8c72fbd977485d8f7", - "source_tree": "sha256:9cf06b5cf7b997b087b4ea61597184fa3fff7637a72dd44dcbf0230316cc03b0" + "files": 406, + "generated_at_commit": "7963940dc7ffb44a00bb162d46d1c861090b2fa7", + "source_tree": "sha256:bd0e4d383cb083e7f623c376d2d4652e96ea8e4430d4c34869e99b6770d3f6c3" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/GATES.md b/native/kernel/GATES.md index 3e33a3cd..b551a442 100644 --- a/native/kernel/GATES.md +++ b/native/kernel/GATES.md @@ -787,6 +787,28 @@ it down). What is enforced, what is not, and the decisions taken: `docs/osc-laun execute an SVC, so only the host test reaches that lock). - Labels: QEMU (aarch64 virt), TEST signer, not physical. Nothing here ran on a Spark. +## OSC_RECEIPT: launch requires a valid Omega realization receipt (aienos#383) -> CK `OSC_RECEIPT` (scripts/qemu_ck_osc_receipt_test.sh) + +Contract: omega `spec/one-layer-receipts.md` (receipt v1). Code: `native/kernel/artifact/osc_receipt.{h,c}` +(pure verifier written from the spec), `core/osc_admit.c` (`ck_osc_policy`, Store receipt table), +`core/osc_task.c` (`ck_osc_launch` verifies the receipt first; no receipt is `RECEIPT_MISSING`). Codes, +policy, ambiguities and the UNVERIFIED list: `docs/osc-receipts.md`. + +- Host tests: `tests/test_osc_receipt.c`, part of `make test` and `make sanitize`, built for the qualification + and the release policy. Mutants: `make osc-receipt-mutants`, 25 of 25 guards killed. +- QEMU gate: one boot of the qualification image built with `CK_SEED0B_TEST_ANCHOR=1 CK_OSC_LAUNCH_TEST=1 + CK_OSC_RECEIPT_TEST=1` (TEST ONLY). The Store holds a01_valid_min.unit and 13 receipts minted by omega + checker2 with its TEST key. 17 launches of a01 add(a, b), one `osc_rcpt_launch:` line each: the valid receipt + RETURNS 3 and, after every refusal, 42; no receipt 64 MISSING; altered 75 BAD_SIGNATURE; replayed 77 + STALE_EPOCH; revoked id 76 REVOKED (`revoked=receipt_id`); revoked TEST key 76 REVOKED (`revoked=signer_key`); + expired 78; not yet valid 79; wrong target 80; l01's receipt 83 EXECUTABLE_MISMATCH; other program 82 + PROGRAM_MISMATCH; 417 bytes 65 SIZE; release policy 73 TEST_SIGNER_IN_PRODUCTION; firmware 81; dependency 88; + other checker 86 UNTRUSTED_CHECKER. Every refusal maps nothing (`ticks=0 pages_mapped=0`). +- The OSC_LAUNCH, OSH_CORE and OSH_OP children now put each unit's receipt in the Store; their launches pass + through the same check. +- Evidence class 2 is refused 96 LRAT_PROOFS_REQUIRED (host test only; no class 2 fixture is in the QEMU Store). +- Labels: QEMU (aarch64 virt), TEST signer, not physical. The physical Spark row stays NOT_RUN. + ## OSH_CORE: the Omega-native shell core as EL0 tasks, same step trace as Linux (OSH-AIENOS-0) -> CK `OSH_CORE` (scripts/qemu_ck_osh_core_test.sh) Label: **QEMU (aarch64 virt), TEST signer, not physical.** Three compiled OSC units (`lex_run`, `parse_run`, `expand_run`; real diff --git a/native/kernel/Makefile b/native/kernel/Makefile index 582bb097..b89d5ffe 100644 --- a/native/kernel/Makefile +++ b/native/kernel/Makefile @@ -820,6 +820,16 @@ $(error CK_OSC_LAUNCH_TEST needs CK_SEED0B_TEST_ANCHOR=1 (it launches TEST-signe endif ART_TRUST_FLAGS += -DCK_OSC_LAUNCH_TEST=1 endif +# aienos#383: the receipt self-test variant of the launch self-test (CK_OSC_LAUNCH_TEST=1 CK_OSC_RECEIPT_TEST=1) runs +# a fixed script of launches with valid, missing and refused realization receipts instead of the C3-3a script. +# TEST ONLY, QEMU only. +CK_OSC_RECEIPT_TEST ?= +ifeq ($(strip $(CK_OSC_RECEIPT_TEST)),1) +ifneq ($(strip $(CK_OSC_LAUNCH_TEST)),1) +$(error CK_OSC_RECEIPT_TEST needs CK_OSC_LAUNCH_TEST=1) +endif +ART_TRUST_FLAGS += -DCK_OSC_RECEIPT_TEST=1 +endif # OSH-AIENOS-0: the shell-core self-test (core/osh_test.c) runs the three osh units over embedded fixture scripts and # prints the step trace. TEST ONLY, QEMU only; not combined with the launch self-test. CK_OSH_TEST ?= @@ -893,7 +903,7 @@ endif # (argus), Ed25519/SHA-512 (sig). Built into the core so every image carries # the loader; the TEST-anchor qualification build is CK_SEED0B_TEST_ANCHOR=1. ART_C := $(KDIR)/core/artifact_loader.c $(KDIR)/core/osc_admit.c $(KDIR)/core/osc_task.c $(KDIR)/artifact/osc_launch.c $(KDIR)/artifact/format.c $(KDIR)/artifact/admission.c \ - $(KDIR)/artifact/receipt.c $(KDIR)/artifact/osc_unit.c $(NATIVE)/argus/sha256.c $(NATIVE)/sig/sha512.c \ + $(KDIR)/artifact/receipt.c $(KDIR)/artifact/osc_unit.c $(KDIR)/artifact/osc_receipt.c $(NATIVE)/argus/sha256.c $(NATIVE)/sig/sha512.c \ $(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) @@ -1320,7 +1330,7 @@ HOST_SRCS := $(KDIR)/core/fmt.c $(KDIR)/core/acpi.c $(KDIR)/core/smmu.c $(KDIR)/ $(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/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 \ +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_osc_receipt 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_artifact_card HCFLAGS := -std=gnu11 -O1 -g -Wall -Wextra -Werror -I$(KDIR)/core -I$(KDIR)/mm -I$(KDIR)/tests -I$(BOOT) @@ -1474,8 +1484,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 artifact-card-mutant artifact-tier-pi5 artifact-tier-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 artifact-tier-pi5 artifact-tier-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)) osc-receipt-mutants osc-receipt-release handoff-mutant acpi-dev-mutant iort-mutants smmu-l2-mutants osh-op-mutant context-mutant agent-cmd-mutant artifact-card-mutant artifact-tier-pi5 artifact-tier-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 osc-receipt-mutants osc-receipt-release handoff-mutant acpi-dev-mutant iort-mutants smmu-l2-mutants osh-op-mutant context-mutant agent-cmd-mutant artifact-card-mutant artifact-tier-pi5 artifact-tier-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)) @@ -1496,7 +1506,7 @@ $(OUT)/host/ck_udp_echo: $(KDIR)/tools/ck_udp_echo.c # Artifact library host test and the in-tree C artifact tool (pack, sign with # TEST keys, negative corpus, bundle, receipt check) used by the QEMU gate. -ART_HOST_SRCS := $(KDIR)/artifact/format.c $(KDIR)/artifact/admission.c $(KDIR)/artifact/receipt.c $(KDIR)/artifact/osc_unit.c $(KDIR)/artifact/osc_launch.c \ +ART_HOST_SRCS := $(KDIR)/artifact/format.c $(KDIR)/artifact/admission.c $(KDIR)/artifact/receipt.c $(KDIR)/artifact/osc_unit.c $(KDIR)/artifact/osc_receipt.c $(KDIR)/artifact/osc_launch.c \ $(NATIVE)/argus/sha256.c $(NATIVE)/sig/sha512.c $(NATIVE)/sig/ed25519.c $(NATIVE)/sig/ct.c ART_HOST_INC := -I$(KDIR)/artifact -I$(NATIVE)/sig -I$(NATIVE)/argus ART_HOST_DEPS := $(ART_HOST_SRCS) $(wildcard $(KDIR)/artifact/*.h) $(ART_HDRS) @@ -1556,6 +1566,51 @@ $(OUT)/host-san/test_osc_admit: $(KDIR)/tests/test_osc_admit.c $(KDIR)/core/osc_ @mkdir -p $(dir $@) $(HOSTCC) $(HCFLAGS) $(SANFLAGS) $(ART_HOST_INC) -I$(KDIR)/include -o $@ $< $(KDIR)/core/osc_admit.c $(ART_HOST_SRCS) +# aienos#383 realization receipts (artifact/osc_receipt.c): host test over the checker2-minted fixtures +# (tests/fixtures/osc_receipt) and the kernel's own policy (core/osc_admit.c, release and qualification builds), plus +# the mutation run: each MUT(n) guard of osc_receipt.c removed in turn (-DOSC_RCPT_MUTANT=n) must make the test FAIL. +# The run refuses a guard count that differs from OSC_RCPT_MUTANTS, and a kernel-side build of a mutant. +OSC_RCPT_MUTANTS := 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 +OSC_RCPT_TEST_DEF := -DOSC_RCPT_HOST_TEST -I$(KDIR)/include -DOSC_FIXTURE_DIR='"$(abspath $(KDIR)/tests/fixtures)"' +OSC_RCPT_TEST_SRCS := $(KDIR)/tests/test_osc_receipt.c $(KDIR)/core/osc_admit.c $(ART_HOST_SRCS) +$(OUT)/host/test_osc_receipt: $(KDIR)/tests/test_osc_receipt.c $(KDIR)/core/osc_admit.c $(ART_HOST_DEPS) $(KDIR)/tests/ck_test.h $(wildcard $(KDIR)/tests/fixtures/osc_receipt/*) + @mkdir -p $(dir $@) + $(HOSTCC) $(HCFLAGS) $(ART_HOST_INC) $(OSC_RCPT_TEST_DEF) -DCK_SEED0B_TEST_ANCHOR=1 -o $@ $(OSC_RCPT_TEST_SRCS) + +$(OUT)/host-san/test_osc_receipt: $(KDIR)/tests/test_osc_receipt.c $(KDIR)/core/osc_admit.c $(ART_HOST_DEPS) $(KDIR)/tests/ck_test.h $(wildcard $(KDIR)/tests/fixtures/osc_receipt/*) + @mkdir -p $(dir $@) + $(HOSTCC) $(HCFLAGS) $(SANFLAGS) $(ART_HOST_INC) $(OSC_RCPT_TEST_DEF) -DCK_SEED0B_TEST_ANCHOR=1 -o $@ $(OSC_RCPT_TEST_SRCS) + +# the same test against the release policy of core/osc_admit.c (no CK_SEED0B_TEST_ANCHOR): every TEST receipt refused +$(OUT)/host/test_osc_receipt_release: $(KDIR)/tests/test_osc_receipt.c $(KDIR)/core/osc_admit.c $(ART_HOST_DEPS) $(KDIR)/tests/ck_test.h $(wildcard $(KDIR)/tests/fixtures/osc_receipt/*) + @mkdir -p $(dir $@) + $(HOSTCC) $(HCFLAGS) $(ART_HOST_INC) $(OSC_RCPT_TEST_DEF) -o $@ $(OSC_RCPT_TEST_SRCS) + +osc-receipt-release: $(OUT)/host/test_osc_receipt_release + @$< + +osc-receipt-mutants: $(OUT)/host/test_osc_receipt + @mkdir -p $(OUT)/host-mut; fail=0; \ + tags=$$(grep -o 'MUT([0-9]*)' $(KDIR)/artifact/osc_receipt.c | sort -u | wc -l); \ + uses=$$(grep -o 'MUT([0-9]*)' $(KDIR)/artifact/osc_receipt.c | wc -l); \ + if [ $$tags != $(words $(OSC_RCPT_MUTANTS)) ] || [ $$uses != $$tags ]; then \ + echo "guard count: $$uses uses, $$tags distinct, $(words $(OSC_RCPT_MUTANTS)) mutants listed (FAIL)"; fail=1; fi; \ + $(OUT)/host/test_osc_receipt > $(OUT)/host-mut/osc_receipt_base.log 2>&1 || { echo "unmutated test_osc_receipt fails"; fail=1; }; \ + killed=0; \ + for m in $(OSC_RCPT_MUTANTS); do \ + b=$(OUT)/host-mut/test_osc_receipt_m$$m; \ + if ! $(HOSTCC) $(HCFLAGS) $(ART_HOST_INC) $(OSC_RCPT_TEST_DEF) -DCK_SEED0B_TEST_ANCHOR=1 -DOSC_RCPT_MUTANT=$$m -o $$b $(OSC_RCPT_TEST_SRCS); then \ + echo "mutant $$m: does not build (FAIL)"; fail=1; continue; fi; \ + if $$b > $$b.log 2>&1; then echo "mutant $$m: SURVIVED (FAIL)"; fail=1; \ + elif grep -q "^test_osc_receipt: FAIL" $$b.log; then killed=$$((killed + 1)); \ + echo "mutant $$m: killed ($$(grep -c '^ FAIL ' $$b.log) checks failed)"; \ + else echo "mutant $$m: no FAIL verdict (crashed?) (FAIL)"; fail=1; fi; \ + done; \ + if $(HOSTCC) $(HCFLAGS) $(ART_HOST_INC) -DOSC_RCPT_MUTANT=1 -fsyntax-only $(KDIR)/artifact/osc_receipt.c 2>/dev/null; then \ + echo "mutant flag accepted without OSC_RCPT_HOST_TEST (FAIL)"; fail=1; \ + else echo "mutant flag refused without OSC_RCPT_HOST_TEST"; fi; \ + if [ $$fail = 0 ]; then echo "CK_OSC_RECEIPT_MUTANTS: PASS ($$killed of $(words $(OSC_RCPT_MUTANTS)) killed)"; else echo "CK_OSC_RECEIPT_MUTANTS: FAIL"; exit 1; fi + # Continuity codec (C port cut 1, contract CONTINUITY_RECOVERY_CONTRACT.md, # aienos#222): host test plus TEST-only -D mutants, each of which must make # the test print its FAIL verdict. Mutant flags are refused under @@ -2208,7 +2263,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: artifact-tier-pi5 artifact-tier-mutant -.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 +.PHONY: osc-receipt-mutants osc-receipt-release 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/artifact/.crumb b/native/kernel/artifact/.crumb index f85ab2bc..9d28bf8a 100644 --- a/native/kernel/artifact/.crumb +++ b/native/kernel/artifact/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-14T02:20:15Z", + "compiled_at": "2026-10-14T19:55:50Z", "compiler": "crumb-compile/1", - "digest": "sha256:29a3372d4ab6170718cb870e8d586c94f9828a20755277bf052588376e47333e", + "digest": "sha256:243ae0c0be907222d5ae7105f655ee87020e18f47023ee53ca71d914e0ff4676", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 9, - "generated_at_commit": "7cd74cbbd0a45def4384618e7f82513c76021aad", - "source_tree": "sha256:97063e311a1ca103b8e9b5c82abbea0a70a928b172b050ec99a4dba8110e15c9" + "files": 13, + "generated_at_commit": "29a30a6c135f5840b90a64031ed8f532c84ed80a", + "source_tree": "sha256:2b5860c776f68affc13b988df8ad75963335bb0df6322c20ca0c469927ee55a0" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/artifact/osc_receipt.c b/native/kernel/artifact/osc_receipt.c new file mode 100644 index 00000000..930f877a --- /dev/null +++ b/native/kernel/artifact/osc_receipt.c @@ -0,0 +1,207 @@ +/* osc_receipt.c -- Omega realization receipt v1 verification. See osc_receipt.h and omega + * spec/one-layer-receipts.md. Written from the spec: section 2 (layout), 3 (signature), 5 (checker identity), + * 6 (order and reasons). One comment per step of section 6; the first failure decides the result. + * + * MUT(n) marks a guard the host mutation run (Makefile osc-receipt-mutants) removes, one at a time: with + * -DOSC_RCPT_MUTANT=n guard n is skipped and tests/test_osc_receipt.c must fail. Mutants build only with + * OSC_RCPT_HOST_TEST; a kernel build refuses the flag. */ +#include <string.h> +#include "osc_receipt.h" +#include "osc_receipt_anchor.h" +#include "aienos_sig.h" +#include "sha256.h" + +#ifdef OSC_RCPT_MUTANT +#ifndef OSC_RCPT_HOST_TEST +#error "receipt mutants are TEST-only host builds (OSC_RCPT_HOST_TEST)" +#endif +#define MUT(n) (OSC_RCPT_MUTANT == (n)) +#else +#define MUT(n) 0 +#endif + +static uint16_t rd16(const uint8_t *p) { return (uint16_t)(p[0] | (p[1] << 8)); } +static uint64_t rd64(const uint8_t *p) +{ + uint64_t v = 0; + for (int i = 7; i >= 0; i--) + v = (v << 8) | p[i]; + return v; +} + +/* constant time over the 32 bytes (keys, hashes, identities; AGENTS.md section 6) */ +static int eq32(const uint8_t *a, const uint8_t *b) +{ + uint8_t d = 0; + for (unsigned i = 0; i < 32; i++) + d |= (uint8_t)(a[i] ^ b[i]); + return d == 0; +} + +static int in_list(const uint8_t *v, const uint8_t (*list)[32], unsigned n) +{ + int hit = 0; + for (unsigned i = 0; list && i < n; i++) + hit |= eq32(v, list[i]); + return hit; +} + +/* Index of the anchor whose SHA-256 is fp, or -1. */ +static int anchor_by_fp(const uint8_t *fp, const uint8_t (*anchors)[32], unsigned n) +{ + int found = -1; + for (unsigned i = 0; anchors && i < n; i++) { + uint8_t h[32]; + sha256_hash(anchors[i], 32, h); + if (eq32(h, fp) && found < 0) + found = (int)i; + } + return found; +} + +void osc_receipt_target_hash(const char *name, size_t name_len, uint8_t out[32]) +{ + static const char dom[] = "OMEGA-TARGET-V1"; /* + its terminating NUL (16 bytes) */ + sha256_ctx c; + sha256_init(&c); + sha256_update(&c, (const uint8_t *)dom, sizeof dom); + sha256_update(&c, (const uint8_t *)name, name_len); + sha256_final(&c, out); +} + +/* SHA-256("OMEGA-RECEIPT-DEPS-V1\0" || u32 count = 0): the empty dependency list (spec section 2, offset 112). */ +static void empty_deps(uint8_t out[32]) +{ + static const char dom[] = "OMEGA-RECEIPT-DEPS-V1"; + static const uint8_t zero_count[4] = { 0, 0, 0, 0 }; + sha256_ctx c; + sha256_init(&c); + sha256_update(&c, (const uint8_t *)dom, sizeof dom); + sha256_update(&c, zero_count, sizeof zero_count); + sha256_final(&c, out); +} + +static const uint8_t zero32[32]; + +unsigned osc_receipt_verify(const uint8_t *r, size_t len, const struct osc_accept *a, const struct osc_policy *p, + struct osc_receipt_info *info) +{ + struct osc_receipt_info local; + if (!info) + info = &local; + memset(info, 0, sizeof *info); + if (!r || len == 0) + return OSC_RCPT_MISSING; + if (!a || !p) + return OSC_RCPT_ARGUMENT; + + /* 1. Structure: SIZE, MAGIC, VERSION, SIGNATURE_ALGORITHM, SIGNER_CLASS, EVIDENCE_CLASS, EPOCH_ORDER */ + if (!MUT(1) && len != OSC_RCPT_BYTES) + return OSC_RCPT_SIZE; + sha256_hash(r, OSC_RCPT_BYTES, info->id); + info->have_id = 1; + if (!MUT(2) && memcmp(r, "OMRCPT1\0", 8) != 0) + return OSC_RCPT_MAGIC; + if (!MUT(3) && rd16(r + 8) != 1) + return OSC_RCPT_VERSION; + unsigned cls = rd16(r + 10), alg = rd16(r + 12), ev = rd16(r + 14); + info->signer_class = (uint16_t)cls; + info->evidence_class = (uint16_t)ev; + info->policy_epoch = rd64(r + 304); + info->expiry_epoch = rd64(r + 312); + if (!MUT(4) && alg != 1) + return OSC_RCPT_SIGNATURE_ALGORITHM; + if (!MUT(5) && cls != OSC_SIGNER_TEST && cls != OSC_SIGNER_OWNER) + return OSC_RCPT_SIGNER_CLASS; + if (!MUT(6) && ev != 1 && ev != 2) + return OSC_RCPT_EVIDENCE_CLASS; + if (!MUT(7) && info->expiry_epoch < info->policy_epoch) + return OSC_RCPT_EPOCH_ORDER; + + /* 2. Class policy. Release mode is the spec's production mode: only OWNER receipts. The key comes from the + * verifier's own anchor set for the receipt's class, matched by fingerprint, never from the receipt. In + * release mode the only owner anchor honoured is the listed owner root; a key anchored in both classes is + * refused. */ + if (!MUT(8) && p->release && cls != OSC_SIGNER_OWNER) + return OSC_RCPT_TEST_SIGNER_IN_PRODUCTION; + const uint8_t *fp = r + 320; + const uint8_t (*mine)[32] = cls == OSC_SIGNER_TEST ? p->rcpt_test_anchors : p->rcpt_owner_anchors; + unsigned n_mine = cls == OSC_SIGNER_TEST ? p->n_rcpt_test : p->n_rcpt_owner; + int k = anchor_by_fp(fp, mine, n_mine); + if (!MUT(9) && k < 0) + return OSC_RCPT_UNTRUSTED_SIGNER; + if (k < 0) /* only reachable under mutant 9: there is no key to verify with */ + return OSC_RCPT_BAD_SIGNATURE; + const uint8_t *pk = mine[k]; + if (!MUT(10) && p->release && cls == OSC_SIGNER_OWNER && !eq32(pk, osc_rcpt_owner_root_pk)) + return OSC_RCPT_UNTRUSTED_SIGNER; + { + const uint8_t (*other)[32] = cls == OSC_SIGNER_TEST ? p->rcpt_owner_anchors : p->rcpt_test_anchors; + unsigned n_other = cls == OSC_SIGNER_TEST ? p->n_rcpt_owner : p->n_rcpt_test; + if (!MUT(11) && in_list(pk, other, n_other)) + return OSC_RCPT_UNTRUSTED_SIGNER; + } + + /* 3. Signature over "OMEGA-REALIZATION-RECEIPT-SIG-V1\0" || SHA-256("OMEGA-REALIZATION-RECEIPT-V1\0" || [0,352)) */ + { + static const char body_dom[] = "OMEGA-REALIZATION-RECEIPT-V1"; + static const char sig_dom[] = "OMEGA-REALIZATION-RECEIPT-SIG-V1"; + uint8_t msg[sizeof sig_dom + 32]; + sha256_ctx c; + memcpy(msg, sig_dom, sizeof sig_dom); + sha256_init(&c); + sha256_update(&c, (const uint8_t *)body_dom, sizeof body_dom); + sha256_update(&c, r, OSC_RCPT_SIGNED_BYTES); + sha256_final(&c, msg + sizeof sig_dom); + _Static_assert(sizeof msg == 65, "signed message is 65 bytes"); + if (!MUT(12) && aienos_ed25519_verify(r + OSC_RCPT_SIGNED_BYTES, msg, sizeof msg, pk) != AIENOS_SIG_OK) + return OSC_RCPT_BAD_SIGNATURE; + } + + /* 4. Revocation: receipt id, then signer key fingerprint */ + if (!MUT(13) && in_list(info->id, p->rcpt_revoked_ids, p->n_rcpt_revoked_ids)) { + info->revoked = OSC_RCPT_REVOKED_ID; + return OSC_RCPT_REVOKED; + } + if (!MUT(14) && in_list(fp, p->rcpt_revoked_keys, p->n_rcpt_revoked_keys)) { + info->revoked = OSC_RCPT_REVOKED_KEY; + return OSC_RCPT_REVOKED; + } + + /* 5. Freshness in policy epochs (no clock), window inclusive at both ends */ + if (!MUT(15) && info->policy_epoch < p->rcpt_epoch_floor) + return OSC_RCPT_STALE_EPOCH; + if (!MUT(16) && p->rcpt_epoch_now > info->expiry_epoch) + return OSC_RCPT_EXPIRED; + if (!MUT(17) && p->rcpt_epoch_now < info->policy_epoch) + return OSC_RCPT_NOT_YET_VALID; + + /* 6. Checker identity: in the accepted list (an empty list refuses every receipt) */ + if (!MUT(18) && !in_list(r + 144, p->rcpt_checkers, p->n_rcpt_checkers)) + return OSC_RCPT_UNTRUSTED_CHECKER; + + /* 7. Binding to the unit being launched */ + if (!MUT(19) && (!p->rcpt_target || !eq32(r + 208, p->rcpt_target))) + return OSC_RCPT_WRONG_TARGET; + if (!MUT(20) && !eq32(r + 240, p->rcpt_firmware ? p->rcpt_firmware : zero32)) + return OSC_RCPT_WRONG_FIRMWARE; + if (!MUT(21) && !eq32(r + 48, a->ir_sha256)) + return OSC_RCPT_PROGRAM_MISMATCH; + if (!MUT(22) && !eq32(r + 80, a->code_sha256)) + return OSC_RCPT_EXECUTABLE_MISMATCH; + if (!MUT(23) && !eq32(r + 176, p->rcpt_producer ? p->rcpt_producer : zero32)) + return OSC_RCPT_WRONG_PRODUCER; + { + uint8_t deps[32]; + empty_deps(deps); + if (!MUT(24) && !eq32(r + 112, deps)) + return OSC_RCPT_DEPENDENCIES_MISMATCH; + } + + /* 8. Evidence class 2 (spec section 10): valid only when the same LRAT proofs are given and replayed. The + * kernel is given none and has no LRAT checker, so class 2 is refused (fail closed). The spec does not place + * this check in the section 6 order; it runs last, after every section 6 step passed. */ + if (!MUT(25) && ev == 2) + return OSC_RCPT_LRAT_PROOFS_REQUIRED; + return 0; +} diff --git a/native/kernel/artifact/osc_receipt.h b/native/kernel/artifact/osc_receipt.h new file mode 100644 index 00000000..b782bf6e --- /dev/null +++ b/native/kernel/artifact/osc_receipt.h @@ -0,0 +1,92 @@ +/* osc_receipt.h -- verification of Omega realization receipts (receipt v1) for OSC unit launch (aienos#383). + * + * Contract: aien-dev/omega spec/one-layer-receipts.md (normative; section numbers below refer to it), the + * receipt format minted by omega's independent checker `checker2 receipt issue` (omega#448). This verifier was + * written from that spec; no checker2 code was copied. It reuses the in-tree SHA-256 (argus/sha256.c) and + * Ed25519 verify (sig/ed25519.c) and adds no crypto of its own. + * + * What a receipt says (spec section 1): checker2 judged one exact program (OSC IR) and accepted it, the + * executable is bound to it by hash only (evidence class 1 is NOT translation validation), and a key of a + * stated class vouches for that record. A receipt grants no capability: grants stay with the unit's + * capability table and the kernel's authority, unchanged. + * + * osc_receipt_verify is a pure function of (receipt bytes, admitted unit, policy): no allocation, no global + * state, no I/O. It runs AFTER osc_unit_admit accepted the unit and does not change admission. It returns 0 + * (the receipt is valid for this unit under this policy) or the FIRST refusal in the fixed order of spec + * section 6, as a kernel code OSC_RCPT_BASE + the spec's stable reason number. + * + * Bound to the admitted unit: program = the unit's ir_sha256 (section 1 hash), executable = its code_sha256, + * target = SHA-256("OMEGA-TARGET-V1\0" || OSC_RCPT_TARGET_NAME), firmware = none (all zero unless the policy + * names one), dependencies = the empty list (the kernel resolves no dependency receipts, so any claimed + * dependency is refused). Checker identity: required to be in the policy's list (an empty list refuses every + * receipt). Producer: none (all zero unless the policy names one; the unit carries no producer identity). NOT bound by a receipt: the container + * manifest (entry table, capability table, stack and tick budgets); those stay bound by the unit signature. + * Requirements and input fields are NOT CHECKED. Evidence class 2 (LRAT): spec section 10 makes a class 2 receipt + * valid only when its proofs are given and replayed; the kernel has no proofs and no LRAT checker, so it refuses + * class 2 as RECEIPT_LRAT_PROOFS_REQUIRED (fail closed; see docs/osc-receipts.md). */ +#ifndef AIENOS_CK_OSC_RECEIPT_H +#define AIENOS_CK_OSC_RECEIPT_H +#include <stddef.h> +#include <stdint.h> +#include "osc_unit.h" + +#define OSC_RCPT_BYTES 416u +#define OSC_RCPT_SIGNED_BYTES 352u +/* The kernel's target name (spec section 2, offset 208). Chosen for aienos#383: an OSC unit run as an EL0 task of + * the AIENOS C kernel on AArch64. Receipts for this kernel are issued with `--target aienos-ck-aarch64-el0`. */ +#define OSC_RCPT_TARGET_NAME "aienos-ck-aarch64-el0" + +/* Kernel refusal codes: OSC_RCPT_BASE + the spec section 6 reason number (stable). They share the osc_code + * space of osc_unit.h (osc_code_name names them "RECEIPT_<spec name>") and fit osc_result.refused_code. */ +#define OSC_RCPT_BASE 64u +enum osc_rcpt_code { + OSC_RCPT_MISSING = 64, /* kernel only: no receipt came with the unit */ + OSC_RCPT_SIZE = 65, /* 1: not exactly 416 bytes */ + OSC_RCPT_MAGIC = 66, /* 2 */ + OSC_RCPT_VERSION = 67, /* 3 */ + OSC_RCPT_SIGNATURE_ALGORITHM = 68, /* 4 */ + OSC_RCPT_SIGNER_CLASS = 69, /* 5 */ + OSC_RCPT_EVIDENCE_CLASS = 70, /* 6 */ + OSC_RCPT_EPOCH_ORDER = 71, /* 7: expiry below the policy epoch */ + OSC_RCPT_TEST_SIGNER_IN_PRODUCTION = 73, /* 9: release mode and not OWNER */ + OSC_RCPT_UNTRUSTED_SIGNER = 74, /* 10 */ + OSC_RCPT_BAD_SIGNATURE = 75, /* 11 */ + OSC_RCPT_REVOKED = 76, /* 12: receipt id, then signer key fingerprint */ + OSC_RCPT_STALE_EPOCH = 77, /* 13: policy epoch below the floor (replay of a superseded receipt) */ + OSC_RCPT_EXPIRED = 78, /* 14 */ + OSC_RCPT_NOT_YET_VALID = 79, /* 15 */ + OSC_RCPT_WRONG_TARGET = 80, /* 16 */ + OSC_RCPT_WRONG_FIRMWARE = 81, /* 17 */ + OSC_RCPT_PROGRAM_MISMATCH = 82, /* 18 */ + OSC_RCPT_EXECUTABLE_MISMATCH = 83, /* 19 */ + OSC_RCPT_ARGUMENT = 84, /* 20: verifier called without a unit or a policy */ + OSC_RCPT_UNTRUSTED_CHECKER = 86, /* 22 */ + OSC_RCPT_WRONG_PRODUCER = 87, /* 23 */ + OSC_RCPT_DEPENDENCIES_MISMATCH = 88, /* 24 */ + /* kernel-assigned: spec section 10 names LRAT-PROOFS-REQUIRED without a number. The kernel is given no LRAT + * proofs, so every evidence class 2 receipt that passes the section 6 steps is refused with it. */ + OSC_RCPT_LRAT_PROOFS_REQUIRED = 96 +}; + +enum { OSC_RCPT_REVOKED_ID = 1, OSC_RCPT_REVOKED_KEY = 2 }; + +/* Facts about a receipt, filled as far as the verifier got (id once the length is right, the rest after the + * structure checks). Diagnostic only: nothing here is authority. */ +struct osc_receipt_info { + uint8_t id[32]; /* SHA-256 of the 416 bytes (spec section 2) */ + uint16_t signer_class; /* OSC_SIGNER_TEST or OSC_SIGNER_OWNER */ + uint16_t evidence_class; /* 1 IR_CHECKED, 2 IR_CHECKED_LRAT (refused: no proofs to replay) */ + uint64_t policy_epoch, expiry_epoch; + unsigned revoked; /* OSC_RCPT_REVOKED_ID or OSC_RCPT_REVOKED_KEY when the verdict is REVOKED */ + int have_id; +}; + +/* 0: valid for unit *a under *p. Else the first refusal code (OSC_RCPT_*). r == NULL or len == 0 is + * OSC_RCPT_MISSING. info may be NULL. */ +unsigned osc_receipt_verify(const uint8_t *r, size_t len, const struct osc_accept *a, const struct osc_policy *p, + struct osc_receipt_info *info); + +/* SHA-256("OMEGA-TARGET-V1\0" || name) (spec section 2, offset 208). */ +void osc_receipt_target_hash(const char *name, size_t name_len, uint8_t out[32]); + +#endif diff --git a/native/kernel/artifact/osc_receipt_anchor.h b/native/kernel/artifact/osc_receipt_anchor.h new file mode 100644 index 00000000..3ab0c0a0 --- /dev/null +++ b/native/kernel/artifact/osc_receipt_anchor.h @@ -0,0 +1,23 @@ +/* osc_receipt_anchor.h -- receipt trust inputs that are not TEST material (aienos#383). + * + * osc_rcpt_owner_root_pk: Drake's owner root public key from the aienos#380 ceremony + * (docs/OWNER_KEY_CEREMONY.md; the private key lives on a YubiKey, PIV slot 9c). It is LISTED here so that a + * release-mode verifier can honour no other owner anchor (omega spec/one-layer-receipts.md section 6 step 2), + * but it is NOT TRUSTED for receipts: no kernel policy puts it in rcpt_owner_anchors until + * docs/OWNER_KEY_CEREMONY.md records that it may sign realization receipts. Nothing in this repository signs + * with it. tests/test_osc_receipt.c checks that the release and qualification policies do not trust it. + * + * osc_rcpt_checker_ids: the accepted checker2 identities (spec section 5). One entry: checker2 of omega + * 265ce82a (omega#448), `checker2 version` checker_id. A changed checker2 has a new identity and its receipts are + * refused UNTRUSTED_CHECKER until it is added here. */ +#ifndef AIENOS_CK_OSC_RECEIPT_ANCHOR_H +#define AIENOS_CK_OSC_RECEIPT_ANCHOR_H +#include <stdint.h> +static const uint8_t osc_rcpt_owner_root_pk[32] = { + 0x57, 0x8a, 0xda, 0x3c, 0xb0, 0xc2, 0xd1, 0x54, 0x62, 0x3a, 0xc0, 0x89, 0x19, 0x10, 0x23, 0xc8, + 0xad, 0x4b, 0xc5, 0xe6, 0x3b, 0x8c, 0xcd, 0x1a, 0x38, 0xdb, 0x2d, 0x67, 0x9b, 0x8c, 0x9e, 0x76}; +#define OSC_RCPT_N_CHECKERS 1u +static const uint8_t osc_rcpt_checker_ids[OSC_RCPT_N_CHECKERS][32] = { { + 0xd7, 0xaa, 0xe6, 0x01, 0xe7, 0x32, 0xb4, 0xb1, 0x45, 0xc7, 0x3e, 0x8d, 0x4f, 0x92, 0x76, 0x9f, + 0x56, 0xda, 0xc2, 0xe6, 0xfb, 0xa5, 0xf7, 0x7a, 0xed, 0x49, 0x0a, 0xec, 0x42, 0x9c, 0xf3, 0xba} }; +#endif diff --git a/native/kernel/artifact/osc_receipt_test_anchor.h b/native/kernel/artifact/osc_receipt_test_anchor.h new file mode 100644 index 00000000..2155857e --- /dev/null +++ b/native/kernel/artifact/osc_receipt_test_anchor.h @@ -0,0 +1,23 @@ +/* osc_receipt_test_anchor.h -- THROWAWAY TEST material for realization receipts (aienos#383). It protects nothing. + * + * osc_rcpt_test_pk: omega checker2's TEST receipt key (omega spec/one-layer-receipts.md section 3, class TEST), + * seed = SHA-256("OMEGA-CHECKER2-TEST-KEY-v1 NOT FOR PRODUCTION"), public on purpose. This is NOT the OSC unit + * container TEST key (osc_unit_test_anchor.h, aien-protocols test1): the two keys sign different things and are + * anchored separately. tests/test_osc_receipt.c checks these bytes against the checker2-minted fixtures + * (tests/fixtures/osc_receipt, PROVENANCE.txt). + * + * osc_rcpt_qual_revoked_id: the id of tests/fixtures/osc_receipt/n_revoked_id.rcpt, on the qualification + * policy's revoked-id list so the REVOKED path is exercised (test checks it is that file's SHA-256). + * + * Compiled only into the host tests and into the TEST-anchor qualification image (CK_SEED0B_TEST_ANCHOR=1, + * banner "TEST ONLY"); never into a release image's anchor set. */ +#ifndef AIENOS_CK_OSC_RECEIPT_TEST_ANCHOR_H +#define AIENOS_CK_OSC_RECEIPT_TEST_ANCHOR_H +#include <stdint.h> +static const uint8_t osc_rcpt_test_pk[32] = { + 0x60, 0x28, 0x10, 0xd4, 0x3c, 0x01, 0x15, 0xdf, 0x87, 0x7b, 0x0c, 0xf8, 0xc3, 0x27, 0x01, 0x0e, + 0x5a, 0x7e, 0x57, 0x04, 0x90, 0xc8, 0x5e, 0x31, 0x46, 0x6c, 0x0c, 0xff, 0x6c, 0xa3, 0x74, 0xc5}; +static const uint8_t osc_rcpt_qual_revoked_id[32] = { + 0xe4, 0x52, 0x12, 0xd1, 0xea, 0x69, 0x56, 0xe4, 0xef, 0x65, 0xb9, 0xa8, 0x39, 0xda, 0x20, 0xaf, + 0x3f, 0xf9, 0xbd, 0x53, 0xc5, 0x66, 0xcd, 0x23, 0x3a, 0x6a, 0xe2, 0x6c, 0xad, 0x65, 0x8f, 0xf3}; +#endif diff --git a/native/kernel/artifact/osc_unit.c b/native/kernel/artifact/osc_unit.c index 5aa40a21..7c419ae8 100644 --- a/native/kernel/artifact/osc_unit.c +++ b/native/kernel/artifact/osc_unit.c @@ -39,6 +39,19 @@ const char *osc_code_name(unsigned code) return "LAUNCH_BAD_ENTRY"; if (code == OSC_LAUNCH_ARG_SHAPE) return "LAUNCH_ARG_SHAPE"; + /* Realization receipt refusals (artifact/osc_receipt.h): 64 + the omega receipt spec's reason number. */ + static const char *const rcpt_names[] = { + [0] = "RECEIPT_MISSING", [1] = "RECEIPT_SIZE", [2] = "RECEIPT_MAGIC", [3] = "RECEIPT_VERSION", + [4] = "RECEIPT_SIGNATURE_ALGORITHM", [5] = "RECEIPT_SIGNER_CLASS", [6] = "RECEIPT_EVIDENCE_CLASS", + [7] = "RECEIPT_EPOCH_ORDER", [9] = "RECEIPT_TEST_SIGNER_IN_PRODUCTION", [10] = "RECEIPT_UNTRUSTED_SIGNER", + [11] = "RECEIPT_BAD_SIGNATURE", [12] = "RECEIPT_REVOKED", [13] = "RECEIPT_STALE_EPOCH", + [14] = "RECEIPT_EXPIRED", [15] = "RECEIPT_NOT_YET_VALID", [16] = "RECEIPT_WRONG_TARGET", + [17] = "RECEIPT_WRONG_FIRMWARE", [18] = "RECEIPT_PROGRAM_MISMATCH", [19] = "RECEIPT_EXECUTABLE_MISMATCH", + [20] = "RECEIPT_ARGUMENT", [22] = "RECEIPT_UNTRUSTED_CHECKER", [23] = "RECEIPT_WRONG_PRODUCER", + [24] = "RECEIPT_DEPENDENCIES_MISMATCH", [32] = "RECEIPT_LRAT_PROOFS_REQUIRED", + }; + if (code >= 64 && code - 64 < sizeof rcpt_names / sizeof rcpt_names[0] && rcpt_names[code - 64]) + return rcpt_names[code - 64]; return "?"; } diff --git a/native/kernel/artifact/osc_unit.h b/native/kernel/artifact/osc_unit.h index 92ee4db6..447a60ac 100644 --- a/native/kernel/artifact/osc_unit.h +++ b/native/kernel/artifact/osc_unit.h @@ -95,6 +95,23 @@ struct osc_policy { /* Step 16: nonzero refuses with RESOURCE_UNAVAILABLE. NULL: reservation succeeds. */ int (*reserve)(void *ctx, const struct osc_accept *a); void *ctx; + /* Realization receipts (artifact/osc_receipt.h, aienos#383): read only by osc_receipt_verify, never by + * osc_unit_admit. Local authority, never taken from a receipt. `release` above also refuses TEST receipts. */ + const uint8_t (*rcpt_test_anchors)[32]; /* raw Ed25519 public keys, receipt class TEST */ + unsigned n_rcpt_test; + const uint8_t (*rcpt_owner_anchors)[32]; /* receipt class OWNER; empty until the owner key ceremony says so */ + unsigned n_rcpt_owner; + const uint8_t (*rcpt_checkers)[32]; /* accepted checker2 identities; none: every receipt is refused */ + unsigned n_rcpt_checkers; + const uint8_t (*rcpt_revoked_ids)[32]; /* revoked receipt ids (SHA-256 of the 416 bytes) */ + unsigned n_rcpt_revoked_ids; + const uint8_t (*rcpt_revoked_keys)[32]; /* revoked signer key fingerprints (SHA-256 of the public key) */ + unsigned n_rcpt_revoked_keys; + uint64_t rcpt_epoch_floor; /* receipts issued under an older policy epoch are replays */ + uint64_t rcpt_epoch_now; /* the kernel's current policy epoch (no clock) */ + const uint8_t *rcpt_target; /* 32-byte target hash; NULL: every receipt is WRONG_TARGET */ + const uint8_t *rcpt_firmware; /* 32-byte firmware hash; NULL: none (all zero) */ + const uint8_t *rcpt_producer; /* 32-byte producer identity; NULL: none (all zero) */ }; /* 0 accepted (*out filled), else the first refusal code. out may be NULL only if the caller diff --git a/native/kernel/core/.crumb b/native/kernel/core/.crumb index cbc47a56..3750c915 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-14T01:54:45Z", + "compiled_at": "2026-10-14T19:55:50Z", "compiler": "crumb-compile/1", - "digest": "sha256:9333ad224a18c87c3e0e241c69209b761a27f72d7f2067354f0658b917cd77ef", + "digest": "sha256:b9bbf4b8af5e31c209a7e31e2ceaab640969dd762058218763857c73aef02d38", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 69, - "generated_at_commit": "8307a68a2eedcc5c8d6c2a6ffbf7c12f398c094b", - "source_tree": "sha256:d7b7e5c99b8d6cdb89349e4d4e2aa115ea53302976425ee3bf5da97fb302f0d0" + "generated_at_commit": "29a30a6c135f5840b90a64031ed8f532c84ed80a", + "source_tree": "sha256:2be7b723b4c00aa3332bdbae1d60e2a1608804f39eaf72d1511281dc9597d8c1" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/core/artifact_loader.c b/native/kernel/core/artifact_loader.c index 8ceee3eb..fe1d7fd9 100644 --- a/native/kernel/core/artifact_loader.c +++ b/native/kernel/core/artifact_loader.c @@ -1182,6 +1182,12 @@ static uint32_t disk_source(void) run_seen++; continue; } + if (a->state == CK_DISK_ART_OK && a->bytes && ck_osc_is_receipt(a->bytes, a->len)) { + /* Omega realization receipt (aienos#383): kept for the launch that presents it, never an artifact. */ + ck_osc_receipt_candidate(name, a->bytes, a->len); + run_seen++; + continue; + } if (a->state == CK_DISK_ART_OK && a->bytes && a->len >= 1 && a->len <= MAX_BATCH * PAGE) process_candidate(a->bytes, a->len, &rep); else if (a->state == CK_DISK_ART_TOO_LARGE || a->len > MAX_BATCH * PAGE) { diff --git a/native/kernel/core/osc_admit.c b/native/kernel/core/osc_admit.c index 63d958c6..cc777872 100644 --- a/native/kernel/core/osc_admit.c +++ b/native/kernel/core/osc_admit.c @@ -14,12 +14,16 @@ #include "ck_internal.h" #include "osc_admit.h" #include "osc_unit.h" +#include "osc_receipt.h" +#include "osc_receipt_anchor.h" +#include "sha256.h" #ifdef CK_OSH_TEST void ck_osh_save(const char *name, const uint8_t *b, size_t len, const struct osc_accept *acc); void ck_osh_all(void); #endif #ifdef CK_SEED0B_TEST_ANCHOR #include "osc_unit_test_anchor.h" +#include "osc_receipt_test_anchor.h" #endif static unsigned seen, accepted, refused, oversize, announced; @@ -45,7 +49,24 @@ static void hex(char *out, const uint8_t *b, size_t n) out[2 * n] = 0; } -static void policy(struct osc_policy *p) +/* Realization receipt policy (artifact/osc_receipt.h, aienos#383), local to this build: + * - both builds: the accepted checker2 identities of osc_receipt_anchor.h, target aienos-ck-aarch64-el0, no + * firmware, no dependencies, no producer (all zero: the unit names no producer), epoch floor and current epoch + * fixed below (the kernel has no epoch authority yet, so they are compile-time constants), no OWNER receipt + * anchor (the owner root is listed, not trusted, until docs/OWNER_KEY_CEREMONY.md says so). + * - release build: release mode, so every TEST receipt is TEST_SIGNER_IN_PRODUCTION; no receipt anchor at all, + * so no receipt is valid and nothing can be launched. + * - qualification build (CK_SEED0B_TEST_ANCHOR=1): checker2's TEST key as the only receipt anchor and the + * fixture n_revoked_id.rcpt on the revoked-id list (osc_receipt_test_anchor.h). TEST ONLY. */ +#define CK_OSC_RCPT_EPOCH_FLOOR 10u +#define CK_OSC_RCPT_EPOCH_NOW 20u +static uint8_t rcpt_target[32]; +#ifdef CK_OSC_LAUNCH_TEST +int ck_osc_rcpt_variant; /* TEST ONLY: 1 release mode, 2 the TEST key fingerprint revoked (receipt self-test) */ +static uint8_t rcpt_test_fp[1][32]; +#endif + +void ck_osc_policy(struct osc_policy *p) { memset(p, 0, sizeof *p); p->unit_formats = OSC_PROFILE_UNIT_FORMATS; @@ -53,14 +74,92 @@ static void policy(struct osc_policy *p) p->cap_domains = 1u << 1; p->staging_max = OSC_STAGING_MAX; p->gen_lookup = no_resource; + osc_receipt_target_hash(OSC_RCPT_TARGET_NAME, sizeof OSC_RCPT_TARGET_NAME - 1, rcpt_target); + p->rcpt_checkers = osc_rcpt_checker_ids; + p->n_rcpt_checkers = OSC_RCPT_N_CHECKERS; + p->rcpt_epoch_floor = CK_OSC_RCPT_EPOCH_FLOOR; + p->rcpt_epoch_now = CK_OSC_RCPT_EPOCH_NOW; + p->rcpt_target = rcpt_target; #ifdef CK_SEED0B_TEST_ANCHOR static const uint8_t (*const ta)[32] = &osc_unit_test1_pk; + static const uint8_t (*const rta)[32] = &osc_rcpt_test_pk; + static const uint8_t (*const rid)[32] = &osc_rcpt_qual_revoked_id; p->release = 0; p->test_anchors = ta; p->n_test = 1; + p->rcpt_test_anchors = rta; + p->n_rcpt_test = 1; + p->rcpt_revoked_ids = rid; + p->n_rcpt_revoked_ids = 1; #else p->release = 1; #endif +#ifdef CK_OSC_LAUNCH_TEST + if (ck_osc_rcpt_variant == 1) + p->release = 1; + if (ck_osc_rcpt_variant == 2) { + sha256_hash(osc_rcpt_test_pk, 32, rcpt_test_fp[0]); + p->rcpt_revoked_keys = (const uint8_t (*)[32])rcpt_test_fp; + p->n_rcpt_revoked_keys = 1; + } +#endif +} + +/* ---- receipts that arrived through the Store, kept by name until a launch asks for one ---- */ +#define RCPT_SLOTS 24u +#define RCPT_KEEP 512u /* more than 416 so a wrong-length receipt reaches the verifier and is refused SIZE */ +static struct { + char name[33]; + uint8_t bytes[RCPT_KEEP]; + size_t len; +} rcpt[RCPT_SLOTS]; +static unsigned rcpt_n, rcpt_seen, rcpt_dropped; + +static int name_eq(const char *a, const char *b) +{ + size_t n = strlen(a); + return n == strlen(b) && memcmp(a, b, n) == 0; +} + +int ck_osc_is_receipt(const uint8_t *b, size_t len) +{ + return b && len >= 8 && memcmp(b, "OMRCPT1\0", 8) == 0; +} + +void ck_osc_receipt_candidate(const char *name, const uint8_t *b, size_t len) +{ + rcpt_seen++; + size_t nl = strlen(name); + if (rcpt_n >= RCPT_SLOTS || nl >= sizeof rcpt[0].name) { + rcpt_dropped++; + ck_printf("osc_receipt: %s DROPPED (receipt table full or name too long; a launch that needs it is refused " + "RECEIPT_MISSING)\n", name); + return; + } + memcpy(rcpt[rcpt_n].name, name, nl + 1); + /* a receipt longer than RCPT_KEEP is kept as its first RCPT_KEEP bytes: still not 416, so refused SIZE */ + rcpt[rcpt_n].len = len <= RCPT_KEEP ? len : RCPT_KEEP; + memcpy(rcpt[rcpt_n].bytes, b, rcpt[rcpt_n].len); + char idh[65] = "-"; + if (len == OSC_RCPT_BYTES) { + uint8_t id[32]; + sha256_hash(b, len, id); + hex(idh, id, 32); + } + ck_printf("osc_receipt: %s STORED bytes=%llu id=%s (verified at launch against the unit launched)\n", name, + (unsigned long long)len, idh); + rcpt_n++; +} + +const uint8_t *ck_osc_receipt_find(const char *name, size_t *len) +{ + *len = 0; + for (unsigned i = 0; name && i < rcpt_n; i++) + if (name_eq(rcpt[i].name, name)) { + *len = rcpt[i].len; + return rcpt[i].bytes; + } + return 0; } @@ -113,8 +212,21 @@ struct lt_step { const char *in; int ws; /* 0 none, 1..2 which caller workspace */ uint64_t cap; + const char *rcpt; /* receipt Store entry; NULL: the unit's own (lt_rcpt_for), "-": none */ + int variant; /* receipt policy variant for this launch (ck_osc_rcpt_variant): 0 qual, 1 release, 2 revoked key */ }; +/* The receipt of each launched unit: a receipt binds the IR and the code, so l02 (l01 with a bigger stack) shares + * l01's and a06 (a01's IR and code, other limits) shares a01's. */ +static const char *lt_rcpt_for(const char *unit) +{ + if (lt_streq(unit, "a01_valid_min.unit") || lt_streq(unit, "a06_valid_limits_at_max.unit")) + return "a01.rcpt"; + if (lt_streq(unit, "l01_launch_fns.unit") || lt_streq(unit, "l02_stack_over.unit")) + return "l01.rcpt"; + return "-"; +} + extern void ck_osc_state_range(uint64_t *addr, uint64_t *len); static uint8_t lt_ws_mem1[4 * 4096], lt_ws_mem2[4 * 4096], lt_ws_mem3[23 * 4096], lt_ws_mem4[33 * 4096] __attribute__((aligned(4096))); @@ -150,7 +262,12 @@ static void lt_run(const struct lt_step *s) rq.ws = <_ws[s->ws - 1]; struct osc_result r; struct ck_osc_launch_info info; - ck_osc_launch(lt_unit[u].bytes, lt_unit[u].len, <_unit[u].acc, &rq, &r, &info); + const char *rn = s->rcpt ? s->rcpt : lt_rcpt_for(s->unit); + size_t rlen = 0; + const uint8_t *rb = lt_streq(rn, "-") ? 0 : ck_osc_receipt_find(rn, &rlen); + ck_osc_rcpt_variant = s->variant; + ck_osc_launch(lt_unit[u].bytes, lt_unit[u].len, <_unit[u].acc, rb, rlen, &rq, &r, &info); + ck_osc_rcpt_variant = 0; char rs[96], as[80]; ck_osc_result_str(&r, rs, sizeof rs); unsigned n = 0; @@ -166,18 +283,73 @@ static void lt_run(const struct lt_step *s) else n += (unsigned)ck_snprintf(as + n, sizeof as - n, "%s%llu", i ? "," : "", (unsigned long long)v); } +#ifdef CK_OSC_RECEIPT_TEST + static const char *const vname[3] = { "qualification", "release", "revoked_test_key" }; + char idh[17] = "-"; + if (info.rcpt.have_id) + hex(idh, info.rcpt.id, 8); + ck_printf("osc_rcpt_launch: %s %s(%s) receipt=%s policy=%s -> %s receipt_id=%s revoked=%s ticks=%llu " + "pages_mapped=%u page_tables_zeroed=%u slot_free=%u; QEMU (aarch64 virt), TEST signer, not physical\n", + s->unit, s->fn, as, rb ? rn : "none", vname[s->variant], rs, idh, + info.rcpt.revoked == OSC_RCPT_REVOKED_ID ? "receipt_id" + : info.rcpt.revoked == OSC_RCPT_REVOKED_KEY ? "signer_key" : "-", + (unsigned long long)r.ticks, info.pages_mapped, (unsigned)info.tables_zeroed, + (unsigned)info.slot_free_after); +#else ck_printf("osc_launch: %s %s(%s) -> %s ticks=%llu budget=%llu pages_mapped=%u page_tables_zeroed=%u slot_free=%u; " "QEMU (aarch64 virt), TEST signer, not physical\n", s->unit, s->fn, as, rs, (unsigned long long)r.ticks, (unsigned long long)info.budget, info.pages_mapped, (unsigned)info.tables_zeroed, (unsigned)info.slot_free_after); +#endif lt_counts[r.cls]++; return; } ck_printf("osc_launch: %s %s -> NOT_RUN (unit was not admitted)\n", s->unit, s->fn); } +#ifdef CK_OSC_RECEIPT_TEST +/* aienos#383 receipt self-test: every launch of a01_valid_min.unit add(a, b), each with one receipt from the Store + * (tests/fixtures/osc_receipt, minted by omega checker2 with its TEST key) or none. Only the valid receipt may run + * the unit; every refusal names its reason and maps nothing. Variant 1 and 2 change the policy for that one launch + * (release mode; the TEST key fingerprint revoked), to show the release rule and key revocation in one boot. */ +static void rt_all(void) +{ + static const struct lt_step steps[] = { + { "a01_valid_min.unit", "add", 2, { 1, 2 }, 0, 0, 0, "a01.rcpt", 0 }, + { "a01_valid_min.unit", "add", 2, { 2, 3 }, 0, 0, 0, "-", 0 }, + { "a01_valid_min.unit", "add", 2, { 3, 4 }, 0, 0, 0, "n_altered.rcpt", 0 }, + { "a01_valid_min.unit", "add", 2, { 4, 5 }, 0, 0, 0, "n_stale.rcpt", 0 }, + { "a01_valid_min.unit", "add", 2, { 5, 6 }, 0, 0, 0, "n_revoked_id.rcpt", 0 }, + { "a01_valid_min.unit", "add", 2, { 6, 7 }, 0, 0, 0, "a01.rcpt", 2 }, + { "a01_valid_min.unit", "add", 2, { 7, 8 }, 0, 0, 0, "n_expired.rcpt", 0 }, + { "a01_valid_min.unit", "add", 2, { 8, 9 }, 0, 0, 0, "n_future.rcpt", 0 }, + { "a01_valid_min.unit", "add", 2, { 9, 10 }, 0, 0, 0, "n_target.rcpt", 0 }, + { "a01_valid_min.unit", "add", 2, { 10, 11 }, 0, 0, 0, "l01.rcpt", 0 }, + { "a01_valid_min.unit", "add", 2, { 11, 12 }, 0, 0, 0, "n_program.rcpt", 0 }, + { "a01_valid_min.unit", "add", 2, { 12, 13 }, 0, 0, 0, "n_length.rcpt", 0 }, + { "a01_valid_min.unit", "add", 2, { 13, 14 }, 0, 0, 0, "a01.rcpt", 1 }, + { "a01_valid_min.unit", "add", 2, { 14, 15 }, 0, 0, 0, "n_firmware.rcpt", 0 }, + { "a01_valid_min.unit", "add", 2, { 15, 16 }, 0, 0, 0, "n_deps.rcpt", 0 }, + { "a01_valid_min.unit", "add", 2, { 16, 17 }, 0, 0, 0, "n_checker.rcpt", 0 }, + { "a01_valid_min.unit", "add", 2, { 20, 22 }, 0, 0, 0, "a01.rcpt", 0 }, + }; + ck_printf("osc_rcpt_selftest: launches=%u unit=a01_valid_min.unit; QEMU (aarch64 virt), TEST signer, not physical\n", + (unsigned)(sizeof steps / sizeof steps[0])); + for (unsigned i = 0; i < sizeof steps / sizeof steps[0]; i++) + lt_run(&steps[i]); + ck_printf("osc_rcpt_launches: returned=%u trapped=%u refused=%u unknown=%u; QEMU (aarch64 virt), TEST signer, not " + "physical\n", + lt_counts[OSC_RES_RETURNED], lt_counts[OSC_RES_TRAPPED], lt_counts[OSC_RES_REFUSED], + lt_counts[OSC_RES_UNKNOWN]); +} +#endif + static void lt_all(void) { +#ifdef CK_OSC_RECEIPT_TEST + rt_all(); + return; +#endif uint64_t sa, sl; ck_osc_state_range(&sa, &sl); lt_ws[6].mem = (uint8_t *)(uintptr_t)sa; /* a workspace aimed at the launcher's own state */ @@ -185,50 +357,50 @@ static void lt_all(void) memcpy(lt_ws_mem2 + 64, "Zeta", 5); /* an input buffer that lies inside workspace 8 (index 7) */ *(uint32_t *)(lt_ws_mem1 + 512) = 0xd65f03c0u; /* a valid `ret` in workspace 1, cell 64, for jump_ws */ static const struct lt_step steps[] = { - { "a01_valid_min.unit", "add", 2, { 1000000007, 998244353 }, 0, 0, 0 }, - { "a01_valid_min.unit", "add", 1, { 5 }, 0, 0, 0 }, - { "a01_valid_min.unit", "nosuch", 0, { 0 }, 0, 0, 0 }, - { "a01_valid_min.unit", "ADD", 2, { 1, 2 }, 0, 0, 0 }, - { "a01_valid_min.unit", "first_byte", 2, { IN_PTR, 4 }, "Zeta", 0, 0 }, - { "a01_valid_min.unit", "first_byte", 2, { 0x1000, 16 }, "Zeta", 0, 0 }, - { "l01_launch_fns.unit", "trap", 1, { 3 }, 0, 0, 0 }, - { "l01_launch_fns.unit", "trap", 1, { 14 }, 0, 0, 0 }, - { "l01_launch_fns.unit", "trap", 1, { 15 }, 0, 0, 0 }, - { "l01_launch_fns.unit", "bare_brk", 0, { 0 }, 0, 0, 0 }, - { "l01_launch_fns.unit", "spin", 0, { 0 }, 0, 0, 5 }, - { "a01_valid_min.unit", "add", 2, { 40, 2 }, 0, 0, 0 }, - { "l01_launch_fns.unit", "peek0", 0, { 0 }, 0, 0, 0 }, - { "a01_valid_min.unit", "add", 2, { 20, 22 }, 0, 0, 0 }, - { "l01_launch_fns.unit", "poke_rt", 0, { 0 }, 0, 0, 0 }, - { "l01_launch_fns.unit", "exec_stack", 0, { 0 }, 0, 0, 0 }, - { "l01_launch_fns.unit", "overflow", 0, { 0 }, 0, 0, 0 }, - { "a01_valid_min.unit", "add", 2, { 6, 36 }, 0, 0, 0 }, - { "l01_launch_fns.unit", "counter", 2, { WS_PTR, 1 }, 0, 1, 0 }, - { "l01_launch_fns.unit", "counter", 2, { WS_PTR, 1 }, 0, 1, 0 }, - { "l01_launch_fns.unit", "counter", 2, { WS_PTR, 1 }, 0, 1, 0 }, - { "l01_launch_fns.unit", "counter", 2, { WS_PTR, 1 }, 0, 2, 0 }, - { "l01_launch_fns.unit", "counter", 2, { WS_PTR | 4, 1 }, 0, 1, 0 }, - { "l01_launch_fns.unit", "counter", 2, { WS_PTR | 94200, 1 }, 0, 3, 0 }, - { "l01_launch_fns.unit", "counter", 2, { WS_PTR | 94200, 1 }, 0, 3, 0 }, - { "l01_launch_fns.unit", "counter", 2, { WS_PTR, 1 }, 0, 4, 0 }, - { "a06_valid_limits_at_max.unit", "add", 2, { 1, 2 }, 0, 0, 0 }, - { "l02_stack_over.unit", "peek0", 0, { 0 }, 0, 0, 0 }, - { "a01_valid_min.unit", "add", 2, { 3, 4 }, 0, 0, 0 }, - { "l01_launch_fns.unit", "peek_kernel", 1, { KERN_PTR }, 0, 0, 0 }, - { "a01_valid_min.unit", "add", 2, { 5, 6 }, 0, 0, 0 }, - { "l01_launch_fns.unit", "jump_ws", 2, { WS_PTR | 512, 1 }, 0, 1, 0 }, - { "a01_valid_min.unit", "add", 2, { 7, 8 }, 0, 0, 0 }, - { "l01_launch_fns.unit", "jump_in", 2, { IN_PTR, 4 }, "\xc0\x03\x5f\xd6", 0, 0 }, - { "a01_valid_min.unit", "add", 2, { 9, 10 }, 0, 0, 0 }, - { "l01_launch_fns.unit", "dirty", 0, { 0 }, 0, 0, 0 }, - { "l01_launch_fns.unit", "regs_or", 0, { 0 }, 0, 0, 0 }, - { "l01_launch_fns.unit", "touch_past", 2, { WS_PTR | 16376, 1 }, 0, 1, 0 }, - { "a01_valid_min.unit", "add", 2, { 11, 12 }, 0, 0, 0 }, - { "l01_launch_fns.unit", "counter", 2, { WS_PTR | 8, 1 }, 0, 5, 0 }, - { "l01_launch_fns.unit", "counter", 2, { WS_PTR | 16, 1 }, 0, 6, 0 }, - { "l01_launch_fns.unit", "counter", 2, { WS_PTR | 24, 1 }, 0, 7, 0 }, - { "l01_launch_fns.unit", "counter", 2, { WS_PTR | 32, 1 }, (const char *)(lt_ws_mem2 + 64), 8, 0 }, - { "a01_valid_min.unit", "add", 2, { 13, 14 }, 0, 0, 0 }, + { "a01_valid_min.unit", "add", 2, { 1000000007, 998244353 }, 0, 0, 0, 0, 0 }, + { "a01_valid_min.unit", "add", 1, { 5 }, 0, 0, 0, 0, 0 }, + { "a01_valid_min.unit", "nosuch", 0, { 0 }, 0, 0, 0, 0, 0 }, + { "a01_valid_min.unit", "ADD", 2, { 1, 2 }, 0, 0, 0, 0, 0 }, + { "a01_valid_min.unit", "first_byte", 2, { IN_PTR, 4 }, "Zeta", 0, 0, 0, 0 }, + { "a01_valid_min.unit", "first_byte", 2, { 0x1000, 16 }, "Zeta", 0, 0, 0, 0 }, + { "l01_launch_fns.unit", "trap", 1, { 3 }, 0, 0, 0, 0, 0 }, + { "l01_launch_fns.unit", "trap", 1, { 14 }, 0, 0, 0, 0, 0 }, + { "l01_launch_fns.unit", "trap", 1, { 15 }, 0, 0, 0, 0, 0 }, + { "l01_launch_fns.unit", "bare_brk", 0, { 0 }, 0, 0, 0, 0, 0 }, + { "l01_launch_fns.unit", "spin", 0, { 0 }, 0, 0, 5, 0, 0 }, + { "a01_valid_min.unit", "add", 2, { 40, 2 }, 0, 0, 0, 0, 0 }, + { "l01_launch_fns.unit", "peek0", 0, { 0 }, 0, 0, 0, 0, 0 }, + { "a01_valid_min.unit", "add", 2, { 20, 22 }, 0, 0, 0, 0, 0 }, + { "l01_launch_fns.unit", "poke_rt", 0, { 0 }, 0, 0, 0, 0, 0 }, + { "l01_launch_fns.unit", "exec_stack", 0, { 0 }, 0, 0, 0, 0, 0 }, + { "l01_launch_fns.unit", "overflow", 0, { 0 }, 0, 0, 0, 0, 0 }, + { "a01_valid_min.unit", "add", 2, { 6, 36 }, 0, 0, 0, 0, 0 }, + { "l01_launch_fns.unit", "counter", 2, { WS_PTR, 1 }, 0, 1, 0, 0, 0 }, + { "l01_launch_fns.unit", "counter", 2, { WS_PTR, 1 }, 0, 1, 0, 0, 0 }, + { "l01_launch_fns.unit", "counter", 2, { WS_PTR, 1 }, 0, 1, 0, 0, 0 }, + { "l01_launch_fns.unit", "counter", 2, { WS_PTR, 1 }, 0, 2, 0, 0, 0 }, + { "l01_launch_fns.unit", "counter", 2, { WS_PTR | 4, 1 }, 0, 1, 0, 0, 0 }, + { "l01_launch_fns.unit", "counter", 2, { WS_PTR | 94200, 1 }, 0, 3, 0, 0, 0 }, + { "l01_launch_fns.unit", "counter", 2, { WS_PTR | 94200, 1 }, 0, 3, 0, 0, 0 }, + { "l01_launch_fns.unit", "counter", 2, { WS_PTR, 1 }, 0, 4, 0, 0, 0 }, + { "a06_valid_limits_at_max.unit", "add", 2, { 1, 2 }, 0, 0, 0, 0, 0 }, + { "l02_stack_over.unit", "peek0", 0, { 0 }, 0, 0, 0, 0, 0 }, + { "a01_valid_min.unit", "add", 2, { 3, 4 }, 0, 0, 0, 0, 0 }, + { "l01_launch_fns.unit", "peek_kernel", 1, { KERN_PTR }, 0, 0, 0, 0, 0 }, + { "a01_valid_min.unit", "add", 2, { 5, 6 }, 0, 0, 0, 0, 0 }, + { "l01_launch_fns.unit", "jump_ws", 2, { WS_PTR | 512, 1 }, 0, 1, 0, 0, 0 }, + { "a01_valid_min.unit", "add", 2, { 7, 8 }, 0, 0, 0, 0, 0 }, + { "l01_launch_fns.unit", "jump_in", 2, { IN_PTR, 4 }, "\xc0\x03\x5f\xd6", 0, 0, 0, 0 }, + { "a01_valid_min.unit", "add", 2, { 9, 10 }, 0, 0, 0, 0, 0 }, + { "l01_launch_fns.unit", "dirty", 0, { 0 }, 0, 0, 0, 0, 0 }, + { "l01_launch_fns.unit", "regs_or", 0, { 0 }, 0, 0, 0, 0, 0 }, + { "l01_launch_fns.unit", "touch_past", 2, { WS_PTR | 16376, 1 }, 0, 1, 0, 0, 0 }, + { "a01_valid_min.unit", "add", 2, { 11, 12 }, 0, 0, 0, 0, 0 }, + { "l01_launch_fns.unit", "counter", 2, { WS_PTR | 8, 1 }, 0, 5, 0, 0, 0 }, + { "l01_launch_fns.unit", "counter", 2, { WS_PTR | 16, 1 }, 0, 6, 0, 0, 0 }, + { "l01_launch_fns.unit", "counter", 2, { WS_PTR | 24, 1 }, 0, 7, 0, 0, 0 }, + { "l01_launch_fns.unit", "counter", 2, { WS_PTR | 32, 1 }, (const char *)(lt_ws_mem2 + 64), 8, 0, 0, 0 }, + { "a01_valid_min.unit", "add", 2, { 13, 14 }, 0, 0, 0, 0, 0 }, }; ck_printf("osc_launch_policy: units=%u code_max=%u stack_max=%u in_max=%u ws_max=%u pages; 1 tick = 10 ms; " "QEMU (aarch64 virt), TEST signer, not physical\n", @@ -251,7 +423,7 @@ int ck_osc_is_unit(const uint8_t *b, size_t len) unsigned ck_osc_candidate(const char *name, const uint8_t *b, size_t len) { struct osc_policy p; - policy(&p); + ck_osc_policy(&p); if (!announced) { announced = 1; #ifdef CK_SEED0B_TEST_ANCHOR @@ -261,6 +433,12 @@ unsigned ck_osc_candidate(const char *name, const uint8_t *b, size_t len) ck_printf("osc_policy: mode=release test_anchors=0 owner_anchors=0 (none provisioned) " "domains=1 gen_width=32; QEMU, not physical\n"); #endif + ck_printf("osc_receipt_policy: mode=%s receipt_test_anchors=%u receipt_owner_anchors=0 (owner root listed, not " + "trusted) checkers=%u target=%s epoch_floor=%u epoch_now=%u revoked_ids=%u revoked_keys=0 " + "firmware=none dependencies=none producer=none; launch requires a valid receipt; QEMU, not " + "physical\n", + p.release ? "release" : "qualification", p.n_rcpt_test, p.n_rcpt_checkers, OSC_RCPT_TARGET_NAME, + (unsigned)CK_OSC_RCPT_EPOCH_FLOOR, (unsigned)CK_OSC_RCPT_EPOCH_NOW, p.n_rcpt_revoked_ids); } unsigned rc = osc_unit_admit(b, len, &p, &acc); seen++; @@ -296,6 +474,9 @@ void ck_osc_oversize(const char *name, uint64_t len) void ck_osc_summary(void) { + if (rcpt_seen) + ck_printf("osc_receipts: seen=%u stored=%u dropped=%u (each is verified when a launch presents it)\n", rcpt_seen, + rcpt_n, rcpt_dropped); if (seen || oversize) #if defined(CK_OSC_LAUNCH_TEST) || defined(CK_OSH_TEST) { diff --git a/native/kernel/core/osc_admit.h b/native/kernel/core/osc_admit.h index c17e6a27..66e9dc40 100644 --- a/native/kernel/core/osc_admit.h +++ b/native/kernel/core/osc_admit.h @@ -1,10 +1,13 @@ /* osc_admit.h -- kernel-side use of artifact/osc_unit.c: admission verdict * for OSCUNIT containers that arrive through the artifact candidate path - * (boot disk Store). Admission only: nothing is mapped or launched. */ + * (boot disk Store), and the realization receipts (artifact/osc_receipt.h, + * aienos#383) that arrive the same way. Admission only: nothing is mapped or + * launched here; a launch (core/osc_task.c) verifies its receipt. */ #ifndef AIENOS_CK_OSC_ADMIT_H #define AIENOS_CK_OSC_ADMIT_H #include <stddef.h> #include <stdint.h> +#include "osc_unit.h" /* Nonzero if the bytes begin with the container magic "OSCUNIT\0". */ int ck_osc_is_unit(const uint8_t *b, size_t len); @@ -17,4 +20,17 @@ unsigned ck_osc_candidate(const char *name, const uint8_t *b, size_t len); void ck_osc_oversize(const char *name, uint64_t len); /* Print the "osc_units:" summary line if any OSC candidate or oversize entry was seen. */ void ck_osc_summary(void); + +/* The kernel's local admission and receipt policy (release or qualification build). */ +void ck_osc_policy(struct osc_policy *p); +/* Nonzero if the bytes begin with the receipt magic "OMRCPT1\0" (omega receipt v1). */ +int ck_osc_is_receipt(const uint8_t *b, size_t len); +/* Keep a receipt by its Store name (it is verified later, against the unit a launch presents it with) and + * print its "osc_receipt:" line. */ +void ck_osc_receipt_candidate(const char *name, const uint8_t *b, size_t len); +/* The kept receipt of that name (*len its length), or NULL (*len 0) if none arrived. */ +const uint8_t *ck_osc_receipt_find(const char *name, size_t *len); +#ifdef CK_OSC_LAUNCH_TEST +extern int ck_osc_rcpt_variant; /* TEST ONLY: receipt policy variant of the next launch (osc_admit.c) */ +#endif #endif diff --git a/native/kernel/core/osc_task.c b/native/kernel/core/osc_task.c index 4797a72c..40f76e2d 100644 --- a/native/kernel/core/osc_task.c +++ b/native/kernel/core/osc_task.c @@ -13,6 +13,7 @@ #include "arch.h" #include "ck_internal.h" #include "fmt.h" +#include "osc_admit.h" #include "osc_task.h" #include "pt.h" #include "sha256.h" @@ -154,8 +155,9 @@ static void refuse(struct osc_result *res, unsigned code) res->refused_code = (uint8_t)code; } -void ck_osc_launch(const uint8_t *unit, size_t unit_len, const struct osc_accept *a, - const struct ck_osc_launch_req *rq, struct osc_result *res, struct ck_osc_launch_info *info) +void ck_osc_launch(const uint8_t *unit, size_t unit_len, const struct osc_accept *a, const uint8_t *rcpt, + size_t rcpt_len, const struct ck_osc_launch_req *rq, struct osc_result *res, + struct ck_osc_launch_info *info) { struct ck_osc_launch_info local; if (!info) @@ -164,6 +166,18 @@ void ck_osc_launch(const uint8_t *unit, size_t unit_len, const struct osc_accept info->slot_free_after = 1; info->tables_zeroed = 1; /* a refusal built no tables */ refuse(res, OSC_RESOURCE_UNAVAILABLE); + /* aienos#383: no launch without a valid realization receipt for exactly this unit's program and code, under + * the kernel's own policy (never the caller's). Checked before the name lookup, so a refused receipt runs and + * maps nothing. The code is still hashed again below before it is made executable. */ + { + struct osc_policy pol; + ck_osc_policy(&pol); + unsigned rc = osc_receipt_verify(rcpt, rcpt_len, a, &pol, &info->rcpt); + if (rc != 0) { + refuse(res, rc); + return; + } + } int fi = osc_unit_lookup(a, rq->name, rq->name_len); if (fi < 0) { refuse(res, OSC_LAUNCH_BAD_ENTRY); diff --git a/native/kernel/core/osc_task.h b/native/kernel/core/osc_task.h index 39091f0a..70e09b1b 100644 --- a/native/kernel/core/osc_task.h +++ b/native/kernel/core/osc_task.h @@ -6,6 +6,7 @@ #include <stddef.h> #include <stdint.h> #include "osc_launch.h" +#include "osc_receipt.h" #include "osc_unit.h" #define CK_OSC_PAGE 4096u @@ -38,6 +39,7 @@ struct ck_osc_launch_req { }; struct ck_osc_launch_info { + struct osc_receipt_info rcpt; /* what the receipt check saw (id, class, epochs, which revocation); diagnostic */ uint64_t budget; /* ticks granted */ unsigned pages_mapped; /* user pages that were mapped while the task existed */ int tables_zeroed; /* after teardown every page-table entry of the task is zero and its L0 slot is clear (says nothing about frame contents) */ @@ -50,10 +52,14 @@ uint64_t ck_osc_va_in(void); uint64_t ck_osc_va_ws(void); /* Launch the function rq->name of the accepted unit (bytes `unit`, verdict *a from osc_unit_admit on the - * same bytes) and wait for it. *res is always filled. Refusals (40 unknown name, 41 argument shape or - * range, 30 resources, 16 code hash) mean no unit instruction ran. */ -void ck_osc_launch(const uint8_t *unit, size_t unit_len, const struct osc_accept *a, - const struct ck_osc_launch_req *rq, struct osc_result *res, struct ck_osc_launch_info *info); + * same bytes) and wait for it. *res is always filled. A launch needs a realization receipt (`rcpt`, `rcpt_len`; + * omega receipt v1, artifact/osc_receipt.h, aienos#383): it is verified FIRST, against *a and the kernel policy + * (ck_osc_policy), and a missing or refused receipt is REFUSED with its named reason (64 RECEIPT_MISSING, 65..88 + * RECEIPT_*) before anything else. The receipt grants nothing: entry, arguments, resources and grants are + * checked as before. Refusals (64..88 receipt, 40 unknown name, 41 argument shape or range, 30 resources, + * 14 limits, 16 code hash) mean no unit instruction ran and nothing was mapped. */ +void ck_osc_launch(const uint8_t *unit, size_t unit_len, const struct osc_accept *a, const uint8_t *rcpt, + size_t rcpt_len, const struct ck_osc_launch_req *rq, struct osc_result *res, struct ck_osc_launch_info *info); /* "RETURNED value=..", "TRAPPED trap_code=..", "OUTCOME_UNKNOWN reason=..", "REFUSED code=.." */ int ck_osc_result_str(const struct osc_result *r, char *buf, size_t n); diff --git a/native/kernel/core/osh_test.c b/native/kernel/core/osh_test.c index 85f5ce04..64af2e43 100644 --- a/native/kernel/core/osh_test.c +++ b/native/kernel/core/osh_test.c @@ -47,6 +47,17 @@ enum { U_LEX = 0, U_PARSE = 1, U_EXPAND = 2, U_COUNT = 3 }; static const char *const u_file[U_COUNT] = { "osh_lex.unit", "osh_parse.unit", "osh_expand.unit" }; static const char *const u_entry[U_COUNT] = { "lex_run", "parse_run", "expand_run" }; static const char *const u_label[U_COUNT] = { "lex", "parse", "expand" }; +/* each unit's realization receipt in the Store (aienos#383, tests/fixtures/osc_receipt; minted by omega checker2) */ +static const char *const u_rcpt[U_COUNT] = { "osh_lex.rcpt", "osh_parse.rcpt", "osh_expand.rcpt" }; + +/* ck_osc_launch with the unit's receipt from the Store (none if it did not arrive: refused RECEIPT_MISSING) */ +static void launch_rcpt(const char *rname, const uint8_t *b, size_t len, const struct osc_accept *acc, + const struct ck_osc_launch_req *rq, struct osc_result *r, struct ck_osc_launch_info *info) +{ + size_t rl = 0; + const uint8_t *rb = ck_osc_receipt_find(rname, &rl); + ck_osc_launch(b, len, acc, rb, rl, rq, r, info); +} #define UNIT_BYTES 131072u /* the packed containers (IR + code + manifest) pass 64 KiB; the code stays under CK_OSC_CODE_MAX_BYTES */ static struct { @@ -134,7 +145,7 @@ static int launch(unsigned u, size_t in_len, uint64_t ws_cells, struct ck_osc_ws rq.in_len = in_len; rq.ws = wsr; rq.max_ticks = max_ticks; - ck_osc_launch(unit[u].bytes, unit[u].len, &unit[u].acc, &rq, r, info); + launch_rcpt(u_rcpt[u], unit[u].bytes, unit[u].len, &unit[u].acc, &rq, r, info); launches++; if (!info->slot_free_after) slots_held++; @@ -511,7 +522,7 @@ static void negatives(void) rq.args[4] = 0x3333; rq.args[5] = 0x4444; rq.ws = &main_ws; - ck_osc_launch(unit[U_LEX].bytes, unit[U_LEX].len, &unit[U_LEX].acc, &rq, &r, &info); + launch_rcpt(u_rcpt[U_LEX], unit[U_LEX].bytes, unit[U_LEX].len, &unit[U_LEX].acc, &rq, &r, &info); hex(ws_mem + 512 * 8, sizeof ws_mem - 512 * 8, h1); ck_snprintf(x, sizeof x, "cell17=%llu cells_512_up_unchanged=%u", (unsigned long long)w[17], (unsigned)streq(h0, h1)); neg_line("2a", "lex emit_tok(ws+0,len 512 cells,..) with w[17]=127", &r, &info, x); @@ -557,7 +568,7 @@ static void negatives(void) rq.name = "spin"; rq.name_len = 4; rq.max_ticks = 1; - ck_osc_launch(spin_unit.bytes, spin_unit.len, &spin_unit.acc, &rq, &r, &info); + launch_rcpt("l01.rcpt", spin_unit.bytes, spin_unit.len, &spin_unit.acc, &rq, &r, &info); neg_line("4b", "l01 spin() with the same max_ticks=1 cap", &r, &info, ""); } else { ck_printf("osh_neg4b: NOT_RUN (l01_launch_fns.unit was not admitted); %s\n", LABEL); diff --git a/native/kernel/tests/.crumb b/native/kernel/tests/.crumb index 5446ce10..15430e4c 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-14T13:28:10Z", + "compiled_at": "2026-10-14T19:58:14Z", "compiler": "crumb-compile/1", - "digest": "sha256:67f43d00adce9780c2ae75ece209ac453a1b9debc74d735d9acdb72f36e6df77", + "digest": "sha256:b9bfdf2069bf98725e1dc3b8088c19f4cb7a5ff6acbb2a7a2bb7beb23b787dee", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 165, - "generated_at_commit": "a0fa796235409ce465c467e8c72fbd977485d8f7", - "source_tree": "sha256:01254316e00d1bce77c10d8ac08c618006b73522f6d0da0816da80fef5a065f7" + "files": 186, + "generated_at_commit": "7963940dc7ffb44a00bb162d46d1c861090b2fa7", + "source_tree": "sha256:f9549126c3c2edbfd4022e26e37411e38e6aedb93b439d547fa283e4f9ae30af" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/tests/fixtures/osc_receipt/PROVENANCE.txt b/native/kernel/tests/fixtures/osc_receipt/PROVENANCE.txt new file mode 100644 index 00000000..cf3f04d0 --- /dev/null +++ b/native/kernel/tests/fixtures/osc_receipt/PROVENANCE.txt @@ -0,0 +1,23 @@ +Omega realization receipt fixtures (receipt v1, 416 bytes; omega spec/one-layer-receipts.md) for OSC unit +admission (aienos#383). Label: TEST key only, protects nothing. + +Minted by: omega checker2 (`checker2 receipt issue`), built by make-receipts.sh from aien-dev/omega + 265ce82a1c220caa5f027abe068ca3aa813c633c (omega#448 merged: src/checker2, spec/one-layer-receipts.md). + checker_id = d7aae601e732b4b145c73e8d4f92769f56dac2e6fba5f77aed490aec429cf3ba + (`checker2 version`; pinned in artifact/osc_receipt_anchor.h). n_checker.rcpt was minted by + checker2_other (omega's own test build of the same sources under another identity). +Key: checker2's TEST key, class TEST (1): seed = SHA-256("OMEGA-CHECKER2-TEST-KEY-v1 NOT FOR PRODUCTION"), + public key 602810d43c0115df877b0cf8c327010e5a7e570490c85e31466c0cff6ca374c5, + fingerprint 6b5ab4e52d94a45a2cef54425bc3a321d07f1d3e14746e4a399b66ddc0d6c8ad. + This is NOT the OSC unit container TEST key (osc_unit/keys/test1.pub). The public key was derived + independently with openssl from the seed and matches the fingerprint in every receipt; + tests/test_osc_receipt.c checks the header bytes against these fixtures. +Inputs: the IR (section 1) and code (section 2) of the committed units, extracted by make-receipts.sh from + osc_unit/vectors/a01_valid_min.unit, osc_unit/launch/l01_launch_fns.unit and osh/osh_{lex,parse,expand}.unit + (each extracted section must hash to its section-table entry). Target "aienos-ck-aarch64-el0". +Altered: n_altered.rcpt = a01.rcpt with byte 80 (first byte of the executable hash) XOR 1; + n_length.rcpt = a01.rcpt plus one zero byte (417 bytes). Nothing else was edited by hand. +Reproduce: native/kernel/tests/fixtures/osc_receipt/make-receipts.sh --check <omega checkout at the commit above> + rebuilds everything in a temporary directory and requires byte-identical files (Ed25519 is + deterministic). expected.txt records, per case, checker2's own `receipt verify` verdict under the + same policy as the kernel's (the oracle) next to the verdict the kernel must give. diff --git a/native/kernel/tests/fixtures/osc_receipt/a01.rcpt b/native/kernel/tests/fixtures/osc_receipt/a01.rcpt new file mode 100644 index 00000000..72761c56 Binary files /dev/null and b/native/kernel/tests/fixtures/osc_receipt/a01.rcpt differ diff --git a/native/kernel/tests/fixtures/osc_receipt/expected.txt b/native/kernel/tests/fixtures/osc_receipt/expected.txt new file mode 100644 index 00000000..4688bdf3 --- /dev/null +++ b/native/kernel/tests/fixtures/osc_receipt/expected.txt @@ -0,0 +1,29 @@ +# Receipt fixtures for aienos#383, minted by omega checker2 (TEST key). Generated by make-receipts.sh. +# omega=265ce82a1c220caa5f027abe068ca3aa813c633c checker_id=d7aae601e732b4b145c73e8d4f92769f56dac2e6fba5f77aed490aec429cf3ba other_checker_id=f4298233ed1bdad2e992511163dafd3daa878ed6a1cf582c0bc62674753b20c3 +# test_key_fingerprint=6b5ab4e52d94a45a2cef54425bc3a321d07f1d3e14746e4a399b66ddc0d6c8ad target=aienos-ck-aarch64-el0 floor=10 epoch=20 revoked_id=e45212d1ea6956e4ef65b9a839da20af3ff9bd53c566cd233a6ae26cad658ff3 +# columns: receipt unit variant checker2-verify-verdict kernel-verdict receipt-id +# variant: qual = kernel qualification policy; release = the same with release=1 (TEST refused); +# revoke_key = qual plus the TEST key fingerprint on the revoked-key list; +# producer = qual plus an expected producer (qual expects none = all zero) +a01.rcpt unit=a01 variant=qual checker2=VALID kernel=VALID id=613e1cece39535842e2b3e406147b837b4bb1ed91628caf54735c7c09cb70996 +l01.rcpt unit=l01 variant=qual checker2=VALID kernel=VALID id=8330c39a4142e03fcce68bdff096dfc01dfcbb899ad03ef09b54342e7eeea403 +osh_lex.rcpt unit=osh_lex variant=qual checker2=VALID kernel=VALID id=40ae77b1a1855ed441403394012252549f9669f60a1bea1e4fa58a2f30d25156 +osh_parse.rcpt unit=osh_parse variant=qual checker2=VALID kernel=VALID id=3583baacf2b141f95d82135147f7e2be3b3f0e340fae642356330a54f8a3e9c1 +osh_expand.rcpt unit=osh_expand variant=qual checker2=VALID kernel=VALID id=dcf8988447d69f99304a03a16bed3ca8d4713276edff1c6d5b31227985e813bc +a01.rcpt unit=a01 variant=release checker2=TEST_SIGNER_IN_PRODUCTION kernel=TEST_SIGNER_IN_PRODUCTION id=613e1cece39535842e2b3e406147b837b4bb1ed91628caf54735c7c09cb70996 +a01.rcpt unit=a01 variant=revoke_key checker2=REVOKED kernel=REVOKED id=613e1cece39535842e2b3e406147b837b4bb1ed91628caf54735c7c09cb70996 +n_altered.rcpt unit=a01 variant=qual checker2=BAD_SIGNATURE kernel=BAD_SIGNATURE id=5c89817dc900fee1b945e2e1bcb43f81f0d157dcc0a1838da73b1d0cc674da94 +n_length.rcpt unit=a01 variant=qual checker2=SIZE kernel=SIZE id=26a9a5565bd4742ba640d6ab6ddafdc0962d669250086bc5291e3a84496e1b83 +n_stale.rcpt unit=a01 variant=qual checker2=STALE_EPOCH kernel=STALE_EPOCH id=00521d58131e8ead78dcdc31446c0078b4c7332bfca9d6d32bf0c4f7d6a41ede +n_revoked_id.rcpt unit=a01 variant=qual checker2=REVOKED kernel=REVOKED id=e45212d1ea6956e4ef65b9a839da20af3ff9bd53c566cd233a6ae26cad658ff3 +n_expired.rcpt unit=a01 variant=qual checker2=EXPIRED kernel=EXPIRED id=b6fd9994615e42ae252ace7b1667a41482bd024be3f77835cb091519ca4a5b5b +n_future.rcpt unit=a01 variant=qual checker2=NOT_YET_VALID kernel=NOT_YET_VALID id=d91b9803b39727492d835f2e2e1a3bd87e540fa1d28449f615122ec5cd87d365 +n_target.rcpt unit=a01 variant=qual checker2=WRONG_TARGET kernel=WRONG_TARGET id=b05e59f36066b28069d6a1085dc5f22d27f80441729924315e1cb5aa616ec36f +n_firmware.rcpt unit=a01 variant=qual checker2=WRONG_FIRMWARE kernel=WRONG_FIRMWARE id=be9b831461eaf5d450321c1320372f32ca3f52c3db01ccac6d6f0e89cea20449 +n_program.rcpt unit=a01 variant=qual checker2=PROGRAM_MISMATCH kernel=PROGRAM_MISMATCH id=425adde14903f34672bf626c4162e9230da45dc0c503c52cdf6369a51535ad92 +l01.rcpt unit=a01 variant=qual checker2=EXECUTABLE_MISMATCH kernel=EXECUTABLE_MISMATCH id=8330c39a4142e03fcce68bdff096dfc01dfcbb899ad03ef09b54342e7eeea403 +n_deps.rcpt unit=a01 variant=qual checker2=DEPENDENCIES_MISMATCH kernel=DEPENDENCIES_MISMATCH id=de49adf3d0c35d6d1782eaa7fd8c35074b3fbf9d230ae414b439761dad62d162 +n_checker.rcpt unit=a01 variant=qual checker2=UNTRUSTED_CHECKER kernel=UNTRUSTED_CHECKER id=5c9e707051daf1244985ef16cb18956f372686d3c5d9704142b2d44a68a762bb +n_producer.rcpt unit=a01 variant=qual checker2=WRONG_PRODUCER kernel=WRONG_PRODUCER id=8caf618b4183c11a954ed01e8475b87d50e836a465db954c8cf0b63595c2527d +n_producer.rcpt unit=a01 variant=producer checker2=VALID kernel=VALID id=8caf618b4183c11a954ed01e8475b87d50e836a465db954c8cf0b63595c2527d +a01.rcpt unit=a01 variant=producer checker2=WRONG_PRODUCER kernel=WRONG_PRODUCER id=613e1cece39535842e2b3e406147b837b4bb1ed91628caf54735c7c09cb70996 diff --git a/native/kernel/tests/fixtures/osc_receipt/l01.rcpt b/native/kernel/tests/fixtures/osc_receipt/l01.rcpt new file mode 100644 index 00000000..29a49447 Binary files /dev/null and b/native/kernel/tests/fixtures/osc_receipt/l01.rcpt differ diff --git a/native/kernel/tests/fixtures/osc_receipt/make-receipts.sh b/native/kernel/tests/fixtures/osc_receipt/make-receipts.sh new file mode 100755 index 00000000..f65a47ac --- /dev/null +++ b/native/kernel/tests/fixtures/osc_receipt/make-receipts.sh @@ -0,0 +1,167 @@ +#!/bin/bash +# make-receipts.sh: build the Omega realization receipt fixtures (receipt v1, omega spec/one-layer-receipts.md) +# for OSC unit admission (aienos#383) with omega's own checker2. Usage: +# make-receipts.sh OMEGA_DIR [OUT_DIR] write the fixtures to OUT_DIR (default: this directory) +# make-receipts.sh --check OMEGA_DIR rebuild into a temporary directory and require every committed +# fixture and expected.txt to be byte-identical (Ed25519 is +# deterministic, so the same checker2 gives the same bytes) +# OMEGA_DIR is a checkout of aien-dev/omega with src/checker2 (omega#448). checker2 and checker2_other are built +# from it into a temporary OUT_DIR (omega's own build/ is not touched). Every receipt is minted by +# `checker2 receipt issue` with the checker2 TEST key (class TEST); nothing here signs anything itself. +# Altered bytes (n_altered: one flipped byte; n_length: one extra byte) are copies of a minted receipt. +# Needs bash, make, cc, od, dd, sha256sum, cmp. No Python. +set -eu +export LC_ALL=C +mydir=$(cd "$(dirname "$0")" && pwd) +check=0 +if [ "${1:-}" = --check ]; then check=1; shift; fi +OMEGA=$(cd "${1:?OMEGA_DIR}" && pwd) +OUT=${2:-$mydir} +work=$(mktemp -d) +trap 'rm -rf "$work"' EXIT +if [ "$check" = 1 ]; then OUT=$work/out; fi +mkdir -p "$OUT" + +fix=$(cd "$mydir/.." && pwd) +TARGET=aienos-ck-aarch64-el0 # the kernel's target name (osc_receipt.h OSC_RCPT_TARGET_NAME) +FLOOR=10 # kernel qualification policy (core/osc_admit.c): epoch floor 10, current epoch 20 +NOW=20 + +make -s -C "$OMEGA" OUT_DIR="$work/c2" "$work/c2/checker2/checker2" "$work/c2/checker2/checker2_other" >/dev/null +C2=$work/c2/checker2/checker2 +C2O=$work/c2/checker2/checker2_other +omega_commit=$(git -C "$OMEGA" rev-parse HEAD 2>/dev/null || echo unknown) +omega_dirty=$(git -C "$OMEGA" status --porcelain -- src/checker2 mk/checker2.mk 2>/dev/null | head -1) +[ -z "$omega_dirty" ] || { echo "omega checker2 sources are modified; refusing (fixtures must come from a commit)" >&2; exit 1; } +checker_id=$("$C2" version | sed -n 's/^checker_id=//p') +other_id=$("$C2O" version | sed -n 's/^checker_id=//p') + +# Section 1 (IR) and section 2 (code) of an OSCUNIT container: section table at 128, 48 bytes per entry, +# offset u32 at +4, length u32 at +8, SHA-256 at +16 (OSC_UNIT_ARTIFACT.md section 4). The extracted bytes must +# hash to the table's hash, so a wrong offset cannot go unnoticed. +u32() { od -An -tu4 -j "$2" -N4 "$1" | tr -d ' '; } +hexat() { od -An -tx1 -j "$2" -N "$3" "$1" | tr -d ' \n'; } +extract() { # unit-file short-name + local u=$1 b=$2 k off len ent + for k in 1 2; do + ent=$((128 + (k - 1) * 48)) + off=$(u32 "$u" $((ent + 4))) + len=$(u32 "$u" $((ent + 8))) + dd if="$u" of="$work/$b.s$k" bs=1 skip="$off" count="$len" status=none + [ "$(sha256sum "$work/$b.s$k" | cut -c1-64)" = "$(hexat "$u" $((ent + 16)) 32)" ] \ + || { echo "$u: section $k does not hash to its table entry" >&2; exit 1; } + done + mv "$work/$b.s1" "$work/$b.ir" + mv "$work/$b.s2" "$work/$b.code" +} +extract "$fix/osc_unit/vectors/a01_valid_min.unit" a01 +extract "$fix/osc_unit/launch/l01_launch_fns.unit" l01 +extract "$fix/osh/osh_lex.unit" osh_lex +extract "$fix/osh/osh_parse.unit" osh_parse +extract "$fix/osh/osh_expand.unit" osh_expand +printf 'not a firmware image (receipt fixture)\n' >"$work/firmware.bin" +printf 'stand-in producer identity (receipt fixture)\n' >"$work/producer.bin" + +# issue NAME CHECKER IR CODE EPOCH EXPIRY [extra issue options] +issue() { + local name=$1 c=$2 ir=$3 code=$4 ep=$5 ex=$6 line path + shift 6 + rm -rf "$work/store"; mkdir -p "$work/store" + line=$("$c" receipt issue "$work/$ir.ir" "$work/$code.code" --target "${TGT:-$TARGET}" --epoch "$ep" --expiry "$ex" \ + --out-dir "$work/store" "$@") + path=${line#receipt=} + [ -f "$path" ] || { echo "issue $name: $line" >&2; exit 1; } + cat "$path" >"$OUT/$name.rcpt" +} +id_of() { sha256sum "$OUT/$1.rcpt" | cut -c1-64; } + +# valid receipts, one per launched program+code pair. A receipt binds the IR and the code, not the container +# manifest: l02_stack_over.unit has l01's IR and code (l01.rcpt covers it) and a06_valid_limits_at_max.unit has +# a01's (a01.rcpt covers it; checker2 gives byte-identical receipts for them). +issue a01 "$C2" a01 a01 10 1000 +issue l01 "$C2" l01 l01 10 1000 +issue osh_lex "$C2" osh_lex osh_lex 10 1000 +issue osh_parse "$C2" osh_parse osh_parse 10 1000 +issue osh_expand "$C2" osh_expand osh_expand 10 1000 +# negative receipts, all for a01_valid_min.unit +issue n_stale "$C2" a01 a01 5 1000 # issued under epoch 5, below the floor 10: replay +issue n_revoked_id "$C2" a01 a01 11 1000 # valid except that its id is on the kernel's revoked list +issue n_expired "$C2" a01 a01 10 15 # last fresh epoch 15, kernel is at 20 +issue n_future "$C2" a01 a01 30 1000 # issued under epoch 30, kernel is at 20 +TGT=aarch64-linux-host issue n_target "$C2" a01 a01 10 1000 +issue n_program "$C2" osh_lex a01 10 1000 # another (checker2-accepted) program with a01's code +issue n_firmware "$C2" a01 a01 10 1000 --firmware "$work/firmware.bin" +issue n_producer "$C2" a01 a01 10 1000 --producer "$work/producer.bin" +issue n_deps "$C2" a01 a01 10 1000 --dep "$(id_of a01)" +issue n_checker "$C2O" a01 a01 10 1000 # minted by a checker2 build with another identity +# copies with altered bytes +cat "$OUT/a01.rcpt" >"$OUT/n_altered.rcpt" +b=$(od -An -tu1 -j80 -N1 "$OUT/a01.rcpt" | tr -d ' ') +printf "\\$(printf '%03o' $((b ^ 1)))" | dd of="$OUT/n_altered.rcpt" bs=1 seek=80 conv=notrunc status=none +{ cat "$OUT/a01.rcpt"; printf '\0'; } >"$OUT/n_length.rcpt" + +test_fp=$(hexat "$OUT/a01.rcpt" 320 32) +revoked_id=$(id_of n_revoked_id) +# The same policy for checker2 verify (the oracle) as the kernel's qualification policy: TEST key allowed, +# floor 10, epoch 20, target aienos-ck-aarch64-el0, no firmware, no dependencies, revoked id n_revoked_id. +# Both checker2 and the kernel compare the producer (none = all zero unless the policy names one). +qual=(--allow-test-key --floor "$FLOOR" --epoch "$NOW" --target "$TARGET" --revoked-id "$revoked_id") +# oracle NAME UNIT VARIANT KERNEL-VERDICT [extra verify options] +oracle() { + local name=$1 unit=$2 variant=$3 kv=$4 v opts + shift 4 + case $variant in + qual) opts=("${qual[@]}") ;; + release) opts=(--production --floor "$FLOOR" --epoch "$NOW" --target "$TARGET" --revoked-id "$revoked_id") ;; + revoke_key) opts=("${qual[@]}" --revoked-key "$test_fp") ;; + producer) opts=("${qual[@]}" --producer "$work/producer.bin") ;; + esac + v=$("$C2" receipt verify "$OUT/$name.rcpt" "$work/$unit.ir" "$work/$unit.code" "${opts[@]}" "$@" 2>&1 || true) + v=${v#receipt=} + echo "$name.rcpt unit=$unit variant=$variant checker2=$v kernel=$kv id=$(id_of "$name")" +} +{ + echo "# Receipt fixtures for aienos#383, minted by omega checker2 (TEST key). Generated by make-receipts.sh." + echo "# omega=$omega_commit checker_id=$checker_id other_checker_id=$other_id" + echo "# test_key_fingerprint=$test_fp target=$TARGET floor=$FLOOR epoch=$NOW revoked_id=$revoked_id" + echo "# columns: receipt unit variant checker2-verify-verdict kernel-verdict receipt-id" + echo "# variant: qual = kernel qualification policy; release = the same with release=1 (TEST refused);" + echo "# revoke_key = qual plus the TEST key fingerprint on the revoked-key list;" + echo "# producer = qual plus an expected producer (qual expects none = all zero)" + oracle a01 a01 qual VALID + oracle l01 l01 qual VALID + oracle osh_lex osh_lex qual VALID + oracle osh_parse osh_parse qual VALID + oracle osh_expand osh_expand qual VALID + oracle a01 a01 release TEST_SIGNER_IN_PRODUCTION + oracle a01 a01 revoke_key REVOKED + oracle n_altered a01 qual BAD_SIGNATURE + oracle n_length a01 qual SIZE + oracle n_stale a01 qual STALE_EPOCH + oracle n_revoked_id a01 qual REVOKED + oracle n_expired a01 qual EXPIRED + oracle n_future a01 qual NOT_YET_VALID + oracle n_target a01 qual WRONG_TARGET + oracle n_firmware a01 qual WRONG_FIRMWARE + oracle n_program a01 qual PROGRAM_MISMATCH + oracle l01 a01 qual EXECUTABLE_MISMATCH + oracle n_deps a01 qual DEPENDENCIES_MISMATCH + oracle n_checker a01 qual UNTRUSTED_CHECKER + oracle n_producer a01 qual WRONG_PRODUCER + oracle n_producer a01 producer VALID + oracle a01 a01 producer WRONG_PRODUCER +} >"$OUT/expected.txt" +# The oracle must agree with the kernel column everywhere except where the kernel deliberately does not check: +# n_producer under qual (checker2 compares an all-zero producer; the kernel policy has no producer). +bad=$(awk '!/^#/ { split($4, c, "="); split($5, k, "="); if (c[2] != k[2] && !($1 == "n_producer.rcpt" && $3 == "variant=qual")) print }' "$OUT/expected.txt") +[ -z "$bad" ] || { echo "checker2 and the expected kernel verdict disagree:" >&2; echo "$bad" >&2; exit 1; } + +if [ "$check" = 1 ]; then + rc=0 + for f in "$OUT"/*; do + cmp -s "$f" "$mydir/$(basename "$f")" || { echo "differs from the committed fixture: $(basename "$f")" >&2; rc=1; } + done + [ "$rc" = 0 ] && echo "receipt fixtures reproduced byte for byte ($(ls "$OUT" | wc -l) files, omega $omega_commit)" + exit "$rc" +fi +echo "wrote $(ls "$OUT"/*.rcpt | wc -l) receipts and expected.txt to $OUT (omega $omega_commit, checker_id $checker_id)" diff --git a/native/kernel/tests/fixtures/osc_receipt/n_altered.rcpt b/native/kernel/tests/fixtures/osc_receipt/n_altered.rcpt new file mode 100644 index 00000000..0aa0d1ca Binary files /dev/null and b/native/kernel/tests/fixtures/osc_receipt/n_altered.rcpt differ diff --git a/native/kernel/tests/fixtures/osc_receipt/n_checker.rcpt b/native/kernel/tests/fixtures/osc_receipt/n_checker.rcpt new file mode 100644 index 00000000..8da977a7 Binary files /dev/null and b/native/kernel/tests/fixtures/osc_receipt/n_checker.rcpt differ diff --git a/native/kernel/tests/fixtures/osc_receipt/n_deps.rcpt b/native/kernel/tests/fixtures/osc_receipt/n_deps.rcpt new file mode 100644 index 00000000..72ed2f72 Binary files /dev/null and b/native/kernel/tests/fixtures/osc_receipt/n_deps.rcpt differ diff --git a/native/kernel/tests/fixtures/osc_receipt/n_expired.rcpt b/native/kernel/tests/fixtures/osc_receipt/n_expired.rcpt new file mode 100644 index 00000000..dd3a13ed Binary files /dev/null and b/native/kernel/tests/fixtures/osc_receipt/n_expired.rcpt differ diff --git a/native/kernel/tests/fixtures/osc_receipt/n_firmware.rcpt b/native/kernel/tests/fixtures/osc_receipt/n_firmware.rcpt new file mode 100644 index 00000000..27b588ff Binary files /dev/null and b/native/kernel/tests/fixtures/osc_receipt/n_firmware.rcpt differ diff --git a/native/kernel/tests/fixtures/osc_receipt/n_future.rcpt b/native/kernel/tests/fixtures/osc_receipt/n_future.rcpt new file mode 100644 index 00000000..e67c21ef Binary files /dev/null and b/native/kernel/tests/fixtures/osc_receipt/n_future.rcpt differ diff --git a/native/kernel/tests/fixtures/osc_receipt/n_length.rcpt b/native/kernel/tests/fixtures/osc_receipt/n_length.rcpt new file mode 100644 index 00000000..6d45d88d Binary files /dev/null and b/native/kernel/tests/fixtures/osc_receipt/n_length.rcpt differ diff --git a/native/kernel/tests/fixtures/osc_receipt/n_producer.rcpt b/native/kernel/tests/fixtures/osc_receipt/n_producer.rcpt new file mode 100644 index 00000000..6006c95a Binary files /dev/null and b/native/kernel/tests/fixtures/osc_receipt/n_producer.rcpt differ diff --git a/native/kernel/tests/fixtures/osc_receipt/n_program.rcpt b/native/kernel/tests/fixtures/osc_receipt/n_program.rcpt new file mode 100644 index 00000000..384ab235 Binary files /dev/null and b/native/kernel/tests/fixtures/osc_receipt/n_program.rcpt differ diff --git a/native/kernel/tests/fixtures/osc_receipt/n_revoked_id.rcpt b/native/kernel/tests/fixtures/osc_receipt/n_revoked_id.rcpt new file mode 100644 index 00000000..93404e93 Binary files /dev/null and b/native/kernel/tests/fixtures/osc_receipt/n_revoked_id.rcpt differ diff --git a/native/kernel/tests/fixtures/osc_receipt/n_stale.rcpt b/native/kernel/tests/fixtures/osc_receipt/n_stale.rcpt new file mode 100644 index 00000000..ec1c6f9c Binary files /dev/null and b/native/kernel/tests/fixtures/osc_receipt/n_stale.rcpt differ diff --git a/native/kernel/tests/fixtures/osc_receipt/n_target.rcpt b/native/kernel/tests/fixtures/osc_receipt/n_target.rcpt new file mode 100644 index 00000000..354a3571 Binary files /dev/null and b/native/kernel/tests/fixtures/osc_receipt/n_target.rcpt differ diff --git a/native/kernel/tests/fixtures/osc_receipt/osh_expand.rcpt b/native/kernel/tests/fixtures/osc_receipt/osh_expand.rcpt new file mode 100644 index 00000000..cf8e67f8 Binary files /dev/null and b/native/kernel/tests/fixtures/osc_receipt/osh_expand.rcpt differ diff --git a/native/kernel/tests/fixtures/osc_receipt/osh_lex.rcpt b/native/kernel/tests/fixtures/osc_receipt/osh_lex.rcpt new file mode 100644 index 00000000..ccc46246 Binary files /dev/null and b/native/kernel/tests/fixtures/osc_receipt/osh_lex.rcpt differ diff --git a/native/kernel/tests/fixtures/osc_receipt/osh_parse.rcpt b/native/kernel/tests/fixtures/osc_receipt/osh_parse.rcpt new file mode 100644 index 00000000..7e69a7c2 Binary files /dev/null and b/native/kernel/tests/fixtures/osc_receipt/osh_parse.rcpt differ diff --git a/native/kernel/tests/test_osc_receipt.c b/native/kernel/tests/test_osc_receipt.c new file mode 100644 index 00000000..0a0bb258 --- /dev/null +++ b/native/kernel/tests/test_osc_receipt.c @@ -0,0 +1,505 @@ +/* test_osc_receipt.c -- host test for artifact/osc_receipt.c (Omega realization receipt v1, aienos#383) under + * the kernel's own policy (core/osc_admit.c ck_osc_policy, linked in). + * + * Built twice: with CK_SEED0B_TEST_ANCHOR=1 (the qualification policy: checker2's TEST key anchored) and without + * it (the release policy: no receipt anchor, release mode). Checks: + * - every line of tests/fixtures/osc_receipt/expected.txt: the receipt, minted by omega checker2, verified + * against the admitted unit gives the stated kernel verdict (checker2's own verdict for the same policy is + * recorded beside it by make-receipts.sh); in the release build every one is refused; + * - the trust inputs: the TEST key header against the fixtures, the pinned checker identity, the target hash, + * the revoked fixture id, the owner root listed but never trusted; + * - each structure reason, the order of the checks, anchor rules, epoch window edges, every single-bit flip; + * - the Store receipt table of osc_admit.c (kept by name, oversize, full). + * The mutation run (Makefile osc-receipt-mutants) requires this test to FAIL with any one MUT guard removed. */ +#include <stdarg.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "ck_test.h" +#include "osc_admit.h" +#include "osc_receipt.h" +#include "osc_receipt_anchor.h" +#include "osc_receipt_test_anchor.h" +#include "osc_unit.h" +#include "osc_unit_test_anchor.h" +#include "sha256.h" +#include "aienos_sig.h" + +#ifndef OSC_FIXTURE_DIR +#define OSC_FIXTURE_DIR "native/kernel/tests/fixtures" +#endif + +static char out[8192]; +static size_t outn; +void ck_printf(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + int n = vsnprintf(out + outn, sizeof out - outn, fmt, ap); + va_end(ap); + if (n > 0 && outn + (size_t)n < sizeof out) outn += (size_t)n; +} + +static size_t slurp(const char *rel, uint8_t *buf, size_t cap) +{ + char path[512]; + snprintf(path, sizeof path, "%s/%s", OSC_FIXTURE_DIR, rel); + FILE *f = fopen(path, "rb"); + if (!f) { printf(" cannot open %s\n", path); return 0; } + size_t n = fread(buf, 1, cap, f); + fclose(f); + return n; +} + +static const char *unit_path(const char *u) +{ + if (!strcmp(u, "a01")) return "osc_unit/vectors/a01_valid_min.unit"; + if (!strcmp(u, "l01")) return "osc_unit/launch/l01_launch_fns.unit"; + if (!strcmp(u, "osh_lex")) return "osh/osh_lex.unit"; + if (!strcmp(u, "osh_parse")) return "osh/osh_parse.unit"; + if (!strcmp(u, "osh_expand")) return "osh/osh_expand.unit"; + return "?"; +} + +/* the unit admitted with the container TEST key (admission is not what is tested here) */ +static int admit(const char *u, struct osc_accept *a) +{ + static uint8_t buf[OSC_UNIT_MAX_BYTES]; + size_t n = slurp(unit_path(u), buf, sizeof buf); + struct osc_policy p; + memset(&p, 0, sizeof p); + static const uint8_t (*const ta)[32] = &osc_unit_test1_pk; + p.test_anchors = ta; + p.n_test = 1; + p.unit_formats = OSC_PROFILE_UNIT_FORMATS; + p.abi_versions = OSC_PROFILE_ABI; + p.cap_domains = 1u << 1; + return n && osc_unit_admit(buf, n, &p, a) == OSC_OK; +} + +static size_t rcpt(const char *name, uint8_t *b) +{ + char rel[128]; + snprintf(rel, sizeof rel, "osc_receipt/%s", name); + return slurp(rel, b, 1024); +} + +/* "VALID" -> 0, else the kernel code whose name is RECEIPT_<name>; ~0u if unknown */ +static unsigned code_of(const char *name) +{ + if (!strcmp(name, "VALID")) return 0; + for (unsigned c = 64; c < 96; c++) { + const char *k = osc_code_name(c); + if (!strncmp(k, "RECEIPT_", 8) && !strcmp(k + 8, name)) return c; + } + return ~0u; +} + +static void hex(const uint8_t *p, size_t n, char *o) +{ + for (size_t i = 0; i < n; i++) sprintf(o + 2 * i, "%02x", p[i]); +} + +static uint8_t test_fp[1][32], producer[32]; + +static void apply_variant(struct osc_policy *p, const char *v) +{ + if (!strcmp(v, "release")) p->release = 1; + if (!strcmp(v, "revoke_key")) { p->rcpt_revoked_keys = (const uint8_t (*)[32])test_fp; p->n_rcpt_revoked_keys = 1; } + if (!strcmp(v, "producer")) p->rcpt_producer = producer; +} + +static void expected_table(void) +{ + char path[512], line[512]; + snprintf(path, sizeof path, "%s/osc_receipt/expected.txt", OSC_FIXTURE_DIR); + FILE *f = fopen(path, "r"); + CHECK(f != NULL); + if (!f) return; + int n = 0, refused = 0; + while (fgets(line, sizeof line, f)) { + if (line[0] == '#' || line[0] == '\n') continue; + char name[64], unit[64], variant[32], c2[64], kv[64], idhex[80]; + if (sscanf(line, "%63s unit=%63s variant=%31s checker2=%63s kernel=%63s id=%79s", name, unit, variant, c2, kv, + idhex) != 6) { CHECK(0); continue; } + uint8_t r[1024]; + size_t len = rcpt(name, r); + struct osc_accept a; + CHECK(admit(unit, &a)); + struct osc_policy p; + ck_osc_policy(&p); + apply_variant(&p, variant); + struct osc_receipt_info info; + unsigned got = osc_receipt_verify(r, len, &a, &p, &info), want = code_of(kv); + CHECK(want != ~0u); +#ifdef CK_SEED0B_TEST_ANCHOR + if (got != want) printf(" %s unit=%s variant=%s: got %u %s, want %s\n", name, unit, variant, got, osc_code_name(got), kv); + CHECK(got == want); + /* where the kernel checks what checker2 checks, the verdicts agree (the oracle) */ + CHECK(!strcmp(c2, kv)); +#else + /* release policy: TEST receipts are refused; only a structure fault is reported before that */ + unsigned rel = want == OSC_RCPT_SIZE ? OSC_RCPT_SIZE : OSC_RCPT_TEST_SIGNER_IN_PRODUCTION; + if (got != rel) printf(" release %s: got %u %s\n", name, got, osc_code_name(got)); + CHECK(got == rel); +#endif + if (got) refused++; + if (len == OSC_RCPT_BYTES) { + char h[65]; + hex(info.id, 32, h); + CHECK(info.have_id && !strcmp(h, idhex)); + } + n++; + } + fclose(f); + CHECK(n == 22); + printf(" expected.txt: %d cases, %d refused\n", n, refused); +} + +static void trust_inputs(void) +{ + uint8_t r[1024], h[32]; + CHECK(rcpt("a01.rcpt", r) == OSC_RCPT_BYTES); + /* the TEST key header is the key whose fingerprint checker2 wrote, and it verifies (a01 is VALID above) */ + sha256_hash(osc_rcpt_test_pk, 32, h); + CHECK(memcmp(h, r + 320, 32) == 0); + CHECK(memcmp(osc_rcpt_test_pk, osc_unit_test1_pk, 32) != 0); /* not the container TEST key */ + CHECK(memcmp(osc_rcpt_checker_ids[0], r + 144, 32) == 0); /* pinned checker identity = the minting checker2 */ + osc_receipt_target_hash(OSC_RCPT_TARGET_NAME, strlen(OSC_RCPT_TARGET_NAME), h); + CHECK(memcmp(h, r + 208, 32) == 0); /* target constant = what issue --target wrote */ + uint8_t rv[1024]; + size_t rl = rcpt("n_revoked_id.rcpt", rv); + sha256_hash(rv, rl, h); + CHECK(rl == OSC_RCPT_BYTES && memcmp(h, osc_rcpt_qual_revoked_id, 32) == 0); + struct osc_policy p; + ck_osc_policy(&p); + CHECK(p.n_rcpt_owner == 0 && p.rcpt_owner_anchors == NULL); /* owner root listed, not trusted */ + CHECK(p.n_rcpt_checkers == 1 && p.rcpt_target != NULL && p.rcpt_producer == NULL && p.rcpt_firmware == NULL); + CHECK(p.rcpt_epoch_floor == 10 && p.rcpt_epoch_now == 20 && p.n_rcpt_revoked_keys == 0); + for (unsigned i = 0; i < p.n_rcpt_test; i++) CHECK(memcmp(p.rcpt_test_anchors[i], osc_rcpt_owner_root_pk, 32) != 0); +#ifdef CK_SEED0B_TEST_ANCHOR + CHECK(!p.release && p.n_rcpt_test == 1 && memcmp(p.rcpt_test_anchors[0], osc_rcpt_test_pk, 32) == 0); + CHECK(p.n_rcpt_revoked_ids == 1); +#else + CHECK(p.release && p.n_rcpt_test == 0 && p.n_rcpt_revoked_ids == 0); +#endif + /* the owner root constant is the ceremony key of docs/OWNER_KEY_CEREMONY.md (aienos#380) */ + static const char owner_hex[] = "578ada3cb0c2d154623ac089191023c8ad4bc5e63b8ccd1a38db2d679b8c9e76"; + char oh[65]; + hex(osc_rcpt_owner_root_pk, 32, oh); + CHECK(!strcmp(oh, owner_hex)); +} + +/* the qualification policy, with the TEST anchor whatever this binary's build is */ +static struct osc_policy qual(void) +{ + struct osc_policy p; + ck_osc_policy(&p); + static const uint8_t (*const rta)[32] = &osc_rcpt_test_pk; + static const uint8_t (*const rid)[32] = &osc_rcpt_qual_revoked_id; + p.release = 0; + p.rcpt_test_anchors = rta; + p.n_rcpt_test = 1; + p.rcpt_revoked_ids = rid; + p.n_rcpt_revoked_ids = 1; + return p; +} + +static void put16(uint8_t *p, unsigned v) { p[0] = (uint8_t)v; p[1] = (uint8_t)(v >> 8); } +static void put64(uint8_t *p, uint64_t v) { for (int i = 0; i < 8; i++) p[i] = (uint8_t)(v >> (8 * i)); } + +static unsigned v(const uint8_t *r, size_t len, const struct osc_accept *a, const struct osc_policy *p) +{ + return osc_receipt_verify(r, len, a, p, NULL); +} + +static void structure_and_order(void) +{ + uint8_t g[1024], r[1024]; + CHECK(rcpt("a01.rcpt", g) == OSC_RCPT_BYTES); + struct osc_accept a; + CHECK(admit("a01", &a)); + struct osc_policy p = qual(); + CHECK(v(g, 416, &a, &p) == 0); + CHECK(v(NULL, 416, &a, &p) == OSC_RCPT_MISSING); + CHECK(v(g, 0, &a, &p) == OSC_RCPT_MISSING); + CHECK(v(g, 416, NULL, &p) == OSC_RCPT_ARGUMENT); + CHECK(v(g, 416, &a, NULL) == OSC_RCPT_ARGUMENT); + CHECK(v(g, 415, &a, &p) == OSC_RCPT_SIZE); + CHECK(v(g, 417, &a, &p) == OSC_RCPT_SIZE); +#define MUTATE(stmt, want) do { memcpy(r, g, 416); stmt; unsigned got_ = v(r, 416, &a, &p); \ + if (got_ != (want)) { printf(" %s: got %u %s\n", #stmt, got_, osc_code_name(got_)); } \ + CHECK(got_ == (want)); } while (0) + MUTATE(r[0] ^= 1, OSC_RCPT_MAGIC); + MUTATE(r[7] = 1, OSC_RCPT_MAGIC); + MUTATE(put16(r + 8, 2), OSC_RCPT_VERSION); + MUTATE(put16(r + 8, 0), OSC_RCPT_VERSION); + MUTATE(put16(r + 12, 2), OSC_RCPT_SIGNATURE_ALGORITHM); + MUTATE(put16(r + 10, 3), OSC_RCPT_SIGNER_CLASS); + MUTATE(put16(r + 10, 0), OSC_RCPT_SIGNER_CLASS); + MUTATE(put16(r + 14, 3), OSC_RCPT_EVIDENCE_CLASS); + MUTATE(put16(r + 14, 0), OSC_RCPT_EVIDENCE_CLASS); + MUTATE(put16(r + 14, 2), OSC_RCPT_BAD_SIGNATURE); /* class 2 is well formed; the signature covers the change */ + MUTATE(put64(r + 312, 9), OSC_RCPT_EPOCH_ORDER); /* expiry 9 < policy epoch 10 */ + MUTATE(put64(r + 312, 10), OSC_RCPT_BAD_SIGNATURE); /* expiry == epoch is in order */ + /* order: the first failing step wins */ + MUTATE((r[0] ^= 1, put16(r + 8, 2)), OSC_RCPT_MAGIC); + MUTATE((put16(r + 8, 2), put16(r + 12, 2)), OSC_RCPT_VERSION); + MUTATE((put16(r + 12, 2), put16(r + 10, 3)), OSC_RCPT_SIGNATURE_ALGORITHM); + MUTATE((put16(r + 10, 3), put16(r + 14, 3)), OSC_RCPT_SIGNER_CLASS); + MUTATE((put16(r + 14, 3), put64(r + 312, 9)), OSC_RCPT_EVIDENCE_CLASS); + MUTATE((put64(r + 312, 9), r[400] ^= 1), OSC_RCPT_EPOCH_ORDER); + MUTATE(r[400] ^= 1, OSC_RCPT_BAD_SIGNATURE); + MUTATE(r[303] ^= 1, OSC_RCPT_BAD_SIGNATURE); /* last byte of the input digest, signed */ + MUTATE(r[351] ^= 1, OSC_RCPT_UNTRUSTED_SIGNER); /* last fingerprint byte */ + MUTATE(r[320] ^= 1, OSC_RCPT_UNTRUSTED_SIGNER); /* fingerprint names no anchor */ + MUTATE(put16(r + 10, 2), OSC_RCPT_UNTRUSTED_SIGNER); /* OWNER class: no owner anchor in the kernel policy */ + p.release = 1; + MUTATE((void)0, OSC_RCPT_TEST_SIGNER_IN_PRODUCTION); + MUTATE(put64(r + 312, 9), OSC_RCPT_EPOCH_ORDER); /* structure before class policy */ + MUTATE(put16(r + 10, 2), OSC_RCPT_UNTRUSTED_SIGNER); + /* release: an owner anchor other than the listed owner root is not honoured (here the TEST key as "owner") */ + static const uint8_t (*const tk)[32] = &osc_rcpt_test_pk; + p.rcpt_owner_anchors = tk; + p.n_rcpt_owner = 1; + p.n_rcpt_test = 0; /* so the both-classes rule (guard 11) cannot answer for the owner-root rule (guard 10) */ + MUTATE(put16(r + 10, 2), OSC_RCPT_UNTRUSTED_SIGNER); + p.release = 0; + p.n_rcpt_test = 0; + MUTATE(put16(r + 10, 2), OSC_RCPT_BAD_SIGNATURE); /* qualification honours it, then the class byte breaks the sig */ + /* a key anchored in both classes is refused */ + p = qual(); + p.rcpt_owner_anchors = tk; + p.n_rcpt_owner = 1; + MUTATE((void)0, OSC_RCPT_UNTRUSTED_SIGNER); + p = qual(); + static const uint8_t (*const ok)[32] = &osc_rcpt_owner_root_pk; + p.rcpt_test_anchors = ok; /* wrong key in the TEST set */ + MUTATE((void)0, OSC_RCPT_UNTRUSTED_SIGNER); + p = qual(); + p.n_rcpt_test = 0; + MUTATE((void)0, OSC_RCPT_UNTRUSTED_SIGNER); +#undef MUTATE +} + +static void policy_edges(void) +{ + uint8_t g[1024], rv[1024], fw[1024], np[1024]; + CHECK(rcpt("a01.rcpt", g) == OSC_RCPT_BYTES); + CHECK(rcpt("n_revoked_id.rcpt", rv) == OSC_RCPT_BYTES); + CHECK(rcpt("n_firmware.rcpt", fw) == OSC_RCPT_BYTES); + CHECK(rcpt("n_producer.rcpt", np) == OSC_RCPT_BYTES); + struct osc_accept a; + CHECK(admit("a01", &a)); + struct osc_policy p = qual(); + struct osc_receipt_info info; + /* revocation: the id is checked before the key */ + p.rcpt_revoked_keys = (const uint8_t (*)[32])test_fp; + p.n_rcpt_revoked_keys = 1; + CHECK(osc_receipt_verify(rv, 416, &a, &p, &info) == OSC_RCPT_REVOKED && info.revoked == OSC_RCPT_REVOKED_ID); + CHECK(osc_receipt_verify(g, 416, &a, &p, &info) == OSC_RCPT_REVOKED && info.revoked == OSC_RCPT_REVOKED_KEY); + p = qual(); + p.n_rcpt_revoked_ids = 0; + CHECK(v(rv, 416, &a, &p) == 0); + /* revocation before freshness: a revoked receipt that is also stale says REVOKED */ + p = qual(); + p.rcpt_epoch_floor = 12; + CHECK(v(rv, 416, &a, &p) == OSC_RCPT_REVOKED); + /* epoch window, inclusive at both ends (a01: policy epoch 10, expiry 1000) */ + p = qual(); + p.rcpt_epoch_now = 1000; + CHECK(v(g, 416, &a, &p) == 0); + p.rcpt_epoch_now = 1001; + CHECK(v(g, 416, &a, &p) == OSC_RCPT_EXPIRED); + p.rcpt_epoch_now = 10; + CHECK(v(g, 416, &a, &p) == 0); + p.rcpt_epoch_now = 9; + CHECK(v(g, 416, &a, &p) == OSC_RCPT_NOT_YET_VALID); + p.rcpt_epoch_now = 20; + p.rcpt_epoch_floor = 11; + CHECK(v(g, 416, &a, &p) == OSC_RCPT_STALE_EPOCH); + p.rcpt_epoch_now = 2000; /* stale wins over expired */ + CHECK(v(g, 416, &a, &p) == OSC_RCPT_STALE_EPOCH); + p = qual(); + /* checker list required; empty refuses every receipt */ + p.n_rcpt_checkers = 0; + CHECK(v(g, 416, &a, &p) == OSC_RCPT_UNTRUSTED_CHECKER); + p = qual(); + p.rcpt_epoch_now = 2000; /* freshness before checker identity */ + p.n_rcpt_checkers = 0; + CHECK(v(g, 416, &a, &p) == OSC_RCPT_EXPIRED); + /* binding: target required */ + p = qual(); + p.rcpt_target = NULL; + CHECK(v(g, 416, &a, &p) == OSC_RCPT_WRONG_TARGET); + p = qual(); + p.n_rcpt_checkers = 0; /* checker before binding */ + p.rcpt_target = NULL; + CHECK(v(g, 416, &a, &p) == OSC_RCPT_UNTRUSTED_CHECKER); + /* firmware: a policy that names one accepts exactly that one */ + p = qual(); + p.rcpt_firmware = fw + 240; + CHECK(v(fw, 416, &a, &p) == 0); + CHECK(v(g, 416, &a, &p) == OSC_RCPT_WRONG_FIRMWARE); + /* producer: NULL means none (all zero); a policy that names one accepts exactly that one */ + p = qual(); + CHECK(v(np, 416, &a, &p) == OSC_RCPT_WRONG_PRODUCER); + p.rcpt_producer = np + 176; + CHECK(v(np, 416, &a, &p) == 0); + CHECK(v(g, 416, &a, &p) == OSC_RCPT_WRONG_PRODUCER); + /* the binding reads the admitted unit: a different code hash in the verdict is EXECUTABLE_MISMATCH, a different + * IR hash PROGRAM_MISMATCH (program before executable) */ + p = qual(); + struct osc_accept b = a; + b.code_sha256[31] ^= 1; + CHECK(v(g, 416, &b, &p) == OSC_RCPT_EXECUTABLE_MISMATCH); + b.ir_sha256[0] ^= 1; + CHECK(v(g, 416, &b, &p) == OSC_RCPT_PROGRAM_MISMATCH); + /* every single-bit flip of a valid receipt is refused */ + uint8_t r[416]; + int flips = 0, accepted = 0; + for (unsigned i = 0; i < 416; i++) + for (unsigned bit = 0; bit < 8; bit++) { + memcpy(r, g, 416); + r[i] ^= (uint8_t)(1u << bit); + if (v(r, 416, &a, &p) == 0) accepted++; + flips++; + } + CHECK(flips == 3328 && accepted == 0); + printf(" single-bit flips of a01.rcpt: %d refused of %d\n", flips - accepted, flips); + /* the verifier is pure: the same inputs give the same verdict and the inputs are not written */ + uint8_t before[416]; + memcpy(before, g, 416); + CHECK(v(g, 416, &a, &p) == 0 && v(g, 416, &a, &p) == 0 && memcmp(before, g, 416) == 0); +} + +/* Re-sign a receipt in memory with checker2's published TEST key (spec section 3: seed = SHA-256 of the stated + * string; the key is a TEST key by definition, never a release signer). Written from spec section 3; it must + * reproduce checker2's own signature on an unchanged receipt (Ed25519 is deterministic), which cross-checks the + * signed-message construction of the verifier from a second direction. */ +static void test_seed(uint8_t sk[32]) +{ + static const char s[] = "OMEGA-CHECKER2-TEST-KEY-v1 NOT FOR PRODUCTION"; + sha256_hash((const uint8_t *)s, sizeof s - 1, sk); +} + +static void resign(uint8_t *r) +{ + static const char body_dom[] = "OMEGA-REALIZATION-RECEIPT-V1", sig_dom[] = "OMEGA-REALIZATION-RECEIPT-SIG-V1"; + uint8_t msg[sizeof sig_dom + 32], sk[32]; + sha256_ctx c; + memcpy(msg, sig_dom, sizeof sig_dom); + sha256_init(&c); + sha256_update(&c, (const uint8_t *)body_dom, sizeof body_dom); + sha256_update(&c, r, OSC_RCPT_SIGNED_BYTES); + sha256_final(&c, msg + sizeof sig_dom); + test_seed(sk); + CHECK(aienos_ed25519_sign(r + OSC_RCPT_SIGNED_BYTES, msg, sizeof msg, sk) == AIENOS_SIG_OK); + memset(sk, 0, sizeof sk); +} + +static void resigned(void) +{ + uint8_t g[1024], r[416], sk[32], pk[32]; + CHECK(rcpt("a01.rcpt", g) == OSC_RCPT_BYTES); + test_seed(sk); + CHECK(aienos_ed25519_public_key(pk, sk) == AIENOS_SIG_OK && memcmp(pk, osc_rcpt_test_pk, 32) == 0); + memcpy(r, g, 416); + memset(r + 352, 0, 64); + resign(r); + CHECK(memcmp(r, g, 416) == 0); /* same bytes as checker2 wrote */ + struct osc_accept a; + CHECK(admit("a01", &a)); + struct osc_policy p = qual(); + /* evidence class 2, correctly signed: refused LRAT_PROOFS_REQUIRED, and only after every section 6 step */ + memcpy(r, g, 416); + put16(r + 14, 2); + resign(r); + CHECK(v(r, 416, &a, &p) == OSC_RCPT_LRAT_PROOFS_REQUIRED); + memcpy(r, g, 416); + put16(r + 14, 2); + r[208] ^= 1; + resign(r); + CHECK(v(r, 416, &a, &p) == OSC_RCPT_WRONG_TARGET); + /* a signed class 1 receipt with a changed field reaches the step that reads that field */ + memcpy(r, g, 416); + r[272] ^= 1; /* input digest: NOT CHECKED, still valid */ + r[16] ^= 1; /* requirements digest: NOT CHECKED for class 1, still valid */ + resign(r); + CHECK(v(r, 416, &a, &p) == 0); + memcpy(r, g, 416); + put64(r + 304, 15); /* policy epoch 15, now 20: valid; now 14: NOT_YET_VALID */ + resign(r); + CHECK(v(r, 416, &a, &p) == 0); + p.rcpt_epoch_now = 14; + CHECK(v(r, 416, &a, &p) == OSC_RCPT_NOT_YET_VALID); +} + +static void names(void) +{ + CHECK(!strcmp(osc_code_name(OSC_RCPT_MISSING), "RECEIPT_MISSING")); + CHECK(!strcmp(osc_code_name(OSC_RCPT_REVOKED), "RECEIPT_REVOKED")); + CHECK(!strcmp(osc_code_name(OSC_RCPT_DEPENDENCIES_MISMATCH), "RECEIPT_DEPENDENCIES_MISMATCH")); + CHECK(!strcmp(osc_code_name(OSC_RCPT_LRAT_PROOFS_REQUIRED), "RECEIPT_LRAT_PROOFS_REQUIRED") && !strcmp(osc_code_name(95), "?")); + CHECK(!strcmp(osc_code_name(72), "?") && !strcmp(osc_code_name(85), "?") && !strcmp(osc_code_name(89), "?")); + CHECK(!strcmp(osc_code_name(OSC_CODE_HASH_MISMATCH), "CODE_HASH_MISMATCH")); /* unit codes unchanged */ + /* spec reason n is kernel code 64 + n */ + CHECK(OSC_RCPT_SIZE == OSC_RCPT_BASE + 1 && OSC_RCPT_UNTRUSTED_CHECKER == OSC_RCPT_BASE + 22); +} + +static void store_table(void) +{ + uint8_t g[1024], big[600]; + CHECK(rcpt("a01.rcpt", g) == OSC_RCPT_BYTES); + CHECK(ck_osc_is_receipt(g, 416) && !ck_osc_is_receipt(g, 7) && !ck_osc_is_receipt(NULL, 416)); + CHECK(!ck_osc_is_receipt((const uint8_t *)"OSCUNIT\0", 8)); + size_t len = 99; + CHECK(ck_osc_receipt_find("a01.rcpt", &len) == NULL && len == 0); + outn = 0; + ck_osc_receipt_candidate("a01.rcpt", g, 416); + CHECK(strstr(out, "osc_receipt: a01.rcpt STORED bytes=416 id=613e1cece39535842e2b3e406147b837b4bb1ed91628caf54735c7c09cb70996 ") != NULL); + const uint8_t *k = ck_osc_receipt_find("a01.rcpt", &len); + CHECK(k != NULL && len == 416 && memcmp(k, g, 416) == 0); + CHECK(ck_osc_receipt_find("a01.rcp", &len) == NULL && ck_osc_receipt_find("a01.rcpt2", &len) == NULL); + memcpy(big, g, 416); + memset(big + 416, 0, sizeof big - 416); + ck_osc_receipt_candidate("big.rcpt", big, sizeof big); + k = ck_osc_receipt_find("big.rcpt", &len); + struct osc_accept a; + CHECK(admit("a01", &a)); + struct osc_policy p = qual(); + CHECK(k != NULL && len == 512 && v(k, len, &a, &p) == OSC_RCPT_SIZE); + char nm[16]; + for (unsigned i = 0; i < 30; i++) { + snprintf(nm, sizeof nm, "f%u.rcpt", i); + ck_osc_receipt_candidate(nm, g, 416); + } + CHECK(strstr(out, "osc_receipt: f21.rcpt STORED") != NULL && strstr(out, "osc_receipt: f22.rcpt DROPPED") != NULL); + CHECK(ck_osc_receipt_find("f22.rcpt", &len) == NULL); + outn = 0; + ck_osc_summary(); + CHECK(strstr(out, "osc_receipts: seen=32 stored=24 dropped=8 ") != NULL); +} + +int main(void) +{ + sha256_hash(osc_rcpt_test_pk, 32, test_fp[0]); + { + uint8_t np[1024]; + CHECK(rcpt("n_producer.rcpt", np) == OSC_RCPT_BYTES); + memcpy(producer, np + 176, 32); + } +#ifdef CK_SEED0B_TEST_ANCHOR + printf(" policy: qualification (CK_SEED0B_TEST_ANCHOR)\n"); +#else + printf(" policy: release\n"); +#endif + expected_table(); + trust_inputs(); + structure_and_order(); + policy_edges(); + names(); + resigned(); + store_table(); + return ck_t_verdict("test_osc_receipt"); +} diff --git a/scripts/.crumb b/scripts/.crumb index 869545dc..0fbb0b00 100644 --- a/scripts/.crumb +++ b/scripts/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-14T13:26:06Z", + "compiled_at": "2026-10-14T19:55:50Z", "compiler": "crumb-compile/1", - "digest": "sha256:fe47cb248b0f45e1d91fe38a8787181eee2a42fcd49cc313a70323f207d48392", + "digest": "sha256:45d955c9b529e601b184a680d586daffbe5efe31f98d9524bf58ace7ef3e1e22", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 115, - "generated_at_commit": "0d3545fd67a68cb35cb6604be47008826081b309", - "source_tree": "sha256:2db4f6237f7ea63129e4e850cf2ff96f4e6fd726bf38ad59c5c633305bad391c" + "files": 116, + "generated_at_commit": "29a30a6c135f5840b90a64031ed8f532c84ed80a", + "source_tree": "sha256:e062288c9cefc0fc5b093760d22b205b1d9c96d77a985b6690f16ad54bdd0ba4" }, "owner_lane": "", "provenance": { diff --git a/scripts/ck_gates.sh b/scripts/ck_gates.sh index d687e95d..7ef86853 100755 --- a/scripts/ck_gates.sh +++ b/scripts/ck_gates.sh @@ -12,11 +12,11 @@ # scripts/qemu_ck_infer_test.sh, scripts/qemu_ck_screen_test.sh, # scripts/qemu_ck_console_test.sh, # scripts/qemu_ck_rollback_test.sh, scripts/qemu_ck_osc_unit_test.sh, -# scripts/qemu_ck_osc_launch_test.sh, scripts/qemu_ck_osh_core_test.sh, scripts/qemu_ck_osh_op_test.sh, +# scripts/qemu_ck_osc_launch_test.sh, scripts/qemu_ck_osc_receipt_test.sh, scripts/qemu_ck_osh_core_test.sh, scripts/qemu_ck_osh_op_test.sh, # scripts/qemu_ck_slot_loader_test.sh), and prints # one line per gate: # AIENOS_CK_<gate>: PASS|FAIL|NOT_RUN [(reason)] -# for M1 M3 SMMU NVME_SHUTDOWN P2_ARTIFACT M0_ROLLBACK OSC_UNIT OSC_LAUNCH OSH_CORE OSH_OP M4_NVME M4_STORE M4_STORE_CRASH +# for M1 M3 SMMU NVME_SHUTDOWN P2_ARTIFACT M0_ROLLBACK OSC_UNIT OSC_LAUNCH OSC_RECEIPT OSH_CORE OSH_OP M4_NVME M4_STORE M4_STORE_CRASH # M4_CONTINUITY M4_RECOVERY M4_ALLEN ARGUS1_REVOKE KEYBOARD NET SMP DISK_LAYOUT FPU INFER SCREEN CONSOLE SLOT_LOADER. Gates with no C # implementation print NOT_RUN (MISSING_IMPLEMENTATION: <reason>) and never # run anything. A missing child script, a child that reports NOT_RUN, a child @@ -72,6 +72,7 @@ set -uo pipefail # rollback -> verdict line from scripts/qemu_ck_rollback_test.sh (C image as the one-time BootNext candidate, AAVMF) # osc -> verdict line from scripts/qemu_ck_osc_unit_test.sh (OSC unit admission, OSC_UNIT_ARTIFACT v1; QEMU, TEST signer, not physical) # osc_launch -> verdict line from scripts/qemu_ck_osc_launch_test.sh (OSC unit task launch, OSC_UNIT_ARTIFACT v1 section 9; QEMU, TEST signer, not physical) +# osc_receipt -> verdict line from scripts/qemu_ck_osc_receipt_test.sh (launch requires a valid Omega realization receipt, aienos#383; QEMU, TEST signer, not physical) # osh_core -> verdict line from scripts/qemu_ck_osh_core_test.sh (OSH shell core as EL0 tasks, step trace equals Linux; QEMU, TEST signer, not physical) # osh_op -> verdict line from scripts/qemu_ck_osh_op_test.sh (a real capability-authorized OSH operation, klog; QEMU, TEST signer, not physical) # slots -> verdict line from scripts/qemu_ck_slot_loader_test.sh (SLOTLDR.EFI signed A/B slot loader: bounded tries, rollback, refusals; QEMU, TEST signer, not physical) @@ -86,6 +87,7 @@ P2_ARTIFACT|artifact|- M0_ROLLBACK|rollback|- OSC_UNIT|osc|- OSC_LAUNCH|osc_launch|- +OSC_RECEIPT|osc_receipt|- OSH_CORE|osh_core|- OSH_OP|osh_op|- M4_NVME|store|- @@ -105,7 +107,7 @@ SCREEN|screen|- CONSOLE|console|- SLOT_LOADER|slots|- ' -CHILDREN=(boot store net artifact smp crash disk cont recov allen kbd fpu infer screen console rollback osc osc_launch osh_core osh_op slots) +CHILDREN=(boot store net artifact smp crash disk cont recov allen kbd fpu infer screen console rollback osc osc_launch osc_receipt osh_core osh_op slots) # Gate selection (--only): empty selection means every gate (the default). selection_active=0 declare -A sel_gate=() @@ -188,6 +190,7 @@ set_default_children() { [rollback]="${repo_root}/scripts/qemu_ck_rollback_test.sh" [osc]="${repo_root}/scripts/qemu_ck_osc_unit_test.sh" [osc_launch]="${repo_root}/scripts/qemu_ck_osc_launch_test.sh" + [osc_receipt]="${repo_root}/scripts/qemu_ck_osc_receipt_test.sh" [osh_core]="${repo_root}/scripts/qemu_ck_osh_core_test.sh" [osh_op]="${repo_root}/scripts/qemu_ck_osh_op_test.sh" [slots]="${repo_root}/scripts/qemu_ck_slot_loader_test.sh" @@ -441,11 +444,11 @@ self_test() { } expect_missing_all() { local g - for g in P2_ARTIFACT M0_ROLLBACK OSC_UNIT OSC_LAUNCH OSH_CORE OSH_OP M4_STORE_CRASH M4_CONTINUITY M4_RECOVERY M4_ALLEN KEYBOARD DISK_LAYOUT FPU INFER SCREEN CONSOLE; do expect "${g}" NOT_RUN; done # P2_ARTIFACT: no artifact child in A..G; M4_STORE_CRASH: no crash child in A..J and R; DISK_LAYOUT: no disk child in A..S + for g in P2_ARTIFACT M0_ROLLBACK OSC_UNIT OSC_LAUNCH OSC_RECEIPT OSH_CORE OSH_OP M4_STORE_CRASH M4_CONTINUITY M4_RECOVERY M4_ALLEN KEYBOARD DISK_LAYOUT FPU INFER SCREEN CONSOLE; do expect "${g}" NOT_RUN; done # P2_ARTIFACT: no artifact child in A..G; M4_STORE_CRASH: no crash child in A..J and R; DISK_LAYOUT: no disk child in A..S } scenario() { # NAME BOOT_SCRIPT STORE_SCRIPT [NET_SCRIPT] [ARTIFACT_SCRIPT] [SMP_SCRIPT] [CRASH_SCRIPT] [DISK_SCRIPT] (absent: missing) scen="$1" - declare -gA child_script=([boot]="$2" [store]="$3" [net]="${4:-${tmp}/kids/net_not_present.sh}" [artifact]="${5:-${tmp}/kids/no_artifact_child.sh}" [smp]="${6:-${tmp}/kids/no_smp_child.sh}" [crash]="${7:-${tmp}/kids/no_crash_child.sh}" [disk]="${8:-${tmp}/kids/no_disk_child.sh}" [cont]="${tmp}/kids/no_cont_child.sh" [recov]="${tmp}/kids/no_recov_child.sh" [allen]="${tmp}/kids/no_allen_child.sh" [kbd]="${kbd_kid:-${tmp}/kids/no_kbd_child.sh}" [fpu]="${tmp}/kids/no_fpu_child.sh" [infer]="${tmp}/kids/no_infer_child.sh" [screen]="${tmp}/kids/no_screen_child.sh" [console]="${console_kid:-${tmp}/kids/no_console_child.sh}" [rollback]="${rollback_kid:-${tmp}/kids/no_rollback_child.sh}" [osc]="${osc_kid:-${tmp}/kids/no_osc_child.sh}" [osc_launch]="${osc_launch_kid:-${tmp}/kids/no_osc_launch_child.sh}" [osh_core]="${osh_core_kid:-${tmp}/kids/no_osh_core_child.sh}" [osh_op]="${osh_op_kid:-${tmp}/kids/no_osh_op_child.sh}" [slots]="${slots_kid:-${tmp}/kids/no_slots_child.sh}") + declare -gA child_script=([boot]="$2" [store]="$3" [net]="${4:-${tmp}/kids/net_not_present.sh}" [artifact]="${5:-${tmp}/kids/no_artifact_child.sh}" [smp]="${6:-${tmp}/kids/no_smp_child.sh}" [crash]="${7:-${tmp}/kids/no_crash_child.sh}" [disk]="${8:-${tmp}/kids/no_disk_child.sh}" [cont]="${tmp}/kids/no_cont_child.sh" [recov]="${tmp}/kids/no_recov_child.sh" [allen]="${tmp}/kids/no_allen_child.sh" [kbd]="${kbd_kid:-${tmp}/kids/no_kbd_child.sh}" [fpu]="${tmp}/kids/no_fpu_child.sh" [infer]="${tmp}/kids/no_infer_child.sh" [screen]="${tmp}/kids/no_screen_child.sh" [console]="${console_kid:-${tmp}/kids/no_console_child.sh}" [rollback]="${rollback_kid:-${tmp}/kids/no_rollback_child.sh}" [osc]="${osc_kid:-${tmp}/kids/no_osc_child.sh}" [osc_launch]="${osc_launch_kid:-${tmp}/kids/no_osc_launch_child.sh}" [osc_receipt]="${osc_receipt_kid:-${tmp}/kids/no_osc_receipt_child.sh}" [osh_core]="${osh_core_kid:-${tmp}/kids/no_osh_core_child.sh}" [osh_op]="${osh_op_kid:-${tmp}/kids/no_osh_op_child.sh}" [slots]="${slots_kid:-${tmp}/kids/no_slots_child.sh}") run_children 2>/dev/null evaluate_table >"${tmp}/${scen}.out" } @@ -461,8 +464,8 @@ self_test() { "$(fake smpA 0 'PASS 3 secondary cores checked in' 'AIENOS_CK_SMP_MUTATION: FAIL' 'AIENOS_CK_SMP: PASS')" expect M1 PASS; expect M3 PASS; expect M4_NVME PASS; expect M4_STORE PASS; expect ARGUS1_REVOKE PASS; expect SMMU PASS; expect NVME_SHUTDOWN PASS; expect NET PASS; expect SMP PASS; expect_missing_all count_rows - [[ "${n_pass}/${n_fail}/${n_notrun}/${n_total}" == "9/0/17/26" && ${overall} == NOT_ALL_GATES_PASS ]] \ - && ok "A: counts 9/0/17 of 26, verdict NOT_ALL_GATES_PASS" || bad "A: counts ${n_pass}/${n_fail}/${n_notrun}/${n_total} ${overall}" + [[ "${n_pass}/${n_fail}/${n_notrun}/${n_total}" == "9/0/18/27" && ${overall} == NOT_ALL_GATES_PASS ]] \ + && ok "A: counts 9/0/18 of 27, verdict NOT_ALL_GATES_PASS" || bad "A: counts ${n_pass}/${n_fail}/${n_notrun}/${n_total} ${overall}" [[ "$(nvme_dma_mode)" == "Confined (QEMU SMMUv3 stage 1, out-of-window DMA faulted); no-SMMU boot denied (NoSmmu); TEST-ONLY bypass image checked separately" ]] && ok "A: confined DMA mode recorded from the store PASS lines" || bad "A: dma mode '$(nvme_dma_mode)'" grep -qxF "AIENOS_CK_M4_NVME: PASS (${M4_NVME_PASS_NOTE})" "${tmp}/A.out" \ && ok "A: M4_NVME PASS line carries the confined-mode note" || bad "A: M4_NVME PASS line lacks the note" @@ -474,7 +477,7 @@ self_test() { && ok "a missing-source row is NOT_RUN (MISSING_IMPLEMENTATION: reason)" || bad "missing-source row not NOT_RUN" grep -q '^AIENOS_CK_KEYBOARD: NOT_RUN' "${tmp}/A.out" \ && ok "A: KEYBOARD claimed PASS by the store child stays NOT_RUN without its own child" || bad "A: KEYBOARD line wrong" - [[ "$(grep -c '^AIENOS_CK_[A-Z0-9_]*: ' "${tmp}/A.out")" == 26 ]] && ok "A: exactly 26 verdict lines" || bad "A: verdict line count" + [[ "$(grep -c '^AIENOS_CK_[A-Z0-9_]*: ' "${tmp}/A.out")" == 27 ]] && ok "A: exactly 27 verdict lines" || bad "A: verdict line count" # B: boot FAIL; store script missing -> its three gates NOT_RUN, never PASS. scenario B "$(fake bootB 1 'FAIL kernel: alive' 'AIENOS_CK_M3: FAIL' 'AIENOS_CK_M1: FAIL')" "${tmp}/kids/does_not_exist.sh" @@ -615,6 +618,17 @@ self_test() { scenario LB "$(fake bootLB 0 'AIENOS_CK_M1: PASS')" "$(fake storeLB 0 'AIENOS_CK_OSC_LAUNCH: PASS')" expect OSC_LAUNCH FAIL unset osc_launch_kid + # EA, EB, EC: OSC_RECEIPT comes only from its own child (scripts/qemu_ck_osc_receipt_test.sh, aienos#383). + osc_receipt_kid="$(fake orA 0 'PASS x' 'AIENOS_CK_OSC_RECEIPT: PASS')" + scenario EA "$(fake bootEA 0 'AIENOS_CK_M1: PASS')" "$(fake storeEA 0 'AIENOS_CK_OSC_RECEIPT: FAIL')" + expect OSC_RECEIPT PASS + osc_receipt_kid="$(fake orB 1 'FAIL y' 'AIENOS_CK_OSC_RECEIPT: FAIL')" + scenario EB "$(fake bootEB 0 'AIENOS_CK_M1: PASS')" "$(fake storeEB 0 'AIENOS_CK_OSC_RECEIPT: PASS')" + expect OSC_RECEIPT FAIL + osc_receipt_kid="$(fake orC 3 'NOT_RUN QEMU gate lock held' 'AIENOS_CK_OSC_RECEIPT: NOT_RUN')" + scenario EC "$(fake bootEC 0 'AIENOS_CK_M1: PASS')" "$(fake storeEC 0 'AIENOS_CK_OSC_RECEIPT: PASS')" + expect OSC_RECEIPT NOT_RUN + unset osc_receipt_kid # HA, HB: OSH_CORE comes only from its own child (scripts/qemu_ck_osh_core_test.sh). osh_core_kid="$(fake ohA 0 'PASS x' 'AIENOS_CK_OSH_CORE: PASS')" scenario HA "$(fake bootHA 0 'AIENOS_CK_M1: PASS')" "$(fake storeHA 0 'AIENOS_CK_OSH_CORE: FAIL')" @@ -634,10 +648,10 @@ self_test() { && ok "SEL1: the store child was not run, the boot child was" || bad "SEL1: child selection wrong" grep -qxF "AIENOS_CK_SMMU: NOT_SELECTED (not in this run's --only list)" "${tmp}/SEL1.out" \ && ok "SEL1: selected-out gate prints an explicit NOT_SELECTED line" || bad "SEL1: no NOT_SELECTED line" - [[ "$(grep -c '^AIENOS_CK_' "${tmp}/SEL1.out")" == 26 ]] && ok "SEL1: all 26 gates still reported (none dropped)" || bad "SEL1: gate lines dropped" + [[ "$(grep -c '^AIENOS_CK_' "${tmp}/SEL1.out")" == 27 ]] && ok "SEL1: all 27 gates still reported (none dropped)" || bad "SEL1: gate lines dropped" count_rows - [[ "${n_pass}/${n_fail}/${n_notrun}/${n_notsel}/${n_total}" == "2/0/0/24/26" && ${overall} == SELECTED_GATES_PASS_QEMU_ONLY ]] \ - && ok "SEL1: counts 2 pass, 24 not selected, never ALL_GATES_PASS" || bad "SEL1: counts ${n_pass}/${n_fail}/${n_notrun}/${n_notsel}/${n_total} ${overall}" + [[ "${n_pass}/${n_fail}/${n_notrun}/${n_notsel}/${n_total}" == "2/0/0/25/27" && ${overall} == SELECTED_GATES_PASS_QEMU_ONLY ]] \ + && ok "SEL1: counts 2 pass, 25 not selected, never ALL_GATES_PASS" || bad "SEL1: counts ${n_pass}/${n_fail}/${n_notrun}/${n_notsel}/${n_total} ${overall}" # SEL2: a selected gate that FAILs fails the run; a selected gate with no # verdict is FAIL, not dropped. scenario SEL2 "$(fake bootS2 1 'AIENOS_CK_M1: FAIL' 'AIENOS_CK_M3: PASS')" "$(fake storeS2 0 'AIENOS_CK_SMMU: PASS')" @@ -690,10 +704,10 @@ self_test() { # Restore the clean-tree receipt as the one the checks below look at. write_receipt if command -v jq >/dev/null; then - jq -e '.physical == "NOT_RUN" and (.gates | length) == 26 and .verdict == "NOT_ALL_GATES_PASS" + jq -e '.physical == "NOT_RUN" and (.gates | length) == 27 and .verdict == "NOT_ALL_GATES_PASS" and ([.gates[] | select(.id == "M1")][0].verdict == "PASS") and ([.gates[] | select(.id == "ARGUS1_REVOKE")][0].verdict == "FAIL") - and (.children | length) == 21 and .commit_subject == "quote \" backslash \\ tab\tend"' "${receipt_path}" >/dev/null \ + and (.children | length) == 22 and .commit_subject == "quote \" backslash \\ tab\tend"' "${receipt_path}" >/dev/null \ && ok "receipt is valid JSON (jq) with expected fields" || bad "receipt JSON invalid or fields wrong" else echo "NOT_RUN jq not installed; JSON validity not machine-checked"; jq_skipped=1 @@ -706,18 +720,18 @@ self_test() { bad "an existing receipt was overwritten or the clash was not refused" fi - # The gate table parses: 26 rows, known sources, reasons only on missing rows. + # The gate table parses: 27 rows, known sources, reasons only on missing rows. local g s w rows=0 tbad=0 while IFS='|' read -r g s w; do [[ -n "${g}" ]] || continue rows=$((rows + 1)) case "${s}" in - boot|store|net|artifact|smp|crash|disk|cont|recov|allen|kbd|fpu|infer|screen|console|rollback|osc|osc_launch|osh_core|osh_op|slots) [[ "${w}" == - ]] || tbad=1 ;; + boot|store|net|artifact|smp|crash|disk|cont|recov|allen|kbd|fpu|infer|screen|console|rollback|osc|osc_launch|osc_receipt|osh_core|osh_op|slots) [[ "${w}" == - ]] || tbad=1 ;; missing) [[ -n "${w}" && "${w}" != - ]] || tbad=1 ;; *) tbad=1 ;; esac done <<<"${CK_GATE_TABLE}" - [[ ${tbad} == 0 && ${rows} == 26 ]] && ok "gate table: 26 rows well-formed" || bad "gate table malformed (${rows} rows)" + [[ ${tbad} == 0 && ${rows} == 27 ]] && ok "gate table: 27 rows well-formed" || bad "gate table malformed (${rows} rows)" # Dirty-tree refusal, end to end, on a private clone (never this tree). # Both runs stop before any child script (no QEMU). diff --git a/scripts/qemu_ck_osc_launch_test.sh b/scripts/qemu_ck_osc_launch_test.sh index 8f2f5177..69c2d7e0 100755 --- a/scripts/qemu_ck_osc_launch_test.sh +++ b/scripts/qemu_ck_osc_launch_test.sh @@ -61,7 +61,9 @@ make -s -C native/kernel OUT="${out_prod}" store-image gpt-image >/dev/null simg="${out_prod}/host/ck_store_image" fix="native/kernel/tests/fixtures/osc_unit" -files=("${fix}/vectors/a01_valid_min.unit" "${fix}/launch/l01_launch_fns.unit" "${fix}/vectors/a06_valid_limits_at_max.unit" "${fix}/launch/l02_stack_over.unit") +rfix="native/kernel/tests/fixtures/osc_receipt" +# aienos#383: a launch needs a valid realization receipt; a06 shares a01's, l02 shares l01's (same IR and code) +files=("${fix}/vectors/a01_valid_min.unit" "${fix}/launch/l01_launch_fns.unit" "${fix}/vectors/a06_valid_limits_at_max.unit" "${fix}/launch/l02_stack_over.unit" "${rfix}/a01.rcpt" "${rfix}/l01.rcpt") a01_line=$(grep -E '^a01_valid_min\.unit ' "${fix}/vectors/expected.txt") a01_digest=$(sed -E 's/.* unit_digest=([0-9a-f]{64}) .*/\1/' <<<"${a01_line}") [[ ${#a01_digest} == 64 ]] || fail "expected UnitDigest read from the frozen expected.txt" @@ -110,13 +112,18 @@ boot "${out_launch}/full/BOOTAA64.EFI" "${serial}" "${work}/disk-run.img" release_flag check "${serial}" "left firmware and entered the kernel" "kernel: alive" -check "${serial}" "kernel read all four candidates from the boot disk Store" "^artifact_candidates: 4$" +check "${serial}" "kernel read all six candidates (four units, two receipts) from the boot disk Store" "^artifact_candidates: 6$" if has "${serial}" "^report-truncated:"; then fail "kernel report lines were truncated"; else pass "no kernel report line was truncated"; fi check "${serial}" "final report reached the console" "report_kind: final" if has "${serial}" "report_kind: (panic|fault)"; then fail "panic or fault reported (a unit fault must stay contained)"; else pass "no kernel panic or fault report: unit faults stayed contained"; fi check "${serial}" "a01 admitted with the frozen UnitDigest" "^osc_unit: a01_valid_min\\.unit ACCEPT unit_digest=${a01_digest} " check "${serial}" "l01 admitted (every hand-assembled word is in the OSC subset)" "^osc_unit: l01_launch_fns\\.unit ACCEPT .* funcs=14 caps=0 signer=TEST$" check "${serial}" "totals: 4 seen, 4 accepted" "^osc_units: seen=4 accepted=4 refused=0 oversize=0 " +check "${serial}" "receipt policy line (aienos#383): launch requires a valid receipt" \ + "^osc_receipt_policy: mode=qualification receipt_test_anchors=1 .* launch requires a valid receipt; QEMU, not physical$" +check "${serial}" "a01.rcpt stored from the Store" "^osc_receipt: a01\\.rcpt STORED bytes=416 id=$(sha256sum native/kernel/tests/fixtures/osc_receipt/a01.rcpt | cut -c1-64) " +check "${serial}" "l01.rcpt stored from the Store" "^osc_receipt: l01\\.rcpt STORED bytes=416 id=$(sha256sum native/kernel/tests/fixtures/osc_receipt/l01.rcpt | cut -c1-64) " +check "${serial}" "receipt totals: 2 seen, 2 stored" "^osc_receipts: seen=2 stored=2 dropped=0 " check "${serial}" "launch policy line, labelled" "^osc_launch_policy: units=4 code_max=65536 stack_max=65536 in_max=4096 ws_max=32 pages; 1 tick = 10 ms; QEMU \\(aarch64 virt\\), TEST signer, not physical$" label='QEMU \(aarch64 virt\), TEST signer, not physical' diff --git a/scripts/qemu_ck_osc_receipt_test.sh b/scripts/qemu_ck_osc_receipt_test.sh new file mode 100755 index 00000000..0c12edb4 --- /dev/null +++ b/scripts/qemu_ck_osc_receipt_test.sh @@ -0,0 +1,163 @@ +#!/usr/bin/env bash +# AIENOS_CK_OSC_RECEIPT gate (aienos#383): the C kernel refuses to launch an OSC unit unless a valid signed Omega +# realization receipt (omega spec/one-layer-receipts.md, receipt v1) comes with it. Booted in QEMU AArch64 + UEFI +# (AAVMF). +# +# Label: QEMU (aarch64 virt), TEST signer, not physical. Nothing here ran on a Spark or any real machine. The +# receipts are minted by omega checker2 with its TEST key (tests/fixtures/osc_receipt/PROVENANCE.txt); the units +# are signed with the container spec's THROWAWAY TEST key. +# +# One unit (a01_valid_min.unit) and thirteen receipts are written into the sealed C Store of a GPT boot disk +# image. One boot of the qualification image built with CK_SEED0B_TEST_ANCHOR=1 CK_OSC_LAUNCH_TEST=1 +# CK_OSC_RECEIPT_TEST=1 launches a01 add(a, b) seventeen times, each time with one receipt or none, and prints one +# "osc_rcpt_launch:" line each. This gate checks: +# with the valid receipt the unit RETURNS the exact value (first and last launch); +# no receipt, an altered, stale, revoked, expired, not-yet-valid, wrong-target, wrong-firmware, wrong-program, +# wrong-executable, wrong-length, wrong-dependencies or untrusted-checker receipt, the TEST key revoked, and a +# TEST receipt under the release policy are each REFUSED with its own named reason, and nothing is mapped; +# the receipt id printed is the SHA-256 of the receipt file. +# Last line: AIENOS_CK_OSC_RECEIPT: PASS|FAIL|NOT_RUN. +# Needs qemu-system-aarch64 and AAVMF (Ubuntu: qemu-system-arm qemu-efi-aarch64). +set -euo pipefail + +repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +cd "${repo_root}" +verdict=AIENOS_CK_OSC_RECEIPT +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; } + +# Machine quiet flag (read only) and the QEMU gate lock (one gate at a time): +# scripts/lib_gate_hold.sh (aienos#278). +. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/lib_gate_hold.sh" +if ! gh_quiet_check || ! gh_lock_take "qemu_ck_osc_receipt_test" "${AIENOS_GATE_MINUTES:-60}"; then + echo "NOT_RUN ${gh_why}" + echo "${verdict}: NOT_RUN" + exit 3 +fi +# Release only this run's own gate lock record, at most once. +release_flag() { gh_lock_release; } +work="$(mktemp -d)" +cleanup() { rm -rf "${work}"; release_flag; } +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_prod="${AIENOS_CK_OUT_PROD:-${repo_root}/target/native-kernel}" +out_rcpt="${AIENOS_CK_OUT_RECEIPT:-${repo_root}/target/native-kernel-osc-receipt-test}" +mk() { make -s -C native/kernel CROSS="${cross}" AIENOS_COMMIT="${commit}" "$@" >/dev/null; } +mk OUT="${out_rcpt}" CK_SEED0B_TEST_ANCHOR=1 CK_OSC_LAUNCH_TEST=1 CK_OSC_RECEIPT_TEST=1 full +make -s -C native/kernel OUT="${out_prod}" store-image gpt-image >/dev/null +simg="${out_prod}/host/ck_store_image" + +fix="native/kernel/tests/fixtures/osc_unit" +rfix="native/kernel/tests/fixtures/osc_receipt" +rcpts=(a01 l01 n_altered n_stale n_revoked_id n_expired n_future n_target n_program n_length n_firmware n_deps n_checker) +files=("${fix}/vectors/a01_valid_min.unit") +for r in "${rcpts[@]}"; do files+=("${rfix}/${r}.rcpt"); done +disk="${work}/nvme.img" +"${out_prod}/host/ck_gpt_image" create "${disk}" 512 64 aienos-middle >/dev/null || fail "GPT boot disk image created" +if "${simg}" build "${disk}" 512 "${files[@]}" >"${work}/build.txt" 2>&1; then pass "boot disk built: $(head -1 "${work}/build.txt")" +else fail "boot disk build: $(head -3 "${work}/build.txt" | tr '\n' ' ')"; fi +"${simg}" list "${disk}" 512 >"${work}/list.txt" 2>&1 || fail "host read-back of the boot disk Store" +for f in "${files[@]}"; do + grep -qxF "$(basename "${f}") bytes=$(stat -c %s "${f}") sha256=$(sha256sum "${f}" | cut -d' ' -f1)" "${work}/list.txt" \ + || fail "host read-back of $(basename "${f}")" +done + +boot() { # image, serial text output, disk image + local esp="${work}/esp" log="${work}/serial.log" started status + rm -rf "${esp}" + mkdir -p "${esp}/EFI/BOOT" "${esp}/EFI/AIENOS" + touch "${esp}/EFI/AIENOS/BOOTREPORT.TXT" + cp "$1" "${esp}/EFI/BOOT/BOOTAA64.EFI" + cp "${vars_fd}" "${work}/vars.fd" + started=$(date +%s) + set +e + nice -n 10 timeout "${AIENOS_QEMU_TIMEOUT:-300}" qemu-system-aarch64 \ + -M virt,virtualization=on,gic-version=3,iommu=smmuv3 -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 \ + -drive if=none,id=nvme0,format=raw,file="$3" \ + -device nvme,drive=nvme0,serial=aienos-nvme-test \ + -device ramfb -display none -nic none \ + -serial file:"${log}" -no-reboot + status=$? + set -e + tr -d '\r' <"${log}" >"$2" + echo "qemu exit ${status} after $(( $(date +%s) - started )) s (commit ${commit:0:12})" + [[ "${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; } + +serial="${work}/serial.txt" +cp "${disk}" "${work}/disk-run.img" +boot "${out_rcpt}/full/BOOTAA64.EFI" "${serial}" "${work}/disk-run.img" +release_flag + +check "${serial}" "left firmware and entered the kernel" "kernel: alive" +check "${serial}" "kernel read all fourteen candidates (one unit, thirteen receipts) from the boot disk Store" "^artifact_candidates: 14$" +if has "${serial}" "^report-truncated:"; then fail "kernel report lines were truncated"; else pass "no kernel report line was truncated"; fi +check "${serial}" "final report reached the console" "report_kind: final" +if has "${serial}" "report_kind: (panic|fault)"; then fail "panic or fault reported"; else pass "no kernel panic or fault report"; fi +check "${serial}" "a01 admitted (the container check is unchanged)" "^osc_unit: a01_valid_min\\.unit ACCEPT " +check "${serial}" "receipt policy line: qualification, TEST receipt anchor, owner root listed but not trusted, launch requires a receipt" \ + "^osc_receipt_policy: mode=qualification receipt_test_anchors=1 receipt_owner_anchors=0 \\(owner root listed, not trusted\\) checkers=1 target=aienos-ck-aarch64-el0 epoch_floor=10 epoch_now=20 revoked_ids=1 revoked_keys=0 firmware=none dependencies=none producer=none; launch requires a valid receipt; QEMU, not physical$" +for r in "${rcpts[@]}"; do + b=$(stat -c %s "${rfix}/${r}.rcpt"); id=- + [[ "${b}" == 416 ]] && id=$(sha256sum "${rfix}/${r}.rcpt" | cut -c1-64) + check "${serial}" "${r}.rcpt stored from the Store (bytes=${b})" "^osc_receipt: ${r}\\.rcpt STORED bytes=${b} id=${id} " +done +check "${serial}" "receipt totals: 13 seen, 13 stored" "^osc_receipts: seen=13 stored=13 dropped=0 " +check "${serial}" "self-test announces 17 launches" "^osc_rcpt_selftest: launches=17 unit=a01_valid_min\\.unit; " + +label='QEMU \(aarch64 virt\), TEST signer, not physical' +a=a01_valid_min.unit +# rline TEXT ARGS RECEIPT POLICY RESULT REVOKED [run]: one launch line. A refusal ran nothing: no tick, no page. +rline() { + local file="${rfix}/$3" id='-' t + [[ "$3" != none && $(stat -c %s "${file}") == 416 ]] && id=$(sha256sum "${file}" | cut -c1-16) + t="ticks=0 pages_mapped=0 page_tables_zeroed=1 slot_free=1" + [[ "${7:-}" == run ]] && t="ticks=[0-9]+ pages_mapped=[1-9][0-9]* page_tables_zeroed=1 slot_free=1" + check "${serial}" "$1" "^osc_rcpt_launch: ${a} add\\($2\\) receipt=${3//./\\.} policy=$4 -> $5 receipt_id=${id} revoked=$6 ${t}; ${label}\$" +} +ref() { echo "REFUSED_AT_ADMISSION code=$1 name=RECEIPT_$2"; } +rline "valid receipt: the unit runs, add(1,2) RETURNED 3" '1,2' a01.rcpt qualification 'RETURNED value=3' - run +rline "no receipt: refused RECEIPT_MISSING (64)" '2,3' none qualification "$(ref 64 MISSING)" - +rline "altered receipt (one byte of the executable digest flipped): RECEIPT_BAD_SIGNATURE (75)" '3,4' n_altered.rcpt qualification "$(ref 75 BAD_SIGNATURE)" - +rline "replayed receipt below the epoch floor: RECEIPT_STALE_EPOCH (77)" '4,5' n_stale.rcpt qualification "$(ref 77 STALE_EPOCH)" - +rline "revoked receipt id: RECEIPT_REVOKED (76), revoked=receipt_id" '5,6' n_revoked_id.rcpt qualification "$(ref 76 REVOKED)" receipt_id +rline "revoked signer key (the TEST key fingerprint revoked): RECEIPT_REVOKED (76), revoked=signer_key" '6,7' a01.rcpt revoked_test_key "$(ref 76 REVOKED)" signer_key +rline "expired receipt: RECEIPT_EXPIRED (78)" '7,8' n_expired.rcpt qualification "$(ref 78 EXPIRED)" - +rline "receipt not yet valid: RECEIPT_NOT_YET_VALID (79)" '8,9' n_future.rcpt qualification "$(ref 79 NOT_YET_VALID)" - +rline "receipt for another target: RECEIPT_WRONG_TARGET (80)" '9,10' n_target.rcpt qualification "$(ref 80 WRONG_TARGET)" - +rline "receipt for another executable (l01's): RECEIPT_EXECUTABLE_MISMATCH (83)" '10,11' l01.rcpt qualification "$(ref 83 EXECUTABLE_MISMATCH)" - +rline "receipt for another program: RECEIPT_PROGRAM_MISMATCH (82)" '11,12' n_program.rcpt qualification "$(ref 82 PROGRAM_MISMATCH)" - +rline "receipt of the wrong length (417 bytes): RECEIPT_SIZE (65)" '12,13' n_length.rcpt qualification "$(ref 65 SIZE)" - +rline "TEST receipt under the release policy: RECEIPT_TEST_SIGNER_IN_PRODUCTION (73)" '13,14' a01.rcpt release "$(ref 73 TEST_SIGNER_IN_PRODUCTION)" - +rline "receipt naming firmware: RECEIPT_WRONG_FIRMWARE (81)" '14,15' n_firmware.rcpt qualification "$(ref 81 WRONG_FIRMWARE)" - +rline "receipt with a dependency: RECEIPT_DEPENDENCIES_MISMATCH (88)" '15,16' n_deps.rcpt qualification "$(ref 88 DEPENDENCIES_MISMATCH)" - +rline "receipt from an unlisted checker: RECEIPT_UNTRUSTED_CHECKER (86)" '16,17' n_checker.rcpt qualification "$(ref 86 UNTRUSTED_CHECKER)" - +rline "after every refusal, the valid receipt still runs the unit: add(20,22) RETURNED 42" '20,22' a01.rcpt qualification 'RETURNED value=42' - run +check "${serial}" "summary: 2 returned, 15 refused" "^osc_rcpt_launches: returned=2 trapped=0 refused=15 unknown=0; ${label}\$" +nl=$(grep -c '^osc_rcpt_launch: ' "${serial}" || true) +names=$(grep -oE '^osc_rcpt_launch: .* name=RECEIPT_[A-Z_]+' "${serial}" | sed -E 's/.*name=//' | sort | uniq -d | tr '\n' ' ') +[[ "${nl}" == 17 ]] && pass "exactly 17 receipt launch lines" || fail "receipt launch lines (${nl} of 17)" +# REVOKED appears twice on purpose (receipt id, signer key), told apart by the revoked= column +[[ "${names}" == "RECEIPT_REVOKED " ]] && pass "every other refusal names a reason of its own" || fail "refusal reasons repeated: ${names}" +if grep -E '^osc_launch: ' "${serial}" | grep -q .; then fail "a C3-3a launch line appeared in the receipt self-test"; else pass "only the receipt self-test ran"; fi + +if [[ -n "${AIENOS_LOG_DIR:-}" ]]; then cp "${serial}" "${AIENOS_LOG_DIR}/qemu_ck_osc_receipt_serial.log"; fi +if [[ "${failed}" != 0 || -n "${AIENOS_QEMU_VERBOSE:-}" ]]; then + echo "---- serial (osc lines) ----"; grep -E "^(osc_|artifact|kernel|report_kind|panic|fault)" "${serial}" | head -80 || true +fi +echo "label: QEMU (aarch64 virt), TEST signer, not physical" +if [[ "${failed}" == 0 ]]; then echo "${verdict}: PASS"; else echo "${verdict}: FAIL"; exit 1; fi diff --git a/scripts/qemu_ck_osh_core_test.sh b/scripts/qemu_ck_osh_core_test.sh index 5935bf4a..42d1ba4e 100755 --- a/scripts/qemu_ck_osh_core_test.sh +++ b/scripts/qemu_ck_osh_core_test.sh @@ -89,7 +89,8 @@ flip=$(printf '%02x' $(( 0x${orig} ^ 0x01 ))) printf "\\x${flip}" | dd of="${work}/osh_lex_badsig.unit" bs=1 seek=${sig_at} conv=notrunc status=none [[ "$(od -An -tx1 -j${sig_at} -N1 "${work}/osh_lex_badsig.unit" | tr -d ' ')" == "${flip}" ]] && pass "flipped one signature byte at offset ${sig_at} (${orig} -> ${flip})" || fail "signature byte flip" -files=("${fix}/osh_lex.unit" "${fix}/osh_parse.unit" "${fix}/osh_expand.unit" "${work}/osh_lex_flipped.unit" "${work}/osh_lex_badsig.unit" "${fix}/../osc_unit/launch/l01_launch_fns.unit") +files=("${fix}/osh_lex.unit" "${fix}/osh_parse.unit" "${fix}/osh_expand.unit" "${work}/osh_lex_flipped.unit" "${work}/osh_lex_badsig.unit" "${fix}/../osc_unit/launch/l01_launch_fns.unit" + "${fix}/../osc_receipt/osh_lex.rcpt" "${fix}/../osc_receipt/osh_parse.rcpt" "${fix}/../osc_receipt/osh_expand.rcpt" "${fix}/../osc_receipt/l01.rcpt") # aienos#383: receipts disk="${work}/nvme.img" "${out_prod}/host/ck_gpt_image" create "${disk}" 512 64 aienos-middle >/dev/null || fail "GPT boot disk image created" if "${simg}" build "${disk}" 512 "${files[@]}" >"${work}/build.txt" 2>&1; then pass "boot disk built: $(head -1 "${work}/build.txt")" @@ -135,7 +136,7 @@ release_flag label='QEMU \(aarch64 virt\), TEST signer, not physical' check "${serial}" "left firmware and entered the kernel" "kernel: alive" -check "${serial}" "kernel read all six candidates from the boot disk Store" "^artifact_candidates: 6$" +check "${serial}" "kernel read all ten candidates (six units, four receipts) from the boot disk Store" "^artifact_candidates: 10$" if has "${serial}" "^report-truncated:"; then fail "kernel report lines were truncated"; else pass "no kernel report line was truncated"; fi check "${serial}" "final report reached the console" "report_kind: final" if has "${serial}" "report_kind: (panic|fault)"; then fail "panic or fault reported (a unit fault must stay contained)"; else pass "no kernel panic or fault report"; fi diff --git a/scripts/qemu_ck_osh_op_test.sh b/scripts/qemu_ck_osh_op_test.sh index d8fc1f98..542e1fb1 100755 --- a/scripts/qemu_ck_osh_op_test.sh +++ b/scripts/qemu_ck_osh_op_test.sh @@ -57,7 +57,8 @@ mk OUT="${out_osh}" CK_SEED0B_TEST_ANCHOR=1 CK_OSH_TEST=1 CK_OSH_OP_TEST=1 full make -s -C native/kernel OUT="${out_prod}" store-image gpt-image >/dev/null simg="${out_prod}/host/ck_store_image" -files=("${fix}/osh_lex.unit" "${fix}/osh_parse.unit" "${fix}/osh_expand.unit") +# aienos#383: each launch needs the unit's realization receipt +files=("${fix}/osh_lex.unit" "${fix}/osh_parse.unit" "${fix}/osh_expand.unit" "${fix}/../osc_receipt/osh_lex.rcpt" "${fix}/../osc_receipt/osh_parse.rcpt" "${fix}/../osc_receipt/osh_expand.rcpt") disk="${work}/nvme.img" "${out_prod}/host/ck_gpt_image" create "${disk}" 512 64 aienos-middle >/dev/null || fail "GPT boot disk image created" if "${simg}" build "${disk}" 512 "${files[@]}" >"${work}/build.txt" 2>&1; then pass "boot disk built: $(head -1 "${work}/build.txt")" @@ -102,7 +103,7 @@ exact() { # description, regex, expected count if [[ "${n}" == "$3" ]]; then pass "$1 (${n})"; else fail "$1: expected $3, got ${n}"; fi } check "${serial}" "left firmware and entered the kernel" "kernel: alive" -check "${serial}" "kernel read all three candidates from the boot disk Store" "^artifact_candidates: 3$" +check "${serial}" "kernel read all six candidates (three units, three receipts) from the boot disk Store" "^artifact_candidates: 6$" for u in osh_lex osh_parse osh_expand; do check "${serial}" "${u} admitted (real oscc output, TEST signer)" "^osc_unit: ${u}\\.unit ACCEPT unit_digest=[0-9a-f]{64} program_id=[0-9a-f]{64} funcs=[0-9]+ caps=0 signer=TEST$" done