DOCUMENTATION / V1.0.0 LTS

OrbitOne v0.1.16 — An ELF64 Loader for Ring 3

What changed, and why it mattered

v0.1.15 gave every user task its own address space. What it did not give was a program. The shape of a user program was a constant of the kernel: exactly one page, at a hard-coded address, with one set of rights, entered at USER_CODE_ADDR. Nothing was read from the program itself. Adding a data page, or a second program with a different layout, meant editing the kernel.

v0.1.16 moves that decision out of the kernel and into the image. Each program is now a real ELF64 file — assembled together with the kernel, but described by its own header. The kernel reads the entry point, the segments, their addresses, their sizes and their rights, and obeys.

This is the change that makes the word "program" mean something here.

The measurement that proves it

user image data reads a header without running anything:

user_image program=data bytes=305 entry=0x8000000000 segments=2 pages=2
segment vaddr=0x8000000000 filesz=84 memsz=84 pages=1 writable=false executable=true
segment vaddr=0x8000001000 filesz=45 memsz=4096 pages=1 writable=true executable=false

Two segments, opposite rights, different file and memory sizes, in one image. No constant of the kernel can take two values at once, so these numbers can only have come from the header.

user run data then runs it. The program checks, itself, in ring 3, that the part of its data page the file does not cover arrives zeroed, writes to it, reads it back, and exits with 42:

[user] donnees inscriptibles chargees depuis l'image
[syscall] exit code=42

Counter-proof

An assertion that cannot fail proves nothing. Declaring data's data segment as RX instead of RW — one flags field in the header, nothing else — gives:

segment vaddr=0x8000001000 filesz=45 memsz=4096 pages=1 writable=false executable=true
[page_fault] cause=violation_de_protection acces=ecriture mode=utilisateur
[user] defaut de page en anneau 3 rip=0x8000000039 -> tache arretee, noyau intact

The program faults on write instead of exiting with 42. The header therefore drives the hardware page rights, and not the other way round.

Refusals are pronounced before anything is allocated

src/elf.rs is a reader, not a loader. It performs no I/O, allocates nothing, and does not depend on the target — which is why all 37 of its tests run on the host. It turns bytes into a checked description of what will have to be mapped, and refuses twenty distinct ways of being wrong. Five of them carry a security property rather than a well-formedness check:

Refusal What it prevents
SegmentHorsFenetre An image choosing addresses outside the user region
InscriptibleEtExecutable A segment asking for W and X at once
SegmentsSuperposes Two segments sharing a page, the later imposing its rights on the earlier
TropDePages Ring 3 exhausting physical frames on demand
PointEntreeHorsCode An entry point landing outside an executable segment
user image badelf
user_image program=badelf bytes=122 error=elf: segment inscriptible et executable

user run badelf
user_spawn program=badelf error=elf: segment inscriptible et executable

No task is created, and no frame is allocated: the refusal happens while parsing.

W^X is therefore now enforced in two independent places — at parse time, on what the image asks for, and at map time, on what the page tables grant. Neither depends on the good manners of the program.

The virtual window is an argument (Bounds), not a constant. That is what makes the containment rule testable off the target, and it is why the containment tests are among the 37 host tests rather than something one has to boot QEMU to check.

Two holes closed along the way

An information leak, real and now closed. alloc_phys_frame does not clear the frames it hands out, and the user stack page was never zeroed. A fresh task could read, in its own stack, whatever a dead task had left there. Every frame is now cleared before it is handed to ring 3.

A regression that variable-size images would have opened. Once an image may be any size, the user region contains pages no segment covers:

virt=0x8000000000 ... writable=false executable=true  user=true
virt=0x8000001000 ... writable=true  executable=false user=true
virt=0x8000002000 unmapped
virt=0x8000010000 ... writable=true  executable=false user=true
virt=0x200000     kernel                              user=false

The syscall boundary used to bound an interval and stop there. Handed a pointer into one of those holes, the kernel would have taken a page fault in ring 0 — therefore fatal — on an address chosen by ring 3. It now additionally checks that every page the range crosses is present and carries U/S in the active space.

Stated restrictions

The loader is deliberately narrow, and says so rather than failing obscurely: only PT_LOAD segments are honoured, p_vaddr must be page-aligned, only ET_EXEC is accepted, no relocations, no dynamic linking, at most 8 segments and 16 pages. The images are assembled with the kernel; nothing is loaded from disk or from /tmp yet.

Try it

cargo bootimage
cargo run
user image hello
user image data
user image badelf
user run data
user run badelf
user map
user status

Verification

Suite Before After
scripts/test_ring3.sh 13 assertion groups 17
scripts/test_regression_full.sh 13 structural checks 14
Host unit tests 186 223
scripts/scenarios/elf.txt — new serial comparison scenario
Clippy warnings 0 0

The new scenario replays the six images and keeps only lines whose content depends on the image bytes — no physical address, no task id. It catches an unintended move of a segment that no assertion spells out.