DOCUMENTATION / V1.0.0 LTS

OrbitOne v0.1.14 — Ring 3 and the syscall boundary

What changed

Until this release everything OrbitOne ran, ran in ring 0. The scheduler added in v0.1.13 gave the kernel real threads, but all of them shared the kernel's privilege and the kernel's page tables. There was no line to cross, so there was nothing to defend.

This release draws that line. Code now runs at privilege level 3, on pages the processor marks as user-accessible, and it can only reach the kernel through one door: int 0x80. A program that faults kills its own task; the shell keeps answering.

How to see it

user run hello        # prints through a syscall, exits with code 0
user status           # syscalls, rejections, user faults, last exit code
user map              # the user pages, plus a kernel page as a counter-example
user run fault        # writes to kernel memory: the task dies, the kernel lives
user run peek         # asks the kernel to read kernel memory: refused
health                # still ok after both

user run fault is the interesting one. The program writes a byte to 0x200000, which is kernel code. The processor raises a page fault with error=0x7 — protection violation, write, from user mode. Before this release that would have been KERNEL HALTED. Now the task is stopped, its pages are reclaimed, and health still reports ok.

user run peek is the other half of the same problem. Instead of touching kernel memory itself, the program asks the kernel to do it: it calls write with a pointer to 0x200000. The kernel has every right to read that address — which is exactly why the call must be refused before the pointer is dereferenced. user status shows the rejection.

Design

Why int 0x80 and not syscall

An interrupt gate makes the processor load rsp0 from the TSS and switch to it before pushing anything. The kernel therefore never executes a single instruction on a stack the caller controls. sysret would enter the kernel on the user's stack, leaving the kernel to swap it by hand, and would need three MSRs configured first.

The descriptor order in the GDT is nevertheless the one the STAR MSR imposes — kernel code, kernel data, user data, user code — so syscall/sysret can be added later without moving anything.

Where the isolation actually lives

Mechanism Where What it stops
U/S bit on all 4 page levels arch/x86_64/paging.rs Ring 3 reading or executing kernel pages
TSS rsp0, rewritten per entry arch/x86_64/gdt.rs The kernel running on a user stack
Gate DPL 3 on vector 0x80 only arch/x86_64/interrupts.rs Ring 3 invoking any other vector
Pointer range check syscall.rs The confused deputy: the kernel reading its own memory for the caller
W^X on the code page arch/x86_64/user.rs A user program rewriting its own code
Trap frame diversion arch/x86_64/interrupts.rs A user fault halting the kernel

Reachability from ring 3 is the AND of the U/S bit across the four page table levels, so user map reports that AND rather than the leaf entry alone. It is the same rule the processor applies.

Proof

scripts/test_ring3.sh boots the kernel in QEMU and checks nine groups of assertions, including that the log contains no KERNEL HALTED after the deliberate fault and that health=ok and tasks_live=1 still hold afterwards. It is wired into scripts/test_regression_all.sh.

Two counter-proofs were run and both behaved as required:

  1. Removing the U/S bit from the leaf page makes the program fault on its very first instruction, with error=0x15 and fetch_instruction=true. The bit is what makes the page executable from ring 3, and nothing else was hiding the failure.
  2. Renaming the pointer-validation function to a disjoint name still compiles cleanly, and the structural check [12/12] fails. The marker bites.

A measurement worth recording: QEMU's info mem showed, before any of this work, that no page carried the u flag. The kernel was already unreachable from ring 3 — because nothing ran in ring 3. The isolation gained here is real rather than decorative precisely because there is now something on the other side.

Known limitations

Next Reading