diff --git a/.crumb b/.crumb index 0a04b94f..ef844abf 100644 --- a/.crumb +++ b/.crumb @@ -33,27 +33,27 @@ "purpose": "Directory docs. Purpose not yet described by a human." }, { - "digest": "f25d5173b3b773a434fe623f51db3f3ab79b41fa6bf46b66e2f1dd2ddf525594", - "last_commit": "e811eda", + "digest": "46b6348c6d3b05c623e9ef9814d8b90ed1cc6449906f361d41547b264b12dd50", + "last_commit": "e4abc01", "name": "native", "purpose": "Directory native. Purpose not yet described by a human." }, { - "digest": "c53533f3712e26103f053602b917b580a6ac839b71f7ecab13fae29e49c0aa50", - "last_commit": "e342b8e", + "digest": "72ac07324618c0fce9dc8a227666dec8ee62d66865103810f494e7d7e12b924f", + "last_commit": "ac4e021", "name": "scripts", "purpose": "Directory scripts. Purpose not yet described by a human." } ], - "children_root": "sha256:b04feb3c6bde0bc83be3945cfe7fca50b15f2bf06ee5edb08d6d6b31a189481f", - "compiled_at": "2026-10-09T12:07:39Z", + "children_root": "sha256:257ee1500de1e80a15ee5e24ed6a186707e0cd797879962a4f2971f4340b6072", + "compiled_at": "2026-10-09T12:47:22Z", "compiler": "crumb-compile/1", - "digest": "sha256:7a11342d4432f6e9447655f4ad3bb82beff4cb87f939f2bebc4a4057dc3499bf", + "digest": "sha256:4b75e7310a6b6c1cef9096cbc8a4f2fc26628057e80fa46275c1c75e60598880", "evidence_files": 155, "evidence_root": "sha256:d59c0cef4e7dd5172923754a95b411ca54b01f35baca4587f792f1b259f1eaf7", - "files": 3028, - "generated_at_commit": "e811eda1e29c31f9c0364d29e5ae0a4f5e1c9349", - "source_tree": "sha256:a0bb3cd6cb5f552f73230ca26d596142e59ba6edc4faf0bbdf6a94216d38f97b" + "files": 3032, + "generated_at_commit": "e4abc01d183d0bf59804b848443802c0151de57a", + "source_tree": "sha256:5fe25eb2ab994c467b6ef0dfc7d3ce7489274f636e781dfcb6385a151804f101" }, "owner_lane": "", "provenance": { diff --git a/native/.crumb b/native/.crumb index 7f78b940..8869b146 100644 --- a/native/.crumb +++ b/native/.crumb @@ -79,8 +79,8 @@ "purpose": "Directory native/disk. Purpose not yet described by a human." }, { - "digest": "06229f7e9e08d1b65b41f18c7e615f64e4689bf6853d1d73b19a1829e4c97587", - "last_commit": "ee2ff16", + "digest": "d410f7e809cdbf670066c1658a7b3734c9ffa99f07e4191b474891854852a826", + "last_commit": "e4abc01", "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:843015b58d4bff5705662a9ef3b7520e1a131742d26f34fcab5d0c0a385dd76f", - "compiled_at": "2026-10-09T02:37:36Z", + "children_root": "sha256:c41ae3e0ea8b90fb31d168cf9044152212884d7456d5b6c5c2e01732f2281ab0", + "compiled_at": "2026-10-09T12:47:22Z", "compiler": "crumb-compile/1", - "digest": "sha256:f25d5173b3b773a434fe623f51db3f3ab79b41fa6bf46b66e2f1dd2ddf525594", + "digest": "sha256:46b6348c6d3b05c623e9ef9814d8b90ed1cc6449906f361d41547b264b12dd50", "evidence_files": 4, "evidence_root": "sha256:e410b845507e00568e15b51a5797af32a97e0e4b8ab4e8487bb7c98e7e0cf335", - "files": 453, - "generated_at_commit": "23b2249dd1bbac3314e17b5d70357e71e226cf03", - "source_tree": "sha256:7b2ab90154cb69b4dc837965f01c31e85360b64fef31d8ddcea76d30487d59a1" + "files": 456, + "generated_at_commit": "e4abc01d183d0bf59804b848443802c0151de57a", + "source_tree": "sha256:c5d5c5ba6874200927790555c15975a79e9c119823ee1eb67f85dbb593f0669d" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/.crumb b/native/kernel/.crumb index 38a52916..9163c162 100644 --- a/native/kernel/.crumb +++ b/native/kernel/.crumb @@ -57,14 +57,14 @@ "purpose": "Directory native/kernel/artifact. Purpose not yet described by a human." }, { - "digest": "ef1dd930dc3a359952e25dfc3c6d4c7a3a9ef3113bc2bd61c82efb8018f4dec3", - "last_commit": "3b26ea9", + "digest": "9fa14e9032eeb17c172aa6016ba1e2248220b48fe1389270cf4dc743925b023f", + "last_commit": "ac4e021", "name": "core", "purpose": "Directory native/kernel/core. Purpose not yet described by a human." }, { "digest": "2dce85eb060adebc9b668fa932ad213985f63bf08b3738d6c8e02fe60db32a0f", - "last_commit": "ee2ff16", + "last_commit": "98fbc3c", "name": "dev", "purpose": "Directory native/kernel/dev. Purpose not yet described by a human." }, @@ -82,13 +82,13 @@ }, { "digest": "2712bd906a89792008981a3dc88d1f28f5c4ebcf278751ab852bfd0e76a62e1c", - "last_commit": "ee2ff16", + "last_commit": "98fbc3c", "name": "svc", "purpose": "Directory native/kernel/svc. Purpose not yet described by a human." }, { - "digest": "914e88d9cb6247068ad34e800b17579e9f4d3717c4a9e94cd66ee44ecf0b9bc0", - "last_commit": "2bc7146", + "digest": "b07c3b809edc64472fd5e97f82063d7894758a708c6147f33dad1ad2736599c1", + "last_commit": "e4abc01", "name": "tests", "purpose": "Directory native/kernel/tests. Purpose not yet described by a human." }, @@ -99,15 +99,15 @@ "purpose": "Directory native/kernel/tools. Purpose not yet described by a human." } ], - "children_root": "sha256:7b7fbe34bdb423c68314ee267f788571ba601474bb69a90d8d198a85cd9e8793", - "compiled_at": "2026-10-09T02:37:36Z", + "children_root": "sha256:a5f26a6aa28dd0fd361cfe8a2b033742817a83d8f928a570fe4908b0a9f8218c", + "compiled_at": "2026-10-09T12:47:22Z", "compiler": "crumb-compile/1", - "digest": "sha256:06229f7e9e08d1b65b41f18c7e615f64e4689bf6853d1d73b19a1829e4c97587", + "digest": "sha256:d410f7e809cdbf670066c1658a7b3734c9ffa99f07e4191b474891854852a826", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 289, - "generated_at_commit": "23b2249dd1bbac3314e17b5d70357e71e226cf03", - "source_tree": "sha256:cfceb670b94cfe8d7e7cae23710621c2dc6e7041c7ca8a3155e1533109efd589" + "files": 292, + "generated_at_commit": "e4abc01d183d0bf59804b848443802c0151de57a", + "source_tree": "sha256:e7f17c02d4d2ed98c19f6eaf6d5a010633d002fb0ad73d8f70bfeff06ba31e1d" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/GATES.md b/native/kernel/GATES.md index f8ed7be6..8fde5c3c 100644 --- a/native/kernel/GATES.md +++ b/native/kernel/GATES.md @@ -781,3 +781,27 @@ control 4a (long fixture, `max_ticks=1`) returns inside the tick, and the cap is (4b). (2) A list buffer over the 4096-byte input window is refused by the driver on both sides (`event input_window_exceeded`); the >4096 fixture shows that, it does not show a >4096-byte list running. (3) `alloc`/arenas are not provided by the launcher; the units do not use them. (4) Nothing executes: no environment, files or exec. + +## OSH_OP: a real capability-authorized operation through the shared OSH interface (OSH-AIENOS-OP) -> CK `OSH_OP` (scripts/qemu_ck_osh_op_test.sh) + +Label: **QEMU (aarch64 virt), TEST signer, not physical.** Part of aien-dev/aien-architecture#158. The OSH_CORE gate above (fixture traces, +nothing executes) is unchanged and separate. This gate runs the same three shell units as admitted EL0 tasks (build flags +`CK_SEED0B_TEST_ANCHOR=1 CK_OSH_TEST=1 CK_OSH_OP_TEST=1`; the fixtures are not run in that image). On a ready pipeline the driver +hands the request record (OSH_PLATFORM_ABI section 7, aien-protocols#16 DRAFT) to the adapter layer `core/osh_op.c`, which does +no lexing, parsing or expansion. Operation: `klog ` writes `osh_op_out: ` to the console. Authority: WRITE on the +console-log resource in the session's kernel IPC capability table (domain 1, `core/ipc.c`). Checked at the effect boundary +(binding of section 9: principal, domain, index, generation, resource class, operation), after the intent record and before the +write. Refusals are the contract's names: DENIED, REVOKED, STALE, CAP_DOMAIN_MISMATCH, CAP_GEN_NARROW, NOT_SUPPORTED, NOT_FOUND. +Cases: allow (two lines; the second carries `$?` = the real status), no capability, read-only capability, revoked after the request +was built, interrupt before pipeline 2 of 3, adapter lost after the effect (restart reports OUTCOME_UNKNOWN with the digest and +never replays), a new request after the loss, pipe/redirect/unknown command. Every case: capability released, no task slot held. +Host test `test_osh_op` (59 checks, also under ASan+UBSan) covers the binding checks and the error paths; a mutant that makes the +permission check always OK must fail it (`make osh-op-mutant`). +Limits: (1) intent and outcome records are RAM only: the loss case is simulated by a hook and a restart that keeps the record array; +a durable store is not exercised (integration point: `struct osh_intent` and `osh_op_recover`, for omega's durable records). +(2) One command per pipeline: pipes, redirections, assignments and builtins are refused NOT_SUPPORTED, so PARTIAL_LAUNCH cannot +occur and is not exercised. (3) Revoke, interrupt, loss and sink failure are injected by test hooks at named points, not by +real asynchronous events. (4) Numeric resource-class and operation ids, the REVOKED/STALE split, the shell statuses 126/127/130/70 +are this adapter's choices (UNVERIFIED against a frozen contract). (5) The request digest covers the request cells and the OUT +bytes; the contract's exact digest input is not defined (UNVERIFIED). (6) The "task" is the adapter's session; the EL0 shell units +hold no capability (caps=0) and the check is made by the kernel-side adapter. diff --git a/native/kernel/Makefile b/native/kernel/Makefile index 8b3bd26e..9f91eea9 100644 --- a/native/kernel/Makefile +++ b/native/kernel/Makefile @@ -460,6 +460,15 @@ $(error CK_OSH_TEST and CK_OSC_LAUNCH_TEST are exclusive) endif ART_TRUST_FLAGS += -DCK_OSH_TEST=1 OSH_TEST_C := $(KDIR)/core/osh_test.c +# OSH-AIENOS-OP: instead of the fixture traces, drive a real capability-authorized operation (core/osh_op.c) through the same shell units. +CK_OSH_OP_TEST ?= +ifeq ($(strip $(CK_OSH_OP_TEST)),1) +ifneq ($(strip $(CK_HARDWARE_STAGING)),) +$(error CK_OSH_OP_TEST (test-only OSH adapter with injection hooks) cannot be combined with CK_HARDWARE_STAGING) +endif +ART_TRUST_FLAGS += -DCK_OSH_OP_TEST=1 +OSH_TEST_C += $(KDIR)/core/osh_op.c +endif endif # Screen hold before reset (core/console.c ck_console_fb_hold): seconds the @@ -616,6 +625,16 @@ $(KOBJ)/kernel/core/osc_admit.o: $(KDIR)/core/osc_admit.c $(HDRS) $(ART_HDRS) $( @mkdir -p $(dir $@) $(KCC) $(KCFLAGS) $(ART_TRUST_FLAGS) -c -o $@ $< +# core/osh_op.c refuses to build without CK_OSH_OP_TEST (and with CK_HARDWARE_STAGING): it takes the trust flags too. +$(KOBJ)/kernel/core/osh_op.o: $(KDIR)/core/osh_op.c $(KDIR)/core/osh_op.h $(HDRS) $(OUT)/trust.stamp + @mkdir -p $(dir $@) + $(KCC) $(KCFLAGS) $(ART_TRUST_FLAGS) -c -o $@ $< + +# core/osh_test.c reads CK_OSH_OP_TEST, so it takes the trust flags too (and is rebuilt when they change). +$(KOBJ)/kernel/core/osh_test.o: $(KDIR)/core/osh_test.c $(HDRS) $(ART_HDRS) $(OUT)/trust.stamp + @mkdir -p $(dir $@) + $(KCC) $(KCFLAGS) $(ART_TRUST_FLAGS) -c -o $@ $< + $(KOBJ)/%.o: $(NATIVE)/%.S @mkdir -p $(dir $@) $(KCC) $(KCFLAGS) -c -o $@ $< @@ -789,7 +808,7 @@ $(FULL_EFI): $(FULL_ELF) HOST_SRCS := $(KDIR)/core/fmt.c $(KDIR)/core/acpi.c $(KDIR)/core/smmu.c $(KDIR)/mm/frames.c \ $(KDIR)/mm/pt.c $(KDIR)/mm/heap.c $(KDIR)/core/sched.c $(KDIR)/core/ipc.c $(KDIR)/core/entropy.c \ $(KDIR)/core/handoff_check.c $(KDIR)/core/fbcon.c $(KDIR)/core/acpi_dev.c -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 \ +TESTS := test_fmt test_frames test_pt test_acpi test_acpi_dev test_heap test_smmu test_sched test_ipc test_artifact test_osc_unit test_osc_launch test_osc_admit test_entropy test_handoff test_fbcon test_osh_op \ test_continuity_codec test_continuity_resolve test_continuity_commit test_continuity_recovery test_continuity_geometry \ test_continuity_subject test_continuity_subject_provision HCFLAGS := -std=gnu11 -O1 -g -Wall -Wextra -Werror -I$(KDIR)/core -I$(KDIR)/mm -I$(KDIR)/tests -I$(BOOT) @@ -803,6 +822,27 @@ $(OUT)/host-san/%: $(KDIR)/tests/%.c $(HOST_SRCS) $(KDIR)/tests/ck_test.h $(HDRS @mkdir -p $(dir $@) $(HOSTCC) $(HCFLAGS) $(SANFLAGS) -o $@ $< $(HOST_SRCS) +# OSH adapter operation layer (core/osh_op.c, aien-architecture#158): pure logic over ipc.c capabilities, SHA-256 for the +# request digest. Its own rule because it needs the argus SHA-256 source. +OSH_OP_SRCS := $(KDIR)/core/osh_op.c $(KDIR)/core/ipc.c $(KDIR)/core/fmt.c $(NATIVE)/argus/sha256.c +$(OUT)/host/test_osh_op: $(KDIR)/tests/test_osh_op.c $(OSH_OP_SRCS) $(KDIR)/tests/ck_test.h $(HDRS) + @mkdir -p $(dir $@) + $(HOSTCC) $(HCFLAGS) -DCK_OSH_OP_TEST -I$(NATIVE)/argus -o $@ $< $(OSH_OP_SRCS) + +$(OUT)/host-san/test_osh_op: $(KDIR)/tests/test_osh_op.c $(OSH_OP_SRCS) $(KDIR)/tests/ck_test.h $(HDRS) + @mkdir -p $(dir $@) + $(HOSTCC) $(HCFLAGS) $(SANFLAGS) -DCK_OSH_OP_TEST -I$(NATIVE)/argus -o $@ $< $(OSH_OP_SRCS) + +# TEST-ONLY mutant of core/osh_op.c: the permission check always says OK. test_osh_op must FAIL against it (red before +# green); "make test" fails if the test stops catching it. Host only (osh_op.c refuses the flag freestanding). +$(OUT)/host/test_osh_op_mutant: $(KDIR)/tests/test_osh_op.c $(OSH_OP_SRCS) $(KDIR)/tests/ck_test.h $(HDRS) + @mkdir -p $(dir $@) + $(HOSTCC) $(HCFLAGS) -DCK_OSH_OP_TEST -I$(NATIVE)/argus -DCK_OSH_OP_MUTANT_SKIP_PERM -o $@ $< $(OSH_OP_SRCS) + +osh-op-mutant: $(OUT)/host/test_osh_op_mutant + @if $< > $<.log 2>&1; then cat $<.log; echo "test_osh_op mutant (permission check always OK): PASSED, test does not catch it"; exit 1; \ + else grep -F "test_osh_op: FAIL" $<.log && echo "test_osh_op mutant (permission check always OK): FAILS as required"; fi + # TEST-ONLY mutant of core/handoff_check.c (reserved0 check removed): the # handoff test must FAIL against it, so "make test" fails if the test stops # catching the mutation. Host only (handoff_check.c refuses it freestanding @@ -874,8 +914,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 test-continuity-subject-restart - @fail=0; for t in $(filter-out handoff-mutant acpi-dev-mutant iort-mutants smmu-l2-mutants test-continuity-subject-restart,$^); do $$t || fail=1; done; \ +test: $(addprefix $(OUT)/host/,$(TESTS)) handoff-mutant acpi-dev-mutant iort-mutants smmu-l2-mutants osh-op-mutant test-continuity-subject-restart + @fail=0; for t in $(filter-out handoff-mutant acpi-dev-mutant iort-mutants smmu-l2-mutants osh-op-mutant test-continuity-subject-restart,$^); 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)) diff --git a/native/kernel/core/.crumb b/native/kernel/core/.crumb index 44399c74..ebda7e17 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-08T13:50:06Z", + "compiled_at": "2026-10-09T02:51:28Z", "compiler": "crumb-compile/1", - "digest": "sha256:ef1dd930dc3a359952e25dfc3c6d4c7a3a9ef3113bc2bd61c82efb8018f4dec3", + "digest": "sha256:9fa14e9032eeb17c172aa6016ba1e2248220b48fe1389270cf4dc743925b023f", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 37, - "generated_at_commit": "5732003041b383285046a0f8f2694e94a61886a7", - "source_tree": "sha256:8afe651e311dd744704c59ba23c4d86f0ca84eafa9e36a03e16c3b543dbc9bd8" + "files": 39, + "generated_at_commit": "0c53308f596bbccc2c3a8345b139f082ab2532e9", + "source_tree": "sha256:887f01fd9a283bb3747c2a5607b722cf62b4fd3c3a1e0a16d7eb3d01a2653742" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/core/osh_op.c b/native/kernel/core/osh_op.c new file mode 100644 index 00000000..9c53dcfc --- /dev/null +++ b/native/kernel/core/osh_op.c @@ -0,0 +1,356 @@ +/* osh_op.c -- see osh_op.h. The adapter side of OSH on AIENOS: request record in, one capability-checked platform + * operation out. No lexing, parsing or expansion happens here. No libc calls (host and kernel builds share it). */ +#include "osh_op.h" +#include "fmt.h" +#include "sha256.h" + +#if defined(CK_OSH_OP_MUTANT_SKIP_PERM) && !__STDC_HOSTED__ +#error "CK_OSH_OP_MUTANT_SKIP_PERM is a host-test-only mutant" +#endif + +/* section 7.1 layout */ +#define REQ_MAGIC 0x4F524551ull +#define REQ_HDR 8u +#define CMD_CELLS 164u +#define MAX_CMDS 8u +#define MAX_ARGV 32u +#define MAX_ASSIGN 16u +#define MAX_REDIR 8u +#define LINE_MAX_BYTES 200u /* longest text after the prefix; over it is LIMIT before any effect */ + +static const char PREFIX[] = "osh_op_out: "; + +static void zero(void *p, size_t n) +{ + uint8_t *b = p; + for (size_t i = 0; i < n; i++) + b[i] = 0; +} + +__attribute__((unused)) static int same(const void *a, const void *b, size_t n) +{ + const uint8_t *x = a, *y = b; + for (size_t i = 0; i < n; i++) + if (x[i] != y[i]) + return 0; + return 1; +} + +const char *osh_err_name(unsigned e) +{ + static const char *const n[] = { "OK", "DENIED", "REVOKED", "STALE", "NOT_FOUND", "UNAVAILABLE", "INVALID_ARG", "LIMIT", + "INTERRUPTED", "BROKEN_PIPE", "IO", "OUTCOME_UNKNOWN", "CAP_DOMAIN_MISMATCH", + "CAP_GEN_NARROW", "NOT_SUPPORTED", "WOULD_BLOCK", "PARTIAL_LAUNCH" }; + return e < sizeof n / sizeof n[0] ? n[e] : "IO"; /* section 8.6: an unknown code is IO, never OK */ +} + +const char *osh_outcome_name(unsigned o) +{ + static const char *const n[] = { "NOT_STARTED", "COMPLETED", "FAILED_NO_EFFECT", "CANCELLED", "OUTCOME_UNKNOWN" }; + return o < sizeof n / sizeof n[0] ? n[o] : "OUTCOME_UNKNOWN"; +} + +static void hex32(const uint8_t d[32], char o[65]) +{ + static const char x[] = "0123456789abcdef"; + for (unsigned i = 0; i < 32; i++) { + o[2 * i] = x[d[i] >> 4]; + o[2 * i + 1] = x[d[i] & 15]; + } + o[64] = 0; +} + +void osh_session_init(struct osh_session *s, unsigned grant_rights) +{ + zero(s, sizeof *s); + ck_cap_init(&s->caps, 0x4f534800u, 4); + sha256_hash((const uint8_t *)"aienos-osh-test-session", 23, s->principal); + if (grant_rights && ck_cap_insert(&s->caps, OSH_RES_CONSOLE_LOG, grant_rights, &s->console_cap) == CK_CAP_OK) + for (unsigned i = 0; i < 32; i++) + s->cap_holder[i] = s->principal[i]; +} + +int osh_session_close(struct osh_session *s) +{ + if (s->console_cap.generation) + (void)ck_cap_remove(&s->caps, s->console_cap); + for (unsigned i = 0; i < CK_CAP_SLOTS; i++) + if (s->caps.slots[i].live) + return 0; + return 1; +} + +void osh_session_restart(struct osh_session *fresh, const struct osh_session *old) +{ + osh_session_init(fresh, 0); + for (unsigned i = 0; i < OSH_INTENT_MAX; i++) + fresh->intents[i] = old->intents[i]; + fresh->pipelines = old->pipelines; +} + +static void note(const struct osh_env *env, const char *fmt, uint32_t seq, const char *what, const uint8_t dg[32]) +{ + char d[65], line[200]; + hex32(dg, d); + ck_snprintf(line, sizeof line, fmt, (unsigned)seq, what, d); + env->log(env->ctx, line); +} + +/* Mandatory security receipt (section 13): every use of a grant, every denial and every refusal at the effect boundary. + * Names principal, capability domain/index/generation, resource class, operation and the request digest. */ +static void receipt(const struct osh_env *env, const struct osh_result *r, const struct osh_binding *b, const char *result, + const char *effect) +{ + char d[65], p[65], line[420]; + hex32(r->digest, d); + hex32(b->principal_id, p); + ck_snprintf(line, sizeof line, + "osh_op_receipt: seq=%u op=console_write result=%s request_digest=%s effect=%s principal=%s cap_domain=%u " + "cap_index=%u cap_generation=%llu resource_class=%u operation=%u", + (unsigned)r->seq, result, d, effect, p, (unsigned)b->domain, (unsigned)b->cap_index, + (unsigned long long)b->cap_generation, (unsigned)b->resource_class, (unsigned)b->operation); + env->log(env->ctx, line); +} + +unsigned osh_op_recover(struct osh_session *s, const struct osh_env *env) +{ + unsigned n = 0; + for (unsigned i = 0; i < OSH_INTENT_MAX; i++) { + struct osh_intent *t = &s->intents[i]; + if (!t->used || t->closed) + continue; + t->closed = 1; + t->outcome = OSH_O_OUTCOME_UNKNOWN; + t->err = OSH_E_OUTCOME_UNKNOWN; + note(env, "osh_op_record: seq=%u outcome=%s request_digest=%s replayed=0", t->seq, "OUTCOME_UNKNOWN", t->digest); + n++; + } + return n; +} + +/* section 9 rule 2 and 3: validated at the moment of the effect, against the table that holds the capability. The + * REVOKED / STALE split is this adapter's reading of the draft: a handle whose slot is now empty (or a tombstone) and + * whose generation was issued is REVOKED; a slot reused under a newer generation is STALE; anything never issued is DENIED. */ +unsigned osh_op_perm_check(const struct osh_session *s, const struct osh_binding *b) +{ +#ifdef CK_OSH_OP_MUTANT_SKIP_PERM + (void)s; + (void)b; + return OSH_E_OK; +#else + if (b->domain == 2) + return OSH_E_CAP_DOMAIN_MISMATCH; /* the console resource lives in the kernel IPC table (domain 1) */ + if (b->domain != 1) + return OSH_E_INVALID_ARG; + if (b->cap_generation > 0xffffffffull) + return OSH_E_CAP_GEN_NARROW; + if (b->resource_class != OSH_RC_CONSOLE_LOG || b->operation != OSH_OP_WRITE) + return OSH_E_DENIED; + if (!same(b->principal_id, s->cap_holder, 32)) /* the capability belongs to the principal it was granted to */ + return OSH_E_DENIED; + uint32_t gen = (uint32_t)b->cap_generation; + if (gen == 0 || b->cap_index >= s->caps.n) + return OSH_E_DENIED; + const struct ck_cap_slot *sl = &s->caps.slots[b->cap_index]; + struct ck_handle h = { b->cap_index, gen }; + if (sl->live && !sl->tombstone && sl->generation == gen) { + uint32_t res = 0; + int r = ck_cap_lookup(&s->caps, h, CK_R_WRITE, &res); + return r == CK_CAP_OK && res == OSH_RES_CONSOLE_LOG ? OSH_E_OK : OSH_E_DENIED; + } + if (sl->live && !sl->tombstone && sl->generation > gen) + return OSH_E_STALE; + if ((sl->live && sl->tombstone && sl->generation == gen) || (!sl->live && s->caps.generations[b->cap_index] == gen)) + return OSH_E_REVOKED; + return OSH_E_DENIED; +#endif +} + +static int status_for(unsigned err) +{ + if (err == OSH_E_OK) + return 0; + switch (err) { + case OSH_E_NOT_FOUND: return 127; + case OSH_E_DENIED: case OSH_E_REVOKED: case OSH_E_STALE: case OSH_E_CAP_DOMAIN_MISMATCH: case OSH_E_CAP_GEN_NARROW: + case OSH_E_NOT_SUPPORTED: return 126; /* found but not run: the adapter's choice, UNVERIFIED against the reference shell */ + case OSH_E_INTERRUPTED: return 130; + default: return 70; /* IO, INVALID_ARG, LIMIT, unknown: an internal-style failure */ + } +} + +static void finish(struct osh_result *r, unsigned err, unsigned outcome) +{ + r->error = err; + r->outcome = outcome; + r->status = status_for(err); +} + +static void digest_request(const uint64_t *req, unsigned ncmds, const uint64_t *out, uint64_t out_used, uint8_t d[32]) +{ + sha256_ctx c; + uint8_t b[8]; + size_t cells = REQ_HDR + (size_t)ncmds * CMD_CELLS; + sha256_init(&c); + for (size_t i = 0; i < cells; i++) { + for (unsigned k = 0; k < 8; k++) + b[k] = (uint8_t)(req[i] >> (8 * k)); + sha256_update(&c, b, 8); + } + for (uint64_t i = 0; i < out_used; i++) { + b[0] = (uint8_t)out[i]; + sha256_update(&c, b, 1); + } + sha256_final(&c, d); +} + +static struct osh_intent *close_intent(struct osh_intent *t, unsigned outcome, unsigned err, int status) +{ + t->closed = 1; + t->outcome = (uint8_t)outcome; + t->err = (uint8_t)err; + t->status = (uint32_t)status; + return t; +} + +void osh_op_exec(struct osh_session *s, const struct osh_env *env, const uint64_t *req, const uint64_t *out, size_t n_out, + struct osh_result *r) +{ + zero(r, sizeof *r); + r->seq = ++s->pipelines; + + /* 1. the record is the expander's output, but it sits in memory the unit could write: check it before use */ + uint64_t ncmds = req[1], out_used = req[4]; + if (req[0] != REQ_MAGIC || req[5] != 1 || (req[3] & ~1ull) || req[6] || req[7] || ncmds < 1 || ncmds > MAX_CMDS || + out_used > n_out) { + finish(r, OSH_E_INVALID_ARG, OSH_O_NOT_STARTED); + return; + } + digest_request(req, (unsigned)ncmds, out, out_used, r->digest); + const uint64_t *c0 = req + REQ_HDR; + uint64_t nargv = c0[0], nassign = c0[1], nredir = c0[2], builtin = c0[3]; + if (nargv > MAX_ARGV || nassign > MAX_ASSIGN || nredir > MAX_REDIR) { + finish(r, OSH_E_INVALID_ARG, OSH_O_NOT_STARTED); + return; + } + for (uint64_t k = 0; k < nargv; k++) { + uint64_t off = c0[4 + 2 * k], len = c0[5 + 2 * k]; + if (off > out_used || len > out_used - off) { + finish(r, OSH_E_INVALID_ARG, OSH_O_NOT_STARTED); + return; + } + for (uint64_t i = 0; i < len; i++) + if (out[off + i] > 255) { + finish(r, OSH_E_INVALID_ARG, OSH_O_NOT_STARTED); + return; + } + } + + /* 2. RESOLVE (section 8.3): a name is a lookup key only. Class 1, a compiled operation the adapter hosts. */ + if (nargv == 0 || c0[4 + 1] != 4 || out[c0[4]] != 'k' || out[c0[4] + 1] != 'l' || out[c0[4] + 2] != 'o' || + out[c0[4] + 3] != 'g') { + finish(r, OSH_E_NOT_FOUND, OSH_O_NOT_STARTED); + return; + } + /* what this layer cannot do yet is refused before any effect, never approximated */ + if (ncmds != 1 || nassign || nredir || builtin) { + finish(r, OSH_E_NOT_SUPPORTED, OSH_O_NOT_STARTED); /* no pipes, redirections, assignments in this slice */ + return; + } + + /* 3. the text to write: argv[1..] joined by one space; bytes outside 0x20..0x7e become '.' so an argument can + * never forge a record line */ + char line[sizeof PREFIX + LINE_MAX_BYTES + 3]; + size_t n = 0; + for (; PREFIX[n]; n++) + line[n] = PREFIX[n]; + size_t body = 0; + for (uint64_t k = 1; k < nargv; k++) { + uint64_t off = c0[4 + 2 * k], len = c0[5 + 2 * k]; + if (body + (k > 1) + len > LINE_MAX_BYTES) { + finish(r, OSH_E_LIMIT, OSH_O_NOT_STARTED); + return; + } + if (k > 1) + line[n + body++] = ' '; + for (uint64_t i = 0; i < len; i++) { + uint8_t ch = (uint8_t)out[off + i]; + line[n + body++] = ch >= 0x20 && ch <= 0x7e ? (char)ch : '.'; + } + } + n += body; + line[n++] = '\n'; + line[n] = 0; /* the sink may print it as a C string */ + + /* 4. the binding this effect carries, built from what the task holds. Nothing here grants anything. */ + struct osh_binding b; + zero(&b, sizeof b); + for (unsigned i = 0; i < 32; i++) + b.principal_id[i] = s->principal[i]; + b.domain = 1; + b.cap_index = s->console_cap.index; + b.cap_generation = s->console_cap.generation; + b.resource_class = OSH_RC_CONSOLE_LOG; + b.operation = OSH_OP_WRITE; + + /* 5. the intent record, before the effect (section 10). A slot is free when never used or when its outcome is + * already written (and logged); only OPEN intents count against the limit. */ + struct osh_intent *t = 0; + for (unsigned i = 0; i < OSH_INTENT_MAX && !t; i++) + if (!s->intents[i].used) + t = &s->intents[i]; + for (unsigned i = 0; i < OSH_INTENT_MAX && !t; i++) + if (s->intents[i].closed) + t = &s->intents[i]; + if (!t) { + finish(r, OSH_E_LIMIT, OSH_O_NOT_STARTED); + receipt(env, r, &b, osh_err_name(OSH_E_LIMIT), "none"); + return; + } + t->used = 1; + t->closed = 0; + t->seq = r->seq; + for (unsigned i = 0; i < 32; i++) + t->digest[i] = r->digest[i]; + + if (s->hooks.revoke_before_perm_at == r->seq && s->console_cap.generation) + (void)ck_cap_remove(&s->caps, s->console_cap); /* revoked between building the request and using it */ + + /* 6. the effect boundary: validated now, not at parse time */ + unsigned pc = osh_op_perm_check(s, &b); + if (pc != OSH_E_OK) { + close_intent(t, OSH_O_FAILED_NO_EFFECT, pc, status_for(pc)); + finish(r, pc, OSH_O_FAILED_NO_EFFECT); + receipt(env, r, &b, osh_err_name(pc), "none"); + return; + } + if (s->hooks.interrupt_before_effect_at == r->seq) { + close_intent(t, OSH_O_CANCELLED, OSH_E_INTERRUPTED, 130); + finish(r, OSH_E_INTERRUPTED, OSH_O_CANCELLED); + r->stop = 1; + note(env, "osh_op_record: seq=%u outcome=%s request_digest=%s effect=none", r->seq, "CANCELLED", r->digest); + return; + } + + /* 7. the effect */ + int w = s->hooks.sink_fail_at == r->seq ? -1 : env->out(env->ctx, line, n); + if (w != 0) { + /* a failed write-class effect may have partly happened: unknown, not "no effect" */ + close_intent(t, OSH_O_OUTCOME_UNKNOWN, OSH_E_IO, 70); + finish(r, OSH_E_IO, OSH_O_OUTCOME_UNKNOWN); + note(env, "osh_op_record: seq=%u outcome=%s request_digest=%s effect=unknown", r->seq, "OUTCOME_UNKNOWN", r->digest); + return; + } + /* the grant was used: a security receipt, always (section 13), written even if the adapter is lost right after */ + receipt(env, r, &b, "OK", "console_write"); + if (s->hooks.crash_after_effect_at == r->seq) { + r->crashed = 1; /* the adapter is lost here: the effect happened, the outcome is never written */ + r->stop = 1; + r->error = OSH_E_OUTCOME_UNKNOWN; + r->outcome = OSH_O_OUTCOME_UNKNOWN; + r->status = 70; + return; + } + close_intent(t, OSH_O_COMPLETED, OSH_E_OK, 0); + finish(r, OSH_E_OK, OSH_O_COMPLETED); +} diff --git a/native/kernel/core/osh_op.h b/native/kernel/core/osh_op.h new file mode 100644 index 00000000..e39a8b49 --- /dev/null +++ b/native/kernel/core/osh_op.h @@ -0,0 +1,123 @@ +/* osh_op.h -- the AIENOS adapter's platform-operation layer for OSH (aien-architecture#158, contract: aien-protocols PR #16 + * OSH_PLATFORM_ABI.md sections 7 to 12, DRAFT, ABIs unfrozen). + * + * One real operation: `klog ` writes one line to the kernel console ("osh_op_out: "). It needs a + * kernel IPC-table capability (domain 1, ipc.h) on the console-log resource with the WRITE right. The shell core (lex, + * parse, expand) is NOT touched here: this layer only reads the request record the expander produced + * (PIPELINE_READY, section 7), maps it to the platform operation, and reports a status. Pure logic, no hardware: + * host-tested in tests/test_osh_op.c, driven in QEMU by core/osh_test.c (CK_OSH_OP_TEST). + * + * Intent and outcome records (section 10) are kept in RAM here. Omega's durable records are a separate PR; the + * integration point is struct osh_intent and osh_op_recover(): swap the RAM array for the durable store. */ +#ifndef AIENOS_CK_OSH_OP_H +#define AIENOS_CK_OSH_OP_H + +#include +#include +#include "ipc.h" + +/* This layer is a QEMU/host TEST adapter (RAM-only records, injection hooks that can revoke a capability). It is built only + * with CK_OSH_OP_TEST and never into a production or hardware-staging image. */ +#ifndef CK_OSH_OP_TEST +#error "osh_op is test-only: define CK_OSH_OP_TEST (make CK_OSH_TEST=1 CK_OSH_OP_TEST=1, or the host test rules)" +#endif +#ifdef CK_HARDWARE_STAGING +#error "CK_OSH_OP_TEST cannot be combined with CK_HARDWARE_STAGING" +#endif + +/* section 8.6 platform error codes (numbers as in the draft) */ +enum osh_err { + OSH_E_OK = 0, OSH_E_DENIED = 1, OSH_E_REVOKED = 2, OSH_E_STALE = 3, OSH_E_NOT_FOUND = 4, OSH_E_UNAVAILABLE = 5, + OSH_E_INVALID_ARG = 6, OSH_E_LIMIT = 7, OSH_E_INTERRUPTED = 8, OSH_E_BROKEN_PIPE = 9, OSH_E_IO = 10, + OSH_E_OUTCOME_UNKNOWN = 11, OSH_E_CAP_DOMAIN_MISMATCH = 12, OSH_E_CAP_GEN_NARROW = 13, OSH_E_NOT_SUPPORTED = 14, + OSH_E_WOULD_BLOCK = 15, OSH_E_PARTIAL_LAUNCH = 16 +}; +/* section 10 outcomes */ +enum osh_outcome { OSH_O_NOT_STARTED = 0, OSH_O_COMPLETED, OSH_O_FAILED_NO_EFFECT, OSH_O_CANCELLED, OSH_O_OUTCOME_UNKNOWN }; + +/* The one resource and operation this layer knows. The numeric ids are this adapter's own (the draft names the + * fields and leaves the numbering open: UNVERIFIED against a frozen contract). */ +#define OSH_RES_CONSOLE_LOG 0x4f534843u /* "OSHC" */ +#define OSH_RC_CONSOLE_LOG 1u /* binding.resource_class */ +#define OSH_OP_WRITE 1u /* binding.operation */ + +/* section 9 rule 2: the authority record carried by every effect */ +struct osh_binding { + uint8_t principal_id[32]; + uint8_t domain; /* 1 = kernel IPC table (32-bit generation) */ + uint32_t cap_index; + uint64_t cap_generation; + uint16_t resource_class; + uint16_t operation; +}; + +#define OSH_INTENT_MAX 16 +struct osh_intent { + uint8_t used; /* 1 once the intent is written */ + uint8_t closed; /* 1 once an outcome is written */ + uint8_t outcome; /* enum osh_outcome, valid when closed */ + uint8_t err; /* enum osh_err, valid when closed */ + uint32_t seq; /* 1-based pipeline number in the session */ + uint32_t status; /* shell status when COMPLETED */ + uint8_t digest[32]; +}; + +/* Test injection points (all zero in normal use). Each names the 1-based pipeline number of the session. */ +struct osh_hooks { + uint32_t revoke_before_perm_at; /* the capability is revoked after the binding is built, before the effect */ + uint32_t interrupt_before_effect_at; /* an interrupt arrives after the permission check, before the effect */ + uint32_t crash_after_effect_at; /* the adapter is lost after the effect, before the outcome is written */ + uint32_t sink_fail_at; /* the console write reports failure */ +}; + +struct osh_env { + void *ctx; + int (*out)(void *ctx, const char *line, size_t len); /* the effect: 0 = written */ + void (*log)(void *ctx, const char *line); /* receipts and records, one line, no newline */ +}; + +/* One principal per session is the current limit: `principal` is the task running the shell, `cap_holder` is the principal the + * console capability was granted to (recorded at grant). The binding carries `principal`; PERM_CHECK requires it to equal + * `cap_holder`, so a capability is only usable by the principal it was granted to. */ +struct osh_session { + struct ck_cap_table caps; + struct ck_handle console_cap; /* generation 0 = none held */ + uint8_t principal[32]; + uint8_t cap_holder[32]; /* zero when no capability was granted */ + struct osh_intent intents[OSH_INTENT_MAX]; + uint32_t pipelines; + struct osh_hooks hooks; +}; + +struct osh_result { + int status; /* shell status for $? */ + unsigned error; /* enum osh_err */ + unsigned outcome; /* enum osh_outcome */ + int stop; /* 1: interrupted or lost, the list must stop */ + int crashed; /* 1: lost after the effect, outcome open */ + uint32_t seq; + uint8_t digest[32]; +}; + +/* A fresh session. grant_rights = rights of the console capability inserted (0 = no capability held at all). */ +void osh_session_init(struct osh_session *s, unsigned grant_rights); +/* Task end: drops every capability the session holds. Returns 1 if the table is empty afterwards. */ +int osh_session_close(struct osh_session *s); +/* A restart: a new session that inherits only the intent records (what a durable log would give back), holding + * no capability. Intents without an outcome are then reported by osh_op_recover. */ +void osh_session_restart(struct osh_session *fresh, const struct osh_session *old); +/* Marks every open intent OUTCOME_UNKNOWN and logs it with its request digest. Never re-runs anything. + * Returns how many were open. */ +unsigned osh_op_recover(struct osh_session *s, const struct osh_env *env); + +/* Run one PIPELINE_READY request record. req = the REQUEST cells, out = the OUT cells (one byte per cell, n_out cells). */ +void osh_op_exec(struct osh_session *s, const struct osh_env *env, const uint64_t *req, const uint64_t *out, size_t n_out, + struct osh_result *r); + +/* section 9 PERM_CHECK, exposed for the tests: OSH_E_OK or the denial reason */ +unsigned osh_op_perm_check(const struct osh_session *s, const struct osh_binding *b); + +const char *osh_err_name(unsigned e); +const char *osh_outcome_name(unsigned o); + +#endif diff --git a/native/kernel/core/osh_test.c b/native/kernel/core/osh_test.c index e79f99d0..85f5ce04 100644 --- a/native/kernel/core/osh_test.c +++ b/native/kernel/core/osh_test.c @@ -24,6 +24,9 @@ #include "sha256.h" #include "../tests/fixtures/osh/osh_layout.h" #include "osh_fixtures.h" +#ifdef CK_OSH_OP_TEST +#include "osh_op.h" +#endif #define LABEL "QEMU (aarch64 virt), TEST signer, not physical" #define CKOSH_WS_CELLS 11456u @@ -112,6 +115,8 @@ static void hex(const uint8_t *p, size_t n, char *o) o[64] = 0; } +static unsigned long launches, slots_held; /* every launch is one EL0 task; a task slot not free after its call is a leak */ + /* One entry call through the launch interface. 0 = RETURNED (value in *ret), else the result is printed and 1. */ static int launch(unsigned u, size_t in_len, uint64_t ws_cells, struct ck_osc_ws *wsr, uint64_t max_ticks, struct osc_result *r, struct ck_osc_launch_info *info) @@ -130,6 +135,9 @@ static int launch(unsigned u, size_t in_len, uint64_t ws_cells, struct ck_osc_ws rq.ws = wsr; rq.max_ticks = max_ticks; ck_osc_launch(unit[u].bytes, unit[u].len, &unit[u].acc, &rq, r, info); + launches++; + if (!info->slot_free_after) + slots_held++; return r->cls != OSC_RES_RETURNED; } @@ -362,6 +370,11 @@ static void answer(void) w[OSH_STAGING + 4 + i] = val[i]; } +#ifdef CK_OSH_OP_TEST +static int real_mode, real_stop; +static int real_pipeline(void); +#endif + /* returns 1 when the driver must stop */ static int run_list(void) { @@ -384,6 +397,15 @@ static int run_list(void) return 1; } size_t cells = (size_t)(REQ_HDR_CELLS + nc * CMD_CELLS); +#ifdef CK_OSH_OP_TEST + if (real_mode) { + last_status = real_pipeline(); + if (real_stop) + return 1; + w[OSH_S_LAST_STATUS] = (uint64_t)(unsigned)last_status; + continue; + } +#endif char h[65]; hex((const uint8_t *)(w + OSH_REQUEST), cells * 8, h); ck_printf("request %lu sha256=%s\n", ++req_no, h); @@ -548,6 +570,112 @@ static void negatives(void) neg_line("4n", "after the overrun, lex_run(in+0,8) on the same workspace", &r, &info, ""); } +#ifdef CK_OSH_OP_TEST +/* ---- OSH-AIENOS-OP: a real, capability-authorized operation through the same shell units ---- + * The fixture driver above is unchanged and is NOT run in this build (the OSH_CORE gate runs it). Here each script goes + * through the same lex/parse/expand EL0 tasks; on PIPELINE_READY the request record goes to core/osh_op.c instead of + * a fake status. Operation: `klog ` writes "osh_op_out: " to the console; it needs WRITE on the console-log + * resource in the session's kernel capability table. QEMU (aarch64 virt), TEST signer, not physical. */ +static struct osh_session sess; +static const char *case_name; +static unsigned sink_calls; +static int real_crashed; + +static int op_sink(void *ctx, const char *line, size_t len) +{ + (void)ctx; + (void)len; + sink_calls++; + ck_printf("%s", line); + return 0; +} + +static void op_log(void *ctx, const char *line) +{ + (void)ctx; + ck_printf("%s case=%s; %s\n", line, case_name, LABEL); +} + +static const struct osh_env op_env = { 0, op_sink, op_log }; + +static void hex32(const uint8_t d[32], char o[65]) +{ + static const char x[] = "0123456789abcdef"; + for (unsigned i = 0; i < 32; i++) { + o[2 * i] = x[d[i] >> 4]; + o[2 * i + 1] = x[d[i] & 15]; + } + o[64] = 0; +} + +static int real_pipeline(void) +{ + struct osh_result r; + char h[65]; + osh_op_exec(&sess, &op_env, w + OSH_REQUEST, w + OSH_OUT, (size_t)(CKOSH_WS_CELLS - OSH_OUT), &r); + hex32(r.digest, h); + ck_printf("osh_op_pipeline: case=%s n=%u status=%d error=%s outcome=%s stop=%d crashed=%d request_digest=%s; %s\n", case_name, + (unsigned)r.seq, r.status, osh_err_name(r.error), osh_outcome_name(r.outcome), r.stop, r.crashed, h, LABEL); + if (r.stop) + real_stop = 1; + if (r.crashed) + real_crashed = 1; + return r.status; +} + +static void scenario(const char *name, unsigned rights, const char *script, struct osh_hooks hk) +{ + case_name = name; + osh_session_init(&sess, rights); + sess.hooks = hk; + sink_calls = 0; + real_mode = 1; + real_stop = 0; + real_crashed = 0; + stop = 0; + step_no = req_no = 0; + nfake = fake_i = have_status = npos = exhausted = 0; + last_status = 0; + src_text = (const unsigned char *)script; + src_len = strlen(script); + src_pos = 0; + unsigned long l0 = launches, s0 = slots_held; + ck_printf("osh_op_begin: case=%s cap_rights=%u; %s\n", name, rights, LABEL); + int rc = run_src(); + struct ck_handle held = sess.console_cap; + int empty = osh_session_close(&sess); + int released = ck_cap_lookup(&sess.caps, held, 0, 0) != CK_CAP_OK; + ck_printf("osh_op_end: case=%s rc=%d final_status=%d sink_calls=%u launches=%lu slots_held=%lu cap_table_empty=%d cap_released=%d; %s\n", + name, rc, last_status, sink_calls, launches - l0, slots_held - s0, empty, released, LABEL); + if (real_crashed) { + /* the adapter was lost after the effect: a restart keeps only the intent records and holds no capability */ + struct osh_session fresh; + unsigned before = sink_calls; + osh_session_restart(&fresh, &sess); + unsigned n = osh_op_recover(&fresh, &op_env); + unsigned again = osh_op_recover(&fresh, &op_env); + ck_printf("osh_op_restart: case=%s open_intents=%u second_scan=%u sink_calls_before=%u sink_calls_after=%u held_cap=%u; %s\n", + name, n, again, before, sink_calls, (unsigned)fresh.console_cap.generation, LABEL); + } + real_mode = 0; +} + +static void op_scenarios(void) +{ + struct osh_hooks none = { 0, 0, 0, 0 }; + struct osh_hooks rv = { 1, 0, 0, 0 }, ir = { 0, 2, 0, 0 }, cr = { 0, 0, 1, 0 }; + scenario("allow", CK_R_WRITE, "klog hello from osh\nklog \"status=$?\"\n", none); + scenario("deny_no_cap", 0, "klog SECRET-no-cap\n", none); + scenario("deny_read_only", CK_R_READ, "klog SECRET-read-only\n", none); + scenario("revoked", CK_R_WRITE, "klog SECRET-revoked\n", rv); + scenario("interrupt", CK_R_WRITE, "klog one; klog two; klog three\n", ir); + scenario("lost", CK_R_WRITE, "klog LOST-MARKER\n", cr); + scenario("after_restart", CK_R_WRITE, "klog fresh decision\n", none); + scenario("unsupported", CK_R_WRITE, "klog a | klog SECRET-pipe\nklog SECRET-redir >f\nnosuchcmd\n", none); + ck_printf("osh_op_done: cases=8; %s\n", LABEL); +} +#endif + void ck_osh_all(void) { unsigned have = 0; @@ -558,6 +686,10 @@ void ck_osh_all(void) ck_printf("osh_core: NOT_RUN (a shell unit was not admitted); %s\n", LABEL); return; } +#ifdef CK_OSH_OP_TEST + op_scenarios(); + return; +#endif unsigned nfx = (unsigned)(sizeof osh_fx / sizeof osh_fx[0]); unsigned long best = 0; for (unsigned i = 0; i < nfx; i++) { diff --git a/native/kernel/tests/.crumb b/native/kernel/tests/.crumb index 7c27bf49..3af3bb7e 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-08T19:15:06Z", + "compiled_at": "2026-10-09T03:30:34Z", "compiler": "crumb-compile/1", - "digest": "sha256:914e88d9cb6247068ad34e800b17579e9f4d3717c4a9e94cd66ee44ecf0b9bc0", + "digest": "sha256:b07c3b809edc64472fd5e97f82063d7894758a708c6147f33dad1ad2736599c1", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 148, - "generated_at_commit": "9696c7d98e324105b6b161626dc82450f1b8ab2b", - "source_tree": "sha256:26ea29075b182391a5b2d8e126807b405cd78db10c9f9d5446cf041813a373e7" + "files": 149, + "generated_at_commit": "6682b7b406975166e9f60747cb7d12849a30305d", + "source_tree": "sha256:7c929c4de6036231d6c91b703ad431177948af2ef64a5015aaf956d0b89c6e6b" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/tests/test_osh_op.c b/native/kernel/tests/test_osh_op.c new file mode 100644 index 00000000..0295a1dd --- /dev/null +++ b/native/kernel/tests/test_osh_op.c @@ -0,0 +1,328 @@ +/* test_osh_op.c -- host tests for core/osh_op.c: the AIENOS adapter's capability-authorized console write (`klog`). + * Requests are built as the expander's request record (OSH_PLATFORM_ABI section 7) without calling the shell core. */ +#include +#include "ck_test.h" +#include "osh_op.h" + +static char cap_buf[4096]; +static int cap_calls; +static char logs[16][480]; +static int nlogs; + +static int sink(void *ctx, const char *line, size_t len) +{ + (void)ctx; + cap_calls++; + CHECK(line[len] == 0 && len > 0 && line[len - 1] == '\n'); /* a C string the kernel sink may print */ + if (strlen(cap_buf) + len < sizeof cap_buf) + { + size_t at = strlen(cap_buf); + memcpy(cap_buf + at, line, len); + cap_buf[at + len] = 0; + } + return 0; +} +static void logger(void *ctx, const char *line) +{ + (void)ctx; + if (nlogs < 16) + snprintf(logs[nlogs++], sizeof logs[0], "%s", line); +} +static const struct osh_env env = { 0, sink, logger }; + +static void reset_capture(void) +{ + cap_buf[0] = 0; + cap_calls = 0; + nlogs = 0; +} + +static uint64_t req[8 + 8 * 164]; +static uint64_t out[8192]; + +/* one command per block; args NULL-terminated; extra fields set by the caller afterwards */ +static void build(unsigned ncmds, const char *const *argv, const char *const *argv2) +{ + memset(req, 0, sizeof req); + memset(out, 0, sizeof out); + req[0] = 0x4F524551ull; + req[1] = ncmds; + req[3] = 0; + req[5] = 1; + uint64_t used = 0; + for (unsigned c = 0; c < ncmds; c++) { + const char *const *a = c == 0 ? argv : argv2; + uint64_t *b = req + 8 + c * 164; + unsigned n = 0; + for (; a[n]; n++) { + size_t l = strlen(a[n]); + for (size_t i = 0; i < l; i++) + out[used + i] = (uint8_t)a[n][i]; + b[4 + 2 * n] = used; + b[5 + 2 * n] = l; + used += l; + } + b[0] = n; + } + req[4] = used; +} + +static struct osh_result run(struct osh_session *s, const char *const *argv) +{ + struct osh_result r; + build(1, argv, 0); + osh_op_exec(s, &env, req, out, 8192, &r); + return r; +} + +int main(void) +{ + struct osh_session s, t; + struct osh_result r; + const char *const hello[] = { "klog", "hello", "world", 0 }; + + /* allowed: the task holds WRITE on the console resource */ + reset_capture(); + osh_session_init(&s, CK_R_WRITE); + r = run(&s, hello); + CHECK(r.error == OSH_E_OK && r.outcome == OSH_O_COMPLETED && r.status == 0 && !r.stop); + CHECK(strcmp(cap_buf, "osh_op_out: hello world\n") == 0 && cap_calls == 1); + CHECK(s.intents[0].used && s.intents[0].closed && s.intents[0].outcome == OSH_O_COMPLETED && s.intents[0].seq == 1); + CHECK(memcmp(s.intents[0].digest, r.digest, 32) == 0); + uint8_t d1[32]; + memcpy(d1, r.digest, 32); + r = run(&s, hello); + CHECK(memcmp(d1, r.digest, 32) == 0 && r.seq == 2); /* the same request, the same digest */ + const char *const other[] = { "klog", "hello", "worlD", 0 }; + r = run(&s, other); + CHECK(memcmp(d1, r.digest, 32) != 0); + + /* no capability at all: refused before any effect, with the named refusal */ + reset_capture(); + osh_session_init(&s, 0); + r = run(&s, hello); + CHECK(r.error == OSH_E_DENIED && r.outcome == OSH_O_FAILED_NO_EFFECT && r.status == 126); + CHECK(cap_calls == 0 && cap_buf[0] == 0); + CHECK(s.intents[0].closed && s.intents[0].outcome == OSH_O_FAILED_NO_EFFECT && s.intents[0].err == OSH_E_DENIED); + CHECK(nlogs == 1 && strstr(logs[0], "osh_op_receipt:") && strstr(logs[0], "result=DENIED") && strstr(logs[0], "effect=none")); + + /* a capability without WRITE: denied */ + reset_capture(); + osh_session_init(&s, CK_R_READ); + r = run(&s, hello); + CHECK(r.error == OSH_E_DENIED && cap_calls == 0); + + /* revoked between building the request and using it */ + reset_capture(); + osh_session_init(&s, CK_R_WRITE); + s.hooks.revoke_before_perm_at = 1; + r = run(&s, hello); + CHECK(r.error == OSH_E_REVOKED && r.outcome == OSH_O_FAILED_NO_EFFECT && cap_calls == 0); + r = run(&s, hello); /* and it stays revoked */ + CHECK(r.error == OSH_E_REVOKED && cap_calls == 0); + + /* the binding checks, called directly */ + { + struct osh_binding b; + struct ck_handle h2; + osh_session_init(&s, CK_R_WRITE); + memset(&b, 0, sizeof b); + memcpy(b.principal_id, s.principal, 32); + b.domain = 1; + b.cap_index = s.console_cap.index; + b.cap_generation = s.console_cap.generation; + b.resource_class = OSH_RC_CONSOLE_LOG; + b.operation = OSH_OP_WRITE; + CHECK(osh_op_perm_check(&s, &b) == OSH_E_OK); + b.domain = 2; + CHECK(osh_op_perm_check(&s, &b) == OSH_E_CAP_DOMAIN_MISMATCH); + b.domain = 1; + b.cap_generation = 0x100000001ull; + CHECK(osh_op_perm_check(&s, &b) == OSH_E_CAP_GEN_NARROW); + b.cap_generation = s.console_cap.generation; + b.resource_class = 2; + CHECK(osh_op_perm_check(&s, &b) == OSH_E_DENIED); + b.resource_class = OSH_RC_CONSOLE_LOG; + b.operation = 2; + CHECK(osh_op_perm_check(&s, &b) == OSH_E_DENIED); + b.operation = OSH_OP_WRITE; + b.principal_id[0] ^= 1; + CHECK(osh_op_perm_check(&s, &b) == OSH_E_DENIED); + b.principal_id[0] ^= 1; + b.cap_generation = s.console_cap.generation + 5; /* never issued */ + CHECK(osh_op_perm_check(&s, &b) == OSH_E_DENIED); + b.cap_generation = s.console_cap.generation; + b.cap_index = 99; + CHECK(osh_op_perm_check(&s, &b) == OSH_E_DENIED); + b.cap_index = s.console_cap.index; + /* revoke, then the old handle is REVOKED; a new capability in the same slot makes the old handle STALE */ + CHECK(ck_cap_remove(&s.caps, s.console_cap) == CK_CAP_OK); + CHECK(osh_op_perm_check(&s, &b) == OSH_E_REVOKED); + CHECK(ck_cap_insert(&s.caps, OSH_RES_CONSOLE_LOG, CK_R_WRITE, &h2) == CK_CAP_OK); + CHECK(h2.index == b.cap_index && h2.generation > s.console_cap.generation); + CHECK(osh_op_perm_check(&s, &b) == OSH_E_STALE); + /* a capability on another resource does not authorize the console */ + osh_session_init(&s, 0); + CHECK(ck_cap_insert(&s.caps, 0x1234u, CK_R_WRITE, &s.console_cap) == CK_CAP_OK); + memcpy(s.cap_holder, s.principal, 32); /* the principal matches: only the resource is wrong */ + r = run(&s, hello); + CHECK(r.error == OSH_E_DENIED && cap_calls == 0); + } + + /* an interrupt before the effect: cancelled, no bytes, the list stops */ + reset_capture(); + osh_session_init(&s, CK_R_WRITE); + s.hooks.interrupt_before_effect_at = 2; + r = run(&s, hello); + CHECK(r.error == OSH_E_OK && cap_calls == 1); + r = run(&s, hello); + CHECK(r.error == OSH_E_INTERRUPTED && r.outcome == OSH_O_CANCELLED && r.stop && r.status == 130 && cap_calls == 1); + CHECK(s.intents[1].closed && s.intents[1].outcome == OSH_O_CANCELLED); + CHECK(osh_session_close(&s) == 1); + CHECK(ck_cap_lookup(&s.caps, s.console_cap, CK_R_WRITE, 0) != CK_CAP_OK); /* capability released */ + + /* lost after the effect: the outcome is unknown, restart reports it and never replays it */ + reset_capture(); + osh_session_init(&s, CK_R_WRITE); + s.hooks.crash_after_effect_at = 1; + r = run(&s, hello); + CHECK(r.crashed && r.stop && r.outcome == OSH_O_OUTCOME_UNKNOWN && cap_calls == 1); + CHECK(s.intents[0].used && !s.intents[0].closed); + osh_session_restart(&t, &s); + CHECK(t.console_cap.generation == 0); /* the restarted adapter holds no capability */ + nlogs = 0; + CHECK(osh_op_recover(&t, &env) == 1); + CHECK(cap_calls == 1); /* not replayed */ + CHECK(t.intents[0].closed && t.intents[0].outcome == OSH_O_OUTCOME_UNKNOWN); + CHECK(nlogs == 1 && strstr(logs[0], "outcome=OUTCOME_UNKNOWN") && strstr(logs[0], "replayed=0")); + CHECK(osh_op_recover(&t, &env) == 0 && nlogs == 1 && cap_calls == 1); /* idempotent */ + + /* a failed console write is unknown, not "no effect" */ + reset_capture(); + osh_session_init(&s, CK_R_WRITE); + s.hooks.sink_fail_at = 1; + r = run(&s, hello); + CHECK(r.error == OSH_E_IO && r.outcome == OSH_O_OUTCOME_UNKNOWN && s.intents[0].outcome == OSH_O_OUTCOME_UNKNOWN); + + /* refused before any effect or intent: unknown name, and what this slice cannot do yet */ + reset_capture(); + osh_session_init(&s, CK_R_WRITE); + const char *const ls[] = { "ls", 0 }; + r = run(&s, ls); + CHECK(r.error == OSH_E_NOT_FOUND && r.status == 127 && r.outcome == OSH_O_NOT_STARTED && !s.intents[0].used); + const char *const kl[] = { "klog", "a", 0 }; + build(2, kl, kl); + osh_op_exec(&s, &env, req, out, 8192, &r); + CHECK(r.error == OSH_E_NOT_SUPPORTED && r.status == 126 && cap_calls == 0 && !s.intents[0].used); /* a pipe */ + build(1, kl, 0); + req[8 + 2] = 1; /* nredir */ + osh_op_exec(&s, &env, req, out, 8192, &r); + CHECK(r.error == OSH_E_NOT_SUPPORTED && cap_calls == 0); + build(1, kl, 0); + req[8 + 1] = 1; /* nassign */ + osh_op_exec(&s, &env, req, out, 8192, &r); + CHECK(r.error == OSH_E_NOT_SUPPORTED && cap_calls == 0); + build(1, kl, 0); + req[8 + 3] = 3; /* builtin printf */ + osh_op_exec(&s, &env, req, out, 8192, &r); + CHECK(r.error == OSH_E_NOT_SUPPORTED && cap_calls == 0); + CHECK(!s.intents[0].used); + + /* malformed request records are refused without using the memory */ + build(1, kl, 0); + req[0] ^= 1; + osh_op_exec(&s, &env, req, out, 8192, &r); + CHECK(r.error == OSH_E_INVALID_ARG && cap_calls == 0); + build(1, kl, 0); + req[8 + 5] = 99; /* argv[0] length past out_used */ + osh_op_exec(&s, &env, req, out, 8192, &r); + CHECK(r.error == OSH_E_INVALID_ARG && cap_calls == 0); + build(1, kl, 0); + out[0] = 0x14b; /* a cell that is not a byte */ + osh_op_exec(&s, &env, req, out, 8192, &r); + CHECK(r.error == OSH_E_INVALID_ARG && cap_calls == 0); + build(1, kl, 0); + req[1] = 9; /* ncmds over 8 */ + osh_op_exec(&s, &env, req, out, 8192, &r); + CHECK(r.error == OSH_E_INVALID_ARG && cap_calls == 0); + build(1, kl, 0); + req[4] = 9000; /* out_used over the OUT region */ + osh_op_exec(&s, &env, req, out, 8192, &r); + CHECK(r.error == OSH_E_INVALID_ARG && cap_calls == 0); + + /* an argument cannot forge a record line, and an over-long line is a LIMIT before the effect */ + reset_capture(); + const char *const nl[] = { "klog", "a\nosh_op_record: forged", 0 }; + r = run(&s, nl); + CHECK(r.error == OSH_E_OK && strcmp(cap_buf, "osh_op_out: a.osh_op_record: forged\n") == 0); + char big[300]; + memset(big, 'x', 299); + big[299] = 0; + const char *const bg[] = { "klog", big, 0 }; + reset_capture(); + r = run(&s, bg); + CHECK(r.error == OSH_E_LIMIT && cap_calls == 0); + + /* closed intents are reclaimed (their outcome is already logged): 40 sequential klogs succeed, each with a + * "grant used" receipt; only OPEN intents count against the limit */ + reset_capture(); + osh_session_init(&s, CK_R_WRITE); + int okn = 0; + for (int i = 0; i < 40; i++) + okn += run(&s, hello).error == OSH_E_OK; + CHECK(okn == 40 && cap_calls == 40); + CHECK(nlogs == 16); /* the log array keeps the first 16 lines */ + CHECK(strstr(logs[0], "osh_op_receipt: seq=1 op=console_write result=OK ") && strstr(logs[0], "effect=console_write")); + CHECK(strstr(logs[0], "cap_domain=1 cap_index=0 cap_generation=1 resource_class=1 operation=1") && strstr(logs[0], "principal=")); + /* the receipt names the request digest */ + { + reset_capture(); + osh_session_init(&s, CK_R_WRITE); + r = run(&s, hello); + static const char hex[] = "0123456789abcdef"; + char want[64 + 1]; + for (int i = 0; i < 32; i++) { + want[2 * i] = hex[r.digest[i] >> 4]; + want[2 * i + 1] = hex[r.digest[i] & 0xf]; + } + want[64] = '\0'; + CHECK(nlogs == 1 && strstr(logs[0], want)); + } + /* 16 open intents (the adapter lost after each effect) fill the log; the next pipeline is refused LIMIT with a receipt */ + reset_capture(); + osh_session_init(&s, CK_R_WRITE); + for (int i = 0; i < OSH_INTENT_MAX; i++) { + s.hooks.crash_after_effect_at = s.pipelines + 1; + r = run(&s, hello); + CHECK(r.crashed); + } + CHECK(cap_calls == OSH_INTENT_MAX); + nlogs = 0; + r = run(&s, hello); + CHECK(r.error == OSH_E_LIMIT && r.outcome == OSH_O_NOT_STARTED && cap_calls == OSH_INTENT_MAX); + CHECK(nlogs == 1 && strstr(logs[0], "osh_op_receipt:") && strstr(logs[0], "result=LIMIT") && strstr(logs[0], "effect=none")); + /* the denial receipts carry the binding too */ + reset_capture(); + osh_session_init(&s, 0); + r = run(&s, hello); + CHECK(nlogs == 1 && strstr(logs[0], "result=DENIED") && strstr(logs[0], "cap_domain=1") && strstr(logs[0], "principal=")); + + /* the capability belongs to the principal it was granted to: another principal presenting it is DENIED */ + reset_capture(); + osh_session_init(&s, CK_R_WRITE); + CHECK(memcmp(s.cap_holder, s.principal, 32) == 0); + s.principal[0] ^= 1; /* a different task now runs the shell session */ + r = run(&s, hello); + CHECK(r.error == OSH_E_DENIED && cap_calls == 0); + osh_session_init(&s, 0); + { + static const uint8_t zero32[32]; + CHECK(memcmp(s.cap_holder, zero32, 32) == 0); /* nothing granted, no holder */ + } + + /* names */ + CHECK(strcmp(osh_err_name(OSH_E_PARTIAL_LAUNCH), "PARTIAL_LAUNCH") == 0 && strcmp(osh_err_name(99), "IO") == 0); + CHECK(strcmp(osh_outcome_name(OSH_O_CANCELLED), "CANCELLED") == 0); + + return ck_t_verdict("test_osh_op"); +} diff --git a/scripts/.crumb b/scripts/.crumb index 5cc36a12..7f604eb7 100644 --- a/scripts/.crumb +++ b/scripts/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-08T15:06:47Z", + "compiled_at": "2026-10-09T02:51:28Z", "compiler": "crumb-compile/1", - "digest": "sha256:c53533f3712e26103f053602b917b580a6ac839b71f7ecab13fae29e49c0aa50", + "digest": "sha256:72ac07324618c0fce9dc8a227666dec8ee62d66865103810f494e7d7e12b924f", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 75, - "generated_at_commit": "9d9890388426bbfec1080dbbc395d852e1c57eea", - "source_tree": "sha256:ecddd83ad4db05e0617c9a6bf048186ffcebaa9a7795d51c852162eab8bd19a1" + "files": 76, + "generated_at_commit": "0c53308f596bbccc2c3a8345b139f082ab2532e9", + "source_tree": "sha256:e3ec588343b886b34fec7208ae0c7746f5121d99e759682ffe00c0205176978c" }, "owner_lane": "", "provenance": { diff --git a/scripts/ck_gates.sh b/scripts/ck_gates.sh index 7c2189eb..9a57a968 100755 --- a/scripts/ck_gates.sh +++ b/scripts/ck_gates.sh @@ -12,10 +12,10 @@ # 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), and prints +# scripts/qemu_ck_osc_launch_test.sh, scripts/qemu_ck_osh_core_test.sh, scripts/qemu_ck_osh_op_test.sh), and prints # one line per gate: # AIENOS_CK_: PASS|FAIL|NOT_RUN [(reason)] -# for M1 M3 SMMU NVME_SHUTDOWN P2_ARTIFACT M0_ROLLBACK OSC_UNIT OSC_LAUNCH OSH_CORE M4_NVME M4_STORE M4_STORE_CRASH +# 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 # M4_CONTINUITY M4_RECOVERY M4_ALLEN ARGUS1_REVOKE KEYBOARD NET SMP DISK_LAYOUT FPU INFER SCREEN CONSOLE. Gates with no C # implementation print NOT_RUN (MISSING_IMPLEMENTATION: ) and never # run anything. A missing child script, a child that reports NOT_RUN, a child @@ -66,6 +66,7 @@ set -uo pipefail # 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) # 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) # missing -> NOT_RUN (MISSING_IMPLEMENTATION), never run, never PASS # =========================================================================== CK_GATE_TABLE=' @@ -78,6 +79,7 @@ M0_ROLLBACK|rollback|- OSC_UNIT|osc|- OSC_LAUNCH|osc_launch|- OSH_CORE|osh_core|- +OSH_OP|osh_op|- M4_NVME|store|- M4_STORE|store|- M4_STORE_CRASH|crash|- @@ -94,7 +96,7 @@ INFER|infer|- SCREEN|screen|- CONSOLE|console|- ' -CHILDREN=(boot store net artifact smp crash disk cont recov allen kbd fpu infer screen console rollback osc osc_launch osh_core) +CHILDREN=(boot store net artifact smp crash disk cont recov allen kbd fpu infer screen console rollback osc osc_launch osh_core osh_op) # =========================================================================== repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" @@ -151,6 +153,7 @@ set_default_children() { [osc]="${repo_root}/scripts/qemu_ck_osc_unit_test.sh" [osc_launch]="${repo_root}/scripts/qemu_ck_osc_launch_test.sh" [osh_core]="${repo_root}/scripts/qemu_ck_osh_core_test.sh" + [osh_op]="${repo_root}/scripts/qemu_ck_osh_op_test.sh" ) } @@ -380,11 +383,11 @@ self_test() { } expect_missing_all() { local g - for g in P2_ARTIFACT M0_ROLLBACK OSC_UNIT OSC_LAUNCH OSH_CORE 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 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}") + 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}") run_children 2>/dev/null evaluate_table >"${tmp}/${scen}.out" } @@ -400,8 +403,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/15/24" && ${overall} == NOT_ALL_GATES_PASS ]] \ - && ok "A: counts 9/0/15 of 24, 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/16/25" && ${overall} == NOT_ALL_GATES_PASS ]] \ + && ok "A: counts 9/0/16 of 25, 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" @@ -413,7 +416,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")" == 24 ]] && ok "A: exactly 24 verdict lines" || bad "A: verdict line count" + [[ "$(grep -c '^AIENOS_CK_[A-Z0-9_]*: ' "${tmp}/A.out")" == 25 ]] && ok "A: exactly 25 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" @@ -584,10 +587,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) == 24 and .verdict == "NOT_ALL_GATES_PASS" + jq -e '.physical == "NOT_RUN" and (.gates | length) == 25 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) == 19 and .commit_subject == "quote \" backslash \\ tab\tend"' "${receipt_path}" >/dev/null \ + and (.children | length) == 20 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 @@ -600,18 +603,18 @@ self_test() { bad "an existing receipt was overwritten or the clash was not refused" fi - # The gate table parses: 24 rows, known sources, reasons only on missing rows. + # The gate table parses: 25 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) [[ "${w}" == - ]] || tbad=1 ;; + boot|store|net|artifact|smp|crash|disk|cont|recov|allen|kbd|fpu|infer|screen|console|rollback|osc|osc_launch|osh_core|osh_op) [[ "${w}" == - ]] || tbad=1 ;; missing) [[ -n "${w}" && "${w}" != - ]] || tbad=1 ;; *) tbad=1 ;; esac done <<<"${CK_GATE_TABLE}" - [[ ${tbad} == 0 && ${rows} == 24 ]] && ok "gate table: 24 rows well-formed" || bad "gate table malformed (${rows} rows)" + [[ ${tbad} == 0 && ${rows} == 25 ]] && ok "gate table: 25 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_osh_op_test.sh b/scripts/qemu_ck_osh_op_test.sh new file mode 100755 index 00000000..d8fc1f98 --- /dev/null +++ b/scripts/qemu_ck_osh_op_test.sh @@ -0,0 +1,170 @@ +#!/usr/bin/env bash +# AIENOS_CK_OSH_OP gate (OSH-AIENOS-OP, aien-architecture#158): a REAL capability-authorized operation through the shared +# OSH interface. The same three compiled shell units (lex_run, parse_run, expand_run) run as admitted EL0 tasks; on a ready +# pipeline the request record goes to the adapter's operation layer (native/kernel/core/osh_op.c) instead of a fake status. +# Operation: `klog ` writes "osh_op_out: " to the console. Capability: WRITE on the console-log resource in +# the session's kernel IPC capability table (domain 1). The OSH_CORE gate (qemu_ck_osh_core_test.sh, fixture traces) is +# unchanged and separate; this gate does not run the fixtures. +# +# Label: QEMU (aarch64 virt), TEST signer, not physical. Nothing here ran on a Spark or any real machine. +# Cases (one boot, CK_SEED0B_TEST_ANCHOR=1 CK_OSH_TEST=1 CK_OSH_OP_TEST=1): +# allow WRITE held: two lines and two "grant used" receipts on the console (the second shows $? = the real status 0 flowing back into the shell core) +# deny_no_cap no capability: DENIED, no bytes, outcome FAILED_NO_EFFECT, a security receipt line +# deny_read_only READ only: DENIED, no bytes +# revoked revoked between request build and effect: REVOKED, no bytes +# interrupt interrupt before pipeline 2 of 3: pipeline 1 done, 2 CANCELLED, 3 never runs, status 130 +# lost adapter lost after the effect: bytes appear once; restart reports OUTCOME_UNKNOWN with the digest, never replays +# after_restart a new request after the loss is a new decision and runs +# unsupported pipe, redirection, unknown command: NOT_SUPPORTED / NOT_FOUND before any effect +# every case: capability released at the end, no EL0 task slot left held. +# Last line: AIENOS_CK_OSH_OP: PASS|FAIL|NOT_RUN. +set -euo pipefail + +repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +cd "${repo_root}" +verdict=AIENOS_CK_OSH_OP +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_osh_op_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_osh="${AIENOS_CK_OUT_OSH:-${repo_root}/target/native-kernel-osh-op-test}" +mk() { make -s -C native/kernel CROSS="${cross}" AIENOS_COMMIT="${commit}" "$@" >/dev/null; } + +fix="native/kernel/tests/fixtures/osh" +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") +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 + +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:-900}" 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" +boot "${out_osh}/full/BOOTAA64.EFI" "${serial}" "${disk}" +release_flag + +label='QEMU \(aarch64 virt\), TEST signer, not physical' +count() { grep -cE -- "$2" "$1" || true; } +exact() { # description, regex, expected count + local n; n="$(count "${serial}" "$2")" + 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$" +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 +check "${serial}" "core line: 3 units" "^osh_core: units=3 ws_cells=11456 ws_pages=23 input_max=4096; ${label}\$" +check "${serial}" "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 +if has "${serial}" "^osh_fault:"; then fail "a shell launch did not return"; else pass "every shell launch returned"; fi +exact "no fixture trace ran in this build" "^osh_script_begin" 0 +check "${serial}" "all eight cases ran" "^osh_op_done: cases=8; ${label}\$" + +P="^osh_op_pipeline: case=" +E="^osh_op_end: case=" +# allow +exact "allow: the real effect, line 1 on the console" "^osh_op_out: hello from osh\$" 1 +exact "allow: line 2 carries \$? = the real status 0 back through the shell core" "^osh_op_out: status=0\$" 1 +exact "allow: both pipelines COMPLETED with status 0" "${P}allow n=[12] status=0 error=OK outcome=COMPLETED stop=0 crashed=0 request_digest=[0-9a-f]{64}; ${label}\$" 2 +check "${serial}" "allow: 2 console writes, no task slot held, capability released" "${E}allow rc=0 final_status=0 sink_calls=2 launches=[0-9]+ slots_held=0 cap_table_empty=1 cap_released=1; ${label}\$" +# denials +for c in deny_no_cap deny_read_only; do + check "${serial}" "${c}: refused DENIED before any effect (status 126, FAILED_NO_EFFECT)" "${P}${c} n=1 status=126 error=DENIED outcome=FAILED_NO_EFFECT stop=0 crashed=0 request_digest=[0-9a-f]{64}; ${label}\$" + check "${serial}" "${c}: no console write, capability released" "${E}${c} rc=0 final_status=126 sink_calls=0 launches=[0-9]+ slots_held=0 cap_table_empty=1 cap_released=1; ${label}\$" + check "${serial}" "${c}: a security receipt names the denial, principal and capability" "^osh_op_receipt: seq=1 op=console_write result=DENIED request_digest=[0-9a-f]{64} effect=none principal=[0-9a-f]{64} cap_domain=1 cap_index=[0-9]+ cap_generation=[0-9]+ resource_class=1 operation=1 case=${c}; ${label}\$" +done +check "${serial}" "revoked: REVOKED at the effect boundary, FAILED_NO_EFFECT" "${P}revoked n=1 status=126 error=REVOKED outcome=FAILED_NO_EFFECT stop=0 crashed=0 " +check "${serial}" "revoked: no console write, capability released" "${E}revoked rc=0 final_status=126 sink_calls=0 launches=[0-9]+ slots_held=0 cap_table_empty=1 cap_released=1; " +check "${serial}" "revoked: receipt names REVOKED" "^osh_op_receipt: seq=1 op=console_write result=REVOKED " +exact "no refused case wrote any secret marker" "^osh_op_out: .*SECRET" 0 +# interrupt +check "${serial}" "interrupt: pipeline 1 completed" "${P}interrupt n=1 status=0 error=OK outcome=COMPLETED " +check "${serial}" "interrupt: pipeline 2 INTERRUPTED, CANCELLED, list stops, status 130" "${P}interrupt n=2 status=130 error=INTERRUPTED outcome=CANCELLED stop=1 crashed=0 " +exact "interrupt: pipeline 3 never ran" "${P}interrupt n=3 " 0 +check "${serial}" "interrupt: one console write, status 130, capability released, no task slot held" "${E}interrupt rc=1 final_status=130 sink_calls=1 launches=[0-9]+ slots_held=0 cap_table_empty=1 cap_released=1; " +exact "interrupt: 'one' printed, 'two' and 'three' not" "^osh_op_out: one\$" 1 +exact "interrupt: 'two'/'three' absent" "^osh_op_out: (two|three)\$" 0 +# lost +exact "lost: the effect happened exactly once" "^osh_op_out: LOST-MARKER\$" 1 +check "${serial}" "lost: outcome open (OUTCOME_UNKNOWN, crashed)" "${P}lost n=1 status=70 error=OUTCOME_UNKNOWN outcome=OUTCOME_UNKNOWN stop=1 crashed=1 " +check "${serial}" "lost: restart reports the open intent as OUTCOME_UNKNOWN with its digest, replayed=0" "^osh_op_record: seq=1 outcome=OUTCOME_UNKNOWN request_digest=[0-9a-f]{64} replayed=0 case=lost; " +check "${serial}" "lost: restart found 1 open intent, a 2nd scan 0, no console write added, restarted adapter holds no capability" "^osh_op_restart: case=lost open_intents=1 second_scan=0 sink_calls_before=1 sink_calls_after=1 held_cap=0; " +exact "lost: still exactly one LOST-MARKER after restart (never replayed)" "^osh_op_out: LOST-MARKER\$" 1 +check "${serial}" "lost: capability released" "${E}lost rc=1 final_status=70 sink_calls=1 launches=[0-9]+ slots_held=0 cap_table_empty=1 cap_released=1; " +exact "after_restart: a new request is a new decision and runs" "^osh_op_out: fresh decision\$" 1 +# unsupported +check "${serial}" "unsupported: a pipe is NOT_SUPPORTED before any effect" "${P}unsupported n=1 status=126 error=NOT_SUPPORTED outcome=NOT_STARTED " +check "${serial}" "unsupported: a redirection is NOT_SUPPORTED" "${P}unsupported n=2 status=126 error=NOT_SUPPORTED outcome=NOT_STARTED " +check "${serial}" "unsupported: an unknown command is NOT_FOUND (127)" "${P}unsupported n=3 status=127 error=NOT_FOUND outcome=NOT_STARTED " +check "${serial}" "unsupported: no console write, no task slot held" "${E}unsupported rc=0 final_status=127 sink_calls=0 launches=[0-9]+ slots_held=0 cap_table_empty=1 cap_released=1; " +# totals +G="^osh_op_receipt: seq=[0-9]+ op=console_write result=OK request_digest=[0-9a-f]{64} effect=console_write principal=[0-9a-f]{64} cap_domain=1 cap_index=[0-9]+ cap_generation=[0-9]+ resource_class=1 operation=1" +exact "grant used: one security receipt per console write, 5 in all" "${G} case=[a-z_]+; ${label}\$" 5 +exact "grant used: allow wrote 2 lines, 2 receipts" "${G} case=allow; " 2 +exact "grant used: even the lost-after-effect case has its receipt" "${G} case=lost; " 1 +exact "grant used: no receipt for a refused case" "^osh_op_receipt: .* result=OK .* case=(deny_no_cap|deny_read_only|revoked|unsupported); " 0 +exact "the whole boot wrote exactly five console lines through the operation" "^osh_op_out: " 5 +exact "no case leaked a task slot" "^osh_op_end: .* slots_held=[1-9]" 0 +exact "every case released its capability" "^osh_op_end: .* cap_released=1; " 8 +# control: a wrong expectation must turn the check red, then the right one green +if has "${serial}" "^osh_op_out: hello from osh DOES-NOT-APPEAR\$"; then fail "control: the gate cannot go red"; else pass "control: a deliberately wrong expected console line is not found (red), the real one is (above)"; fi + +if [[ -n "${AIENOS_LOG_DIR:-}" ]]; then cp "${serial}" "${AIENOS_LOG_DIR}/qemu_ck_osh_op_serial.log"; fi +if [[ "${failed}" != 0 || -n "${AIENOS_QEMU_VERBOSE:-}" ]]; then + echo "---- serial (osh_op lines) ----"; grep -E "^(osc_|osh_|artifact|kernel|report_kind|panic|fault)" "${serial}" | head -120 || 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