Skip to content

elf, userspace: link user images above the kernel RAM map - #193

Merged
douglasmun merged 1 commit into
mainfrom
fix/user-link-base
Oct 12, 2026
Merged

douglasmun merged 1 commit into
mainfrom
fix/user-link-base

Conversation

@douglasmun

Copy link
Copy Markdown
Owner

Implements option A of doc/DESIGN_USER_LINK_BASE.md (merged in #192) and closes the latent finding in doc/SECURITY_AUDIT_2026-10.md §3.

The bug

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 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 was 0x1000, 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.ld links at __user_image_base, defaulting to 0x20000000. The kernel name is USER_IMAGE_BASE (memory.h), which replaces USER_CODE_BASE.
  • elf.c static-asserts USER_IMAGE_BASE >= PMM_MAX_BYTES. PMM_MAX_BYTES moved from pmm.c to pmm.h.
  • The loader refuses any PT_LOAD that starts below 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 sibling SECURITY: Segment lines. This departs from the design note's plan, and the note's new "As implemented" section records why.
  • All 22 tracked blobs were rebuilt and re-signed with the same key. Crypto is unchanged.

Witness: verify/verify-user-link-base.sh

linkbase is a TINYOS_FAULT_INJECT kshell command that only reads page tables. It does three things:

  • Loads /hello.elf without scheduling it, and counts image pages where the process PDPT maps v elsewhere than the kernel's 1:1 view.
  • Maps a control page that must read as shadowed on any kernel, which proves the probe can see a shadow.
  • Execs /ramprobe.elf, which is signed and linked at 0x0C000000, inside RAM.
Run Result
Unfixed (range check disabled, old blobs) FAIL: 8 of 8 pages shadowed, ramprobe loaded
Fixed PASS: 0 of 9 shadowed, control 1, ramprobe refused
Mutation: loader check reverted FAIL: ramprobe loaded
Mutation: old hello blob with check present FAIL: hello refused at 0x08000000
Fixed, -m 128M PASS

Regressions (all PASS, -m 256M)

  • verify-exec-frame-leak: no leak
  • verify-mseal-counters
  • verify-guard-page-release
  • verify-guard-sync
  • verify-spawn-guard-frame
  • verify-argv
  • verify-elf-loader-hardening
  • verify-elf-enforce-report
  • verify-memory-fixes
  • verify-spawn
  • verify-pipes-exec
  • verify-ring3-relogin-input
  • verify-ring3-pipes
  • verify-privcmd-guard
  • verify-arch-svg

Also

  • The architecture SVG was regenerated with the new base text. Its module count was already stale on main (94); it is now 96. verify-arch-svg was failing on main and now passes.
  • The verify-exec-frame-leak.sh comment is updated: hello.elf is now 9 pages because libc grew since its blob was last built, not because of the base change.
  • Docs: the design note status is now fixed, plus an "As implemented" section; audit §3; a KERNEL_BUGS.md note; and one rule line in CLAUDE.md.
  • Known and unchanged: pmm.c's frames_total is the constant PMM_MAX_FRAMES, so the identity map always spans 256 MB regardless of guest RAM.

🤖 Generated with Claude Code

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>
@douglasmun
douglasmun merged commit fbc9d42 into main Oct 12, 2026
2 checks passed
@douglasmun
douglasmun deleted the fix/user-link-base branch October 12, 2026 00:31
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