Kernel 3: Virtual memory and page tables

Full lecture notes on kernelTextbook readings

Eve’s memory attack

uint8_t* ip = (uint8_t*) 0x40ed0;   // address of `_Z7syscall...` from `obj/kernel.sym`
ip[0] = 0xeb;
ip[1] = 0xfe;
(void) sys_getpid();

Kernel’s response: use vmiter to isolate the kernel

    for (; it.va() < MEMSIZE_PHYSICAL; it += PAGESIZE) {
        uintptr_t addr = it.va();
        int perm = PTE_P | PTE_W | PTE_U;
        if (addr == 0) {
            // nullptr is inaccessible even to the kernel
            perm = 0;
        /***** NEW CODE HERE *****/
        } else if (addr < PROC_START_ADDR && addr != CONSOLE_ADDR) {
            // prevent unprivileged access
            perm = PTE_P | PTE_W;
        }
        // install identity mapping
        int r = it.try_map(addr, perm);
        assert(r == 0);
    }

Virtual memory

Metaphor: Patch panel

From https://www.reddit.com/r/homelab/comments/vwqdkw/added_a_second_patch_panel_to_satisfy_my_ocd/

Metaphor: Switchboard

From https://en.wikipedia.org/wiki/Telephone_switchboard#/media/File:TexasRichardson_telephoneExchangeOperator.jpg

Lily Tomlin as Ernestine, the telephone operator, on Rowan and Martin’s Laugh-In

Example: SLIVEGOAT

Function notation

Invisibility cloak via virtual memory

Virtual memory performance

Paged virtual memory: Look up once per block

Example: SLIVEGOAT

x86-64 page tables

vmiter

vmiter mappings

Multiple page tables with vmiter