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#355 (code only)
Apply it
git checkout -b patch-962ea41f8be74d0b 2529bc07ca9ac053058d2d44823ae66094ad2230 curl -fsSL https://interplane.io/drakestapleton/aienux/patches/962ea41f8be74d0b.patch | git am
Provenance
github-import 1
aien-dev/aienux
355
56d2764839984542cabfc568ed3f7f5ab9157fb6
{"kind":"github-import","owner":"aien-dev","repo":"aienux","number":355,"url":"https://github.com/aien-dev/aienux/pull/355","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:36:15Z","metadata":"unavailable","state_derived":true}
Changes
diff --git a/.crumb b/.crumb index 396d0142..aada0e49 100644 --- a/.crumb +++ b/.crumb @@ -33,27 +33,27 @@ "purpose": "Directory docs. Purpose not yet described by a human." }, { - "digest": "527f2f29be9c6f49513516b66a06c470320a63aa64d4488af321204f40907cdf", - "last_commit": "a01f365", + "digest": "a1e363b0cfc3770a064112706f7fa654879d74e1f5f8c50c8a8b13240e998760", + "last_commit": "5ec8143", "name": "native", "purpose": "Directory native. Purpose not yet described by a human." }, { - "digest": "ebacb9a6843c9319ee3cb65d8af90e79b76b22398528626d71363a7d45b98d1a", - "last_commit": "a01f365", + "digest": "1a09d49dd7e742fd6293ce4c4a1b891c5f7071f18f7ace48203a4aa9e89c066a", + "last_commit": "5ec8143", "name": "scripts", "purpose": "Directory scripts. Purpose not yet described by a human." } ], - "children_root": "sha256:c6830a2a2d8d6b7174eb4eec96bca9f59299ff41ea9dfbac639e5dca22eed04b", - "compiled_at": "2026-10-13T12:30:58Z", + "children_root": "sha256:a1210febe458017335d26437b8719ba4ebcc8c8f687e9da8fcaabe0e3c2b7942", + "compiled_at": "2026-10-13T13:47:59Z", "compiler": "crumb-compile/1", - "digest": "sha256:a302bde0e553440966a84940890dbcce2053da11747fd989ce71dbfc2224fd19", + "digest": "sha256:6baea918b76bdfe995a9981dcda39e4126892197f917117664feee5affbacaf3", "evidence_files": 156, "evidence_root": "sha256:cd53ab119be9de6ce28c4f5949b106c9622f1fe105611de3de21c3bce7932694", - "files": 3145, - "generated_at_commit": "a01f365f16ea16bb4843f97b031ee72b4e028389", - "source_tree": "sha256:e5b17cbe1452fdd8dae0b25b85f9ec501694c527338b9f79f181b99e9521b892" + "files": 3146, + "generated_at_commit": "5ec8143c971e96ddca3aab21b30128ca9b122455", + "source_tree": "sha256:889b80ce425485c7de2895180ee6cce1235e70b823d0e16492502948cf32a602" }, "owner_lane": "", "provenance": { diff --git a/native/.crumb b/native/.crumb index d6b94c1e..d1afc865 100644 --- a/native/.crumb +++ b/native/.crumb @@ -79,8 +79,8 @@ "purpose": "Directory native/disk. Purpose not yet described by a human." }, { - "digest": "238b04ca7654bb6b12fa96199fc185c8ec5e3e50ef7d27e93ab027a0b6ec9e17", - "last_commit": "a01f365", + "digest": "74d1c79c8fa3ea2435764f0e9fe09ce9ad3dfce39ec3fd56189afcf2afc365d9", + "last_commit": "5ec8143", "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:d82d3657c3d9315b627145e341e0ff89d552608d1fef7749739e4717a3592963", - "compiled_at": "2026-10-13T12:30:58Z", + "children_root": "sha256:e303eb4ac8c8978fdd6de41c775eab8654ad7b62f46a803481c8d942f05973c1", + "compiled_at": "2026-10-13T13:47:59Z", "compiler": "crumb-compile/1", - "digest": "sha256:527f2f29be9c6f49513516b66a06c470320a63aa64d4488af321204f40907cdf", + "digest": "sha256:a1e363b0cfc3770a064112706f7fa654879d74e1f5f8c50c8a8b13240e998760", "evidence_files": 4, "evidence_root": "sha256:e410b845507e00568e15b51a5797af32a97e0e4b8ab4e8487bb7c98e7e0cf335", - "files": 512, - "generated_at_commit": "a01f365f16ea16bb4843f97b031ee72b4e028389", - "source_tree": "sha256:7b8eff45b8dfea3c3f6a570a7fae3e81db430c94cbcaba0efd83e34f88cea09f" + "files": 513, + "generated_at_commit": "5ec8143c971e96ddca3aab21b30128ca9b122455", + "source_tree": "sha256:38b36e226f30a506670583fe505a2c139b7c0ddf19557063a58ebea38fd424dc" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/.crumb b/native/kernel/.crumb index bf906e38..bb19f317 100644 --- a/native/kernel/.crumb +++ b/native/kernel/.crumb @@ -46,7 +46,7 @@ "children": [ { "digest": "8f63182b423b274a3fa6dcf0a17811343f93bd1539e33479102ffa87935da1ca", - "last_commit": "a01f365", + "last_commit": "2529bc0", "name": "arch", "purpose": "Directory native/kernel/arch. Purpose not yet described by a human." }, @@ -57,14 +57,14 @@ "purpose": "Directory native/kernel/artifact. Purpose not yet described by a human." }, { - "digest": "1f4276b8bf582552f24f021e12078c4abf288b1e10415b724d7fc71819c115b2", - "last_commit": "a01f365", + "digest": "a7b2d272ffcf67232c93954bcb36fcd9b15465661a7c333dd62a2434f9a2570e", + "last_commit": "5ec8143", "name": "core", "purpose": "Directory native/kernel/core. Purpose not yet described by a human." }, { - "digest": "ce05eacbe36c1ae486f78c41446fe810a33aa95e152437b7d95ebf60437802a8", - "last_commit": "a01f365", + "digest": "65f1848c52d5a496e01ac0ba1c379b221908f5e8a77e3615e205955c41a115cc", + "last_commit": "5ec8143", "name": "dev", "purpose": "Directory native/kernel/dev. Purpose not yet described by a human." }, @@ -81,14 +81,14 @@ "purpose": "Directory native/kernel/mm. Purpose not yet described by a human." }, { - "digest": "f2ef5ffe9eae8f9119dd302b55989b8b50f68def6ad03a2db227e28dbd270ddd", - "last_commit": "2cdd37f", + "digest": "1269af87b047348f0eec4bf57ba98cbff4fd643a8bb7a619fa1771183c95cf17", + "last_commit": "5ec8143", "name": "svc", "purpose": "Directory native/kernel/svc. Purpose not yet described by a human." }, { "digest": "ae1566720e4d7f5c05d03a40297cbc77b0b8891acea51dedbbf181944e89f8a4", - "last_commit": "a01f365", + "last_commit": "2529bc0", "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:1d0b2dee2ea9c91b010e2dfa8ac8975a4bc7cfca2708452e065a721af1fd6199", - "compiled_at": "2026-10-13T12:30:58Z", + "children_root": "sha256:5b1ebacc00ebc6e98db530ddd933ebc6ee89bed0de91e3664e8794939177f2d0", + "compiled_at": "2026-10-13T13:47:59Z", "compiler": "crumb-compile/1", - "digest": "sha256:238b04ca7654bb6b12fa96199fc185c8ec5e3e50ef7d27e93ab027a0b6ec9e17", + "digest": "sha256:74d1c79c8fa3ea2435764f0e9fe09ce9ad3dfce39ec3fd56189afcf2afc365d9", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 335, - "generated_at_commit": "a01f365f16ea16bb4843f97b031ee72b4e028389", - "source_tree": "sha256:82479a2b1ea1cf9be5c313f638ba41251762bc0ad2c4a4186899a1843a1dbc47" + "files": 336, + "generated_at_commit": "5ec8143c971e96ddca3aab21b30128ca9b122455", + "source_tree": "sha256:61d6ce36ed06cd51e6fc75d1f902c0f6433484500f91ffce9afb2c5d9c715e6b" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/Makefile b/native/kernel/Makefile index bbaf201f..18a45905 100644 --- a/native/kernel/Makefile +++ b/native/kernel/Makefile @@ -150,6 +150,26 @@ CK_PI5 := 1 OUT ?= $(REPO)/target/native-kernel-pi5-store CK_EXTRA_CFLAGS += -DCK_PI5_STORE=1 endif + +# Pi unlock image (CK_PI5_UNLOCK=1, "make pi5-unlock", PI5-4 cut 1): the same Store stage, but the Store opens +# ONLY through the ADR 0017 Slot 1 recovery-secret path (ck_store_unlock_boot, PRODUCTION-class keys). +# ck_store_test_keys and ck_store_test_uuid are not compiled, so no TEST key or TEST uuid can reach it. +# It is a separate image from CK_PI5_STORE (TEST keys) and cannot be combined with any other tier flag. +CK_PI5_UNLOCK ?= +ifneq ($(strip $(CK_PI5_UNLOCK)),) +ifneq ($(strip $(CK_PI5_UNLOCK)),1) +$(error CK_PI5_UNLOCK must be empty or 1) +endif +ifneq ($(strip $(CK_PI5_STORE)),) +$(error CK_PI5_UNLOCK (production-class keys from the recovery secret) cannot be combined with CK_PI5_STORE (public TEST keys)) +endif +ifneq ($(strip $(CK_SERVICE)$(CK_TEST_STORE_CRASH)$(CK_TEST_CONTINUITY)$(CK_HARDWARE_STAGING)$(CK_SERVICE_TEST_KEYS)),) +$(error CK_PI5_UNLOCK cannot be combined with CK_SERVICE, CK_SERVICE_TEST_KEYS, CK_TEST_STORE_CRASH, CK_TEST_CONTINUITY or CK_HARDWARE_STAGING) +endif +CK_PI5 := 1 +OUT ?= $(REPO)/target/native-kernel-pi5-unlock +CK_EXTRA_CFLAGS += -DCK_PI5_UNLOCK=1 +endif CK_PI5 ?= ifneq ($(strip $(CK_PI5)),) ifneq ($(strip $(CK_PI5)),1) @@ -781,8 +801,8 @@ endif # are linked: no PCI, NVMe, USB, virtio, SMMU or security stage (none of that hardware is on the # Pi path). core/pi5.c supplies ck_dev_boot_disk and ck_dev_nvme_release over the SD partition view. FULL_STAGE_SYMS := ck_stage_devices ck_stage_security ck_stage_store ck_stage_quiesce ck_stage_disk_artifacts -ifeq ($(strip $(CK_PI5_STORE)),1) -FULL_NAME := full-pi5-store +ifneq ($(strip $(CK_PI5_STORE)$(CK_PI5_UNLOCK)),) +FULL_NAME := $(if $(strip $(CK_PI5_UNLOCK)),full-pi5-unlock,full-pi5-store) FULL_STAGE_SYMS := ck_stage_store ck_stage_disk_artifacts STAGE_SRCS := $(KDIR)/svc/store_boot.c $(KDIR)/svc/artifact_store.c $(KDIR)/svc/store_crash.c $(KDIR)/svc/ck_compat.c \ $(foreach m,store/store_v1 store/store_engine store/store_disk store/store_sealed store/torn_slot m5/m5_keys m5/m5_envelope m5/m5_state crypto/aes crypto/polyval crypto/gcm_siv crypto/hmac crypto/ct argus/sha256,$(NATIVE)/$(m).c) @@ -1814,6 +1834,9 @@ pi5-diag: $(PI5DIAG_EFI) pi5-store: $(MAKE) CK_PI5_STORE=1 full +pi5-unlock: + $(MAKE) CK_PI5_UNLOCK=1 full + pi5: $(MAKE) CK_PI5=1 all @@ -1865,7 +1888,7 @@ $(OUT)/host-san/test_pi5_rng: $(KDIR)/tests/test_pi5_rng.c $(PI5_RNG_SRCS) $(KDI FORCE: .PHONY: uefi-vars slot-loader slot-loader-check pi5-diag -.PHONY: all full pi5 pi5-store test sanitize handoff-mutant acpi-dev-mutant iort-mutants smmu-l2-mutants acpi-scan clean print-kcflags udp-echo tool store-image gpt-image cont-tool owner-gen fb-check continuity-mutants continuity-resolve-mutants FORCE +.PHONY: all full pi5 pi5-store pi5-unlock test sanitize handoff-mutant acpi-dev-mutant iort-mutants smmu-l2-mutants acpi-scan clean print-kcflags udp-echo tool store-image gpt-image cont-tool owner-gen fb-check continuity-mutants continuity-resolve-mutants FORCE # 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/README.md b/native/kernel/README.md index 36ac9b5f..7adaf620 100644 --- a/native/kernel/README.md +++ b/native/kernel/README.md @@ -149,6 +149,22 @@ The Pi image is the default core image plus board glue (`core/pi5.c`). The default and QEMU images link none of it: the hooks in `include/ck.h` are weak and absent, and `scripts/ck_pi5_build_check.sh` checks both images. +**Pi unlock image (PI5-4 cut 1, `make pi5-unlock`, `CK_PI5_UNLOCK=1`).** A +separate image from `pi5-store`: the Store opens only through the ADR 0017 +Slot 1 recovery-secret path (`ck_store_pi5_unlock_run` calls +`ck_store_unlock_boot` with the hardware policy). `ck_store_test_keys` and +`ck_store_test_uuid` are not compiled, a TEST-identity key is refused before +any disk access, a Store without a KeySlotManifest (for example a TEST-tier +Store) is refused, a wrong secret fails the K_vol unwrap tag, and every refusal +writes nothing. The secret source is `ck_pi5_unlock_secret` in `core/pi5.c`; +this cut compiles in no source, so the Store stays closed +(`unlock_source: none`). The Makefile refuses the flag with `CK_PI5_STORE`, +`CK_SERVICE`, `CK_HARDWARE_STAGING` and the test flags. Host test: +`make pi5-unlock-test` (`dev/tests/pi5_unlock_test.c`); image checks: +`scripts/ck_pi5_build_check.sh`. Tier label in receipts: +`PI5-UNLOCK-QUALIFICATION`. Not a production image: no TPM, no operator +ceremony. + | Piece | What | | --- | --- | | `dev/pi5_wdt.c` | BCM2712 PM watchdog (Linux `bcm2835_wdt.c` registers), armed for `CK_PI5_WDT_S` (15 s) at start, petted at every `ck_set_stage`. A hang resets the board; on the hub the tryboot one-shot flag is already cleared, so it comes back on normal Linux. | diff --git a/native/kernel/core/.crumb b/native/kernel/core/.crumb index e3c9d37d..0d236caf 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-13T12:30:58Z", + "compiled_at": "2026-10-13T13:47:59Z", "compiler": "crumb-compile/1", - "digest": "sha256:1f4276b8bf582552f24f021e12078c4abf288b1e10415b724d7fc71819c115b2", + "digest": "sha256:a7b2d272ffcf67232c93954bcb36fcd9b15465661a7c333dd62a2434f9a2570e", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 53, - "generated_at_commit": "a01f365f16ea16bb4843f97b031ee72b4e028389", - "source_tree": "sha256:72143dfd95ecf8012fe7d70ee418793eab596b343933ae88038ca075b1cdd39c" + "generated_at_commit": "5ec8143c971e96ddca3aab21b30128ca9b122455", + "source_tree": "sha256:c75a53dab99231189fe2445f66e3b1e1124c56f77e753febcf5664d30337f469" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/core/artifact_loader.c b/native/kernel/core/artifact_loader.c index 298f0724..de9aa8b7 100644 --- a/native/kernel/core/artifact_loader.c +++ b/native/kernel/core/artifact_loader.c @@ -1066,7 +1066,9 @@ static void print_receipt(const char *name, const struct report *r) /* Qualification tier label printed in every receipt header. A Pi 5 image is never * the QEMU tier and never production: the label names the board. */ -#ifdef CK_PI5 +#if defined(CK_PI5_UNLOCK) +#define CK_RECEIPT_TIER "PI5-UNLOCK-QUALIFICATION" +#elif defined(CK_PI5) #define CK_RECEIPT_TIER "SEED-0B-PI5" #else #define CK_RECEIPT_TIER "SEED-0B-QEMU" diff --git a/native/kernel/core/pi5.c b/native/kernel/core/pi5.c index 04ebc59c..912ed068 100644 --- a/native/kernel/core/pi5.c +++ b/native/kernel/core/pi5.c @@ -201,7 +201,10 @@ void ck_pi5_before_reset(void) ck_pi5_wdt_pet(); } -#ifdef CK_PI5_STORE +#if defined(CK_PI5_STORE) || defined(CK_PI5_UNLOCK) +#if defined(CK_PI5_STORE) && defined(CK_PI5_UNLOCK) +#error "CK_PI5_STORE (TEST keys) and CK_PI5_UNLOCK (production class keys) are separate images" +#endif /* Hand the card's AIENOS partition view to the sealed Store stage (svc/store_boot.c ck_stage_store), the * same stage the QEMU "full" image runs. Tier: SEED-0B-PI5, the Pi counterpart of SEED-0B-QEMU. The Store * keys are the labelled TEST keys (ck_store_test_keys); the production key source stays BLOCKED_OPERATOR @@ -211,11 +214,28 @@ const disk_dev *ck_dev_boot_disk(void) { static int said; if (!said++) +#ifdef CK_PI5_UNLOCK + ck_puts("pi5_unlock_tier: PI5-4 recovery-secret unlock: Store keys derive from K_vol (ADR 0017 Slot 1), " + "PRODUCTION class; no TEST keys and no TEST uuid exist in this image\n"); +#else ck_puts("pi5_store_tier: SEED-0B-PI5 qualification only: Store keys are the public TEST keys, " "Store uuid is the TEST uuid, no production keys, not a production Store\n"); +#endif return sd_up && store_part.valid ? &store_part.dev : 0; } /* The SD card has no bus master or SMMU stream to revoke: nothing to release. */ void ck_dev_nvme_release(void) {} #endif + +#ifdef CK_PI5_UNLOCK +/* The recovery secret source of the Pi unlock image. This image has no UART input and no TPM: with no + * source compiled in, the Store stays closed (ck_store_pi5_unlock_run refuses before reading the disk). */ +int ck_pi5_unlock_secret(uint8_t out[32], const char **source) /* CK_SB_SECRET_LEN, svc/store_boot.h */ +{ + (void)source; + for (unsigned i = 0; i < 32; i++) + out[i] = 0; + return -1; +} +#endif diff --git a/native/kernel/dev/.crumb b/native/kernel/dev/.crumb index 7758279d..c5768b31 100644 --- a/native/kernel/dev/.crumb +++ b/native/kernel/dev/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-13T12:30:58Z", + "compiled_at": "2026-10-13T13:47:59Z", "compiler": "crumb-compile/1", - "digest": "sha256:ce05eacbe36c1ae486f78c41446fe810a33aa95e152437b7d95ebf60437802a8", + "digest": "sha256:65f1848c52d5a496e01ac0ba1c379b221908f5e8a77e3615e205955c41a115cc", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 32, - "generated_at_commit": "a01f365f16ea16bb4843f97b031ee72b4e028389", - "source_tree": "sha256:3c12c30529809e47200d0717160a804e89f7d310a93562d2c55d340b8cb0888b" + "files": 33, + "generated_at_commit": "5ec8143c971e96ddca3aab21b30128ca9b122455", + "source_tree": "sha256:2c382feff91746f353cfe0c993cbde4d6127b5823567db1b37a73ce769392a29" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/dev/tests/pi5_unlock_test.c b/native/kernel/dev/tests/pi5_unlock_test.c new file mode 100644 index 00000000..1bfe685c --- /dev/null +++ b/native/kernel/dev/tests/pi5_unlock_test.c @@ -0,0 +1,217 @@ +/* pi5_unlock_test.c -- AIENOS PI5-4 cut 1 host test: the Pi unlock image's Store policy + * (svc/store_boot.c ck_store_pi5_unlock_run, compiled with -DCK_PI5_UNLOCK exactly as + * "make pi5-unlock" builds it) over the Pi card layout. A file stands in for the card. + * + * Proves: no secret -> refused before the disk is read, nothing written; TEST-identity keys are + * refused by the image's own policy (store_boot_run) before any disk access, on a blank card and on + * a PRODUCTION Store; a TEST-tier Store (formatted with TEST keys and the TEST uuid by a different + * image) is refused by the unlock path with no keyslot manifest, nothing written; a wrong secret + * is refused, nothing written; the right secret on a blank card formats a PRODUCTION-class Store + * under a drawn uuid that is not the TEST uuid; the same secret reopens it and the generation + * advances. The TEST keys are built here from the public label, because the image itself does not + * contain them (scripts/ck_pi5_build_check.sh checks that on the real ELF). Hosted test code only. */ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include "ck.h" +#include "ck_host.h" +#include "disk_file.h" +#include "disk_layout.h" +#include "disk_part.h" +#include "gpt_write.h" +#include "../../core/pi5_marker.h" +#include "m5.h" +#include "sha256.h" +#include "store_boot.h" + +#ifndef CK_PI5_UNLOCK +#error "pi5_unlock_test.c must be built with -DCK_PI5_UNLOCK (the image's policy)" +#endif +#ifdef CK_STORE_TEST_KEYS +#error "the unlock image must not compile the TEST keys" +#endif + +static int checks, failures; +#define CHECK(c) \ + do { \ + checks++; \ + if (!(c)) { \ + failures++; \ + printf(" FAIL %s:%d: %s\n", __FILE__, __LINE__, #c); \ + } \ + } while (0) + +extern int ck_host_entropy_refuse; + +/* The secret source symbol the stage references; the real one lives in core/pi5.c. */ +int ck_pi5_unlock_secret(uint8_t out[CK_SB_SECRET_LEN], const char **source) +{ + (void)out; + (void)source; + return -1; +} + +#define BLOCKS 262144ull +#define PART_FIRST 8192u +#define PART_SECS 8192u +static char g_path[256]; + +/* The public TEST keys and uuid of the SEED-0B-PI5 image, rebuilt here (public label, not secret). */ +static const uint8_t test_uuid[16] = {'A', 'I', 'E', 'N', '-', 'T', 'E', 'S', 'T', '-', 'B', 'O', 'O', 'T', '0', '1'}; +static void test_keys(ss_keys *k) +{ + uint8_t kvol[32]; + m5_subkeys sk; + static const char label[] = "AIENOS-LANE18-TEST-KVOL-NOT-SECRET"; + sha256_hash((const uint8_t *)label, sizeof label - 1, kvol); + memset(k, 0, sizeof *k); + m5_derive_subkeys(kvol, M5_ID_TEST, 0, &sk); + k->identity_class = M5_ID_TEST; + k->key_generation = 1; + memcpy(k->k_root_auth, sk.k_root_auth, 32); + memcpy(k->k_domain, sk.k_artifact, 32); + m5_subkeys_wipe(&sk); +} + +static uint8_t *slurp(size_t *n) +{ + FILE *fp = fopen(g_path, "rb"); + CHECK(fp != 0); + if (!fp) { *n = 0; return 0; } + fseek(fp, 0, SEEK_END); + *n = (size_t)ftell(fp); + rewind(fp); + uint8_t *m = malloc(*n); + CHECK(m && fread(m, 1, *n, fp) == *n); + fclose(fp); + return m; +} + +enum { BOOT_TESTKEYS_POLICY, BOOT_TESTKEYS_IMAGE, BOOT_UNLOCK }; +/* One boot on the Store view of the card file. */ +static int boot(int mode, const uint8_t *secret, ck_store_report *r) +{ + disk_file f; + disk_dev d; + ck_part p, sp; + ck_gpt_info gi; + ss_keys k; + if (disk_file_open(&f, &d, g_path, 512, 0, 0)) return -9999; + if (ck_gpt_find_aienos(&d, &p, &gi) || ck_pi5_store_view(&p, &sp)) { disk_file_close(&f); return -9998; } + ck_host_quiet = 1; + int rc; + test_keys(&k); + if (mode == BOOT_TESTKEYS_POLICY) rc = store_boot_run_policy(&sp.dev, &k, test_uuid, "pi5-unlock-test", 0, r); + else if (mode == BOOT_TESTKEYS_IMAGE) rc = store_boot_run(&sp.dev, &k, test_uuid, "pi5-unlock-test", r); + else rc = ck_store_pi5_unlock_run(&sp.dev, secret, "pi5-unlock-test", r); + ck_host_quiet = 0; + memset(&k, 0, sizeof k); + disk_file_close(&f); + return rc; +} + +static int same_bytes(const uint8_t *a, size_t na, const uint8_t *b, size_t nb) +{ + return a && b && na == nb && memcmp(a, b, na) == 0; +} + +int main(void) +{ + snprintf(g_path, sizeof g_path, "/tmp/aienos-pi5-unlock-test-%d.img", (int)getpid()); + gw_part gp[2] = {{gw_esp_type, 2048, 4095, "AIENOSPI5-ESP", 0x5a}, {ck_aienos_part_type, PART_FIRST, PART_FIRST + PART_SECS - 1, "AIENOS", 0}}; + CHECK(gw_write(g_path, 512, BLOCKS, gp, 2, 0) == 0); + uint8_t S[CK_SB_SECRET_LEN], W[CK_SB_SECRET_LEN]; + for (int i = 0; i < 32; i++) S[i] = (uint8_t)(i * 11 + 3); + memcpy(W, S, 32); + W[31] ^= 0x80; + ck_store_report r; + size_t n0, n1; + uint8_t *b, *a; + + /* 1. No secret source: refused before the disk is read; a blank card stays blank. */ + b = slurp(&n0); + int rc = boot(BOOT_UNLOCK, 0, &r); + a = slurp(&n1); + CHECK(rc == CK_SB_E_BLOCKED_OPERATOR && r.verdict == CK_SB_REFUSED && r.formatted == 0); + CHECK(r.proof && strcmp(r.proof, "keyed") == 0); + CHECK(same_bytes(b, n0, a, n1)); + free(b); + free(a); + + /* 2. TEST keys against the image's own policy (hardware policy): refused before any disk access. */ + b = slurp(&n0); + rc = boot(BOOT_TESTKEYS_IMAGE, 0, &r); + a = slurp(&n1); + CHECK(rc == CK_SB_E_TEST_KEYS && r.verdict == CK_SB_REFUSED && r.formatted == 0); + CHECK(same_bytes(b, n0, a, n1)); + free(b); + free(a); + + /* 3. A TEST-tier Store (made by the SEED-0B-PI5 image's policy, TEST keys + TEST uuid) is not a + * production Store: the unlock path finds no keyslot manifest and refuses, nothing written. */ + rc = boot(BOOT_TESTKEYS_POLICY, 0, &r); + CHECK(rc == 0 && r.verdict == CK_SB_COMMITTED && r.formatted == 1 && r.identity_class == M5_ID_TEST); + b = slurp(&n0); + rc = boot(BOOT_UNLOCK, S, &r); + a = slurp(&n1); + CHECK(rc == CK_SB_E_NO_KEYSLOT && r.verdict == CK_SB_REFUSED && r.formatted == 0); + CHECK(same_bytes(b, n0, a, n1)); + free(b); + free(a); + rc = boot(BOOT_TESTKEYS_IMAGE, 0, &r); /* and the image policy still refuses TEST keys on a Store that has TEST content */ + CHECK(rc == CK_SB_E_TEST_KEYS); + + /* Fresh blank card for the production path. */ + CHECK(gw_write(g_path, 512, BLOCKS, gp, 2, 0) == 0); + + /* 4. Blank card, entropy refused: no genesis, nothing written. */ + b = slurp(&n0); + ck_host_entropy_refuse = 1; + rc = boot(BOOT_UNLOCK, S, &r); + ck_host_entropy_refuse = 0; + a = slurp(&n1); + CHECK(rc == CK_SB_E_ENTROPY && r.formatted == 0 && same_bytes(b, n0, a, n1)); + free(b); + free(a); + + /* 5. Blank card, secret S: formatted PRODUCTION-class Store under a drawn uuid (not the TEST uuid). */ + rc = boot(BOOT_UNLOCK, S, &r); + CHECK(rc == 0 && r.verdict == CK_SB_COMMITTED && r.formatted == 1 && r.unlocked_genesis == 1); + CHECK(r.identity_class == M5_ID_PRODUCTION && r.boot_count_new == 1); + CHECK(r.key_source && strcmp(r.key_source, "recovery-keyslot") == 0); + CHECK(store_boot_store()->has_keyslot == 1 && store_boot_store()->keys.identity_class == M5_ID_PRODUCTION); + CHECK(memcmp(store_boot_store()->uuid, test_uuid, 16) != 0); + uint64_t g1 = r.gen_commit; + + /* 6. Wrong secret: refused, nothing written. */ + b = slurp(&n0); + rc = boot(BOOT_UNLOCK, W, &r); + a = slurp(&n1); + CHECK(rc == CK_SB_E_SECRET_REJECTED && r.verdict == CK_SB_REFUSED && r.formatted == 0); + CHECK(same_bytes(b, n0, a, n1)); + free(b); + free(a); + + /* 7. TEST keys on the production Store: refused by policy, nothing written. */ + b = slurp(&n0); + rc = boot(BOOT_TESTKEYS_IMAGE, 0, &r); + a = slurp(&n1); + CHECK(rc == CK_SB_E_TEST_KEYS && same_bytes(b, n0, a, n1)); + free(b); + free(a); + + /* 8. Reboot, secret S: reopens, no reformat, generation advances, boot count 2. */ + rc = boot(BOOT_UNLOCK, S, &r); + CHECK(rc == 0 && r.verdict == CK_SB_COMMITTED && r.formatted == 0 && r.unlocked_genesis == 0); + CHECK(r.boot_count_prev == 1 && r.boot_count_new == 2 && r.gen_open == g1 && r.gen_commit > g1); + CHECK(strcmp(r.prev_commit, "pi5-unlock-test") == 0 && r.identity_class == M5_ID_PRODUCTION); + CHECK(memcmp(store_boot_store()->uuid, test_uuid, 16) != 0); + + memset(S, 0, sizeof S); + memset(W, 0, sizeof W); + unlink(g_path); + printf("pi5_unlock_test: %d checks, %d failures\n", checks, failures); + printf("CK_PI5_UNLOCK_HOST: %s\n", failures ? "FAIL" : "PASS"); + return failures ? 1 : 0; +} diff --git a/native/kernel/stage.mk b/native/kernel/stage.mk index b6f6d84a..947f6c7f 100644 --- a/native/kernel/stage.mk +++ b/native/kernel/stage.mk @@ -175,3 +175,20 @@ pi5-store-sanitize: $(STAGE_OUT)/pi5_store_test_san ASAN_OPTIONS=detect_leaks=1 UBSAN_OPTIONS=print_stacktrace=1 $< stage-test: pi5-store-test stage-sanitize: pi5-store-sanitize + +# ---- AIENOS PI5-4 cut 1: the Pi unlock image's Store policy (dev/tests/pi5_unlock_test.c) ---- +# store_boot.c is compiled with -DCK_PI5_UNLOCK, as "make pi5-unlock" builds it: no TEST keys, no TEST uuid. +PI5_UNLOCK_TEST_SRCS := $(filter-out %/disk_part_test.c,$(DISK_PART_TEST_SRCS)) $(STAGE_CONT_SRCS) $(STAGE_DIR)/core/pi5_marker.c $(STAGE_DIR)/dev/tests/pi5_unlock_test.c +$(STAGE_OUT)/pi5_unlock_test: $(PI5_UNLOCK_TEST_SRCS) $(DISK_PART_TEST_DEPS) $(STAGE_DIR)/core/pi5_marker.h + @mkdir -p $(@D) + $(STAGE_CC) $(STAGE_HOST_FLAGS) -DCK_PI5_UNLOCK=1 $(DISK_PART_INC) -o $@ $(PI5_UNLOCK_TEST_SRCS) +$(STAGE_OUT)/pi5_unlock_test_san: $(PI5_UNLOCK_TEST_SRCS) $(DISK_PART_TEST_DEPS) $(STAGE_DIR)/core/pi5_marker.h + @mkdir -p $(@D) + $(STAGE_CC) $(STAGE_HOST_FLAGS) $(STAGE_SAN_FLAGS) -DCK_PI5_UNLOCK=1 $(DISK_PART_INC) -o $@ $(PI5_UNLOCK_TEST_SRCS) +.PHONY: pi5-unlock-test pi5-unlock-sanitize +pi5-unlock-test: $(STAGE_OUT)/pi5_unlock_test + $< +pi5-unlock-sanitize: $(STAGE_OUT)/pi5_unlock_test_san + ASAN_OPTIONS=detect_leaks=1 UBSAN_OPTIONS=print_stacktrace=1 $< +stage-test: pi5-unlock-test +stage-sanitize: pi5-unlock-sanitize diff --git a/native/kernel/svc/.crumb b/native/kernel/svc/.crumb index cab092a8..0094d550 100644 --- a/native/kernel/svc/.crumb +++ b/native/kernel/svc/.crumb @@ -30,14 +30,14 @@ } ], "children_root": "sha256:d835471b1405ca482a41beb34ed339d21e11064a59138599ee5754d198926878", - "compiled_at": "2026-10-12T20:56:51Z", + "compiled_at": "2026-10-13T13:47:59Z", "compiler": "crumb-compile/1", - "digest": "sha256:f2ef5ffe9eae8f9119dd302b55989b8b50f68def6ad03a2db227e28dbd270ddd", + "digest": "sha256:1269af87b047348f0eec4bf57ba98cbff4fd643a8bb7a619fa1771183c95cf17", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 43, - "generated_at_commit": "04e39e7223149deef6c14e4175d40e80c63eee0a", - "source_tree": "sha256:8d9bbcbf03ff3204145e5708e278082fbaea58c8b02b12f2c4fbd1adee241633" + "generated_at_commit": "5ec8143c971e96ddca3aab21b30128ca9b122455", + "source_tree": "sha256:f9821387dc747782d77349245ac1145e74fc8da871f0aca910d16863c9af185f" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/svc/store_boot.c b/native/kernel/svc/store_boot.c index 03e45ed2..4e3ec30b 100644 --- a/native/kernel/svc/store_boot.c +++ b/native/kernel/svc/store_boot.c @@ -24,6 +24,18 @@ #if defined(CK_STORE_TEST_KEYS) #error "CK_STORE_TEST_KEYS (TEST Store keys, TEST uuid) cannot be combined with CK_HARDWARE_STAGING" #endif +#if defined(CK_PI5_UNLOCK) +#error "CK_PI5_UNLOCK cannot be combined with CK_HARDWARE_STAGING" +#endif +#define CK_SB_HW 1 +#elif defined(CK_PI5_UNLOCK) +/* Pi unlock image (CK_PI5_UNLOCK): the Store opens only through the Slot 1 recovery-secret path + * (ck_store_pi5_unlock_run). No TEST keys, no TEST uuid are compiled, and the policy is the + * hardware one: TEST-identity keys are refused before any disk access. It needs no owner + * provisioning header (the store uuid is drawn at genesis or read from the manifest). */ +#if defined(CK_STORE_TEST_KEYS) || defined(CK_PI5_STORE) || defined(CK_TEST_STORE_CRASH) || defined(CK_SERVICE) +#error "CK_PI5_UNLOCK cannot be combined with TEST keys, CK_PI5_STORE, CK_TEST_STORE_CRASH or CK_SERVICE" +#endif #define CK_SB_HW 1 #else #define CK_STORE_TEST_KEYS 1 @@ -703,6 +715,26 @@ static int service_continuity(void) } #endif +#ifdef CK_PI5_UNLOCK +/* Pi unlock image policy (ck_stage_store calls this, the host test pi5_unlock_test drives it). + * secret NULL (no source gave one): refused before the disk is read, nothing written. Otherwise the + * Slot 1 recovery path with the hardware policy: a wrong secret fails the K_vol unwrap tag before the + * disk is opened; a disk with no KeySlotManifest (for example a TEST-tier Store) is refused; a blank + * disk is formatted with a PRODUCTION-class Store under a freshly drawn uuid. */ +int ck_store_pi5_unlock_run(const disk_dev *d, const uint8_t *secret, const char *commit, ck_store_report *r) +{ + if (!secret) { + bz(r, sizeof *r); + bcp(r->prev_commit, "none", 5); + r->identity_class = M5_ID_PRODUCTION; + r->key_source = "recovery-keyslot"; + return fail(r, "keyed", "no recovery secret source in this image; disk not read, not formatted", + CK_SB_E_BLOCKED_OPERATOR); + } + return ck_store_unlock_boot(d, secret, 0, commit ? commit : "unknown", CK_SB_HW, r); +} +#endif + /* Kernel stage. ck_dev_boot_disk comes from dev/devices.c. */ const disk_dev *ck_dev_boot_disk(void); void ck_dev_nvme_release(void); @@ -780,10 +812,23 @@ int ck_stage_store(void) "or the lifecycle stop order\n"); (void)commit; return rc; +#else +#if defined(CK_PI5_UNLOCK) + { + uint8_t secret[CK_SB_SECRET_LEN]; + const char *src = 0; + int have = ck_pi5_unlock_secret(secret, &src) == 0; + if (have) ck_printf("unlock_source: %s\n", src ? src : "unknown"); + else ck_puts("unlock_source: none (no recovery secret given); Store not opened\n"); + rc = ck_store_pi5_unlock_run(d, have ? secret : 0, commit, &r); + bz(secret, sizeof secret); + bz(&keys, sizeof keys); + } #else ck_store_test_keys(&keys); rc = store_boot_run(d, &keys, ck_store_test_uuid, commit ? commit : "unknown", &r); #endif +#endif #endif bz(&keys, sizeof keys); store_boot_print(&r); diff --git a/native/kernel/svc/store_boot.h b/native/kernel/svc/store_boot.h index 5d3640e0..8cdb26fa 100644 --- a/native/kernel/svc/store_boot.h +++ b/native/kernel/svc/store_boot.h @@ -153,6 +153,14 @@ int ck_store_unlock_boot(const disk_dev *d, const uint8_t secret[CK_SB_SECRET_LE * nothing. Prints nothing. */ int ck_store_rotate_recovery(const disk_dev *d, const uint8_t current[CK_SB_SECRET_LEN], const uint8_t next[CK_SB_SECRET_LEN], ck_store_report *r); +#ifdef CK_PI5_UNLOCK +/* Pi unlock image only. The board glue (core/pi5.c) supplies the recovery secret source: returns 0 and + * fills out with the 32-byte secret, naming the source in *source (printed by the Store stage, never the + * secret); nonzero = no secret. ck_store_pi5_unlock_run: NULL secret refuses before any disk read; else the + * Slot 1 path with the hardware policy (TEST keys and TEST uuid do not exist in this image). Prints nothing. */ +int ck_pi5_unlock_secret(uint8_t out[CK_SB_SECRET_LEN], const char **source); +int ck_store_pi5_unlock_run(const disk_dev *d, const uint8_t *secret, const char *commit, ck_store_report *r); +#endif /* Print the report lines (also used by the host test). */ void store_boot_print(const ck_store_report *r); /* The open Store of the last store_boot_run (valid only after it returned 0; diff --git a/scripts/.crumb b/scripts/.crumb index 20fb80f7..0973bd83 100644 --- a/scripts/.crumb +++ b/scripts/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-13T12:30:58Z", + "compiled_at": "2026-10-13T13:47:59Z", "compiler": "crumb-compile/1", - "digest": "sha256:ebacb9a6843c9319ee3cb65d8af90e79b76b22398528626d71363a7d45b98d1a", + "digest": "sha256:1a09d49dd7e742fd6293ce4c4a1b891c5f7071f18f7ace48203a4aa9e89c066a", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 93, - "generated_at_commit": "a01f365f16ea16bb4843f97b031ee72b4e028389", - "source_tree": "sha256:49654498fcaa2f5b45324f8fd47fdd36fc150a68a8bcc1252979f9cb38c17c23" + "generated_at_commit": "5ec8143c971e96ddca3aab21b30128ca9b122455", + "source_tree": "sha256:8d55927a4afd59a6326cf5024177e0d5c35099188c8e136de09a82d17394f14d" }, "owner_lane": "", "provenance": { diff --git a/scripts/ck_pi5_build_check.sh b/scripts/ck_pi5_build_check.sh index 305e780f..6922e464 100755 --- a/scripts/ck_pi5_build_check.sh +++ b/scripts/ck_pi5_build_check.sh @@ -32,4 +32,25 @@ done ps_strings="$(strings -a "${ps}")" # no early-exit pipe (SIGPIPE under pipefail) if grep -q "SEED-0B-PI5" <<<"${ps_strings}" && ! grep -q "SEED-0B-QEMU" <<<"${ps_strings}"; then echo "PASS pi5-store image carries the SEED-0B-PI5 tier label only"; else echo "FAIL pi5-store tier label"; fail=1; fi test -s "${root}/target/native-kernel-pi5-store/full-pi5-store/BOOTAA64.EFI" || { echo "FAIL no pi5-store BOOTAA64.EFI"; fail=1; } +# PI5-4 cut 1: the Pi unlock image opens the Store only through the Slot 1 recovery-secret path. +make -C "${root}/native/kernel" pi5-unlock >/dev/null +uo="${root}/target/native-kernel-pi5-unlock/full-pi5-unlock/aienos-ck.elf" +for s in ck_stage_store ck_dev_boot_disk ck_store_unlock_boot ck_store_pi5_unlock_run ck_pi5_unlock_secret; do + if defined "${uo}" "${s}"; then echo "PASS pi5-unlock image defines ${s}"; else echo "FAIL pi5-unlock image lacks ${s}"; fail=1; fi +done +for s in ck_store_test_keys ck_store_test_uuid; do + if defined "${uo}" "${s}"; then echo "FAIL pi5-unlock image defines ${s}"; fail=1; else echo "PASS pi5-unlock image has no ${s}"; fi +done +uo_strings="$(strings -a "${uo}")" +if grep -q "AIEN-TEST-BOOT" <<<"${uo_strings}" || grep -q "LANE18-TEST-KVOL" <<<"${uo_strings}" || grep -q "SEED-0B-PI5" <<<"${uo_strings}" || grep -q "SEED-0B-QEMU" <<<"${uo_strings}"; then + echo "FAIL pi5-unlock image carries a TEST uuid, TEST key label or TEST tier label"; fail=1 +else + echo "PASS pi5-unlock image carries no TEST uuid, TEST key label or TEST tier label" +fi +if defined "${ps}" ck_pi5_unlock_secret; then echo "FAIL pi5-store image defines ck_pi5_unlock_secret"; fail=1; else echo "PASS pi5-store image has no unlock secret source"; fi +# The tier flags are mutually exclusive: the Makefile must refuse each combination. +for combo in CK_PI5_STORE=1 CK_SERVICE=1 CK_HARDWARE_STAGING=1 CK_TEST_STORE_CRASH=1 CK_SERVICE_TEST_KEYS=1; do + if make -n -C "${root}/native/kernel" CK_PI5_UNLOCK=1 "${combo}" full >/dev/null 2>&1; then echo "FAIL Makefile accepts CK_PI5_UNLOCK=1 with ${combo}"; fail=1; else echo "PASS Makefile refuses CK_PI5_UNLOCK=1 with ${combo}"; fi +done +test -s "${root}/target/native-kernel-pi5-unlock/full-pi5-unlock/BOOTAA64.EFI" || { echo "FAIL no pi5-unlock BOOTAA64.EFI"; fail=1; } if [[ ${fail} == 0 ]]; then echo "CK_PI5_BUILD: PASS"; else echo "CK_PI5_BUILD: FAIL"; exit 1; fi