Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/patches/d7e48cfb34820ad2 # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers ## GitHub aien-dev/aienux#512 (code only) closed derived `d7e48cfb34820ad2` #512 Imported from GitHub aien-dev/aienux#512 (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 `1cf4078096216e2206ac63d895fb1658240d7755` · Head `26dc6392c1b5035e07b1033d6801631d89d41ead` ### Fetch it A git bundle of the pull request's head, 7318 bytes. ``` curl -fsSL https://interplane.io/drakestapleton/aienux/patches/d7e48cfb34820ad2.bundle -o d7e48cfb34820ad2.bundle git fetch d7e48cfb34820ad2.bundle refs/pull/512/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 512 26dc6392c1b5035e07b1033d6801631d89d41ead ``` ``` {"kind":"github-import","owner":"aien-dev","repo":"aienux","number":512,"url":"https://github.com/aien-dev/aienux/pull/512","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:36:40Z","metadata":"unavailable","state_derived":true} ``` ### Changes ``` diff --git a/.crumb b/.crumb index a4df6536..9842a113 100644 --- a/.crumb +++ b/.crumb @@ -33,14 +33,14 @@ "purpose": "Directory docs. Purpose not yet described by a human." }, { - "digest": "dea2985c38978d62713f4db77afd6dadc3e9c3130606ed90f015a5bf6d30b280", - "last_commit": "003c74c5", + "digest": "ec2b543af27bd4f66e49c7e10e64ddc54057ef6cd52328c0ddd7eb0e8c83992f", + "last_commit": "a7606b17", "name": "native", "purpose": "Directory native. Purpose not yet described by a human." }, { - "digest": "c7893c9928c69881c17c653c9b31c3b699166a29fa827d48a0f9a5c5d68d101f", - "last_commit": "003c74c5", + "digest": "e9c74468508c5cdba0156bfd9c4cf77b3297cdfdc96f437b7d4d3cd3db2dc7b4", + "last_commit": "a7606b17", "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:f6b14b653363d1bec119ebde3ff071ac94e0df5d26704cfa07c869881a02f1ad", - "compiled_at": "2026-11-06T02:51:44Z", + "children_root": "sha256:c3e230a0fb7011e2e23c7d51bda97388cef32163ae93024eed544a5a23b614a5", + "compiled_at": "2026-11-06T03:18:27Z", "compiler": "crumb-compile/1", - "digest": "sha256:fce9194675e270cd8ddf31444c1bfa57775f613abb1b750bc317d49b002722e8", + "digest": "sha256:0c2a34e5c958d9709bfb0632c6dd4e808c7459224589d9b627ccb6a72ac24d3d", "evidence_files": 274, "evidence_root": "sha256:af014a4ed8f6fe759fc5809807fb47578d3410811b522d9f65d749382b029802", "files": 3779, - "generated_at_commit": "003c74c5f8604a67429b6e3b9dd8fee47ea9ea53", - "source_tree": "sha256:c5bb9e2a056b151b3d74d630c3259915a47df003ab780ceed65ec4b41d72d408" + "generated_at_commit": "a7606b179421dcc201cee98ec461166d90e195f0", + "source_tree": "sha256:73eb749dcc0d30a74c2e06697a492946b0bdb0cec587e03d6efd3605618bffce" }, "owner_lane": "", "provenance": { diff --git a/native/.crumb b/native/.crumb index 8976ff24..95f1d6c3 100644 --- a/native/.crumb +++ b/native/.crumb @@ -79,8 +79,8 @@ "purpose": "Directory native/disk. Purpose not yet described by a human." }, { - "digest": "fa756452a9307b2526dfec40b0deedb69b4b2eb7f11ec411b4b6afd3f01ceb73", - "last_commit": "003c74c5", + "digest": "df204019eddcca08614e507a35057848e2198e76f2b7492f51a9892718f9dc5d", + "last_commit": "a7606b17", "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:dff843524703b8ca03095ca9b3b2c1b7824dc6de73a2c445a70cbb01321fb662", - "compiled_at": "2026-11-06T02:51:44Z", + "children_root": "sha256:6ce32b63f0a2f5ee3686e2b9f3c1951c0dec4bfe58d8a6eef1b311affc9d6c85", + "compiled_at": "2026-11-06T03:18:27Z", "compiler": "crumb-compile/1", - "digest": "sha256:dea2985c38978d62713f4db77afd6dadc3e9c3130606ed90f015a5bf6d30b280", + "digest": "sha256:ec2b543af27bd4f66e49c7e10e64ddc54057ef6cd52328c0ddd7eb0e8c83992f", "evidence_files": 24, "evidence_root": "sha256:ecc7ccf2e924c221a5bac1d91e23b13d8f3c8d78c2a893a882ed7ca5e88d855d", "files": 779, - "generated_at_commit": "003c74c5f8604a67429b6e3b9dd8fee47ea9ea53", - "source_tree": "sha256:905e2b6c823a1df97a568e5f8dec73e624745f7dc357b6c3c517001d333e2fdf" + "generated_at_commit": "a7606b179421dcc201cee98ec461166d90e195f0", + "source_tree": "sha256:d367281c592e948da14f53a9ea51824e1a8e441fbd988e26fdb9ee59c3240f4f" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/.crumb b/native/kernel/.crumb index 295f2925..aff5aeb6 100644 --- a/native/kernel/.crumb +++ b/native/kernel/.crumb @@ -100,14 +100,14 @@ } ], "children_root": "sha256:8ca5e34f0cd76e78a1531d7764f8c2e2f3d7179d2e24a537c6427604ee39a69a", - "compiled_at": "2026-11-06T02:51:44Z", + "compiled_at": "2026-11-06T03:18:27Z", "compiler": "crumb-compile/1", - "digest": "sha256:fa756452a9307b2526dfec40b0deedb69b4b2eb7f11ec411b4b6afd3f01ceb73", + "digest": "sha256:df204019eddcca08614e507a35057848e2198e76f2b7492f51a9892718f9dc5d", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 522, - "generated_at_commit": "003c74c5f8604a67429b6e3b9dd8fee47ea9ea53", - "source_tree": "sha256:92795f28620cee9ccf035c93c64ceff10d545eb5a50b6cdca1262476cb58b6ea" + "generated_at_commit": "a7606b179421dcc201cee98ec461166d90e195f0", + "source_tree": "sha256:5ec9d031b66a929390aa181b21f4d1c25edc6c5436dee78808fb605739682734" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/README.md b/native/kernel/README.md index 0bfd75cb..c7c19455 100644 --- a/native/kernel/README.md +++ b/native/kernel/README.md @@ -177,8 +177,9 @@ The first cut of the C kernel core on x86_64, for the owner's 2017 iMac CHANDOF3 record, checked by `core/handoff_check.c`; `x86/kmain_x86.c` loads its own GDT, TSS and IDT (`x86/trap.S`), builds its own identity page tables (2 MiB pages: RAM write-back, everything else uncached, the framebuffer write-combining, -a 4 KiB guard page under the stack), proves the guard page faults and the fault -is contained, measures the TSC against the HPET, runs the local APIC timer +a 4 KiB guard page under the stack, physical page 0 not mapped so a NULL +dereference faults), proves the guard page and NULL reads and writes fault and the faults +are contained, measures the TSC against the HPET, runs the local APIC timer (xAPIC) for 20 interrupts at 100 Hz, starts every other core the MADT lists (INIT-SIPI-SIPI into the `x86/smp_x86.S` trampoline below 1 MiB; each core loads the kernel's tables, turns interrupts on, checks in and draws or halts), then walks PCI (`x86/pci_x86.c`, MCFG diff --git a/native/kernel/x86/kmain_x86.c b/native/kernel/x86/kmain_x86.c index 93295520..d21f00a2 100644 --- a/native/kernel/x86/kmain_x86.c +++ b/native/kernel/x86/kmain_x86.c @@ -835,11 +835,12 @@ static int in_range(uint64_t p, const char *lo, const char *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). */ + * physical page 0 and the stack guard unmapped (a NULL dereference faults, + * #487), 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) + if (p == 0 || p == (uint64_t)(uintptr_t)kstack) return 0; if (in_range(p, __text_start, __text_end)) return p | PTE_P | TEXT_W | cache; @@ -949,6 +950,7 @@ static void mm_build(void) 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); + split_2m(0); /* page 0 not present */ if (tramp_pa) split_2m(tramp_pa); for (uint64_t g = 0; g < top >> 30; g++) @@ -1661,6 +1663,38 @@ 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); + /* Physical page 0 is not mapped (#487): a NULL read and a NULL write each + * fault (not present), and the fault is contained. */ + uint64_t null_err[2] = {0, 0}; + int null_ok[2] = {0, 0}; + for (int w = 0; w < 2; w++) { + probe.hit = 0; + probe.armed = 1; + if (w) + __asm__ volatile("lea 1f(%%rip), %%rax\n\t" + "mov %%rax, %0\n\t" + "movb $0, (%1)\n" + "1:" + : "=m"(probe.resume) + : "r"((uint64_t)0) + : "rax", "memory"); + else + __asm__ volatile("lea 1f(%%rip), %%rax\n\t" + "mov %%rax, %0\n\t" + "movb (%1), %%al\n" + "1:" + : "=m"(probe.resume) + : "r"((uint64_t)0) + : "rax", "memory"); + probe.armed = 0; + null_err[w] = probe.err; + null_ok[w] = probe.hit && probe.cr2 == 0 && (probe.err & 0x1b) == (w ? 0x02u : 0x00u); + } + if (null_ok[0] && null_ok[1]) + ck_printf("null_page: ok read=fault write=fault (#PF cr2=0x0 error=0x%llx,0x%llx, not present)\n", + (unsigned long long)null_err[0], (unsigned long long)null_err[1]); + else + ck_panic("null_page: FAIL read=%s write=%s", null_ok[0] ? "fault" : "ALLOWED", null_ok[1] ? "fault" : "ALLOWED"); wx_probes(); if (!tsc_hz) diff --git a/scripts/.crumb b/scripts/.crumb index 0a4db8e5..4c793d14 100644 --- a/scripts/.crumb +++ b/scripts/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-11-06T02:51:44Z", + "compiled_at": "2026-11-06T03:18:27Z", "compiler": "crumb-compile/1", - "digest": "sha256:c7893c9928c69881c17c653c9b31c3b699166a29fa827d48a0f9a5c5d68d101f", + "digest": "sha256:e9c74468508c5cdba0156bfd9c4cf77b3297cdfdc96f437b7d4d3cd3db2dc7b4", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 140, - "generated_at_commit": "003c74c5f8604a67429b6e3b9dd8fee47ea9ea53", - "source_tree": "sha256:7b1a0e4740d6a42ffe7340c7d0ace28b809b853913020be7a0faf4d753505bc0" + "generated_at_commit": "a7606b179421dcc201cee98ec461166d90e195f0", + "source_tree": "sha256:e95b781b2e755ef9cb8c1402494cc6f59087b9434eac5aba5728c43f3049bc25" }, "owner_lane": "", "provenance": { diff --git a/scripts/qemu_ck_imac_kernel_test.sh b/scripts/qemu_ck_imac_kernel_test.sh index a04a5c0f..685c31be 100755 --- a/scripts/qemu_ck_imac_kernel_test.sh +++ b/scripts/qemu_ck_imac_kernel_test.sh @@ -22,7 +22,8 @@ # SATA disk, and boots it twice in QEMU q35 with OVMF: "-cpu max" and "-cpu qemu64" # (two CPU models; the kernel drives the local APIC in xAPIC mode on both). Each run # must leave boot services, switch to the kernel's own page tables, prove the guard -# page, measure the TSC against the HPET, take 20 local APIC timer interrupts, print +# page and an unmapped page 0 (a NULL read and write fault, #487), measure the TSC +# against the HPET, take 20 local APIC timer interrupts, print # start the three other cores (-smp 4) drawing the night sky of the startup, find both SATA disks behind # the q35 AHCI controller and an NVMe disk with its own GPT and read them without # writing (the ESP, and a data disk with a GPT whose AIENOS partition the kernel @@ -127,6 +128,7 @@ run() { # name, -cpu model, expected APIC mode chk "${name}: own page tables" "${txt}" '^paging: root=0x[0-9a-f]+ firmware_cr3=0x[0-9a-f]+ switched=yes top_gib=[0-9]+ pages_2m_wb=[1-9][0-9]* pages_2m_wc=[1-9][0-9]* pages_2m_uc=[1-9][0-9]* pt_frames=[0-9]+ fb=wc pat1=wc$' chk "${name}: heap" "${txt}" '^memory: frame_ranges=[1-9][0-9]* free_bytes=[1-9][0-9]* .* heap_test=ok$' chk "${name}: guard page fault contained" "${txt}" '^guard_page: ok fault=contained \(#PF cr2=0x[0-9a-f]+ error=0x[0-9a-f]+, not present\)$' + chk "${name}: NULL read and write fault contained" "${txt}" '^null_page: ok read=fault write=fault \(#PF cr2=0x0 error=0x[0-9a-f]+,0x[0-9a-f]+, not present\)$' chk "${name}: TSC timed by the HPET" "${txt}" '^timebase: hpet period_fs=[1-9][0-9]* tsc_hz=[1-9][0-9]*$' chk "${name}: APIC mode ${mode}" "${txt}" "^apic: mode=${mode} id=0 " chk "${name}: MADT four CPUs" "${txt}" '^madt: cpus=4 ioapics=1 ioapic_lines_masked=[1-9][0-9]*$' ```