diff --git a/.crumb b/.crumb index 28e4e4f2..bae94a2a 100644 --- a/.crumb +++ b/.crumb @@ -33,27 +33,27 @@ "purpose": "Directory docs. Purpose not yet described by a human." }, { - "digest": "64cc87f8507bb580e1788d335c5a76039f3e3a016552595526718448ab5aa098", - "last_commit": "6ad9190", + "digest": "68715b87f615cc47c31dad8e5d21ab63c3a8b1586c54657e86251d8248896701", + "last_commit": "e7e900c", "name": "native", "purpose": "Directory native. Purpose not yet described by a human." }, { - "digest": "9adb69cc749bc97fa48e268f0397b900da83c84191ab6a9373358e8b9ab57922", - "last_commit": "f635add", + "digest": "aa8f4f3a9c1f832da842c4ec2a84e508f28fa47d58065f86073b7b47dd1d100f", + "last_commit": "e7e900c", "name": "scripts", "purpose": "Directory scripts. Purpose not yet described by a human." } ], - "children_root": "sha256:19cc8f21ac13e49018f60836bdaf7c4c23477cf558624048754f1e83c6d88cac", - "compiled_at": "2026-10-18T12:29:38Z", + "children_root": "sha256:6f6c37b03ffdf66f069db9432d4344b0b62e875475b54ef582c7f740219fd235", + "compiled_at": "2026-10-18T15:32:31Z", "compiler": "crumb-compile/1", - "digest": "sha256:306082635f09fe7ba90bcf0ecc06b7cf4c24e5f13023479193bb80930d982081", + "digest": "sha256:92897ff20ab48ae4d606f43239928b10a61724af0f41eb62174babf0a188deff", "evidence_files": 211, "evidence_root": "sha256:3a8f56415109a697e4beb6048c85805c50c9c6c4089629057f4e8b3e76863981", "files": 3501, - "generated_at_commit": "3d2500e11fb42496dd136e3bb3bf8ee98f94dcd7", - "source_tree": "sha256:0ca10e6b509c0b5b6a0e08ee6b6e32313a45d3910fd2f11d3ac364891c715a3a" + "generated_at_commit": "e7e900c15952a4b880d278c46d6ca8af43ef181e", + "source_tree": "sha256:698e12aa1adfbf59cb900fc118687d9cb642ff563678fdd7b65c19b5912c58d7" }, "owner_lane": "", "provenance": { diff --git a/native/.crumb b/native/.crumb index dbbce44e..390c416e 100644 --- a/native/.crumb +++ b/native/.crumb @@ -50,7 +50,7 @@ "children": [ { "digest": "50aa2fbd6ca356b7703517bc7ecf439f7b6e0a6b935d0ca6ca4c6f7caf23ce34", - "last_commit": "4bd49ca", + "last_commit": "09e59a8", "name": "argus", "purpose": "Directory native/argus. Purpose not yet described by a human." }, @@ -62,62 +62,62 @@ }, { "digest": "750c519c466783ed6330a6a2c8fcb2153efdaadb9d65b38a6a85e8463d78b68d", - "last_commit": "4bd49ca", + "last_commit": "7db773a", "name": "capability", "purpose": "Directory native/capability. Purpose not yet described by a human." }, { "digest": "0a3e98a5f36f528eb7ae6e1611d466343068780b9029621286b292ec1c796950", - "last_commit": "4bd49ca", + "last_commit": "7db773a", "name": "crypto", "purpose": "Directory native/crypto. Purpose not yet described by a human." }, { "digest": "99bc55e79695290b65ae08a38e5731e3ed976d79cdb3b6c9bc21c706b1ddab22", - "last_commit": "4bd49ca", + "last_commit": "7db773a", "name": "disk", "purpose": "Directory native/disk. Purpose not yet described by a human." }, { - "digest": "7a81b1b4b47154e15b9682b72d7fa49f309454f093aeb019061b8148550920ae", - "last_commit": "3037967", + "digest": "c759d9a11f945bcf36b897e484815425c5cbe440e0059879de8c03290e0f1fdd", + "last_commit": "e7e900c", "name": "kernel", "purpose": "Directory native/kernel. Purpose not yet described by a human." }, { "digest": "a805df7e3af4b8a2ef345223523b54e7e47565204ec8f8e598f6dcaf53b07419", - "last_commit": "4bd49ca", + "last_commit": "7db773a", "name": "m5", "purpose": "Directory native/m5. Purpose not yet described by a human." }, { "digest": "ff5c88f5e9bf86e7ff836d24c048dd2d4efc94f6f19a21a0caf72ae9c402deaf", - "last_commit": "4bd49ca", + "last_commit": "7db773a", "name": "net", "purpose": "Directory native/net. Purpose not yet described by a human." }, { "digest": "135fd1edbe2388764de7dc755611b483b0c61adab858718c390b7745d141635c", - "last_commit": "4bd49ca", + "last_commit": "7db773a", "name": "sig", "purpose": "Directory native/sig. Purpose not yet described by a human." }, { "digest": "f75197d76b7daaeee8223cf25353251824cd4497400a439724a3a424e014a229", - "last_commit": "4bd49ca", + "last_commit": "e5e8f08", "name": "store", "purpose": "Directory native/store. Purpose not yet described by a human." } ], - "children_root": "sha256:cec690f1b64aaba9f5f7ea41048a25c5b3cdf4834f672e977dc7eb47d34e4be2", - "compiled_at": "2026-10-17T01:49:45Z", + "children_root": "sha256:6507fb8e867d12a7511585ec8106b43da8e96e85cdcc5749b039501c09595bac", + "compiled_at": "2026-10-18T15:32:31Z", "compiler": "crumb-compile/1", - "digest": "sha256:64cc87f8507bb580e1788d335c5a76039f3e3a016552595526718448ab5aa098", + "digest": "sha256:68715b87f615cc47c31dad8e5d21ab63c3a8b1586c54657e86251d8248896701", "evidence_files": 4, "evidence_root": "sha256:e410b845507e00568e15b51a5797af32a97e0e4b8ab4e8487bb7c98e7e0cf335", "files": 606, - "generated_at_commit": "30379678add587e388db4e11713d6bca8d159b08", - "source_tree": "sha256:1d9fe182bcaa94de3564ee02f9e8c63bddcea00fcea22feed112ffe6e01a1b78" + "generated_at_commit": "e7e900c15952a4b880d278c46d6ca8af43ef181e", + "source_tree": "sha256:ddf9527900fcf1d30ffe3e91f1fc9646886be943d54702c4233551a5cd9e0ef8" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/.crumb b/native/kernel/.crumb index 57d1b019..1fca476d 100644 --- a/native/kernel/.crumb +++ b/native/kernel/.crumb @@ -46,68 +46,68 @@ "children": [ { "digest": "8f63182b423b274a3fa6dcf0a17811343f93bd1539e33479102ffa87935da1ca", - "last_commit": "4bd49ca", + "last_commit": "2529bc0", "name": "arch", "purpose": "Directory native/kernel/arch. Purpose not yet described by a human." }, { "digest": "cd3be26829bc7f947521b1e5df144df2504ef25a3763ec0356861b7d17d5d901", - "last_commit": "4bd49ca", + "last_commit": "6ad9190", "name": "artifact", "purpose": "Directory native/kernel/artifact. Purpose not yet described by a human." }, { "digest": "c9035b8f32a9539fe8d1f93ed968b3b56dd3ba4c2630b32b6c286b1dbd19d908", - "last_commit": "4bd49ca", + "last_commit": "6ad9190", "name": "core", "purpose": "Directory native/kernel/core. Purpose not yet described by a human." }, { "digest": "ebdd66c0966fba664f36dc167836b98d26ffae97f9502b4409e9c22da687b473", - "last_commit": "4bd49ca", + "last_commit": "9404c9e", "name": "dev", "purpose": "Directory native/kernel/dev. Purpose not yet described by a human." }, { "digest": "8198bb9a0fbd634281a251b012eca8874c97e469a45eec8b5a6bf06a7e828f9a", - "last_commit": "4bd49ca", + "last_commit": "0735543", "name": "include", "purpose": "Directory native/kernel/include. Purpose not yet described by a human." }, { "digest": "8252fab960e4a3bb686f2e864b0d9a0571f43381d5006de2ff6c134c132ef092", - "last_commit": "4bd49ca", + "last_commit": "2bc7146", "name": "mm", "purpose": "Directory native/kernel/mm. Purpose not yet described by a human." }, { "digest": "2a98333d826d94a7131119aaeb5a15d8bc543baa5531fa930e6f0afc1fccb83d", - "last_commit": "4bd49ca", + "last_commit": "15c19d4", "name": "svc", "purpose": "Directory native/kernel/svc. Purpose not yet described by a human." }, { - "digest": "0f3d28a645346382567a7a279a3e02a095c8e7f298967db175944c0a58ca9c5d", - "last_commit": "3037967", + "digest": "b559f8d41e7bf02619718692bda71d86b883e8c017484343c548304119ec0f03", + "last_commit": "e7e900c", "name": "tests", "purpose": "Directory native/kernel/tests. Purpose not yet described by a human." }, { - "digest": "412f0a290f187935193ec94f1817c46dbe0edc07a5eb427e39977b65c1d00f9f", - "last_commit": "3037967", + "digest": "645804642aab8f2312c02f0f4cac2e490da4c870dcc316a4af65615c68ced0a0", + "last_commit": "e7e900c", "name": "tools", "purpose": "Hosted (Linux-built) checkers for the native kernel, run by `make -C native/kernel test`; nothin" } ], - "children_root": "sha256:658a040f493b6ff9dc4a775b2b73a0c89ded592a235231016dd8594094530e0f", - "compiled_at": "2026-10-17T01:49:45Z", + "children_root": "sha256:a5a48fcfa85f428bba39a9f8ba354d32f7e1ba443729a0922108ee19f73a8e93", + "compiled_at": "2026-10-18T15:32:31Z", "compiler": "crumb-compile/1", - "digest": "sha256:7a81b1b4b47154e15b9682b72d7fa49f309454f093aeb019061b8148550920ae", + "digest": "sha256:c759d9a11f945bcf36b897e484815425c5cbe440e0059879de8c03290e0f1fdd", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 421, - "generated_at_commit": "30379678add587e388db4e11713d6bca8d159b08", - "source_tree": "sha256:cfa9d56bd0bae125be856e13a57758e007e620d1fc9501643728e676f53eaabe" + "generated_at_commit": "e7e900c15952a4b880d278c46d6ca8af43ef181e", + "source_tree": "sha256:e760ad7c457bcfdf4deaed0dab2ce104629350e9ffe54a3d43f269fb515f8aa6" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/Makefile b/native/kernel/Makefile index 20a92ad3..ad9061a2 100644 --- a/native/kernel/Makefile +++ b/native/kernel/Makefile @@ -2242,13 +2242,19 @@ imac-diag: $(IMACDIAG_EFI) # + x86/pci_x86.c (PCI walk; AHCI via x86/ahci_x86.c and NVMe via ../disk/disk_nvme.c, both # read-only, GPT checked by dev/disk_part.c; a look at the Ethernet chip) + x86/smp_x86.S # (secondary cores started and parked) + x86/tg3_x86.c (BCM57766 Ethernet, transmit only) and -# x86/report_x86.c with ../../net/aienos_net.c (the screen sent as UDP broadcasts during the hold; -# host test scripts/ck_imac_report_test.sh, receiver tools/ck_imac_report_listen.c) +# x86/report_x86.c with ../../net/aienos_net.c (laboratory builds only, IMAC_LAB_REPORT=1: the +# allowlisted screen lines sent as unauthenticated UDP broadcasts during the hold; host test +# scripts/ck_imac_report_test.sh, receiver tools/ck_imac_report_listen.c; default 0 sends nothing) # + x86/trap.S + x86/console_x86.c (COM1 when present, GOP framebuffer), on the # arch-neutral core: fbcon, fmt, acpi, handoff_check, frames, heap. Same toolchain and PE # header as IMACDIAG. Copy to a FAT stick as EFI/BOOT/BOOTX64.EFI. # make imac-kernel -> $(OUT)/IMACKERN.EFI QEMU test: scripts/qemu_ck_imac_kernel_test.sh +# make imac-kernel IMAC_LAB_REPORT=1 laboratory diagnostic build with the network report X86K := $(KDIR)/x86 +IMAC_LAB_REPORT ?= 0 +ifneq ($(filter-out 0 1,$(IMAC_LAB_REPORT)),) +$(error IMAC_LAB_REPORT must be 0 or 1) +endif IMACKERN_DIR := $(OUT)/imackern IMACKERN_ELF := $(IMACKERN_DIR)/imackern.elf IMACKERN_EFI := $(OUT)/IMACKERN.EFI @@ -2281,7 +2287,12 @@ $(IMACKERN_DIR)/pci_x86.o: $(X86K)/pci_x86.c $(IMACKERN_HDRS) $(KDIR)/mm/frames. $(IMACKERN_DIR)/smp_x86.o: $(X86K)/smp_x86.S $(IMACKERN_DIR)/disk_nvme.o: $(NATIVE)/disk/disk_nvme.c $(NATIVE)/disk/disk_nvme.h $(NATIVE)/disk/disk.h $(IMACKERN_DIR)/tg3_x86.o: $(X86K)/tg3_x86.c $(IMACKERN_HDRS) $(KDIR)/mm/frames.h -$(IMACKERN_DIR)/report_x86.o: $(X86K)/report_x86.c $(X86K)/report_x86.h $(IMACKERN_HDRS) $(NATIVE)/net/aienos_net.h +$(IMACKERN_DIR)/report_x86.o: $(X86K)/report_x86.c $(X86K)/report_x86.h $(IMACKERN_HDRS) $(NATIVE)/net/aienos_net.h \ + $(IMACKERN_DIR)/lab_report.stamp +$(IMACKERN_DIR)/report_x86.o: IMACKERN_CFLAGS += -DCK_X86_LAB_REPORT=$(IMAC_LAB_REPORT) +$(IMACKERN_DIR)/lab_report.stamp: FORCE + @mkdir -p $(dir $@) + @echo '$(IMAC_LAB_REPORT)' | cmp -s - $@ || echo '$(IMAC_LAB_REPORT)' > $@ $(IMACKERN_DIR)/aienos_net.o: $(NATIVE)/net/aienos_net.c $(NATIVE)/net/aienos_net.h $(IMACKERN_OBJS): @mkdir -p $(dir $@) @@ -2297,6 +2308,9 @@ $(IMACKERN_ELF): $(IMACKERN_OBJS) $(BOOT)/image_x86_64.ld $(X86LD) $(X86LDFLAGS) -o $@ $(IMACKERN_OBJS) @u=$$($(X86NM) -u $@ | grep -v ' w ' || true); \ if [ -n "$$u" ]; then echo "image has undefined symbols: $$u"; rm -f $@; exit 1; fi + @f=$$($(X86NM) $@ | grep -cE ' [Tt] ck_x86_report_(frame|filter)$$' || true); \ + if [ "$$f" != "$$(( $(IMAC_LAB_REPORT) * 2 ))" ]; then \ + echo "IMAC_LAB_REPORT=$(IMAC_LAB_REPORT) but the image has $$f of the 2 report builder symbols"; rm -f $@; exit 1; fi @bad=$$($(X86READELF) -rW $@ | grep -E '^[0-9a-f]+ ' | grep -v R_X86_64_RELATIVE || true); \ if [ -n "$$bad" ]; then echo "image has non-RELATIVE relocations:"; echo "$$bad"; rm -f $@; exit 1; fi @n=$$($(X86NM) $@ | grep -c ' t isr_common$$' || true); s=$$($(X86NM) $@ | grep ' T ck_x86_isr_stubs$$' | cut -c1-16); \ diff --git a/native/kernel/README.md b/native/kernel/README.md index 9b30cc2f..f0dfa55a 100644 --- a/native/kernel/README.md +++ b/native/kernel/README.md @@ -173,13 +173,18 @@ driver (`x86/tg3_x86.c`: core reset, bootcode handshake, rings in one DMA block below 4 GiB, PHY autonegotiation; it never receives and the MAC address is never printed). The last line before the hold is a one-line `summary:`. It prints `kernel: alive`, holds the screen 60 s and powers off through ACPI S5. -During the hold `x86/report_x86.c` sends the RAM copy of the console (first -16 KiB) every 2 s while the link is up, as UDP broadcast from 0.0.0.0 to +In a laboratory diagnostic build only (`make imac-kernel IMAC_LAB_REPORT=1`; +the default image sends nothing and the link step checks it holds no report +builder) `x86/report_x86.c` sends, during the hold, the lines of the console's +RAM copy (first 16 KiB) that start with an allowlisted kernel tag (any other +line, such as chat, memory or keys, is dropped) every 2 s while the link is +up, as unauthenticated UDP broadcast from 0.0.0.0 to 255.255.255.255 port 47031 (TTL 1), in 1 KiB parts that each start with `AIENOS-IMAC-REPORT v=1 run= part=/ bytes=`. `tools/ck_imac_report_listen.c` (`make -C native/kernel imac-report-listen`, run as `ck_imac_report_listen 47031 OUTDIR SECONDS`) rebuilds each run into -`OUTDIR/imac-.txt`; `scripts/ck_imac_report_test.sh` checks frames and +`OUTDIR/imac-.unauthenticated.txt` (never evidence, a receipt or a +command: anyone on the LAN can send that format); `scripts/ck_imac_report_test.sh` checks the filter, frames and reassembly on the host, so a wired iMac no longer needs a photo of its screen. Output: the GOP framebuffer (`core/fbcon.c`, lines from before ExitBootServices replayed onto it) and COM1 when a 16550 answers there (QEMU; the iMac has none). Shared, unchanged: diff --git a/native/kernel/tests/.crumb b/native/kernel/tests/.crumb index fbe93953..a6e10e9b 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-17T01:49:45Z", + "compiled_at": "2026-10-18T15:32:31Z", "compiler": "crumb-compile/1", - "digest": "sha256:0f3d28a645346382567a7a279a3e02a095c8e7f298967db175944c0a58ca9c5d", + "digest": "sha256:b559f8d41e7bf02619718692bda71d86b883e8c017484343c548304119ec0f03", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 189, - "generated_at_commit": "30379678add587e388db4e11713d6bca8d159b08", - "source_tree": "sha256:78682dfae8385bcec29c757bca316fadddcefbfc3c85a3f021a1aa8b948c623a" + "generated_at_commit": "e7e900c15952a4b880d278c46d6ca8af43ef181e", + "source_tree": "sha256:e2ac7ac787d8fd6d865a773bebc93c31d0497c702360d945aabbd6c534f29677" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/tests/test_imac_report.c b/native/kernel/tests/test_imac_report.c index 27cc6473..4619116a 100644 --- a/native/kernel/tests/test_imac_report.c +++ b/native/kernel/tests/test_imac_report.c @@ -1,5 +1,6 @@ /* test_imac_report.c -- host test for the iMac kernel's network report - * frames (x86/report_x86.c, built with -DCK_X86_REPORT_HOST). + * frames and allowlist filter (x86/report_x86.c, built with + * -DCK_X86_REPORT_HOST). * * test_imac_report unit checks on the frames * test_imac_report send PORT LOGFILE also writes a sample report to @@ -47,8 +48,52 @@ static const uint8_t *unwrap(const uint8_t *f, size_t n, size_t *plen) return pl; } +/* Filter checks: allowlisted kernel lines pass unchanged, everything else + * (sentinel chat, key and memory values, control bytes, overlong or + * unfinished lines, a tag that only starts like an allowed one) is dropped. */ +static void filter_checks(void) +{ + static const char screen[] = "cpu: GenuineIntel\n" + "chat: SENTINEL-CHAT-7f3a hello\n" + "pci: nvme 02:00.0 id=144d:a806\n" + "key=SENTINEL-KEY-91c2\n" + "memory_dump: SENTINEL-MEM-44e0\n" + "netx: SENTINEL-NETX\n" + " kernel: SENTINEL-INDENT\n" + "kernel: alive\x1b[2J SENTINEL-CTRL\n" + "\n" + "summary: cores=4/4 writes=none\n" + "AIENOS-IMAC-KERNEL-0 DONE\n" + "power: SENTINEL-UNFINISHED"; + static const char want[] = "cpu: GenuineIntel\n" + "pci: nvme 02:00.0 id=144d:a806\n" + "summary: cores=4/4 writes=none\n" + "AIENOS-IMAC-KERNEL-0 DONE\n"; + char out[sizeof screen]; + unsigned dropped = 0; + size_t n = ck_x86_report_filter(screen, sizeof screen - 1, out, sizeof out, &dropped); + CHECK(n == sizeof want - 1 && memcmp(out, want, n) == 0); + CHECK(dropped == 8); + for (size_t i = 0; i + 8 <= n; i++) + CHECK(memcmp(out + i, "SENTINEL", 8) != 0); + + char longl[CK_X86_REPORT_LINE_MAX + 2]; + memset(longl, 'x', sizeof longl); + memcpy(longl, "kernel: ", 8); + longl[CK_X86_REPORT_LINE_MAX] = '\n'; /* exactly LINE_MAX bytes: kept */ + CHECK(ck_x86_report_filter(longl, CK_X86_REPORT_LINE_MAX + 1, out, sizeof out, &dropped) == + CK_X86_REPORT_LINE_MAX + 1 && + dropped == 0); + longl[CK_X86_REPORT_LINE_MAX] = 'x'; + longl[CK_X86_REPORT_LINE_MAX + 1] = '\n'; /* one byte over: dropped */ + CHECK(ck_x86_report_filter(longl, sizeof longl, out, sizeof out, &dropped) == 0 && dropped == 1); + CHECK(ck_x86_report_filter(want, sizeof want - 1, out, 10, &dropped) == 0 && dropped == 4); + CHECK(ck_x86_report_filter(0, 5, out, sizeof out, &dropped) == 0 && dropped == 0); +} + int main(int argc, char **argv) { + filter_checks(); for (size_t i = 0; i < sizeof log_text; i++) log_text[i] = (i % 61 == 60) ? '\n' : (char)('A' + i % 26); size_t len = sizeof log_text; diff --git a/native/kernel/tools/.crumb b/native/kernel/tools/.crumb index 434135ec..3fec79bb 100644 --- a/native/kernel/tools/.crumb +++ b/native/kernel/tools/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-17T01:49:45Z", + "compiled_at": "2026-10-18T15:32:31Z", "compiler": "crumb-compile/1", - "digest": "sha256:412f0a290f187935193ec94f1817c46dbe0edc07a5eb427e39977b65c1d00f9f", + "digest": "sha256:645804642aab8f2312c02f0f4cac2e490da4c870dcc316a4af65615c68ced0a0", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 24, - "generated_at_commit": "30379678add587e388db4e11713d6bca8d159b08", - "source_tree": "sha256:811d4174e2479ef3a1cf5ed3f0ae69346da056fc12745e9f1b33afbe0b6f6dc5" + "generated_at_commit": "e7e900c15952a4b880d278c46d6ca8af43ef181e", + "source_tree": "sha256:a97b465d7d3b2e1600d971df04211e7077c6cb00a49a7d22fd0497c3f94c8750" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/tools/ck_imac_report_listen.c b/native/kernel/tools/ck_imac_report_listen.c index 7cf699e9..12e02591 100644 --- a/native/kernel/tools/ck_imac_report_listen.c +++ b/native/kernel/tools/ck_imac_report_listen.c @@ -8,10 +8,16 @@ * "AIENOS-IMAC-REPORT v=1 run=<16 hex> part=/ bytes=\n" + chunk * (the kernel broadcasts them from 0.0.0.0 to 255.255.255.255). Part i of n * carries bytes [i * CHUNK, ...) of a report of bytes. When every part - * of a run is in, the report is written once to OUTDIR/imac-.txt and a + * of a run is in, the report is written once to + * OUTDIR/imac-.unauthenticated.txt and a * line "complete run=... bytes=... file=..." goes to OUTDIR/listen.log. Repeats * of a finished run are counted, not rewritten. Anything else is logged as - * ignored. Exit 0 at the deadline, 2 usage, 3 socket/bind error. */ + * ignored. Exit 0 at the deadline, 2 usage, 3 socket/bind error. + * + * The reports are unauthenticated laboratory diagnostics: anyone on the LAN + * can send a datagram in this format and the run id is not a signature. A + * saved report is never evidence, a receipt or a command, and the file name + * says so. */ #define _POSIX_C_SOURCE 200809L #include #include @@ -73,7 +79,7 @@ static FILE *open_private(const char *path, int flags, const char *mode) static void finish_run(FILE *lg, const char *dir, struct run *r) { char path[4096]; - snprintf(path, sizeof path, "%s/imac-%s.txt", dir, r->id); + snprintf(path, sizeof path, "%s/imac-%s.unauthenticated.txt", dir, r->id); FILE *f = open_private(path, O_TRUNC, "w"); if (!f || fwrite(r->data, 1, r->total, f) != r->total || fclose(f) != 0) { fprintf(lg, "write failed run=%s file=%s errno=%d (%s)\n", r->id, path, errno, strerror(errno)); @@ -116,7 +122,7 @@ int main(int argc, char **argv) fclose(lg); return 3; } - fprintf(lg, "ready port=%ld\n", port); + fprintf(lg, "ready port=%ld (unauthenticated lab reports: never evidence, never a command)\n", port); double deadline = now_s() + (double)secs; for (;;) { double left = deadline - now_s(); diff --git a/native/kernel/x86/report_x86.c b/native/kernel/x86/report_x86.c index cbf9c993..29983257 100644 --- a/native/kernel/x86/report_x86.c +++ b/native/kernel/x86/report_x86.c @@ -1,8 +1,13 @@ /* report_x86.c -- sends the iMac kernel's report over Ethernet, so the - * owner no longer has to photograph the screen. + * owner no longer has to photograph the screen. Laboratory diagnostic builds + * only: without IMAC_LAB_REPORT=1 (CK_X86_LAB_REPORT) the hold just waits, + * no frame is built and the image does not contain the frame builder (the + * Makefile checks the symbol). The resident ALLEN service never links it. * - * The report is the console's RAM copy (console_x86.c: everything printed, - * the first 16 KiB). It is cut into parts of CK_X86_REPORT_CHUNK bytes; each + * The report is not the raw console: ck_x86_report_filter keeps only the + * complete lines of the console's RAM copy (console_x86.c, the first 16 KiB) + * that start with a tag from `allowed` below, so a line printed by anything + * else (chat, memory, keys, tokens) cannot be sent. It is cut into parts of CK_X86_REPORT_CHUNK bytes; each * part is one UDP datagram from 0.0.0.0:PORT to 255.255.255.255:PORT in an * Ethernet broadcast frame (no address to configure, no ARP, nothing to * answer), with a one-line header the receiver checks: @@ -11,8 +16,12 @@ * screen hold the whole report is sent again every 2 s while the link is up, * so a receiver that missed a datagram gets it on the next round. * - * ck_x86_report_frame is a pure function of its arguments (no device, no - * clock) and is host-tested by scripts/ck_imac_report_test.sh. */ + * The report is unauthenticated: the run id is not a signature, anyone on the + * LAN can send or read these datagrams, and TTL 1 limits routing, not who + * sees them. A received report is never evidence and never a command. + * + * ck_x86_report_filter and ck_x86_report_frame are pure functions of their + * arguments (no device, no clock), host-tested by scripts/ck_imac_report_test.sh. */ #ifdef CK_X86_REPORT_HOST #include #else @@ -22,6 +31,65 @@ #include "aienos_net.h" #include "report_x86.h" +#ifndef CK_X86_LAB_REPORT +#define CK_X86_LAB_REPORT 0 +#endif + +#if defined(CK_X86_REPORT_HOST) || CK_X86_LAB_REPORT +/* Line tags the iMac kernel prints (kmain_x86.c, pci_x86.c, ahci_x86.c, + * tg3_x86.c, ../disk/disk_nvme.c and the shared core). A new tag is sent + * only once it is added here. */ +static const char *const allowed[] = { + "AIENOS-IMAC-KERNEL-", "acpi_rsdp:", "ahci:", "ahci_disk:", "ahci_gpt:", "ahci_port:", "ahci_read:", + "apic:", "cpu:", "descriptors:", "exit_boot_services:", "firmware_cpl:", "firmware_vendor:", + "guard_page:", "handoff:", "image:", "kernel:", "kernel_impl:", "madt:", "memory:", "net:", "net_tg3:", + "note:", "nvme:", "nvme_disk:", "nvme_gpt:", "nvme_read:", "paging:", "panic:", "pci:", "power:", + "report:", "report_kind:", "screen:", "smp:", "stack:", "storage:", "summary:", "timebase:", + "timer_irq:", "timer_stats:", +}; + +static int line_allowed(const char *l, size_t n) +{ + if (n > CK_X86_REPORT_LINE_MAX) + return 0; + for (size_t i = 0; i < n; i++) + if (l[i] < 0x20 || l[i] > 0x7e) + return 0; + for (size_t t = 0; t < sizeof allowed / sizeof allowed[0]; t++) { + size_t k = strlen(allowed[t]); + if (n >= k && !memcmp(l, allowed[t], k)) + return 1; + } + return 0; +} + +size_t ck_x86_report_filter(const char *log, size_t len, char *out, size_t cap, unsigned *dropped) +{ + size_t w = 0; + unsigned d = 0; + if (!log || !out) + len = 0; + for (size_t i = 0; i < len;) { + size_t n = 0; + while (i + n < len && log[i + n] != '\n') + n++; + if (i + n == len) { /* an unfinished last line is never sent */ + d++; + break; + } + if (line_allowed(log + i, n) && w + n + 1 <= cap) { + memcpy(out + w, log + i, n + 1); + w += n + 1; + } else { + d++; + } + i += n + 1; + } + if (dropped) + *dropped = d; + return w; +} + #define REPORT_HDR "AIENOS-IMAC-REPORT v=1 " static void hex16(char *out, uint64_t v) @@ -98,13 +166,26 @@ size_t ck_x86_report_frame(const uint8_t mac[6], uint64_t run, const char *log, return 0; return ew; } +#endif #ifndef CK_X86_REPORT_HOST +#if !CK_X86_LAB_REPORT +/* Default image: no network report. Holds for `seconds` and returns 0. */ +unsigned ck_x86_report_hold(uint64_t tsc_hz, unsigned seconds) +{ + uint64_t end = ck_rdtsc() + (uint64_t)seconds * tsc_hz; + ck_puts("report: network report off (laboratory builds only: make imac-kernel IMAC_LAB_REPORT=1)\n"); + while (ck_rdtsc() < end) + ck_pause(); + return 0; +} +#else /* Holds for `seconds`, sending the report every 2 s while the link is up. * Without a working network it only waits. Returns the rounds sent. */ unsigned ck_x86_report_hold(uint64_t tsc_hz, unsigned seconds) { static uint8_t frame[1600]; + static char kept[CK_X86_REPORT_MAX]; static int busy; /* a fault while sending ends up here again: only wait */ uint64_t t0 = ck_rdtsc(), end = t0 + (uint64_t)seconds * tsc_hz, next = t0; if (busy++ || !ck_x86_tg3_ready()) { @@ -112,10 +193,14 @@ unsigned ck_x86_report_hold(uint64_t tsc_hz, unsigned seconds) ck_pause(); return 0; } - ck_printf("report: sending this screen to UDP port %u (broadcast) every 2 s during the hold\n", + ck_printf("report: LAB BUILD sending allowlisted lines of this screen to UDP port %u (broadcast, " + "unauthenticated) every 2 s during the hold\n", (unsigned)CK_X86_REPORT_PORT); - size_t len; - const char *log = ck_x86_console_log(&len); + size_t raw; + unsigned dropped; + const char *screen = ck_x86_console_log(&raw); + size_t len = ck_x86_report_filter(screen, raw, kept, sizeof kept, &dropped); + const char *log = kept; unsigned parts = ck_x86_report_parts(len), rounds = 0, failed = 0; uint8_t mac[6]; ck_x86_tg3_mac(mac); @@ -138,7 +223,9 @@ unsigned ck_x86_report_hold(uint64_t tsc_hz, unsigned seconds) rounds++; } /* Printed after the snapshot, so only the screen shows it. */ - ck_printf("report: rounds=%u parts=%u bytes=%u send_failures=%u\n", rounds, parts, (unsigned)len, failed); + ck_printf("report: rounds=%u parts=%u bytes=%u lines_dropped=%u send_failures=%u\n", rounds, parts, + (unsigned)len, dropped, failed); return rounds; } #endif +#endif diff --git a/native/kernel/x86/report_x86.h b/native/kernel/x86/report_x86.h index 72b67577..1a90be85 100644 --- a/native/kernel/x86/report_x86.h +++ b/native/kernel/x86/report_x86.h @@ -1,6 +1,10 @@ /* report_x86.h -- the iMac kernel's network report (report_x86.c): the - * console's RAM copy cut into UDP broadcast datagrams. No machine access in - * here, so the frame builder is also compiled and tested on the host. */ + * allowlisted lines of the console's RAM copy cut into UDP broadcast + * datagrams. Laboratory diagnostic builds only (make imac-kernel + * IMAC_LAB_REPORT=1); the default image sends nothing and does not contain + * the frame builder. Reports are unauthenticated: never a receipt, never a + * command. No machine access in here, so the filter and the frame builder are + * also compiled and tested on the host. */ #ifndef AIENOS_CK_X86_REPORT_H #define AIENOS_CK_X86_REPORT_H #include @@ -9,6 +13,13 @@ #define CK_X86_REPORT_PORT 47031u /* UDP, source and destination */ #define CK_X86_REPORT_CHUNK 1024u /* report bytes per datagram */ #define CK_X86_REPORT_MAX 16384u /* the console's RAM copy */ +#define CK_X86_REPORT_LINE_MAX 200u /* longer lines are never sent */ + +/* Copies into `out` only the complete lines of `log` that start with an + * allowlisted kernel tag (report_x86.c), are at most LINE_MAX bytes and hold + * printable ASCII only; every other line is dropped and counted in *dropped. + * Bytes written (never more than cap). */ +size_t ck_x86_report_filter(const char *log, size_t len, char *out, size_t cap, unsigned *dropped); /* Datagrams needed for a report of len bytes; 0 when len is 0 or too big. */ unsigned ck_x86_report_parts(size_t len); diff --git a/native/kernel/x86/x86.h b/native/kernel/x86/x86.h index d2e2f7f5..30c43722 100644 --- a/native/kernel/x86/x86.h +++ b/native/kernel/x86/x86.h @@ -111,8 +111,9 @@ int ck_x86_tg3_link(void); void ck_x86_tg3_mac(uint8_t mac[6]); int ck_x86_tg3_send(const uint8_t *frame, size_t len); int ck_x86_tg3_drain(unsigned ms); -/* report_x86.c: holds `seconds`, sending the console's RAM copy over the - * network every 2 s while the link is up; returns the rounds sent. */ +/* report_x86.c: holds `seconds`; in a laboratory build (IMAC_LAB_REPORT=1) + * also sends the allowlisted console lines over the network every 2 s while + * the link is up. Returns the rounds sent (always 0 in the default image). */ unsigned ck_x86_report_hold(uint64_t tsc_hz, unsigned seconds); /* smp_x86.S: the secondary-core trampoline, copied below 1 MiB and patched. */ diff --git a/scripts/.crumb b/scripts/.crumb index 2bac4872..86955c6d 100644 --- a/scripts/.crumb +++ b/scripts/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-17T01:30:44Z", + "compiled_at": "2026-10-18T15:32:31Z", "compiler": "crumb-compile/1", - "digest": "sha256:9adb69cc749bc97fa48e268f0397b900da83c84191ab6a9373358e8b9ab57922", + "digest": "sha256:aa8f4f3a9c1f832da842c4ec2a84e508f28fa47d58065f86073b7b47dd1d100f", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 119, - "generated_at_commit": "44cf2dd5925747aebf105136d31c8db58d8851a4", - "source_tree": "sha256:8ae58db519604c153d7140c6898139a24d1664716d187229aa125e147d370af1" + "generated_at_commit": "e7e900c15952a4b880d278c46d6ca8af43ef181e", + "source_tree": "sha256:34a1b31d9c0cc2c59c496bf16e76252a7ef087cc48042fd99636f12f66b250af" }, "owner_lane": "", "provenance": { diff --git a/scripts/ck_imac_report_test.sh b/scripts/ck_imac_report_test.sh index 03aa0b17..739b6030 100755 --- a/scripts/ck_imac_report_test.sh +++ b/scripts/ck_imac_report_test.sh @@ -1,7 +1,8 @@ #!/bin/sh # ck_imac_report_test.sh -- host test of the iMac kernel's network report: # the frames x86/report_x86.c builds (Ethernet broadcast, IPv4, UDP with a -# checksum, part headers) and the receiver tools/ck_imac_report_listen.c, +# checksum, part headers), the allowlist filter (sentinel chat/key/memory +# lines never reach a frame) and the receiver tools/ck_imac_report_listen.c, # which must rebuild the report byte for byte from parts sent out of order # and repeated. Hosted only; the BCM57766 itself cannot be emulated. # Ends with "AIENOS_IMAC_REPORT: PASS" or "AIENOS_IMAC_REPORT: FAIL ". @@ -33,7 +34,7 @@ until grep -q "^complete run=0123456789abcdef " "$W/out/listen.log"; do i=$((i + 1)); [ $i -gt 50 ] && fail "report not completed: $(cat "$W/out/listen.log")" sleep 0.1 done -cmp -s "$W/sent.txt" "$W/out/imac-0123456789abcdef.txt" || fail "rebuilt report differs" +cmp -s "$W/sent.txt" "$W/out/imac-0123456789abcdef.unauthenticated.txt" || fail "rebuilt report differs" [ "$(grep -c '^complete ' "$W/out/listen.log")" = 1 ] || fail "report written more than once" grep -q '^ignored' "$W/out/listen.log" && fail "listener ignored a valid part" echo "AIENOS_IMAC_REPORT: PASS"