danos/system/kernel/architecture/x86_64
Daniel Samson cb30faf15f
kernel: a hostile return address cannot fault the kernel
SYSRETQ with a non-canonical RIP raises a general protection fault in ring
0 — on the kernel stack, an instruction after the swapgs that installed the
user's GS base. It is one of the better-known escalation primitives, and
ring 3 reaches it without any kernel bug at all: the processor saves the
address of the instruction after SYSCALL, so a program whose SYSCALL is the
last two bytes of the last canonical page returns to the first
non-canonical address. The new test does exactly that.

The exit path now sign-extends the return address from bit 47 and compares;
if the value changed, it returns through IRETQ instead, which commits the
privilege change before fetching the new address, so the fault arrives from
ring 3 and the process dies like any other. Four register-only operations
and a branch that a correct program can never take — it could not have
executed at a non-canonical address in the first place. Bit 47 is the right
pivot because danos builds four-level page tables and nothing sets the
five-level bit; a future port must move the pivot, and the comment says so.

SFMASK grows one bit while we are here. SYSCALL, unlike an interrupt gate,
does not clear the nested-task flag, so the kernel had been running every
system call with whatever ring 3 last chose — harmless while the only exit
was SYSRETQ, and a question worth not having now that one exit is IRETQ.
The kernel is never nested; ring 3 still gets its own flag back.

Suite 113/113. The new case asserts the refusal counter rather than the
dying process: the emulator we test on kills it either way, so only the
counter distinguishes a guard that ran from one that did not.
2026-08-01 11:22:07 +01:00
..
apic.zig kernel: ring 0 cannot execute a user page 2026-08-01 10:05:58 +01:00
cpu.zig kernel: a hostile return address cannot fault the kernel 2026-08-01 11:22:07 +01:00
cpuid.zig kernel: ring 0 cannot execute a user page 2026-08-01 10:05:58 +01:00
gdt.zig Re-organize the source tree as a monorepo mirroring the FHS 2026-07-10 12:55:56 +01:00
idt.zig zig fmt 2026-07-12 16:04:58 +01:00
io.zig Re-organize the source tree as a monorepo mirroring the FHS 2026-07-10 12:55:56 +01:00
ioapic.zig Re-organize the source tree as a monorepo mirroring the FHS 2026-07-10 12:55:56 +01:00
iommu-amd.zig kernel: the IOMMU backends move behind the architecture boundary 2026-07-30 07:16:08 +01:00
iommu-intel.zig kernel: the IOMMU backends move behind the architecture boundary 2026-07-30 07:16:08 +01:00
iommu.zig kernel: the IOMMU backends move behind the architecture boundary 2026-07-30 07:16:08 +01:00
isr.s kernel: a hostile return address cannot fault the kernel 2026-08-01 11:22:07 +01:00
linker.ld Re-organize the source tree as a monorepo mirroring the FHS 2026-07-10 12:55:56 +01:00
paging.zig kernel: user memory is reached only through a checked copy 2026-07-31 20:57:49 +01:00
per-cpu.zig kernel: a hostile return address cannot fault the kernel 2026-08-01 11:22:07 +01:00
serial.zig serial: skip a dead COM1 via a loopback probe (fixes ~57s real-HW boot) 2026-07-13 21:15:56 +01:00
smp.zig kernel: ring 0 cannot execute a user page 2026-08-01 10:05:58 +01:00
trampoline.s Re-organize the source tree as a monorepo mirroring the FHS 2026-07-10 12:55:56 +01:00
tss.zig Re-organize the source tree as a monorepo mirroring the FHS 2026-07-10 12:55:56 +01:00