You are browsing as a guest. Sign up (or log in) to start making projects!

2h 32m 40s logged

Memory Mapping and Paging Stuff

With the stack no longer exploding, I finally got to refactoring the page fault handler. Before, it operated based on whether the fault happened in ring 3 or ring 0, when it should actually mainly distinguish between kernel and user addresses.


Why distinguish between addresses instead of rings?

Imagine this: we’re handling a syscall, attempting to read userspace-provided memory, and we page fault. The fault happens in ring 0 but we’re actually working with userspace memory. Now, if we handle it like a kernel page fault, where our mindset is “Either there’s a valid VMA and we can map this or there’s a kernel bug so we panic”, a malicious userspace process could just provide a wrong address and panic the whole system.
Even worse: a valid pointer also brings down the system if it points into lazily allocated memory.

Now, the page fault handler looks at the address (and for user address page faults also at the current ring) and decides based on that what to do.

As proof that this works, the user binary now uses the stack for printing a text smiley, which works, even with the userspace stack now being lazily allocated.


What’s still left to do

Currently, bad user programs can still bring down the system because the page fault handler is among others still missing the so called “Exception Table” but more on that next devlog.

0
8

Comments 0

No comments yet. Be the first!