diff --git a/.crumb b/.crumb index 6936aa77..9a36c8c4 100644 --- a/.crumb +++ b/.crumb @@ -33,14 +33,14 @@ "purpose": "Directory docs. Purpose not yet described by a human." }, { - "digest": "2f0e9c94164c2bd5a636599a0ebd6ad30126554588585866c9eeea3d4541d2e6", - "last_commit": "1cdddde4", + "digest": "d00d952f7f65b7021eadacc75d8a89f2fb7c217364191a47d775e0baa4f77bc4", + "last_commit": "b079990e", "name": "native", "purpose": "Directory native. Purpose not yet described by a human." }, { - "digest": "e0dc411d63c301b7e021989ec99530f4013bb626194f394552d9c325ac693e42", - "last_commit": "544e12b3", + "digest": "e8aeac2d60e55081ae3c39f89c4946cd8f9f6994f97883281f41fcf1a3555c68", + "last_commit": "b079990e", "name": "scripts", "purpose": "Directory scripts. Purpose not yet described by a human." }, @@ -51,15 +51,15 @@ "purpose": "First-party host artifact preparation tools" } ], - "children_root": "sha256:fd3fed97c87bd83a14ba05bf5425bac5dc5608e52a6cf6fbcb858586ffed5dc6", - "compiled_at": "2026-11-06T01:29:55Z", + "children_root": "sha256:baf3ce29fd4257473f8e28326c4fb1142e98ed64f4eb94f5d29deff43c017124", + "compiled_at": "2026-11-06T01:37:45Z", "compiler": "crumb-compile/1", - "digest": "sha256:f41c738a7d0057863398482d053be3aa396fda67a3340b2bb36843b9a72e92d3", + "digest": "sha256:d5891c77ccb010b261c2fe7f7019a3faa5a0afd4b44f381aa2544089f0337c8b", "evidence_files": 274, "evidence_root": "sha256:af014a4ed8f6fe759fc5809807fb47578d3410811b522d9f65d749382b029802", "files": 3777, - "generated_at_commit": "1cdddde4612e29a21bd975e2388bbb1684fffbba", - "source_tree": "sha256:47fdf7c4fba73b65bfbdf2aa8e9f6b6ff00dabda13006b97122328e79eb5fc18" + "generated_at_commit": "b079990e34b1ac0ce69894b065d83e23bae56676", + "source_tree": "sha256:385f607a3faaffd0b6da010ec148bc173ac3e33bc8acdb7a7f38d3b8783e7c76" }, "owner_lane": "", "provenance": { diff --git a/native/.crumb b/native/.crumb index c309e541..cbfccbaa 100644 --- a/native/.crumb +++ b/native/.crumb @@ -79,8 +79,8 @@ "purpose": "Directory native/disk. Purpose not yet described by a human." }, { - "digest": "1d3aa1055d34f79662066b46c6c929ff6fd84acfea6b16d5c871da883c891595", - "last_commit": "1cdddde4", + "digest": "b4bbedb50095112fdc0e833f441e9da1423ea3f003c086dd9a478d598530ae68", + "last_commit": "b079990e", "name": "kernel", "purpose": "Directory native/kernel. Purpose not yet described by a human." }, @@ -115,15 +115,15 @@ "purpose": "Directory native/store. Purpose not yet described by a human." } ], - "children_root": "sha256:82f960a3bf830bfa1028b362165d08fb2fc2b577dd2c1bee7a2e2982cd28b211", - "compiled_at": "2026-11-06T01:29:55Z", + "children_root": "sha256:b0ef7e80795c3cc305298c8ee420e2838e5939075185a91f78875871a715645f", + "compiled_at": "2026-11-06T01:37:45Z", "compiler": "crumb-compile/1", - "digest": "sha256:2f0e9c94164c2bd5a636599a0ebd6ad30126554588585866c9eeea3d4541d2e6", + "digest": "sha256:d00d952f7f65b7021eadacc75d8a89f2fb7c217364191a47d775e0baa4f77bc4", "evidence_files": 24, "evidence_root": "sha256:ecc7ccf2e924c221a5bac1d91e23b13d8f3c8d78c2a893a882ed7ca5e88d855d", "files": 777, - "generated_at_commit": "1cdddde4612e29a21bd975e2388bbb1684fffbba", - "source_tree": "sha256:0e14167046ef17a0ea5067c1151b0a7308d2709fb2f4bd4f377aa1965e5f1f2a" + "generated_at_commit": "b079990e34b1ac0ce69894b065d83e23bae56676", + "source_tree": "sha256:90c4769a3bb9c9eb02121fb3e89957fd99f1aaa855bec80833f75c542563125f" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/.crumb b/native/kernel/.crumb index 134af0ec..b4dc66cb 100644 --- a/native/kernel/.crumb +++ b/native/kernel/.crumb @@ -64,13 +64,13 @@ }, { "digest": "d7f5e8dd68e101384b6c1c3513ee06d473f840addb7e4bcd90c294124036d3ad", - "last_commit": "1cdddde4", + "last_commit": "a57e101d", "name": "dev", "purpose": "Directory native/kernel/dev. Purpose not yet described by a human." }, { "digest": "c03a8c9d5c47b3077af1859020a39eb35c7790164dc869d86fcf8d46abc83522", - "last_commit": "1cdddde4", + "last_commit": "a57e101d", "name": "include", "purpose": "Directory native/kernel/include. Purpose not yet described by a human." }, @@ -82,7 +82,7 @@ }, { "digest": "a8b2e2fd088d3b5986cad907f73edc93447deffb9d3343575c973c3dd767aab1", - "last_commit": "1cdddde4", + "last_commit": "a57e101d", "name": "svc", "purpose": "Directory native/kernel/svc. Purpose not yet described by a human." }, @@ -100,14 +100,14 @@ } ], "children_root": "sha256:a341474d105d0feef8eefadfbec2cd6412c5ac3002d8abf436559f6e0de2c3cf", - "compiled_at": "2026-11-06T01:29:55Z", + "compiled_at": "2026-11-06T01:37:45Z", "compiler": "crumb-compile/1", - "digest": "sha256:1d3aa1055d34f79662066b46c6c929ff6fd84acfea6b16d5c871da883c891595", + "digest": "sha256:b4bbedb50095112fdc0e833f441e9da1423ea3f003c086dd9a478d598530ae68", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 521, - "generated_at_commit": "1cdddde4612e29a21bd975e2388bbb1684fffbba", - "source_tree": "sha256:bfa3a2b9695e87b6f0fa730160ff6053f284e7a353ac3edca6ebd49ef8cc9e19" + "generated_at_commit": "b079990e34b1ac0ce69894b065d83e23bae56676", + "source_tree": "sha256:ed78d88879c472f6029badf396ae2d4b9cd2b344bf8b8174190bca214224fb5b" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/Makefile b/native/kernel/Makefile index 503ade1a..607a661f 100644 --- a/native/kernel/Makefile +++ b/native/kernel/Makefile @@ -2759,10 +2759,11 @@ $(IMACKERN_EFI): $(IMACKERN_ELF) @[ "$$(od -An -tx1 -j68 -N2 $@ | tr -d ' ')" = "6486" ] || { echo "PE Machine is not x86_64 (0x8664)"; rm -f $@; exit 1; } @echo "built $@ (commit $(AIENOS_COMMIT))" imac-kernel: $(IMACKERN_EFI) -# W^X negative controls (#409), TEST-ONLY, QEMU only, never deployed: IMACKERN_WX_MUTANT=no_nx drops every -# NX bit, =text_writable leaves the kernel's code writable. The kernel's W^X probes must then panic -# (scripts/qemu_ck_imac_kernel_test.sh builds both into their own OUT). The stamp rebuilds kmain_x86.o -# whenever the setting changes, so a mutant object never lingers in a default build. +# W^X negative controls (#409, #484), TEST-ONLY, QEMU only, never deployed: IMACKERN_WX_MUTANT=no_nx drops +# every NX bit, =text_writable leaves the kernel's code writable, =ap_no_wp starts the secondary cores +# without CR0.WP. The kernel's W^X probes (or, for ap_no_wp, the wx_audit core count) must then panic +# (scripts/qemu_ck_imac_kernel_test.sh builds each into its own OUT). The stamp rebuilds kmain_x86.o and +# smp_x86.o whenever the setting changes, so a mutant object never lingers in a default build. IMACKERN_WX_MUTANT ?= ifeq ($(strip $(IMACKERN_WX_MUTANT)),) IMACKERN_WX_FLAGS := @@ -2770,11 +2771,13 @@ else ifeq ($(strip $(IMACKERN_WX_MUTANT)),no_nx) IMACKERN_WX_FLAGS := -DCK_X86_WX_MUTANT_NO_NX=1 else ifeq ($(strip $(IMACKERN_WX_MUTANT)),text_writable) IMACKERN_WX_FLAGS := -DCK_X86_WX_MUTANT_TEXT_RW=1 +else ifeq ($(strip $(IMACKERN_WX_MUTANT)),ap_no_wp) +IMACKERN_WX_FLAGS := -DCK_X86_WX_MUTANT_AP_NO_WP=1 else -$(error IMACKERN_WX_MUTANT must be empty, no_nx or text_writable) +$(error IMACKERN_WX_MUTANT must be empty, no_nx, text_writable or ap_no_wp) endif -$(IMACKERN_DIR)/kmain_x86.o: IMACKERN_CFLAGS += $(IMACKERN_WX_FLAGS) -$(IMACKERN_DIR)/kmain_x86.o: $(IMACKERN_DIR)/wx_mutant.stamp +$(IMACKERN_DIR)/kmain_x86.o $(IMACKERN_DIR)/smp_x86.o: IMACKERN_CFLAGS += $(IMACKERN_WX_FLAGS) +$(IMACKERN_DIR)/kmain_x86.o $(IMACKERN_DIR)/smp_x86.o: $(IMACKERN_DIR)/wx_mutant.stamp $(IMACKERN_DIR)/wx_mutant.stamp: FORCE @mkdir -p $(dir $@) @echo '$(strip $(IMACKERN_WX_MUTANT))' | cmp -s - $@ || echo '$(strip $(IMACKERN_WX_MUTANT))' > $@ diff --git a/native/kernel/x86/kmain_x86.c b/native/kernel/x86/kmain_x86.c index bebb2551..26e05e5b 100644 --- a/native/kernel/x86/kmain_x86.c +++ b/native/kernel/x86/kmain_x86.c @@ -85,7 +85,8 @@ /* W^X negative controls (make IMACKERN_WX_MUTANT=..., QEMU only, never * deployed): no_nx drops every NX bit, text_writable leaves the code - * writable. The W^X probes below must then fail. */ + * writable, ap_no_wp starts the secondary cores without CR0.WP (smp_x86.S). + * The W^X probes or the wx_audit core count below must then fail. */ #define PTE_XD (1ull << 63) /* the hardware execute-disable bit */ #ifdef CK_X86_WX_MUTANT_NO_NX #define PTE_NX 0ull @@ -1590,7 +1591,7 @@ void ck_x86_kernel_entry(struct ck_handoff *h) hand = h; tables_load(); ck_puts("\nreport_kind: kernel\n"); -#if defined(CK_X86_WX_MUTANT_NO_NX) || defined(CK_X86_WX_MUTANT_TEXT_RW) +#if defined(CK_X86_WX_MUTANT_NO_NX) || defined(CK_X86_WX_MUTANT_TEXT_RW) || defined(CK_X86_WX_MUTANT_AP_NO_WP) ck_puts("wx: TEST-ONLY W^X mutant build, page permissions deliberately broken, never deploy\n"); #endif ck_printf("exit_boot_services: ok attempts=%u\n", h->exit_attempts); diff --git a/native/kernel/x86/smp_x86.S b/native/kernel/x86/smp_x86.S index 59b6e186..cb1ae7b2 100644 --- a/native/kernel/x86/smp_x86.S +++ b/native/kernel/x86/smp_x86.S @@ -49,7 +49,11 @@ tramp_pm32: or $0x900, %eax /* LME + NXE: the kernel's tables carry NX bits */ wrmsr mov %cr0, %eax +#ifdef CK_X86_WX_MUTANT_AP_NO_WP + or $0x80000000, %eax /* TEST-ONLY mutant (#484): PG without WP on the AP */ +#else or $0x80010000, %eax /* PG + WP: read-only pages bind this core too */ +#endif mov %eax, %cr0 ljmpl *(ck_x86_tramp_far64 - ck_x86_tramp_start)(%ebx) diff --git a/scripts/.crumb b/scripts/.crumb index 0f443038..aefc6da8 100644 --- a/scripts/.crumb +++ b/scripts/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-11-04T20:56:36Z", + "compiled_at": "2026-11-06T01:37:45Z", "compiler": "crumb-compile/1", - "digest": "sha256:e0dc411d63c301b7e021989ec99530f4013bb626194f394552d9c325ac693e42", + "digest": "sha256:e8aeac2d60e55081ae3c39f89c4946cd8f9f6994f97883281f41fcf1a3555c68", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 140, - "generated_at_commit": "9680b207508e0e10eb479df3eca4b214681f119a", - "source_tree": "sha256:bf545da2ac761e76e90c2532b9d6c828b4f84e4212dbb562b080b288825d9de1" + "generated_at_commit": "b079990e34b1ac0ce69894b065d83e23bae56676", + "source_tree": "sha256:41348c109b6e0a62e5ee4f9b85adb2f4e5df6f5e89af2c80a89486858ced2916" }, "owner_lane": "", "provenance": { diff --git a/scripts/qemu_ck_imac_kernel_test.sh b/scripts/qemu_ck_imac_kernel_test.sh index 59280fcf..2cb5e4d8 100755 --- a/scripts/qemu_ck_imac_kernel_test.sh +++ b/scripts/qemu_ck_imac_kernel_test.sh @@ -31,8 +31,9 @@ # ACPI S5 by itself. W^X (#409): each run must show writes to code and read-only # data and execution from heap and stack faulting with the right #PF error code, # and an audit of every page table leaf (only the code executable, nothing -# writable and executable, NXE and WP on every core). Two TEST-ONLY mutant builds -# (IMACKERN_WX_MUTANT=no_nx, =text_writable) must make those probes panic. +# writable and executable, NXE and WP on every core). Three TEST-ONLY mutant builds +# (IMACKERN_WX_MUTANT=no_nx, =text_writable at -smp 1; =ap_no_wp, secondary cores +# without CR0.WP, at -smp 4) must make those checks panic. # The kernel's report reaches the serial log through COM1, which QEMU has and the # iMac does not. Needs qemu-system-x86_64, OVMF, mtools and an x86_64 gcc. Final line: # AIENOS_IMAC_KERNEL: PASS|FAIL|NOT_RUN [(...)] exit 0 / 1 / 2 (tools) / 3 (NOT_RUN) @@ -176,15 +177,15 @@ run max max xapic run qemu64 qemu64 xapic # W^X negative controls: the probes run before the clock is measured, so a mutant's # panic halts instead of powering off; wait for the panic line, then stop QEMU. -mutant() { # IMACKERN_WX_MUTANT value, expected panic pattern - local m="$1" mo="${out}-wx-$1" mi="${work}/wx-$1.img" log="${work}/wx-$1.log" hit=0 +mutant() { # IMACKERN_WX_MUTANT value, expected panic pattern, QEMU core count (default 1) + local m="$1" mo="${out}-wx-$1" mi="${work}/wx-$1.img" log="${work}/wx-$1.log" hit=0 smp="${3:-1}" make -s -C native/kernel X86_CROSS="${cross}" OUT="${mo}" AIENOS_COMMIT="${commit}" IMACKERN_WX_MUTANT="${m}" imac-kernel >/dev/null truncate -s 64M "${mi}" mformat -i "${mi}" -F :: mmd -i "${mi}" ::/EFI ::/EFI/BOOT mcopy -i "${mi}" "${mo}/IMACKERN.EFI" ::/EFI/BOOT/BOOTX64.EFI cp "${vars_fd}" "${work}/vars.fd" - qemu-system-x86_64 -M q35 -accel tcg -cpu max -smp 1 -m 1024 \ + qemu-system-x86_64 -M q35 -accel tcg -cpu max -smp "${smp}" -m 1024 \ -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="${mi}" -device ide-hd,drive=esp,bus=ide.0 \ @@ -208,5 +209,8 @@ mutant() { # IMACKERN_WX_MUTANT value, expected panic pattern } mutant no_nx '^panic: wx: FAIL nx=on wp=on text_write=fault ro_write=fault heap_exec=ALLOWED stack_exec=ALLOWED$' mutant text_writable '^panic: wx: FAIL nx=on wp=on text_write=ALLOWED ro_write=fault heap_exec=fault stack_exec=fault$' +# The secondary cores start without CR0.WP (#484): the boot core's probes pass, so the failure must be the +# wx_audit core count, 1 of 4 cores with NXE and WP, after all three cores started. +mutant ap_no_wp '^panic: wx_audit: FAIL wx_pages=0 exec_pages=([1-9][0-9]*) text_pages=\1 exec_outside_text=0 ro_writable=0 cores_nx_wp=1/4$' 4 if [[ ${fails} == 0 ]]; then echo "${tag}: PASS"; exit 0; fi echo "${tag}: FAIL (${fails} checks)"; exit 1