Skip to content

fix(#742,#743): single-source the mmap floor, close MAP_FIXED gap, repair teardown census - #744

Merged
ryanbreen merged 4 commits into
mainfrom
fix/742-743-mmap-census
Sep 1, 2026
Merged

fix(#742,#743): single-source the mmap floor, close MAP_FIXED gap, repair teardown census#744
ryanbreen merged 4 commits into
mainfrom
fix/742-743-mmap-census

Conversation

@ryanbreen

@ryanbreen ryanbreen commented Sep 1, 2026

Copy link
Copy Markdown
Owner

Summary

Test plan

  • x86_64 release build (--target x86_64-breenix.json -Z build-std=core,alloc, --bin kernel): zero warnings/errors
  • aarch64 release build (--target aarch64-breenix-kernel.json -Z build-std=core,alloc, --bin kernel-aarch64): zero warnings/errors
  • cargo test --release --test teardown_structure: 81/81 passed
  • cargo test --release --test mmap_floor_structure: 9/9 passed (new ratchet — the branch's newest load-bearing verification artifact)
  • All other host structure-test suites (*_structure.rs, percpu_stack_custody, stack_bounds_tests, kernel_no_neon_guard, x86_gate_verdict_test, repo_symlink_hygiene): all green, 0 failures
  • aarch64 boot-tests-only strict gate (run-aarch64-boot-test-strict.sh, 20 iterations): 20/20 SUCCESS
  • Both new layout.rs const-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 actual cargo check against each target, not modeled

🤖 Generated with Claude Code

ryanbreen and others added 2 commits September 1, 2026 08:55
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>
ryanbreen and others added 2 commits September 1, 2026 09:55
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant