interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

GitHub aien-dev/aienux#426 (code only)

closed derived 9b83dfbd0509a138 #426

Imported from GitHub aien-dev/aienux#426 (code only)

GitHub's metadata for this pull request is unavailable: its state is DERIVED from the commits (merged: the head is reachable from this project's main; open: GitHub kept a merge ref; else closed).

Base ce2ce2ab21dad32ec9c1103a94a148179cf58892 · Head 59dbb17a3bb8607655af75d26a42d00a5510f032

drakestapleton reviewed (COMMENTED) on 2026-10-30 11:18 UTC

Triage: blocked (merge conflicts with main; needs on-hardware evidence)

This is security-relevant (W^X for the iMac kernel page tables) and the direction is right. Review focus: native/kernel/x86/kmain_x86.c page-table construction: make sure no leaf stays W+X (including the 2 MiB pages around the image and the trampoline), NX is enabled in EFER before use, and the smp_x86.S AP path gets the same protections.

Hardware: please attach an iMac serial log showing the kernel booting with the new mappings, all APs up, and a deliberate write to .text or execution of data faulting.

To be merge-ready: rebase and attach that evidence.

drakestapleton reviewed (COMMENTED) on 2026-10-30 12:43 UTC

Full W^X security review at a3b3542a9848580d63b7dcf179af40a9f2858bbb (COMMENT, not an approval). This is not hardware-verified: the physical 2017 iMac run is NOT_RUN, and all runtime evidence comes from QEMU TCG.

What I read at this head:

  • native/kernel/x86/kmain_x86.c and x86/smp_x86.S
  • native/boot/image_x86_64.ld
  • the IMACKERN part of native/kernel/Makefile
  • scripts/qemu_ck_imac_kernel_test.sh
  • the README paragraph
  • the compare 111a3715...a3b3542a (my previous review head to this head)
  • issuecomment-6523039640

Merges (fefbbe65, 89a57143) and crumb recompile (a3b3542a)

  • The compare from 111a3715 to this head touches none of x86/kmain_x86.c, x86/smp_x86.S, boot/image_x86_64.ld or scripts/qemu_ck_imac_kernel_test.sh, so the W^X code is the code I reviewed before.
  • The PR's diff against main (b00c728c) is exactly 9 files: the 5 W^X files plus 4 .crumb files.
  • Makefile diff against main: only the IMACKERN_WX_MUTANT block (Makefile:2401-2419). Nothing else.
  • README resolution is harmless. README.md:232 drops "NX" from the "Not yet" list. README.md:237-256 (the W^X paragraph) says that the kernel refuses a CPU without NX and sets EFER.NXE and CR0.WP on every core. Main's RTL8127 paragraph follows it unchanged.
  • What main added since this PR opened:
    • The SMMU P07 event readout (core/smmu.c, core/smmu_svc.c), the RTL8127 binding (dev/rtl8127_bind.c, net/aienos_rtl8127.c) and the Spark input image are AArch64/Spark-only.
    • None of them is in IMACKERN_OBJS (Makefile:2328-2335, unchanged), and X86CFLAGS (Makefile:2257) does not pull in CK_EXTRA_CFLAGS.
    • rtl8127_bind.c maps its BAR through the existing ck_mmio_map and gets its rings from ck_dma_alloc. mm/ is unchanged by main, so it adds no new CPU mapping primitive.
    • The only header shared with the iMac image is ck_internal.h, which gains a declaration behind CK_B7B_EVENT_READOUT; the iMac image never defines that.
    • The efi_main.c change is the AArch64 loader, which is not linked into IMACKERN.
    • Nothing main brought in skips the x86 W^X setup or needs XN in the iMac image.

W^X: holds after enforcement. One pre-enforcement window (non-blocking).

  • kmain_x86.c:512-517: every 2 MiB identity leaf starts as RW+NX.
  • kmain_x86.c:535-538: the 2 MiB pages that hold the image and the trampoline are split.
  • leaf_4k (kmain_x86.c:425-434) produces:
    • .text as P without W, executable (RX)
    • the PE header and .rodata/rela/dynamic/GOT/.data.rel.ro as R+NX
    • everything else as RW+NX
    • the stack guard as not present
  • The sections are page aligned in image_x86_64.ld:70-74 (text start and end), :95-98 (__ro_end/__rw_start) and :110-111, so no 4 KiB page mixes text with data.
  • High MMIO: ck_x86_map_mmio (kmain_x86.c:584-601) adds only RW+NX 2 MiB UC leaves.
  • Framebuffer (kmain_x86.c:529-533): only the PAT bits change and the page stays NX. The framebuffer is also refused if it overlaps RAM.
  • Stacks, heap, AP stacks, DMA buffers and page-table frames all come from identity RAM, which is RW+NX.
  • Trampoline (kmain_x86.c:819-824 and :845-882): RW+NX while being filled, RX (tramp_prot(0)) while a core runs it, then R+NX. Every state transition is followed by a local invlpg.
  • Loader: there is no module loader, JIT or loaded-program path in this image.
  • wx_audit (kmain_x86.c:947-1002) runs after SMP and storage bring-up (:1124-1125). It walks every present leaf, including 1 GiB/2 MiB huge leaves (:958-975), and panics on any W+X page, any executable page outside .text, or any writable RO page.
  • Pre-enforcement window (non-blocking): from _start until mm_build loads CR3 (kmain_x86.c:563), the kernel runs on the firmware's tables, which on Apple firmware may be RWX. This covers relocation by efi_entry_x86_64.S, tables_load, the handoff check and mm_build itself. No untrusted input is executed in that window. Please document it in the README.

NX: holds on every core.

  • BSP: CPUID leaf 0x80000000 is checked to be at least 0x80000001, then EDX bit 20 is checked, and the kernel panics (fail closed) if either is missing (kmain_x86.c:503-509). EFER.NXE is set (:562) before the NX tables are loaded (:563).
  • AP: smp_x86.S:42-53 sets CR4.PAE, then CR3, then EFER |= 0x900 (LME and NXE), and only then CR0 |= PG|WP. So NXE is on before paging, and therefore before any NX-marked entry is used.
  • AP CPUID: an AP is not separately CPUID-checked. A core without NX would #GP on the wrmsr and never check in, so started, smp: and the audit's cores_nx_wp comparison (kmain_x86.c:993) fail closed.
  • ap_entry (kmain_x86.c:782-783) reads EFER.NXE and CR0.WP on the AP itself, and the audit requires the count of such APs to equal started.
  • XD bit is set on data, bss, stack, heap, MMIO, the framebuffer and page tables (PTE_NX = bit 63, :82-87).

CR0.WP: holds on every core.

  • BSP: kmain_x86.c:564.
  • AP: set in the same mov %eax, %cr0 that turns on PG (smp_x86.S:51-53), and checked on the AP at kmain_x86.c:782.
  • The trampoline GDT descriptors have the accessed bit preset (smp_x86.S:75-77), so the CPU never writes to the RX page after paging is on.
  • The only cr0 writes in the image are these two. efi_x86.c:57 only reads CR0.
  • Nit: on the BSP, WP is set three instructions after the CR3 load, with no stores in between. That is harmless.

Page-table permissions: correct.

  • The non-leaf PML4, PDPT and PD entries are always P|W without XD and without U/S (kmain_x86.c:511, :514, :447, :580). The effective permission is therefore set by the leaf, and no higher level widens or narrows it unexpectedly.
  • Huge pages: 2 MiB leaves inherit only cache bits on split (:443). No 1 GiB leaves are built, and the audit counts them if any appear.
  • TLB: invlpg covers only the local core. There is no shootdown. That is safe today because APs only ever cli; hlt after ap_entry (:784-786), and every later change on the BSP removes rights rather than adding them.
  • Note for later: a stale RX trampoline entry on a parked AP while the BSP has the page RW+NX is a cross-core W/X alias in time. It is unreachable because the AP is halted.

W+X paths: none found.

  • No code toggles WP or NXE off, either at runtime or on an error path. ck_panic → finish() leaves both on.
  • There is no runtime patching, module loading or JIT.
  • smp_start's early-exit path still retires the trampoline to R+NX (kmain_x86.c:840-843, tramp_prot(PTE_NX)).
  • -z noexecstack, and --no-warn-rwx-segments only quiets the ELF segment flags; the kernel's own tables govern permissions after mm_build.

Mutant tests: real panics, positively asserted.

  • no_nx: PTE_NX becomes 0 (kmain_x86.c:83-84). The heap and stack jmp *%rax probes (probe_exec, :907-923) then return without a #PF, so hx and sx are 0 and wx_probes calls ck_panic("wx: FAIL ...") (:935-939). That runs cli, prints panic: and calls finish() (:314-324).
  • text_writable: TEXT_W becomes PTE_W (:88-89). The store probe to __text_start then does not fault, tw is 0, and the same ck_panic runs.
  • Test assertions: qemu_ck_imac_kernel_test.sh:162-195 requires a match for the exact ^panic: wx: FAIL ...$ line, with heap_exec=ALLOWED stack_exec=ALLOWED for no_nx and text_write=ALLOWED for text_writable. It also requires the wx: TEST-ONLY banner. The test does not merely notice that a success line is missing.
  • The default runs fail if the banner appears (:142). The stamp (Makefile:2416-2419) forces kmain_x86.o to rebuild whenever the mutant setting changes.
  • Gap (non-blocking): the mutants run with -smp 1, so the AP path (trampoline NXE/WP) has no negative control; it is covered only by the cores_nx_wp count. A third mutant that drops 0x800 or 0x10000 in smp_x86.S would close it.

Evidence status

  • QEMU (TCG, -cpu max and qemu64, 4 cores, plus both mutants): claimed PASS in the PR body and in issuecomment-6523039640. The serial logs are pasted as excerpts only; they are neither attached nor committed, and no CI job runs qemu_ck_imac_kernel_test.sh. So this evidence is asserted, not independently checkable.
  • Physical iMac: NOT_RUN, hardware-unverified. Apple firmware's own page tables, real NX/WP behaviour on the i5/i7 and SMP on silicon are not proven.

CI and mergeability at a3b3542a: mergeable: true, mergeable_state: clean. These checks succeeded: AIEN Checks, sbom, CodeQL, Analyze (actions, c-cpp, python, rust) and .github/dependabot.yml. AIEN Alpha was skipped, which is expected on PRs.

Must-fix: none in the W^X code.

Recommended before relying on this outside QEMU:

  1. Attach the two QEMU serial logs, or commit them under evidence/.
  2. Add an AP-path mutant.
  3. Add a TLB shootdown, required before any work is scheduled on APs. The PR already lists this as a limit.
  4. Document the pre-mm_build firmware-table window in the README.

Optional nit: leaf_4k maps physical page 0 RW+NX (kmain_x86.c:433). Returning 0 for p == 0 would make null dereferences fault.

Overall: the W^X design is sound and complete for the current single-address-space ring-0 kernel with parked APs. The merges brought in no regression. The result is QEMU-only and hardware-unverified, and merging is the maintainers' decision.

— Grokbot

drakestapleton reviewed (COMMENTED) on 2026-10-30 13:07 UTC

Head re-check at 3e157636411b2e360023ed02fe8b00f3fb1eb3ab (COMMENT, not an approval).

This branch is now conflicted with main. Main moved to a1fc1f34 (#391 merge); mergeable_state: dirty. It needs a refresh before merge, and that new head will need its own re-check.

  • Contents since a3b3542a. This head adds only three things:
    • the main 77514f7e merge a80255e8
    • the four evidence logs in 8e442136
    • the .crumb regeneration in 3e157636

    The workflow pins are byte-identical to main: aien-verification.yml e8a75fa3, copilot-setup-steps.yml 340c5d04, sbom.yml ed36c38e. Nothing touches the W^X/NX code, smp_x86.S, page tables or build files. The head chain in the PR body matches.

  • Log provenance. All four logs are stamped 111a3715, which is an ancestor of this head. The native/kernel/x86 tree is identical at both commits (27cae02f). The iMac build inputs are unchanged:
    • The IMACKERN rule (native/kernel/Makefile ~L2294-2422 at head) does not compile native/boot/efi_main.c; it uses x86/efi_x86.c + boot/efi_gop.c.
    • IMACKERN_CFLAGS is built only from X86CFLAGS (~L2255-2258, unchanged) and never pulls in CK_EXTRA_CFLAGS. So CK_KLOG, CK_PI5, CK_B7B_PROBE, CK_RTL8127 and CK_SPARK_INPUT are never defined.
    • All 7 Makefile hunks between 111a3715 and this head fall outside the X86/IMACKERN section.
    • efi_main.c changes only its two CK_KLOG guards (to && CK_PI5).
    • The one changed IMACKERN input is core/ck_internal.h (in IMACKERN_HDRS). That change is a prototype under #ifdef CK_B7B_PROBE, so it is preprocessed out of the iMac build.
    • No other changed arm64, dev, net or disk file is an IMACKERN object or header.
    • The mutants are build flags (IMACKERN_WX_MUTANT → -DCK_X86_WX_MUTANT_*), not source edits.
  • CI at this SHA. These all succeeded: AIEN Checks, sbom, CodeQL, and Analyze (actions, c-cpp, python, rust). AIEN Alpha was skipped.
  • PR body. It says "QEMU-verified only; iMac hardware NOT_RUN" and links #485 (TLB shootdown) as a blocking follow-up.

QEMU-verified only; iMac hardware NOT_RUN.

— Grokbot

drakestapleton reviewed (COMMENTED) on 2026-10-30 13:25 UTC

Head re-check at 59dbb17a3bb8607655af75d26a42d00a5510f032 (COMMENT, not an approval).

Since 3e157636, this head adds only the main merge and crumbs. 59dbb17a is a merge with parents 3e157636 and ce2ce2ab; ce2ce2ab is the current main.

  • Since 77514f7e, main gained a1fc1f34 (#391) and ce2ce2ab (#482).
  • Every file changed since 3e157636 is either a .crumb or has the same blob as at ce2ce2ab. The one exception is native/kernel/Makefile, which differs from main only by this PR's IMACKERN_WX_MUTANT block (one hunk after imac-kernel:).
  • Regenerated crumbs: root, native, native/kernel and scripts. All other crumbs are main's.

W^X code and logs are unchanged. Excluding crumbs, the net diff against main has the same files and blobs as 3e157636 had against its main:

  • x86/kmain_x86.c f3865112, x86/smp_x86.S 59b6e186
  • README.md af832a08, qemu_ck_imac_kernel_test.sh 624e43d0
  • the 4 evidence/qemu_imac_wx_* logs: 42465019, 613e0b3e, 1937f165, b35fc260

The 111a3715 logs still represent the iMac image. Main's changes since 77514f7e don't touch any iMac build input:

  • They touch nothing in native/kernel/x86, boot/efi_gop.c, any IMACKERN object or header, X86CFLAGS or IMACKERN_CFLAGS.
  • The files they do change (osc_admit.c, xhci_fence.*, net_bind.*, svc tests, GATES.md) are not IMACKERN inputs.
  • Their Makefile hunks (osc receipt, KCFLAGS/CK_EXTRA_CFLAGS, arm64 image and host tests) are outside the x86 recipe, and IMACKERN never reads CK_EXTRA_CFLAGS.

CI at this SHA is green. These all succeeded: AIEN Checks, osc-code-flip-guard, sbom, CodeQL, and Analyze (actions, c-cpp, python, rust). AIEN Alpha was skipped. The PR is mergeable and clean, and the head chain in the PR body is accurate.

QEMU-verified only; iMac hardware NOT_RUN. #485 (TLB shootdown) must land before any PR lets APs run work.

— Grokbot

drakestapleton wrote on 2026-10-30 12:46 UTC

I've filed follow-up issues for the points in review 5712406189:

  • #485 — cross-core TLB shootdown. This is BLOCKING for any PR that lets application processors (APs) run work. Today invlpg only flushes the current core's TLB. That's safe while the APs stay parked at cli; hlt, and stops being safe once they run code.
  • #484 — add an AP-path mutant (drop NXE 0x800 or WP 0x10000 in smp_x86.S) and run it with more than one core.
  • #486 — docs: describe in the README the stretch before the CR3 switch, when the kernel still runs on the firmware's page tables.
  • #487 — (optional) unmap physical page 0 so null-pointer dereferences fault.

None of these change this PR's scope. The QEMU serial logs will be added to evidence/ in a separate update. Everything here is still QEMU-verified only; it hasn't been run on iMac hardware.

— Grokbot

Fetch it

A git bundle of the pull request's head, 30863 bytes.

curl -fsSL https://interplane.io/drakestapleton/aienux/patches/9b83dfbd0509a138.bundle -o 9b83dfbd0509a138.bundle
git fetch 9b83dfbd0509a138.bundle refs/pull/426/head

Raw bundle · Diff

Provenance

This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record:

github-import 1
aien-dev/aienux
426
59dbb17a3bb8607655af75d26a42d00a5510f032
{"kind":"github-import","owner":"aien-dev","repo":"aienux","number":426,"url":"https://github.com/aien-dev/aienux/pull/426","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:36:25Z","metadata":"unavailable","state_derived":true}

Changes

diff --git a/.crumb b/.crumb
index 1842c96f..5002fd8d 100644
--- a/.crumb
+++ b/.crumb
@@ -33,14 +33,14 @@
           "purpose": "Directory docs. Purpose not yet described by a human."
         },
         {
-          "digest": "871748acc4c06434293d833e95acc5ca0063361e71a75c4cc545bd5028af50b6",
-          "last_commit": "d41d5c2b",
+          "digest": "1fb0f1833fe438d23063374924f8a06bd25111fe45bdc6987847eddd039f5fa4",
+          "last_commit": "89a57143",
           "name": "native",
           "purpose": "Directory native. Purpose not yet described by a human."
         },
         {
-          "digest": "2eeb83a186f413cd87d904a1bff118758e10bc3921c288762c2e07d87d21e503",
-          "last_commit": "8182d6d3",
+          "digest": "2dffaed43899cb00c03694e7e840f7fd844898f3a155797eee43a17f397c8af5",
+          "last_commit": "fefbbe65",
           "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:d1820360796b68a79c143355fa8c7b6d36b1886d7d8dd6bf54c593e83106e8fc",
-      "compiled_at": "2026-10-30T13:06:28Z",
+      "children_root": "sha256:3ab7abb27f123b3df8a3e4da1661cd9fac817d7b6a6942b2cabe937b78cb09b9",
+      "compiled_at": "2026-10-30T13:17:50Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:7ae6b69a0de99da6a409490cd158f041a6fed957be1c0d47b1328f90cd373795",
-      "evidence_files": 238,
-      "evidence_root": "sha256:7a2a6f0fd6318a14bc86b8707a3bf324f2ed8e5c55403e5a01ab2e8df45ff308",
-      "files": 3586,
-      "generated_at_commit": "595140e5bd22ebbe9b14d5c9abb683f44a0fa11c",
-      "source_tree": "sha256:902ecdc8c89ba8ebd84862899c737b08ac45e3d7c5e1dc8e11ea23bcc9c98c5a"
+      "digest": "sha256:8082a7097e11d6bebd6c19cc9c645198604b6bfeb6fbe83fa0767f55896fdad4",
+      "evidence_files": 242,
+      "evidence_root": "sha256:b12605c0d31ef6d1edadc70e16f25a7b9d9696a2a9f972d60c514bf8939c945e",
+      "files": 3590,
+      "generated_at_commit": "3e157636411b2e360023ed02fe8b00f3fb1eb3ab",
+      "source_tree": "sha256:7aa9cf804d338b878e35627f7a63bb23a0228b7a5a29b3b99e02540386838752"
     },
     "owner_lane": "",
     "provenance": {
diff --git a/evidence/qemu_imac_wx_mutant_no_nx_serial.log b/evidence/qemu_imac_wx_mutant_no_nx_serial.log
new file mode 100644
index 00000000..1937f165
--- /dev/null
+++ b/evidence/qemu_imac_wx_mutant_no_nx_serial.log
@@ -0,0 +1,27 @@
+[=3h[=3h[=3hBdsDxe: loading Boot0001 "UEFI QEMU HARDDISK QM00001 " from PciRoot(0x0)/Pci(0x1F,0x2)/Sata(0x0,0xFFFF,0x0)
+BdsDxe: starting Boot0001 "UEFI QEMU HARDDISK QM00001 " from PciRoot(0x0)/Pci(0x1F,0x2)/Sata(0x0,0xFFFF,0x0)
+AIENOS-IMAC-KERNEL-0
+report_kind: pre_exit
+aienos_commit: 111a37150967d0e030cdef4dd8783fc1441d0e99
+kernel_impl: c (native/kernel/x86, x86_64)
+firmware_vendor: Ubuntu distribution of EDK II
+firmware_revision: 0x10000
+firmware_cpl: 0
+gop: ok from=conout handles=2 mode=0/30 1280x800 pitch=1280 format=1 base=0x80000000 size=0x3e8000
+acpi_rsdp: 0x3fb7e014
+image: 0x3e3a2000-0x3e3f9000
+exiting firmware boot services
+
+report_kind: kernel
+wx: TEST-ONLY W^X mutant build, page permissions deliberately broken, never deploy
+exit_boot_services: ok attempts=1
+cpu: AuthenticAMD QEMU TCG CPU version 2.5+
+descriptors: gdt=5 tss=yes ist1=df,nmi,mc idt=256
+handoff: CHANDOF3 ok
+screen: gop 1280x800 pitch=1280 format=bgrx base=0x80000000 map=wc scale=1 grid=160x80
+paging: root=0x2000 firmware_cr3=0x3fc01000 switched=yes top_gib=512 pages_2m_wb=510 pages_2m_wc=2 pages_2m_uc=261630 pt_frames=516 fb=wc pat1=wc
+memory: frame_ranges=8 free_bytes=1024655360 heap=0x266000+1048576 heap_test=ok
+stack: 0x3e3ca000-0x3e3da000 guard=0x3e3c9000 ist1=0x3e3de000
+guard_page: ok fault=contained (#PF cr2=0x3e3c9000 error=0x0, not present)
+panic: wx: FAIL nx=on wp=on text_write=fault ro_write=fault heap_exec=ALLOWED stack_exec=ALLOWED
+power: halted before the clock was measured; hold the power button to turn the machine off
diff --git a/evidence/qemu_imac_wx_mutant_text_writable_serial.log b/evidence/qemu_imac_wx_mutant_text_writable_serial.log
new file mode 100644
index 00000000..b35fc260
--- /dev/null
+++ b/evidence/qemu_imac_wx_mutant_text_writable_serial.log
@@ -0,0 +1,27 @@
+[=3h[=3h[=3hBdsDxe: loading Boot0001 "UEFI QEMU HARDDISK QM00001 " from PciRoot(0x0)/Pci(0x1F,0x2)/Sata(0x0,0xFFFF,0x0)
+BdsDxe: starting Boot0001 "UEFI QEMU HARDDISK QM00001 " from PciRoot(0x0)/Pci(0x1F,0x2)/Sata(0x0,0xFFFF,0x0)
+AIENOS-IMAC-KERNEL-0
+report_kind: pre_exit
+aienos_commit: 111a37150967d0e030cdef4dd8783fc1441d0e99
+kernel_impl: c (native/kernel/x86, x86_64)
+firmware_vendor: Ubuntu distribution of EDK II
+firmware_revision: 0x10000
+firmware_cpl: 0
+gop: ok from=conout handles=2 mode=0/30 1280x800 pitch=1280 format=1 base=0x80000000 size=0x3e8000
+acpi_rsdp: 0x3fb7e014
+image: 0x3e3a2000-0x3e3f9000
+exiting firmware boot services
+
+report_kind: kernel
+wx: TEST-ONLY W^X mutant build, page permissions deliberately broken, never deploy
+exit_boot_services: ok attempts=1
+cpu: AuthenticAMD QEMU TCG CPU version 2.5+
+descriptors: gdt=5 tss=yes ist1=df,nmi,mc idt=256
+handoff: CHANDOF3 ok
+screen: gop 1280x800 pitch=1280 format=bgrx base=0x80000000 map=wc scale=1 grid=160x80
+paging: root=0x2000 firmware_cr3=0x3fc01000 switched=yes top_gib=512 pages_2m_wb=510 pages_2m_wc=2 pages_2m_uc=261630 pt_frames=516 fb=wc pat1=wc
+memory: frame_ranges=8 free_bytes=1024655360 heap=0x266000+1048576 heap_test=ok
+stack: 0x3e3ca000-0x3e3da000 guard=0x3e3c9000 ist1=0x3e3de000
+guard_page: ok fault=contained (#PF cr2=0x3e3c9000 error=0x0, not present)
+panic: wx: FAIL nx=on wp=on text_write=ALLOWED ro_write=fault heap_exec=fault stack_exec=fault
+power: halted before the clock was measured; hold the power button to turn the machine off
diff --git a/evidence/qemu_imac_wx_pass_qemu64_serial.log b/evidence/qemu_imac_wx_pass_qemu64_serial.log
new file mode 100644
index 00000000..613e0b3e
--- /dev/null
+++ b/evidence/qemu_imac_wx_pass_qemu64_serial.log
@@ -0,0 +1,57 @@
+[=3h[=3h[=3hBdsDxe: failed to load Boot0001 "UEFI QEMU NVMe Ctrl AIENOSQEMU 1" from PciRoot(0x0)/Pci(0x2,0x0)/NVMe(0x1,00-00-00-00-00-00-00-00): Not Found
+BdsDxe: loading Boot0002 "UEFI QEMU HARDDISK QM00001 " from PciRoot(0x0)/Pci(0x1F,0x2)/Sata(0x0,0xFFFF,0x0)
+BdsDxe: starting Boot0002 "UEFI QEMU HARDDISK QM00001 " from PciRoot(0x0)/Pci(0x1F,0x2)/Sata(0x0,0xFFFF,0x0)
+AIENOS-IMAC-KERNEL-0
+report_kind: pre_exit
+aienos_commit: 111a37150967d0e030cdef4dd8783fc1441d0e99
+kernel_impl: c (native/kernel/x86, x86_64)
+firmware_vendor: Ubuntu distribution of EDK II
+firmware_revision: 0x10000
+firmware_cpl: 0
+gop: ok from=conout handles=2 mode=0/30 1280x800 pitch=1280 format=1 base=0x80000000 size=0x3e8000
+acpi_rsdp: 0x3f77e014
+image: 0x3df32000-0x3df89000
+exiting firmware boot services
+
+report_kind: kernel
+exit_boot_services: ok attempts=1
+cpu: AuthenticAMD QEMU Virtual CPU version 2.5+
+descriptors: gdt=5 tss=yes ist1=df,nmi,mc idt=256
+handoff: CHANDOF3 ok
+screen: gop 1280x800 pitch=1280 format=bgrx base=0x80000000 map=wc scale=1 grid=160x80
+paging: root=0x2000 firmware_cr3=0x3f801000 switched=yes top_gib=512 pages_2m_wb=510 pages_2m_wc=2 pages_2m_uc=261630 pt_frames=516 fb=wc pat1=wc
+memory: frame_ranges=9 free_bytes=1019813888 heap=0x267000+1048576 heap_test=ok
+stack: 0x3df5a000-0x3df6a000 guard=0x3df59000 ist1=0x3df6e000
+guard_page: ok fault=contained (#PF cr2=0x3df59000 error=0x0, not present)
+wx: ok nx=on wp=on text_write=fault ro_write=fault heap_exec=fault stack_exec=fault
+timebase: hpet period_fs=10000000 tsc_hz=2400102519
+apic: mode=xapic id=0 version=0x50014 timer_hz=62703900
+madt: cpus=4 ioapics=1 ioapic_lines_masked=24
+timer_irq: 20 ticks in 200 ms
+timer_stats: vector=0x40 period_us=10000 min_us=9904 avg_us=10031 max_us=10246 stray_irqs=0
+smp: cpus=4 started=3 failed=0 bsp_id=0 ap_ids=1,2,3 trampoline=0x1000 state=halted
+pci: ahci 00:1f.2 id=8086:2922 bar5=0x81010000
+ahci: ctrl=0 abar=0x81010000 version=1.00 ports=6 implemented=0x3f s64a=1 polled=yes
+ahci_disk: ctrl=0 disk=0 port=0 link=gen1 model="QEMU HARDDISK" blocks=131072 block=512 mib=64 access=read-only
+ahci_read: ctrl=0 disk=0 lba=0 bytes=512 boot_sig=55aa first=eb58904d
+ahci_gpt: ctrl=0 disk=0 refused: no protective MBR
+ahci_disk: ctrl=0 disk=1 port=1 link=gen1 model="QEMU HARDDISK" blocks=131072 block=512 mib=64 access=read-only
+ahci_read: ctrl=0 disk=1 lba=0 bytes=512 boot_sig=55aa first=00000000
+ahci_gpt: ctrl=0 disk=1 gpt=valid used=3 aienos first_lba=18432 last_lba=116735
+ahci_port: ctrl=0 port=2 link=none det=0
+ahci_port: ctrl=0 port=3 link=none det=0
+ahci_port: ctrl=0 port=4 link=none det=0
+ahci_port: ctrl=0 port=5 link=none det=0
+pci: nvme 00:02.0 id=1b36:0010 bar0=0xc000000000
+nvme_disk: ctrl=0 disk=0 version=1.4 nsid=1 blocks=65536 block=512 mib=32 access=read-only
+nvme_read: ctrl=0 disk=0 lba=0 bytes=512 boot_sig=55aa first=00000000
+nvme_gpt: ctrl=0 disk=0 gpt=valid used=3 aienos first_lba=18432 last_lba=51199
+net: no Ethernet controller
+storage: pci_functions=6 ahci_controllers=1 disks=2 nvme_controllers=1 nvme_disks=1 gpt_valid=2 writes=none
+wx_audit: ok wx_pages=0 exec_pages=15 text_pages=15 exec_outside_text=0 ro_writable=0 cores_nx_wp=4/4 trampoline=retired
+kernel: alive
+summary: cores=4/4 timer=ok sata_disks=2 nvme_disks=1 gpt_valid=2 writes=none net=none
+AIENOS-IMAC-KERNEL-0 DONE
+note: QEMU qualifies nothing physical
+power: holding the screen 60 s, then ACPI S5
+power: off via ACPI S5 pm1a=0x604 pm1b=0x0 slp_typ=0/0
diff --git a/evidence/qemu_imac_wx_pass_serial.log b/evidence/qemu_imac_wx_pass_serial.log
new file mode 100644
index 00000000..42465019
--- /dev/null
+++ b/evidence/qemu_imac_wx_pass_serial.log
@@ -0,0 +1,57 @@
+[=3h[=3h[=3hBdsDxe: failed to load Boot0001 "UEFI QEMU NVMe Ctrl AIENOSQEMU 1" from PciRoot(0x0)/Pci(0x2,0x0)/NVMe(0x1,00-00-00-00-00-00-00-00): Not Found
+BdsDxe: loading Boot0002 "UEFI QEMU HARDDISK QM00001 " from PciRoot(0x0)/Pci(0x1F,0x2)/Sata(0x0,0xFFFF,0x0)
+BdsDxe: starting Boot0002 "UEFI QEMU HARDDISK QM00001 " from PciRoot(0x0)/Pci(0x1F,0x2)/Sata(0x0,0xFFFF,0x0)
+AIENOS-IMAC-KERNEL-0
+report_kind: pre_exit
+aienos_commit: 111a37150967d0e030cdef4dd8783fc1441d0e99
+kernel_impl: c (native/kernel/x86, x86_64)
+firmware_vendor: Ubuntu distribution of EDK II
+firmware_revision: 0x10000
+firmware_cpl: 0
+gop: ok from=conout handles=2 mode=0/30 1280x800 pitch=1280 format=1 base=0x80000000 size=0x3e8000
+acpi_rsdp: 0x3fb7e014
+image: 0x3e332000-0x3e389000
+exiting firmware boot services
+
+report_kind: kernel
+exit_boot_services: ok attempts=1
+cpu: AuthenticAMD QEMU TCG CPU version 2.5+
+descriptors: gdt=5 tss=yes ist1=df,nmi,mc idt=256
+handoff: CHANDOF3 ok
+screen: gop 1280x800 pitch=1280 format=bgrx base=0x80000000 map=wc scale=1 grid=160x80
+paging: root=0x2000 firmware_cr3=0x3fc01000 switched=yes top_gib=512 pages_2m_wb=510 pages_2m_wc=2 pages_2m_uc=261630 pt_frames=516 fb=wc pat1=wc
+memory: frame_ranges=9 free_bytes=1024008192 heap=0x267000+1048576 heap_test=ok
+stack: 0x3e35a000-0x3e36a000 guard=0x3e359000 ist1=0x3e36e000
+guard_page: ok fault=contained (#PF cr2=0x3e359000 error=0x0, not present)
+wx: ok nx=on wp=on text_write=fault ro_write=fault heap_exec=fault stack_exec=fault
+timebase: hpet period_fs=10000000 tsc_hz=2400191556
+apic: mode=xapic id=0 version=0x50014 timer_hz=62706800
+madt: cpus=4 ioapics=1 ioapic_lines_masked=24
+timer_irq: 20 ticks in 200 ms
+timer_stats: vector=0x40 period_us=10000 min_us=9965 avg_us=10032 max_us=10140 stray_irqs=0
+smp: cpus=4 started=3 failed=0 bsp_id=0 ap_ids=1,2,3 trampoline=0x1000 state=halted
+pci: ahci 00:1f.2 id=8086:2922 bar5=0x81010000
+ahci: ctrl=0 abar=0x81010000 version=1.00 ports=6 implemented=0x3f s64a=1 polled=yes
+ahci_disk: ctrl=0 disk=0 port=0 link=gen1 model="QEMU HARDDISK" blocks=131072 block=512 mib=64 access=read-only
+ahci_read: ctrl=0 disk=0 lba=0 bytes=512 boot_sig=55aa first=eb58904d
+ahci_gpt: ctrl=0 disk=0 refused: no protective MBR
+ahci_disk: ctrl=0 disk=1 port=1 link=gen1 model="QEMU HARDDISK" blocks=131072 block=512 mib=64 access=read-only
+ahci_read: ctrl=0 disk=1 lba=0 bytes=512 boot_sig=55aa first=00000000
+ahci_gpt: ctrl=0 disk=1 gpt=valid used=3 aienos first_lba=18432 last_lba=116735
+ahci_port: ctrl=0 port=2 link=none det=0
+ahci_port: ctrl=0 port=3 link=none det=0
+ahci_port: ctrl=0 port=4 link=none det=0
+ahci_port: ctrl=0 port=5 link=none det=0
+pci: nvme 00:02.0 id=1b36:0010 bar0=0xc000000000
+nvme_disk: ctrl=0 disk=0 version=1.4 nsid=1 blocks=65536 block=512 mib=32 access=read-only
+nvme_read: ctrl=0 disk=0 lba=0 bytes=512 boot_sig=55aa first=00000000
+nvme_gpt: ctrl=0 disk=0 gpt=valid used=3 aienos first_lba=18432 last_lba=51199
+net: no Ethernet controller
+storage: pci_functions=6 ahci_controllers=1 disks=2 nvme_controllers=1 nvme_disks=1 gpt_valid=2 writes=none
+wx_audit: ok wx_pages=0 exec_pages=15 text_pages=15 exec_outside_text=0 ro_writable=0 cores_nx_wp=4/4 trampoline=retired
+kernel: alive
+summary: cores=4/4 timer=ok sata_disks=2 nvme_disks=1 gpt_valid=2 writes=none net=none
+AIENOS-IMAC-KERNEL-0 DONE
+note: QEMU qualifies nothing physical
+power: holding the screen 60 s, then ACPI S5
+power: off via ACPI S5 pm1a=0x604 pm1b=0x0 slp_typ=0/0
diff --git a/native/.crumb b/native/.crumb
index f5ff4423..ba36c2c1 100644
--- a/native/.crumb
+++ b/native/.crumb
@@ -79,8 +79,8 @@
           "purpose": "Directory native/disk. Purpose not yet described by a human."
         },
         {
-          "digest": "f3976d31e569c32a762d471a506f10eb96b9278ca8b2070801487560f3a37f48",
-          "last_commit": "d41d5c2b",
+          "digest": "12489846450f78b28013d14ce5fea95920b9d1b586c86a4d48bcbfab2b9c8488",
+          "last_commit": "fefbbe65",
           "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:8be3d44aab9400ece8fa18db46c9b3a222e818af5c1c004dc6ea917d57f089dc",
-      "compiled_at": "2026-10-30T13:06:28Z",
+      "children_root": "sha256:65c5c18c1473da245d2bd88d28eaf7348d8443f0fb7e69b755afe9dad4dee86b",
+      "compiled_at": "2026-10-30T13:17:50Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:871748acc4c06434293d833e95acc5ca0063361e71a75c4cc545bd5028af50b6",
+      "digest": "sha256:1fb0f1833fe438d23063374924f8a06bd25111fe45bdc6987847eddd039f5fa4",
       "evidence_files": 24,
       "evidence_root": "sha256:ecc7ccf2e924c221a5bac1d91e23b13d8f3c8d78c2a893a882ed7ca5e88d855d",
       "files": 676,
-      "generated_at_commit": "595140e5bd22ebbe9b14d5c9abb683f44a0fa11c",
-      "source_tree": "sha256:bd98a7f271e3a2407afcc4325d64664630ccc51f02ac27b65d3408566a0d68fb"
+      "generated_at_commit": "3e157636411b2e360023ed02fe8b00f3fb1eb3ab",
+      "source_tree": "sha256:f2fb4fd7a5a61b86a49fcbb64c31f18689e26e24cdf1c9d2fccf2ff71e838e1c"
     },
     "owner_lane": "",
     "provenance": {
diff --git a/native/kernel/.crumb b/native/kernel/.crumb
index 30368f86..25015da6 100644
--- a/native/kernel/.crumb
+++ b/native/kernel/.crumb
@@ -64,7 +64,7 @@
         },
         {
           "digest": "bc4d7808a4b43b8ebe3e68df30b702819e08783c49de07fd0e049f19f8e34845",
-          "last_commit": "f2071203",
+          "last_commit": "8182d6d3",
           "name": "dev",
           "purpose": "Directory native/kernel/dev. Purpose not yet described by a human."
         },
@@ -82,7 +82,7 @@
         },
         {
           "digest": "e0a0bed1e95c876ea3d0a2dc136b94d3744491e72d5809c11de6ff787b21fd0a",
-          "last_commit": "f2071203",
+          "last_commit": "8182d6d3",
           "name": "svc",
           "purpose": "Directory native/kernel/svc. Purpose not yet described by a human."
         },
@@ -100,14 +100,14 @@
         }
       ],
       "children_root": "sha256:051fc2730b7a0431ca3a2819a4936f2a5a2ab49192e0c18d0a96393e04a27055",
-      "compiled_at": "2026-10-30T13:06:28Z",
+      "compiled_at": "2026-10-30T13:17:50Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:f3976d31e569c32a762d471a506f10eb96b9278ca8b2070801487560f3a37f48",
+      "digest": "sha256:12489846450f78b28013d14ce5fea95920b9d1b586c86a4d48bcbfab2b9c8488",
       "evidence_files": 0,
       "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
       "files": 429,
-      "generated_at_commit": "595140e5bd22ebbe9b14d5c9abb683f44a0fa11c",
-      "source_tree": "sha256:091dc3feafccd2e486dcd472082cc9de8c627af6727ce48141607bc00776ab3c"
+      "generated_at_commit": "3e157636411b2e360023ed02fe8b00f3fb1eb3ab",
+      "source_tree": "sha256:6ce076ca4b6f6ff5d21dceec7065b8aee3e07ef6720008104eb0647b6b23029a"
     },
     "owner_lane": "",
     "provenance": {
diff --git a/native/kernel/Makefile b/native/kernel/Makefile
index 6c7b826d..6e9a41aa 100644
--- a/native/kernel/Makefile
+++ b/native/kernel/Makefile
@@ -2519,6 +2519,25 @@ $(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.
+IMACKERN_WX_MUTANT ?=
+ifeq ($(strip $(IMACKERN_WX_MUTANT)),)
+IMACKERN_WX_FLAGS :=
+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
+$(error IMACKERN_WX_MUTANT must be empty, no_nx or text_writable)
+endif
+$(IMACKERN_DIR)/kmain_x86.o: IMACKERN_CFLAGS += $(IMACKERN_WX_FLAGS)
+$(IMACKERN_DIR)/kmain_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))' > $@
 
 # ---- NETLDR.EFI: the lab network loader for the 2017 iMac (x86_64) ----
 # native/boot/net_loader.c + netboot_proto.c (wire spec netboot_proto.h). Stays on the stick as
diff --git a/native/kernel/README.md b/native/kernel/README.md
index 7ec1c284..af832a08 100644
--- a/native/kernel/README.md
+++ b/native/kernel/README.md
@@ -229,11 +229,32 @@ when a 16550 answers there (QEMU; the iMac has none). Shared, unchanged:
 cores and attaches a SATA data disk and an NVMe disk, each with a GPT from
 `ck_gpt_image`, and fails unless three cores check in, the kernel finds each
 AIENOS partition where the tool wrote it and both disks are byte-identical
-afterwards. Not yet: work scheduled on the other cores, x2APIC, NX, disk writes,
+afterwards. Not yet: work scheduled on the other cores, x2APIC, disk writes,
 VT-d, receiving on the network, a store. QEMU (no BCM57766 there)
 qualifies nothing physical; copy the image to a FAT stick as
 `EFI/BOOT/BOOTX64.EFI` and start it from the Option-key boot picker.
 
+Page permissions (W^X, #409): the kernel refuses a CPU without NX, sets
+EFER.NXE and CR0.WP on the boot core and in the trampoline for every other
+core, and maps its code read-only executable, its PE header and read-only data
+(`.rodata`, relocations, GOT) read-only no-execute, and everything else (data,
+bss, stacks, heap, page tables, MMIO, the framebuffer) no-execute, keeping the
+PAT cache types and the stack guard; the 2 MiB pages around the image and the
+trampoline are split into 4 KiB pages at the boundaries from
+`../boot/image_x86_64.ld`. The trampoline page is never writable and executable
+at once (writable while it is filled, executable while a core runs it,
+read-only no-execute once the cores are parked). At boot the kernel proves it:
+writes to code and to read-only data and execution from heap and stack must
+each fault with the right error code (`wx: ok ...`), and after the cores and
+disks are up an audit of every page table leaf must find nothing writable and
+executable, only the code executable, and NXE and WP on every core
+(`wx_audit: ok ...`). The QEMU test also builds two TEST-ONLY mutants
+(`make imac-kernel IMACKERN_WX_MUTANT=no_nx` or `=text_writable`) and fails
+unless their probes panic. W^X is not process isolation: everything here still
+runs in ring 0 in one address space, any kernel code can change the page
+tables, and learned or generated code must never be given kernel authority.
+QEMU only; not yet run on the iMac.
+
 The Spark's Realtek RTL8127 10 GbE (10ec:8127, segment 7) has a driver core in
 `native/net/aienos_rtl8127.c` and a binding in `dev/rtl8127_bind.c` (L198): SMMU
 window first (no SMMU, no DMA), BAR 2, reset and bring-up from Realtek's Linux r8127
diff --git a/native/kernel/x86/kmain_x86.c b/native/kernel/x86/kmain_x86.c
index 5658b0cf..f3865112 100644
--- a/native/kernel/x86/kmain_x86.c
+++ b/native/kernel/x86/kmain_x86.c
@@ -23,7 +23,11 @@
  * allocator over the memory map (mm/frames.c), own 4-level page tables that
  * identity map [0, top) with 2 MiB pages (RAM write-back, the rest uncached,
  * the GOP framebuffer write-combining through PAT entry 1) and a 4 KiB guard
- * page under the kernel stack, CR3 switched and the stack moved. Then: the
+ * page under the kernel stack, CR3 switched and the stack moved. W^X (#409):
+ * EFER.NXE and CR0.WP on every core, the image's code read-only executable,
+ * its read-only data read-only no-execute, everything else (data, bss,
+ * stacks, heap, MMIO, framebuffer) no-execute; probes and an audit of every
+ * leaf prove it. W^X is not process isolation. Then: the
  * screen console (core/fbcon.c), heap (mm/heap.c), the guard page proven to
  * fault and the fault contained, the TSC measured against the HPET, the
  * local APIC (xAPIC) with its timer at 100 Hz for 20 ticks, the MADT CPU
@@ -68,6 +72,29 @@
 #define PTE_PCD 0x10ull
 #define PTE_PS 0x80ull
 #define PTE_ADDR 0x000ffffffffff000ull
+#define MSR_EFER 0xc0000080u
+#define EFER_NXE (1ull << 11)
+#define CR0_WP (1ull << 16)
+
+/* 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. */
+#define PTE_XD (1ull << 63) /* the hardware execute-disable bit */
+#ifdef CK_X86_WX_MUTANT_NO_NX
+#define PTE_NX 0ull
+#else
+#define PTE_NX PTE_XD
+#endif
+#ifdef CK_X86_WX_MUTANT_TEXT_RW
+#define TEXT_W PTE_W
+#else
+#define TEXT_W 0ull
+#endif
+
+/* image_x86_64.ld, runtime addresses: [image_base, text_start) PE header,
+ * [text_start, text_end) code, [ro_start, ro_end) rodata/relocs/GOT, then
+ * data and bss up to image_end. All page aligned. */
+extern char __image_base[], __text_start[], __text_end[], __ro_start[], __ro_end[], __image_end[];
 
 const char *ck_commit(void) { return AIENOS_COMMIT; }
 
@@ -368,6 +395,7 @@ struct mm {
     int fb_ok;
 };
 static struct mm mm;
+static uint64_t *pds[MAP_TOP_MAX >> 30];
 
 static uint64_t *table_new(void)
 {
@@ -386,6 +414,45 @@ static int efi_ram(uint32_t type)
     return type <= 10 && type != 0 && type != 8;
 }
 
+static int in_range(uint64_t p, const char *lo, const char *hi)
+{
+    return p >= (uint64_t)(uintptr_t)lo && p < (uint64_t)(uintptr_t)hi;
+}
+
+/* One 4 KiB page of a split 2 MiB page (cache bits from the 2 MiB entry):
+ * the stack guard unmapped, code RX, the PE header and read-only data R+NX,
+ * everything else RW+NX (the trampoline page included until smp_start). */
+static uint64_t leaf_4k(uint64_t p, uint64_t cache)
+{
+    if (p == (uint64_t)(uintptr_t)kstack)
+        return 0;
+    if (in_range(p, __text_start, __text_end))
+        return p | PTE_P | TEXT_W | cache;
+    if (in_range(p, __image_base, __text_start) || in_range(p, __ro_start, __ro_end))
+        return p | PTE_P | PTE_NX | cache;
+    return p | PTE_P | PTE_W | PTE_NX | cache;
+}
+
+/* The 2 MiB page holding a, split into 4 KiB pages at the protection
+ * boundaries above; a no-op when it already is. */
+static void split_2m(uint64_t a)
+{
+    uint64_t *e = &pds[a >> 30][(a >> 21) & 511];
+    if (!(*e & PTE_PS))
+        return;
+    uint64_t cache = *e & (PTE_PCD | PTE_PWT), *pt = table_new();
+    a &= ~((2ull << 20) - 1);
+    for (uint64_t j = 0; j < 512; j++)
+        pt[j] = leaf_4k(a | j << 12, cache);
+    *e = (uint64_t)(uintptr_t)pt | PTE_P | PTE_W;
+}
+
+static uint64_t *pte_4k(uint64_t a)
+{
+    uint64_t e = pds[a >> 30][(a >> 21) & 511];
+    return (uint64_t *)(uintptr_t)(e & PTE_ADDR) + ((a >> 12) & 511);
+}
+
 static void mm_build(void)
 {
     const struct ck_handoff *h = hand;
@@ -427,30 +494,26 @@ static void mm_build(void)
     /* Every 2 MiB page starts uncached (PCD|PWT, PAT index 3): device memory
      * (local APIC, I/O APIC, HPET, PCI BARs) whatever the MTRRs say. Pages
      * that hold RAM from the memory map become write-back (index 0), the
-     * framebuffer write-combining (PWT alone, index 1, set to WC below). The
-     * 2 MiB page holding the stack guard is split into 4 KiB pages. */
-    static uint64_t *pds[MAP_TOP_MAX >> 30];
+     * framebuffer write-combining (PWT alone, index 1, set to WC below).
+     * Every 2 MiB page is no-execute; the ones holding the image or the
+     * trampoline are split into 4 KiB pages (leaf_4k) after the cache types
+     * are set. */
     if (ck_rd_cr4() & (1ull << 12))
         ck_panic("paging: firmware runs 5-level paging (CR4.LA57); this kernel builds 4-level tables");
+    uint32_t x[4];
+    ck_cpuid(0x80000000, 0, x);
+    if (x[0] < 0x80000001)
+        ck_panic("paging: no CPUID leaf 0x80000001, so no NX");
+    ck_cpuid(0x80000001, 0, x);
+    if (!(x[3] & (1u << 20)))
+        ck_panic("paging: CPU has no NX (execute disable); this kernel needs it for W^X");
     uint64_t *pml4 = table_new(), *pdpt = table_new();
     pml4[0] = (uint64_t)(uintptr_t)pdpt | PTE_P | PTE_W;
-    uint64_t guard = (uint64_t)(uintptr_t)kstack;
     for (uint64_t g = 0; g < top >> 30; g++) {
         uint64_t *pd = pds[g] = table_new();
         pdpt[g] = (uint64_t)(uintptr_t)pd | PTE_P | PTE_W;
-        for (uint64_t i = 0; i < 512; i++) {
-            uint64_t a = g << 30 | i << 21;
-            if (a <= guard && guard < a + (2ull << 20)) {
-                uint64_t *pt = table_new();
-                for (uint64_t j = 0; j < 512; j++) {
-                    uint64_t p = a | j << 12;
-                    pt[j] = p == guard ? 0 : (p | PTE_P | PTE_W);
-                }
-                pd[i] = (uint64_t)(uintptr_t)pt | PTE_P | PTE_W;
-                continue;
-            }
-            pd[i] = a | PTE_P | PTE_W | PTE_PS | PTE_PCD | PTE_PWT;
-        }
+        for (uint64_t i = 0; i < 512; i++)
+            pd[i] = (g << 30 | i << 21) | PTE_P | PTE_W | PTE_PS | PTE_PCD | PTE_PWT | PTE_NX;
     }
     for (uint64_t off = 0; off + h->desc_size <= h->map_size; off += h->desc_size) {
         const struct ck_efi_desc *d = (const void *)(uintptr_t)(h->memory_map + off);
@@ -468,6 +531,11 @@ static void mm_build(void)
         if (*e & PTE_PS)
             *e = (*e & ~PTE_PCD) | PTE_PWT;
     }
+    for (uint64_t a = (uint64_t)(uintptr_t)__image_base & ~((2ull << 20) - 1); a < (uint64_t)(uintptr_t)__image_end;
+         a += 2ull << 20)
+        split_2m(a);
+    if (tramp_pa)
+        split_2m(tramp_pa);
     for (uint64_t g = 0; g < top >> 30; g++)
         for (uint64_t i = 0; i < 512; i++) {
             uint64_t e = pds[g][i];
@@ -489,7 +557,11 @@ static void mm_build(void)
         ck_panic("paging: CPU has no PAT");
     __asm__ volatile("wbinvd" ::: "memory");
     ck_wrmsr(0x277, 0x0007040600070106ull);
+    /* NX bits are reserved (every access faults) until EFER.NXE is set;
+     * CR0.WP makes read-only pages bind the kernel too. */
+    ck_wrmsr(MSR_EFER, ck_rdmsr(MSR_EFER) | EFER_NXE);
     ck_wr_cr3(mm.root);
+    __asm__ volatile("mov %0, %%cr0" ::"r"(ck_rd_cr0() | CR0_WP) : "memory");
     /* Toggling CR4.PGE drops global TLB entries the firmware's tables left. */
     uint64_t cr4 = ck_rd_cr4();
     if (cr4 & 0x80) {
@@ -520,7 +592,7 @@ int ck_x86_map_mmio(uint64_t pa, uint64_t len)
         uint64_t *pd = sub_table(sub_table(pml4, (unsigned)(a >> 39) & 511), (unsigned)(a >> 30) & 511);
         uint64_t *e = &pd[(a >> 21) & 511];
         if (!(*e & PTE_P)) {
-            *e = a | PTE_P | PTE_W | PTE_PS | PTE_PCD | PTE_PWT;
+            *e = a | PTE_P | PTE_W | PTE_PS | PTE_PCD | PTE_PWT | PTE_NX;
             mm.pages_uc++;
         }
         __asm__ volatile("invlpg (%0)" ::"r"(a) : "memory");
@@ -683,7 +755,7 @@ struct smp_report {
     uint32_t ids[SMP_MAX], up_ids[SMP_MAX];
     const char *why;
 };
-static volatile uint32_t ap_up, ap_ids[SMP_MAX];
+static volatile uint32_t ap_up, ap_ids[SMP_MAX], ap_nx_wp; /* ap_nx_wp: cores that came up with EFER.NXE and CR0.WP */
 
 static void delay_us(uint64_t us)
 {
@@ -707,6 +779,8 @@ static void ap_entry(void *arg)
     apic_wr(APIC_TPR, 0);
     apic_wr(APIC_SVR, 0x100 | VEC_SPURIOUS);
     ap_ids[idx] = apic_rd(APIC_ID) >> 24;
+    if ((ck_rdmsr(MSR_EFER) & EFER_NXE) && (ck_rd_cr0() & CR0_WP))
+        __atomic_fetch_add(&ap_nx_wp, 1, __ATOMIC_SEQ_CST);
     __atomic_fetch_add(&ap_up, 1, __ATOMIC_SEQ_CST);
     for (;;)
         __asm__ volatile("cli; hlt");
@@ -739,6 +813,16 @@ static uint32_t tramp_at(const char *sym)
     return (uint32_t)(tramp_pa + (uint64_t)(uintptr_t)(sym - ck_x86_tramp_start));
 }
 
+/* The trampoline page is never writable and executable at once: RW+NX while
+ * it is filled, RX while a core runs it, R+NX once the cores are parked (a
+ * parked core runs nothing, so no TLB shootdown). */
+static void tramp_prot(uint64_t bits)
+{
+    uint64_t *e = pte_4k(tramp_pa);
+    *e = (*e & (PTE_ADDR | PTE_PCD | PTE_PWT)) | PTE_P | bits;
+    __asm__ volatile("invlpg (%0)" ::"r"(tramp_pa) : "memory");
+}
+
 static void smp_start(const struct apic_report *ar, struct smp_report *sr)
 {
     const uint8_t *m = ck_acpi_lookup(hand->rsdp, "APIC");
@@ -753,8 +837,11 @@ static void smp_start(const struct apic_report *ar, struct smp_report *sr)
         sr->why = "page tables above 4 GiB";
     else if (size > CK_PAGE)
         sr->why = "trampoline larger than a page";
-    if (sr->why)
+    if (sr->why) {
+        if (tramp_pa)
+            tramp_prot(PTE_NX);
         return;
+    }
     memcpy((void *)(uintptr_t)tramp_pa, ck_x86_tramp_start, size);
     tramp_put32(ck_x86_tramp_gdtr + 2, tramp_at(ck_x86_tramp_gdt));
     tramp_put32(ck_x86_tramp_far32, tramp_at(ck_x86_tramp_pm32));
@@ -771,8 +858,10 @@ static void smp_start(const struct apic_report *ar, struct smp_report *sr)
             continue;
         }
         unsigned before = ap_up;
+        tramp_prot(PTE_W | PTE_NX);
         tramp_put64(ck_x86_tramp_stack, st + AP_STACK_PAGES * CK_PAGE);
         tramp_put64(ck_x86_tramp_arg, before);
+        tramp_prot(0);
         __asm__ volatile("mfence" ::: "memory");
         int bad = icr_send(id, 0x4500); /* INIT, assert */
         delay_ms(10);
@@ -790,6 +879,126 @@ static void smp_start(const struct apic_report *ar, struct smp_report *sr)
         if (ap_up > before + 1)
             break; /* a core checked in twice or out of turn: stop starting more */
     }
+    tramp_prot(PTE_NX);
+}
+
+/* ---- W^X (#409) ----
+ * Each probe arms the #PF catcher (ck_x86_trap), touches one address and
+ * resumes after the access. The store writes back the byte it read, so a
+ * build that lets it through changes nothing. The execute probe jumps to
+ * `jmp *%rax` (rax = the resume label), so code that does run comes straight
+ * back and the probe sees no fault. Error code bits: P 0, W 1, RSVD 3, I/D 4. */
+static int probe_write(uint64_t a)
+{
+    probe.hit = 0;
+    probe.armed = 1;
+    __asm__ volatile("lea 1f(%%rip), %%rax\n\t"
+                     "mov %%rax, %0\n\t"
+                     "movb (%1), %%cl\n\t"
+                     "movb %%cl, (%1)\n"
+                     "1:"
+                     : "=m"(probe.resume)
+                     : "r"(a)
+                     : "rax", "rcx", "memory");
+    probe.armed = 0;
+    return probe.hit && probe.cr2 == a && (probe.err & 0x1b) == 0x03;
+}
+
+static int probe_exec(uint8_t *buf)
+{
+    buf[0] = 0xff; /* jmp *%rax */
+    buf[1] = 0xe0;
+    uint64_t a = (uint64_t)(uintptr_t)buf;
+    probe.hit = 0;
+    probe.armed = 1;
+    __asm__ volatile("lea 1f(%%rip), %%rax\n\t"
+                     "mov %%rax, %0\n\t"
+                     "jmp *%1\n"
+                     "1:"
+                     : "=m"(probe.resume)
+                     : "r"(a)
+                     : "rax", "memory");
+    probe.armed = 0;
+    return probe.hit && probe.cr2 == a && (probe.err & 0x1b) == 0x11;
+}
+
+static void wx_probes(void)
+{
+    uint64_t efer = ck_rdmsr(MSR_EFER), cr0 = ck_rd_cr0();
+    uint8_t *hb = ck_heap_alloc(&heap, 16);
+    uint8_t sb[16];
+    if (!hb)
+        ck_panic("wx: no heap for the execute probe");
+    int tw = probe_write((uint64_t)(uintptr_t)__text_start), rw = probe_write((uint64_t)(uintptr_t)__ro_start);
+    int hx = probe_exec(hb), sx = probe_exec(sb);
+    ck_heap_free(&heap, hb);
+    const char *f = "fault", *n = "ALLOWED";
+    if (!(efer & EFER_NXE) || !(cr0 & CR0_WP) || !tw || !rw || !hx || !sx)
+        ck_panic("wx: FAIL nx=%s wp=%s text_write=%s ro_write=%s heap_exec=%s stack_exec=%s",
+                 efer & EFER_NXE ? "on" : "off", cr0 & CR0_WP ? "on" : "off", tw ? f : n, rw ? f : n,
+                 hx ? f : n, sx ? f : n);
+    ck_puts("wx: ok nx=on wp=on text_write=fault ro_write=fault heap_exec=fault stack_exec=fault\n");
+}
+
+/* Every present leaf of the live tables (identity map, MMIO above it, the
+ * trampoline): no page may be writable and executable, the executable ones
+ * must be exactly the code, and the PE header and read-only data must not
+ * be writable. Counts are 4 KiB pages. */
+static void wx_audit(unsigned started)
+{
+    uint64_t wx = 0, ex = 0, ex_out = 0, ro_w = 0, text = (uint64_t)(__text_end - __text_start) >> 12;
+    const uint64_t *pml4 = (const uint64_t *)(uintptr_t)mm.root;
+    for (uint64_t i = 0; i < 512; i++) {
+        if (!(pml4[i] & PTE_P))
+            continue;
+        const uint64_t *pdpt = (const uint64_t *)(uintptr_t)(pml4[i] & PTE_ADDR);
+        for (uint64_t j = 0; j < 512; j++) {
+            if (!(pdpt[j] & PTE_P))
+                continue;
+            if (pdpt[j] & PTE_PS) { /* 1 GiB page: never built here, counted if present */
+                if (!(pdpt[j] & PTE_XD)) {
+                    ex += 1u << 18, ex_out += 1u << 18;
+                    wx += pdpt[j] & PTE_W ? 1u << 18 : 0;
+                }
+                continue;
+            }
+            const uint64_t *pd = (const uint64_t *)(uintptr_t)(pdpt[j] & PTE_ADDR);
+            for (uint64_t k = 0; k < 512; k++) {
+                uint64_t e = pd[k];
+                if (!(e & PTE_P))
+                    continue;
+                if (e & PTE_PS) {
+                    if (!(e & PTE_XD)) {
+                        ex += 512, ex_out += 512;
+                        wx += e & PTE_W ? 512 : 0;
+                    }
+                    continue;
+                }
+                const uint64_t *pt = (const uint64_t *)(uintptr_t)(e & PTE_ADDR);
+                for (uint64_t l = 0; l < 512; l++) {
+                    uint64_t p = i << 39 | j << 30 | k << 21 | l << 12;
+                    if (!(pt[l] & PTE_P))
+                        continue;
+                    if ((pt[l] & PTE_W) && (in_range(p, __image_base, __text_start) || in_range(p, __ro_start, __ro_end)))
+                        ro_w++;
+                    if (pt[l] & PTE_XD)
+                        continue;
+                    ex++;
+                    ex_out += !in_range(p, __text_start, __text_end);
+                    wx += !!(pt[l] & PTE_W);
+                }
+            }
+        }
+    }
+    if (wx || ex != text || ex_out || ro_w || ap_nx_wp != started)
+        ck_panic("wx_audit: FAIL wx_pages=%llu exec_pages=%llu text_pages=%llu exec_outside_text=%llu ro_writable=%llu "
+                 "cores_nx_wp=%u/%u",
+                 (unsigned long long)wx, (unsigned long long)ex, (unsigned long long)text,
+                 (unsigned long long)ex_out, (unsigned long long)ro_w, ap_nx_wp + 1, started + 1);
+    ck_printf("wx_audit: ok wx_pages=0 exec_pages=%llu text_pages=%llu exec_outside_text=0 ro_writable=0 "
+              "cores_nx_wp=%u/%u trampoline=%s\n",
+              (unsigned long long)ex, (unsigned long long)text, ap_nx_wp + 1, started + 1,
+              tramp_pa ? "retired" : "none");
 }
 
 /* ---- the kernel ---- */
@@ -876,6 +1085,7 @@ static __attribute__((noreturn)) void kernel_main(void *arg)
     else
         ck_panic("guard_page: FAIL hit=%d cr2=0x%llx error=0x%llx", probe.hit, (unsigned long long)probe.cr2,
                  (unsigned long long)probe.err);
+    wx_probes();
 
     tsc_measure();
     if (!tsc_hz)
@@ -912,6 +1122,7 @@ static __attribute__((noreturn)) void kernel_main(void *arg)
     }
 
     const struct ck_x86_storage_result *st = ck_x86_storage(h->rsdp, &frames, tsc_hz, mm.top);
+    wx_audit(sr.started);
     ck_puts("kernel: alive\n");
     ck_printf("summary: cores=%u/%u timer=ok sata_disks=%u nvme_disks=%u gpt_valid=%u writes=none net=%s\n",
               sr.started + 1, sr.listed, st->ahci_disks, st->nvme_disks, st->gpt_valid,
@@ -931,6 +1142,9 @@ 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)
+    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);
     cpu_line();
     ck_puts("descriptors: gdt=5 tss=yes ist1=df,nmi,mc idt=256\n");
diff --git a/native/kernel/x86/smp_x86.S b/native/kernel/x86/smp_x86.S
index a49955ee..59b6e186 100644
--- a/native/kernel/x86/smp_x86.S
+++ b/native/kernel/x86/smp_x86.S
@@ -7,9 +7,11 @@
  * INIT, SIPI, SIPI with the page number as the vector. A core then starts
  * here in real mode at CS = page >> 4, IP = 0, and walks: 16-bit -> 32-bit
  * protected mode (the trampoline's own flat GDT) -> PAE + the kernel's page
- * tables + EFER.LME + paging -> 64-bit, then calls entry(arg) on its own
- * stack (-mabi=ms: the argument in rcx, 32 bytes of shadow space). If entry
- * returns, the core halts with interrupts off. */
+ * tables + EFER.LME/NXE + paging and CR0.WP -> 64-bit, then calls entry(arg)
+ * on its own stack (-mabi=ms: the argument in rcx, 32 bytes of shadow space).
+ * If entry returns, the core halts with interrupts off. Once paging is on the
+ * page is read-only executable (W^X, kmain_x86.c tramp_prot), so the GDT
+ * descriptors carry their accessed bit already: the CPU never writes them. */
 
     .text
     .globl ck_x86_tramp_start, ck_x86_tramp_end
@@ -44,10 +46,10 @@ tramp_pm32:
     mov %eax, %cr3
     mov $0xc0000080, %ecx              /* EFER */
     rdmsr
-    or $0x100, %eax                    /* LME */
+    or $0x900, %eax                    /* LME + NXE: the kernel's tables carry NX bits */
     wrmsr
     mov %cr0, %eax
-    or $0x80000000, %eax               /* PG */
+    or $0x80010000, %eax               /* PG + WP: read-only pages bind this core too */
     mov %eax, %cr0
     ljmpl *(ck_x86_tramp_far64 - ck_x86_tramp_start)(%ebx)
 
@@ -70,9 +72,9 @@ tramp_lm64:
     .p2align 3
 tramp_gdt:
     .quad 0
-    .quad 0x00cf9a000000ffff           /* 0x08: 32-bit code */
-    .quad 0x00cf92000000ffff           /* 0x10: data */
-    .quad 0x00209a0000000000           /* 0x18: 64-bit code */
+    .quad 0x00cf9b000000ffff           /* 0x08: 32-bit code, accessed */
+    .quad 0x00cf93000000ffff           /* 0x10: data, accessed */
+    .quad 0x00209b0000000000           /* 0x18: 64-bit code, accessed */
 ck_x86_tramp_gdtr:
     .word 31
     .long 0                            /* page + (tramp_gdt - start) */
diff --git a/scripts/.crumb b/scripts/.crumb
index 2b332246..49ecf9f6 100644
--- a/scripts/.crumb
+++ b/scripts/.crumb
@@ -7,14 +7,14 @@
     "generated": {
       "children": [],
       "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
-      "compiled_at": "2026-10-30T11:55:22Z",
+      "compiled_at": "2026-10-30T13:17:50Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:2eeb83a186f413cd87d904a1bff118758e10bc3921c288762c2e07d87d21e503",
+      "digest": "sha256:2dffaed43899cb00c03694e7e840f7fd844898f3a155797eee43a17f397c8af5",
       "evidence_files": 0,
       "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
       "files": 125,
-      "generated_at_commit": "5566de422237b0ec4616289cd87dda907a2241b6",
-      "source_tree": "sha256:b69a48f00af9067820610a6cd768685c79386bdf2b9d9d64aa1bf0d79ab98714"
+      "generated_at_commit": "3e157636411b2e360023ed02fe8b00f3fb1eb3ab",
+      "source_tree": "sha256:23bdd38fdff4372416b91a9231898663760450e57d193eb13aeb3fac2abcd620"
     },
     "owner_lane": "",
     "provenance": {
diff --git a/scripts/qemu_ck_imac_kernel_test.sh b/scripts/qemu_ck_imac_kernel_test.sh
index 03149cf9..624e43d0 100755
--- a/scripts/qemu_ck_imac_kernel_test.sh
+++ b/scripts/qemu_ck_imac_kernel_test.sh
@@ -28,7 +28,11 @@
 # writing (the ESP, and a data disk with a GPT whose AIENOS partition the kernel
 # must locate where ck_gpt_image wrote it; the data disk must be byte-identical
 # afterwards), print "kernel: alive", hold the screen and power QEMU off through
-# ACPI S5 by itself.
+# 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.
 # 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)
@@ -133,6 +137,9 @@ run() { # name, -cpu model, expected APIC mode
     chk "${name}: one-line summary" "${txt}" "^summary: cores=4/4 timer=ok sata_disks=2 nvme_disks=1 gpt_valid=2 writes=none net=none\$"
     [[ "$(sha256sum "${nvm}" | cut -d" " -f1)" == "${nvm_sum}" ]] && echo "PASS  ${name}: NVMe disk unchanged" || { echo "FAIL  ${name}: NVMe disk changed"; fails=$((fails + 1)); }
     [[ "$(sha256sum "${data}" | cut -d" " -f1)" == "${data_sum}" ]] && echo "PASS  ${name}: data disk unchanged" || { echo "FAIL  ${name}: data disk changed"; fails=$((fails + 1)); }
+    chk "${name}: W^X probes fault" "${txt}" '^wx: ok nx=on wp=on text_write=fault ro_write=fault heap_exec=fault stack_exec=fault$'
+    chk "${name}: W^X audit, only code executable, every core" "${txt}" '^wx_audit: ok wx_pages=0 exec_pages=([1-9][0-9]*) text_pages=\1 exec_outside_text=0 ro_writable=0 cores_nx_wp=4/4 trampoline=retired$'
+    if grep -aq '^wx: TEST-ONLY' "${txt}"; then echo "FAIL  ${name}: default image is a W^X mutant"; fails=$((fails + 1)); fi
     chk "${name}: kernel alive" "${txt}" '^kernel: alive$'
     chk "${name}: DONE" "${txt}" '^AIENOS-IMAC-KERNEL-0 DONE$'
     chk "${name}: ACPI S5 power off" "${txt}" '^power: off via ACPI S5 pm1a=0x[0-9a-f]+ '
@@ -152,5 +159,39 @@ run() { # name, -cpu model, expected APIC mode
 }
 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
+    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 \
+        -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 \
+        -display none -nic none -serial file:"${log}" -no-reboot &
+    qpid=$!
+    for _ in $(seq 1 "${AIENOS_IMAC_KERNEL_WAIT:-300}"); do
+        if tr -d '\r' <"${log}" 2>/dev/null | grep -aqE -- "$2"; then hit=1; break; fi
+        kill -0 "${qpid}" 2>/dev/null || break
+        sleep 1
+    done
+    kill "${qpid}" 2>/dev/null || true
+    wait "${qpid}" 2>/dev/null || true
+    qpid=""
+    if [[ ${hit} == 1 ]] && tr -d '\r' <"${log}" | grep -aq '^wx: TEST-ONLY W^X mutant build'; then
+        echo "PASS  mutant ${m}: W^X probes catch it"
+        tr -d '\r' <"${log}" | grep -a '^panic: wx'
+    else
+        echo "FAIL  mutant ${m}: no match for: $2"; fails=$((fails + 1))
+        tr -d '\r' <"${log}" | tail -20
+    fi
+}
+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$'
 if [[ ${fails} == 0 ]]; then echo "${tag}: PASS"; exit 0; fi
 echo "${tag}: FAIL (${fails} checks)"; exit 1