fix(#742,#743): single-source the mmap floor, close MAP_FIXED gap, repair teardown census - #744
Merged
Merged
Conversation
The mmap validator's lower bound (MMAP_REGION_START) was never the allocators' own floor. sys_mmap and five graphics.rs producers (handle_create_window_buffer, handle_resize_window_buffer, handle_map_window_buffer, handle_map_compositor_texture, sys_fbmmap) each hardcoded their own 0x1000_0000 floor instead -- ~17.6 TB below the validator's real MMAP_REGION_START (0x7000_0000_0000). A sufficiently-descended mmap_hint could hand out a "successfully mapped" region every syscall pointer into it would then EFAULT against, the same "validator anchored to a bound the allocator does not use" shape #729's B4-a was. The honest fix is for the producers to consume the constant, not the other way around: MMAP_REGION_START is already what is_valid_user_range's mmap arm polices, and redefining it down to 0x1000_0000 would violate the existing USERSPACE_CODE_DATA_END <= MMAP_REGION_START layout invariant. All six call sites now floor against crate::memory::vma::MMAP_REGION_START directly. M-2: sys_mmap's MAP_FIXED arm accepted any page-aligned address with no region check at all, so a MAP_FIXED mapping outside the three windows the validator recognizes would return memory userspace could touch directly but no syscall could ever accept via a user pointer. It now requires the mapping to land wholly inside [MMAP_REGION_START, MMAP_REGION_END). layout.rs gains two new load-bearing const-asserts: MMAP_REGION_START now proves acceptance is tight (one byte below is refused) rather than being a bare re-export-integrity check, and the mmap region is proven non-empty (now load-bearing since producers rely on the floor being below the ceiling). Both mutation-verified to redden: loosening the mmap arm's lower bound by one, and collapsing MMAP_REGION_START onto MMAP_REGION_END, each reproducibly fail the build with the new assert's own message. Co-Authored-By: Ryan Breen <ryan.breen@gmail.com> Co-Authored-By: Claude Code <noreply@anthropic.com>
…ensus PR #740 landed driver_h.rs::corroborating_nonprogress_bit(), which seeds a fixed-size StrandCandidate scratch buffer with a placeholder `state: ThreadState::Running` -- the same non-progressing fill-value shape driver_a.rs::strand_census and strand_oracle.rs::sample_once already use, immediately overwritten by collect_strand_census before anything reads it. The thread-state-construction ratchet in teardown_structure.rs never got the new construction site added to its allow-list, so it read the placeholder as an unreviewed new publication and failed closed, exactly as designed -- a census-drift red, not a behavioral regression. Registers the new row. 81/81 tests in tests/teardown_structure.rs pass (previously 79 passed, 2 failed: v3_structural_closures_are_exact and deliberately_broken_variants_fail_the_ratchet). Co-Authored-By: Ryan Breen <ryan.breen@gmail.com> Co-Authored-By: Claude Code <noreply@anthropic.com>
…oor/seed ratchet layout.rs's #742 commit claimed "there is nowhere left for either bound and the allocators' seed/floor to drift apart again" and that the MMAP_REGION_START accept-assert is "a proof about the lowest address a real allocator can hand out" -- neither was backed by anything that would fail a build (PR #744 review B2, the same unpinned-drift shape that produced #742 in the first place). Add tests/mmap_floor_structure.rs: a census-shaped ratchet (never a literal file/line list, per the #549/#551/#527 lesson) pinning, by (file, enclosing function, occurrence count), the six producer floor comparisons #742 fixed and the five mmap_hint seed sites, all resolving to the named MMAP_REGION_START/_END constants rather than an independently hardcoded literal. Mutation-proven against the real tree (temporarily reverted one graphics.rs site to the stale 0x1000_0000 literal; both the census test and a direct anti-regression grep failed with the right diagnostic; reverted clean) as well as nine synthetic-source tests covering both directions (re-literalized/deleted sites redden; reflowed lines and renamed locals stay green). Rewrite layout.rs's prose to describe what the ratchet actually proves -- today's known producers, not a mathematical impossibility of future drift -- and close five cheap non-blocking review items along the way: the non-emptiness assert's honest-scope note now records its real distinguishing mutation (found and verified: START=0x7FFF_FEE0_0000, END=0x5000_0000 reddens only that assert) instead of a non-distinguishing one; the N1 justification's inverted "falls below" is corrected to "falls above" with the omitted stack-arm half restored; sys_mmap's MAP_FIXED comment now states its Linux-semantics deviation explicitly; sys_munmap now uses checked_add like its sys_mmap sibling instead of relying on incidental release-profile wraparound. Also corrects the #728 aarch64 durable record (review B1): PATCHed the posted issue comment, which rested on three claims falsified by the kernel's own source (a spinning writer does not bound the livelock to one CPU once new readers must also spin at acquisition; ordinary readers do not park when WRITER/UPGRADED is already set; aarch64's -smp 4+ configs are not a structural mitigation, just a workload fact that no boot service writes ext2 during the concurrent-read window today). Widened #728's title/body from x86-only to both arches and both filesystems (HOME_EXT2 carries the identical shape and was never mentioned). No lock-discipline fix attempted -- that remains its own arc. Verification: x86 and aarch64 builds clean (zero warnings), teardown_structure 81/81, all listed host structure suites green, aarch64 strict boot 20/20. Co-Authored-By: Ryan Breen <ryan.breen@gmail.com> Co-Authored-By: Claude Code <noreply@anthropic.com>
…serve #728's live repro PR #744 review round 2 (fix2-review.md) found the F3 mutation record this branch's second commit added to layout.rs's honest-scope note repeated the exact defect it was repairing: it recorded MMAP_REGION_START=0x7FFF_FEE0_0000 /MMAP_REGION_END=0x5000_0000 as isolating the mmap non-empty const-assert "and nothing else", verified only on x86_64. On aarch64 the same pair also reddens the START-accept assert, because that address sits below aarch64's own stack region_bottom (a different subtrahend, USER_STACK_SIZE not MAX_USER_STACK_SIZE, off a different USER_STACK_REGION_START) while it sits exactly on x86_64's. No arch-neutral pair isolates the non-empty assert. Verified per-arch by actually running cargo check against both x86_64-breenix.json/--bin kernel and aarch64-breenix-kernel.json/--bin kernel-aarch64 for both the recorded pair and its aarch64-isolating mirror (0xFFFF_FEFF_0000/0x5000_0000) -- not modeled. Rewrote the note to record both pairs per-arch and state plainly that no single pair isolates on both. Diff is comment-only (git diff filtered for non-`//` lines: empty); both arches still build clean. Also, per the same review round: - Preserves the unattributed docker/qemu/run-boot-parallel.sh stall at sys_mkdir("/var") observed during the prior fix round's extra verification, under docs/planning/green-program/nic-bus/serials/ 728-live-repro/ -- a live corroboration of #728's corrected livelock shape, not attributed to this branch's diff (no fs/lock/scheduler code touched here). Co-Authored-By: Ryan Breen <ryan.breen@gmail.com> Co-Authored-By: Claude <noreply@anthropic.com>
This was referenced Sep 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
MMAP_REGION_START) was never the allocators' own floor.sys_mmapand fivegraphics.rsproducers each hardcoded0x1000_0000instead, ~17.6 TB below the validator's real floor — the same "validator anchored to a bound the allocator does not use" shape as x86: sys_spawn's copy_string_from_user validator misses heap addresses (spawn may EFAULT from a shell) #729's B4-a, just not yet live. All six call sites now floor againstcrate::memory::vma::MMAP_REGION_STARTdirectly (the single source of truth is the constant; redefining it down to the old hardcoded floor would violate the existingUSERSPACE_CODE_DATA_END <= MMAP_REGION_STARTlayout invariant, so the producers move to match the constant, not the reverse).sys_mmap'sMAP_FIXEDarm accepted any page-aligned address with no region check at all. It now requires the mapping to land wholly inside[MMAP_REGION_START, MMAP_REGION_END), the same window the validator polices. (Deliberately more conservative than Linux here — it also refuses addressesis_valid_user_rangewould otherwise accept as code/data/stack, since there are zero in-treeMAP_FIXEDcallers today to need that.)layout.rsgains two new load-bearing const-asserts (mmap-region tightness + non-emptiness), both mutation-verified to redden, on both arches.tests/mmap_floor_structure.rs(new): a structural ratchet census-pinning the six< MMAP_REGION_STARTproducer comparisons mmap validator's lower bound (MMAP_REGION_START) is not the allocators' floor, and MAP_FIXED bypasses all region checks #742 fixed and the fivemmap_hintseed sites that readMMAP_REGION_END, by(file, enclosing function, occurrence count)— never a literal line/file list. Closes a false-universal doc comment this branch's first commit left inlayout.rs(review round B2: "there is nowhere left for either bound … to drift apart again" replaced with an accurate, scoped description of what the ratchet does and does not prove). Mutation-proven against the real tree (a temporarily re-literalizedgraphics.rsfloor site reddens it with an exact diagnostic, then reverts clean) as well as against six synthetic-source mutations, two of them negative controls.driver_h.rs'scorroborating_nonprogress_bit()(landed by PR proof(core): rung 3 - dispatch admission torture harness (component H) + rung-2 review leftovers #740) seeds a scratchStrandCandidatebuffer with a placeholderThreadState::Running, the same non-progressing fill-value shape two existing rows already cover — just a construction site the thread-state census's allow-list never got updated for. Registered the row;tests/teardown_structure.rsis back to 81/81 (was 79 passed, 2 failed).ROOT_EXT2/HOME_EXT2), not the "verified NOT-LIVE on aarch64" this section originally claimed. The original aarch64 scoping rested on three claims a review round falsified against the kernel's own source (a spinning writer occupying more than one CPU once other threads must also spin to acquireROOT_EXT2/HOME_EXT2; ordinary readers spinning, not parking, onceWRITER/UPGRADEDis set; and aarch64's own stock boot workload already supplying most of the concurrency the livelock needs). See the corrected issue and its pinned comment for the full mechanism. A live, observed reproduction of the corrected shape — an unattributeddocker/qemu/run-boot-parallel.sh 1stall atsys_mkdir("/var")with several concurrent ext2 readers in flight — is preserved in-repo atdocs/planning/green-program/nic-bus/serials/728-live-repro/and posted to the issue as a repro path for whoever picks up the actual fix. No lock-discipline fix is attempted by this PR; Both arches: concurrent ext2 read-park vs write-spin is a livelock shape (root & home filesystems) #728's own "Suggested directions" section remains the pointer to that arc.Test plan
--target x86_64-breenix.json -Z build-std=core,alloc,--bin kernel): zero warnings/errors--target aarch64-breenix-kernel.json -Z build-std=core,alloc,--bin kernel-aarch64): zero warnings/errorscargo test --release --test teardown_structure: 81/81 passedcargo test --release --test mmap_floor_structure: 9/9 passed (new ratchet — the branch's newest load-bearing verification artifact)*_structure.rs,percpu_stack_custody,stack_bounds_tests,kernel_no_neon_guard,x86_gate_verdict_test,repo_symlink_hygiene): all green, 0 failuresrun-aarch64-boot-test-strict.sh, 20 iterations): 20/20 SUCCESSlayout.rsconst-asserts mutation-proved to redden on the regression they exist to catch, per-arch — including the review-round finding (C1) that the mmap non-empty assert's isolating mutation is arch-specific (no single constant pair isolates it on both x86_64 and aarch64); both arch-specific pairs verified by an actualcargo checkagainst each target, not modeled🤖 Generated with Claude Code