Repository navigation
elf, userspace: link user images above the kernel RAM map - #193
Merged
Merged
Conversation
User programs linked at 0x08000000, inside the range the kernel maps 1:1 (up to PMM_MAX_BYTES, 256 MiB). Loading image page n replaced the kernel's identity PTE for physical frame 128 MB + n*4K in that process's PDPT, so while its CR3 was loaded a kernel object in such a frame read and wrote the process's own image page. The loader's only lower bound was 0x1000, so a signed image could be linked over any RAM the kernel uses. Latent: nothing reachable allocates that high today (doc/SECURITY_AUDIT_2026-10.md §3). Option A of doc/DESIGN_USER_LINK_BASE.md: - user.ld links at __user_image_base, default 0x20000000; the kernel's name for it is USER_IMAGE_BASE (memory.h, replaces USER_CODE_BASE). - elf.c static-asserts USER_IMAGE_BASE >= PMM_MAX_BYTES (moved to pmm.h) and refuses any PT_LOAD starting below PMM_MAX_BYTES. The check runs after the ECDSA gate, so like its sibling SECURITY lines it is one line per signed exec and carries no counter. - All 22 tracked blobs rebuilt and re-signed with the same key. Witness: verify/verify-user-link-base.sh drives a TINYOS_FAULT_INJECT kshell command, `linkbase`, that loads /hello.elf unscheduled and counts image pages the process PDPT maps away from the kernel's 1:1 view, with a control mapping that must read as shadowed on any kernel, then execs /ramprobe.elf (signed, linked at 0x0C000000). Unfixed tree: FAIL (8/8 shadowed, ramprobe loaded). Fixed: PASS. Mutations: loader check reverted -> FAIL (ramprobe loaded); old hello blob with the check -> FAIL (refused). Also: architecture SVG regenerated (base text; module count was already stale at 94 on main, now 96); frame-leak harness comment updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Implements option A of
doc/DESIGN_USER_LINK_BASE.md(merged in #192) and closes the latent finding indoc/SECURITY_AUDIT_2026-10.md§3.The bug
User programs linked at
0x08000000, inside the range the kernel maps 1:1 (up toPMM_MAX_BYTES, 256 MiB). Loading image page n replaced the kernel's identity PTE for physical frame 128 MB + n×4K in that process's PDPT. So while the process's CR3 was loaded, a kernel object in such a frame was read from and written to the process's own image page. The loader's only lower bound was0x1000, so a signed image could be linked over any RAM the kernel uses. It was latent: nothing reachable allocates that high today.The fix
userspace/user.ldlinks at__user_image_base, defaulting to0x20000000. The kernel name isUSER_IMAGE_BASE(memory.h), which replacesUSER_CODE_BASE.elf.cstatic-assertsUSER_IMAGE_BASE >= PMM_MAX_BYTES.PMM_MAX_BYTESmoved frompmm.ctopmm.h.PMM_MAX_BYTES. The check runs after the ECDSA gate, so only a validly signed image reaches it. It prints one line per exec and has no counter, like the siblingSECURITY: Segmentlines. This departs from the design note's plan, and the note's new "As implemented" section records why.Witness:
verify/verify-user-link-base.shlinkbaseis aTINYOS_FAULT_INJECTkshell command that only reads page tables. It does three things:/hello.elfwithout scheduling it, and counts image pages where the process PDPT mapsvelsewhere than the kernel's 1:1 view./ramprobe.elf, which is signed and linked at0x0C000000, inside RAM.helloblob with check present0x08000000-m 128MRegressions (all PASS,
-m 256M)verify-exec-frame-leak: no leakverify-mseal-countersverify-guard-page-releaseverify-guard-syncverify-spawn-guard-frameverify-argvverify-elf-loader-hardeningverify-elf-enforce-reportverify-memory-fixesverify-spawnverify-pipes-execverify-ring3-relogin-inputverify-ring3-pipesverify-privcmd-guardverify-arch-svgAlso
verify-arch-svgwas failing on main and now passes.verify-exec-frame-leak.shcomment is updated:hello.elfis now 9 pages because libc grew since its blob was last built, not because of the base change.KERNEL_BUGS.mdnote; and one rule line inCLAUDE.md.pmm.c'sframes_totalis the constantPMM_MAX_FRAMES, so the identity map always spans 256 MB regardless of guest RAM.🤖 Generated with Claude Code