17. seL4 and the verified kernel

What the seL4 proofs connect, and what they assume Three boxes stacked: the abstract specification, the C implementation, the binary. A solid arrow labelled refinement proof joins the abstract specification to the C implementation. A dashed arrow labelled binary proof joins the C implementation to the binary; the verified-configurations page lists binary correctness for the AArch32 configurations and not for RISCV64. A box to the side lists what the proof does not cover: assembly entry and exit code, hardware and cache and TLB handling, boot code and the device tree it is handed, DMA-capable devices, timing channels, the compiler where no binary proof is listed, and whether the specification is what the author wanted. A dashed rule below the figure is labelled: a verified hearth is a named refusal, chapter 51. abstract specification what the kernel does, in a logic refinement proof: the C behaves only as the specification allows C implementation src/ at 16.0.0 binary proof: listed for the AArch32 configurations, not for RISCV64 binary kernel.elf not covered assembly entry and exit code hardware, caches, TLB handling boot code, and the DTB it is handed DMA-capable devices timing channels the compiler, where no binary proof that the specification is what you meant a verified hearth is a named refusal (chapter 51)

Why this layer exists

Chapter 14 placed five kernels on three axes, and the middle one, who is the TCB, was a count: every line that can set the U bit or the mode bit wrongly. seL4 is the kernel where that cell is answered by a proof. The book names it so that verified has a fixed meaning by the time chapter 51 lists a verified hearth among the things it did not build: a statement about a specific kernel, of a specific form, resting on specific assumptions, and not a grade.

seL4 is also a hypervisor, and the book names that too so that nobody takes the next step. The white paper (revision 1.4.1 of 2026-07-17, fetched 2026-10-01T01:36Z from https://sel4.systems/About/seL4-whitepaper.pdf) says that seL4 “runs in the appropriate hypervisor mode (EL2 on Arm, Root Ring-0 on x86, HS on RISC-V)” and hands VM exits to a user-level VMM. That is the design. This is the tree at the pin:

cd $C/seL4-16.0.0
grep -rn 'HypervisorSupport\|CONFIG_RISCV_HYP\|hyp' src/arch/riscv config.cmake kernel-config*

kernel-config* matches no file at 16.0.0. src/arch/riscv matches nothing. The only hits are config.cmake:314 and config.cmake:461, both KernelArmHypervisorSupport, which src/arch/arm/config.cmake:79 defines. The tree at 16.0.0 has no RISC-V hypervisor configuration, and the verified-configurations page says the same for the verified RISCV64 configurations (“Hypervisor mode: No”). A kernel plus a user-level VMM is also a different shape from the one image that chapter 14 gave hearth, and hearth is not that.

This is a reading chapter. seL4 is not built: its build wants its own toolchain and Python environment, and what the chapter is about is what the proof says, not how to boot sel4test. The Lab section records the exception.

Mechanism

What is proved

A refinement proof shows that a concrete description of a system has no behaviour the abstract one forbids. The 2009 paper puts it as a correspondence “between a high-level (abstract) and a low-level (concrete, or refined) representation of a system”, and as a consequence: properties proved of the abstract model also hold of the refined one. The white paper’s version for seL4 is that the possible behaviours of the C code “are a subset of those allowed by the abstract model”. That is the first arrow in the figure: the abstract specification is the kernel’s behaviour written in higher-order logic, the C implementation is the code under src/, parsed into the same logic by a C parser that gives it a semantics, and the proof says the second refines the first.

The proofs sit on three different arrows, each from a page fetched on 2026-10-01 UTC:

  • Functional correctness, the arrow in the figure: the C refines the abstract specification. The white paper’s gloss is that the kernel “cannot behave in ways that are not allowed by the spec” (https://sel4.systems/About/seL4-whitepaper.pdf, fetched 01:36Z), other than in time.
  • Binary correctness, the dashed arrow: the compiled binary refines the C. A tool checks it by translation validation, an automatic comparison of the compiler’s output against the C’s logic rather than a manual proof.
  • Integrity and availability, and confidentiality, a third arrow that the figure leaves out: they are proved of the abstract specification, not of the C, and carry down to the code through the refinement. Integrity: no entity modifies data without write access. Confidentiality: none reads or infers data without read access, in “a correctly configured system”. The white paper adds that the confidentiality proofs rule out covert storage channels and “presently not covert timing channels”, and that the integrity and availability proofs do not cover timeliness (same fetch).

Which claim holds for which architecture is in the verified-configurations page (https://docs.sel4.systems/projects/sel4/verified-configurations.html, fetched 2026-10-01T01:37Z). RISCV64: “C-level functional correctness, no fast path”, integrity and availability, and confidentiality. ARM (AArch32): the same C-level claim including the fast path, integrity and availability, confidentiality, and “binary correctness, covering C functions that have C-level verification”. AARCH64: C-level functional correctness including the fast path, integrity and availability, and confidentiality, with the kernel “running in EL2” as a hypervisor. ARM_HYP and X64: C-level functional correctness only. The fast path is an optimised version of the two IPC system calls, Call and ReplyRecv: traps.S jumps to it (c_handle_fastpath_call, line 117) before the general system-call code when CONFIG_FASTPATH is set, and “no fast path” means the page does not claim it is covered. The tree and the page differ here, as they do for the binary claim: configs/include/RISCV64_verified_include.cmake sets KernelFastpath ON and KernelBinaryVerificationBuild ON, and the page’s list is the status. Exercise (e) reads the binary one.

The 2009 paper (SOSP 2009, fetched 01:41Z) was the first of the three, and it had an executable specification as a middle layer between the abstract one and the C. The chain the white paper draws today is abstract specification, C, binary.

What is assumed

The assumptions page (https://sel4.systems/Verification/assumptions.html, fetched 01:37Z) lists seven. Four matter to this book:

  • Assembly. “the seL4 kernel, like all operating system kernels, contains some assembly code”, mainly “entry to and exit from the kernel, as well as direct hardware accesses”, and “For the proof, we assume this code is correct”. On RISC-V that is src/arch/riscv/traps.S, head.S, and the inline assembly of restore_user_context in c_traps.c (the path to sret).
  • Hardware, and, separately, hardware management: cache consistency and TLB maintenance are assumed to be done correctly in that assembly and to have no effect on the kernel’s behaviour. The sfence() after a page-table write (vspace.c:1088 and vspace.c:1131) is that assumption being used.
  • Boot code. The proof starts after the kernel has been loaded and brought into a consistent minimal state. The boot code is not part of it.
  • DMA. The CPU and MMU are assumed to be the only devices that touch memory directly. A driver for a DMA-capable device has to be verified, or the proof does not carry over to it.

Two more apply to the configuration the book would actually run. The configurations page says that none of the verified configurations “take into account address translation for devices (System MMU or IOMMU), debug/profiling/printing interfaces, or the kernel startup at boot”. And where no binary proof is listed, nothing checks the compiler’s output: the assumptions page’s own sentence is that the compiler and linker need no trust “on architectures that are supported by our binary verification”.

The device tree appears on neither page as a name. It enters through the boot code, and the chapter’s own observation is where. src/plat/qemu-riscv-virt/config.cmake declares the board this book uses, qemu-riscv-virt, and builds its device tree by asking QEMU for it (dumpdtb, lines 60-65 and 133-138). That blob is the kind ember was handed in a1 in chapter 2 and dumped in that chapter’s exercise (f). seL4’s init_kernel receives its address and size from the loader (src/arch/riscv/kernel/boot.c:456-457). The boot-time blob is outside the proof because the boot code is; the build-time DTB becomes constants in the preprocessed C (kernel_all_pp.c, the configurations page says) that verification does cover. And grep -rnil 'libfdt\|fdt_' src prints nothing at the pin: no kernel code parses it.

The kernel on the axes

Chapter 14’s three axes, for this kernel:

Shared. Nothing, by default. An address space is an object that a program holds a capability to, and src/arch/riscv/kernel/vspace.c is where the RISC-V one is made and edited.

The copy. An IPC message, which only an endpoint can carry (src/object/endpoint.c).

Trusted. The kernel, and the proof is about exactly that TCB. The word capability is chapter 14’s: an unforgeable reference to a kernel object that carries the right to use it. The design makes a capability the only way to reach an object: the white paper says that invoking a capability is “the one and only way of performing an operation on a system object”. What the proofs add is that access control is enforced: integrity and confidentiality, in a correctly configured system. Together the TCB question has an answer by type. There are two comparisons with what the reader built, and each is a rule, not a line count.

The first is chapter 7’s trap entry. ember’s user_vec begins csrrw sp, sscratch, sp (ember/proc.S:25): the hardware does not switch stacks on a trap, so the first instruction swaps the user’s sp for a kernel stack parked in sscratch, and nothing is stored before it. seL4’s entry has two forms. With SMP it is the same swap (traps.S:28); without SMP it swaps t0 instead and leaves sp alone until every general register is saved and sp itself is stored as data in the frame. The kernel stack is then a link-time constant (traps.S:94). The rule is that no value the user supplied is used as an address before it has been put somewhere safe.

The second is chapter 4’s map_page. ember’s map_page is a function any kernel code can call with any virtual address, physical address and flags, and chapter 14’s TCB count for ember was every map_page call that passes PTE_U together with the paths that write sstatus or execute sret. seL4’s map functions, performPageTableInvocationMap and performPageInvocationMapPTE in vspace.c, are called from one place each, from the decode functions at vspace.c:798 and vspace.c:907, and those are reached from decodeRISCVMMUInvocation (vspace.c:933), which switches on the type of the capability the caller invoked. No capability, no mapping, with one exception: the boot code builds the first user program’s tables without one (map_it_pt_cap, vspace.c:167, and map_it_frame_cap, vspace.c:197, both BOOT_CODE), which is the boot-code assumption again. Nothing is counted; the type system of the kernel’s own object model says there is one way in.

Walkthrough

Read in the README’s order. Each excerpt is sed -n from the pinned checkout, and the header names the lines.

1. src/plat/qemu-riscv-virt/config.cmake. The platform is declared in line 8, qemu-riscv-virt, for riscv64 and riscv32, with OpenSBI’s generic platform (line 13). The kernel runs in S mode and M mode is OpenSBI’s, where ember’s -bios none image owns M mode itself. The device tree is not hand-written for this board:

// seL4 16.0.0, src/plat/qemu-riscv-virt/config.cmake:16-26
    # If neither QEMU_DTS nor QEMU_DTB is set explicitly, the device tree is
    # extracted from QEMU. This keeps it nicely up to date with the the actual
    # QEMU versions that is used, and it's quite convenient for development.
    if(NOT DEFINED QEMU_DTS)

        set(QEMU_DTS "${CMAKE_BINARY_DIR}/qemu-riscv-virt.dts")

        if(NOT DEFINED QEMU_DTB)

            message(STATUS "Extracting device tree from QEMU")
            set(QEMU_DTB "${CMAKE_BINARY_DIR}/qemu-riscv-virt.dtb")

Line 185 appends the extracted DTS and the overlay to KernelDTSList, and the top-level config.cmake (lines 410-424) concatenates that list into one DTS and compiles it to kernel.dtb.

2. src/plat/qemu-riscv-virt/overlay-qemu-riscv-virt.dts. The overlay changes three things. It names which nodes are kernel devices, adds a clint node whose size comes from QEMU’s source, and reserves the first 2 MiB of DRAM, from 0x80000000, for SBI. That is the address ember’s image is entered at with -bios none:

// seL4 16.0.0, src/plat/qemu-riscv-virt/overlay-qemu-riscv-virt.dts:7-20
/ {
    chosen {
        /*
         * - elfloader and kernel use SBI console by default
         * - QEMU emulates a SiFive PLIC and CLINT by default
         *
         * Nothing needed for elfloader
         *      seL4,elfloader-devices = ... ;
         *
         */
        seL4,kernel-devices =
            &{/soc/clint@2000000},
            &{/soc/plic@c000000};
    };

3. src/arch/riscv/kernel/boot.c. There is no M-to-S drop here, because the loader and OpenSBI did it. The kernel’s first C, init_kernel, ends up in init_cpu, whose first act is the chapter 4 act, a kernel page table in force (activate_kernel_vspace, after map_kernel_window at line 227), and whose second is stvec, chapter 5’s:

// seL4 16.0.0, src/arch/riscv/kernel/boot.c:126-143
BOOT_CODE static void init_cpu(void)
{

    activate_kernel_vspace();
    /* Write trap entry address to stvec */
    write_stvec((word_t)trap_entry);
    initLocalIRQController();
#ifndef CONFIG_KERNEL_MCS
    initTimer();
#endif

    /* disable FPU access */
    set_fs_off();

#ifdef CONFIG_HAVE_FPU
    init_fpu();
#endif
}

head.S:42-52 documents the arguments the loader hands over in a0-a5, a4 and a5 being the DTB’s address and size.

4. src/arch/riscv/kernel/vspace.c. The walk. CONFIG_PT_LEVELS is 3 by default (src/arch/riscv/config.cmake:11, whose comment ties 3 to Sv39), and the loop descends only while the slot it is looking at is a page table:

// seL4 16.0.0, src/arch/riscv/kernel/vspace.c:392-415
lookupPTSlot_ret_t lookupPTSlot(pte_t *lvl1pt, vptr_t vptr)
{
    lookupPTSlot_ret_t ret;

    word_t level = CONFIG_PT_LEVELS - 1;
    pte_t *pt = lvl1pt;

    /* this is how many bits we potentially have left to decode. Initially we have the
     * full address space to decode, and every time we walk this will be reduced. The
     * final value of this after the walk is the size of the frame that can be inserted,
     * or already exists, in ret.ptSlot. The following formulation is an invariant of
     * the loop: */
    ret.ptBitsLeft = PT_INDEX_BITS * level + seL4_PageBits;
    ret.ptSlot = pt + ((vptr >> ret.ptBitsLeft) & MASK(PT_INDEX_BITS));

    while (isPTEPageTable(ret.ptSlot) && likely(0 < level)) {
        level--;
        ret.ptBitsLeft -= PT_INDEX_BITS;
        pt = getPPtrFromHWPTE(ret.ptSlot);
        ret.ptSlot = pt + ((vptr >> ret.ptBitsLeft) & MASK(PT_INDEX_BITS));
    }

    return ret;
}

The map invocations dispatch on capability type:

// seL4 16.0.0, src/arch/riscv/kernel/vspace.c:933-942
exception_t decodeRISCVMMUInvocation(word_t label, word_t length, cptr_t cptr,
                                     cte_t *cte, cap_t cap, bool_t call, word_t *buffer)
{
    switch (cap_get_capType(cap)) {

    case cap_page_table_cap:
        return decodeRISCVPageTableInvocation(label, length, cte, cap, buffer);

    case cap_frame_cap:
        return decodeRISCVFrameInvocation(label, length, cte, cap, call, buffer);

5. src/arch/riscv/traps.S and c_traps.c. The entry, whose two stack forms Mechanism explains:

// seL4 16.0.0, src/arch/riscv/traps.S:24-38
BEGIN_FUNC(trap_entry)

#ifdef ENABLE_SMP_SUPPORT
/* The sscratch contains the stack for the current core */
  csrrw sp, sscratch, sp
/* Now we have a valid kernel stack */
  STORE t0, (-2*REGBYTES)(sp)
  LOAD  t0, (-1*REGBYTES)(sp)
#else
  csrrw t0, sscratch, t0
#endif
  STORE ra, (0*REGBYTES)(t0)
#ifndef ENABLE_SMP_SUPPORT
  STORE sp, (1*REGBYTES)(t0)
#endif

The kernel stack is loaded only after every register is saved (traps.S:93-95), and restore_user_context in c_traps.c writes sscratch back with the thread’s register block before sret (c_traps.c:77-80), which is what makes the non-SMP swap in line 33 find the frame:

// seL4 16.0.0, src/arch/riscv/traps.S:92-95
#else
  /* Load kernel's stack address */
  la sp, (kernel_stack_alloc + BIT(CONFIG_KERNEL_STACK_BITS))
#endif

6. src/object/endpoint.c. The sender’s half of IPC. The case the message actually moves in is the receiver already waiting:

// seL4 16.0.0, src/object/endpoint.c:62-86
    case EPState_Recv: {
        tcb_queue_t queue;
        tcb_t *dest;

        /* Get the head of the endpoint queue. */
        queue = ep_ptr_get_queue(epptr);
        dest = queue.head;

        /* Haskell error "Receive endpoint queue must not be empty" */
        assert(dest);

        /* Dequeue the first TCB */
#ifdef CONFIG_KERNEL_MCS
        tcbEPDequeue(dest, epptr);
#else
        queue = tcbEPDequeue(dest, queue);
        ep_ptr_set_queue(epptr, queue);

        if (!queue.head) {
            endpoint_ptr_set_state(epptr, EPState_Idle);
        }
#endif /* CONFIG_KERNEL_MCS */

        /* Do the transfer */
        doIPCTransfer(thread, epptr, badge, canGrant, dest);

doIPCTransfer is in src/kernel/thread.c and the word copy, copyMRs, in src/object/tcb.c, as chapter 14’s Walkthrough says. This file is where the decision to copy is made.

Exercises

(a) The assumptions page has no entry named for the device tree. Where does the DTB enter a seL4 build and boot on this board, and which of the page’s assumptions does each entry fall under?

Answer

Two places. At build time, the top-level config.cmake (lines 410–424) joins KernelDTSList, which for this board is QEMU’s dumped DTS plus the overlay, into kernel.dts and compiles it to kernel.dtb; tools/hardware/fdt.py:76-77 has a function that returns the nodes listed under seL4,kernel-devices, the property the overlay sets (overlay-qemu-riscv-virt.dts:17-19, the CLINT and the PLIC). A wrong DTS here is closest to the page’s hardware assumption failing (the machine not as the model describes it), with the mistake made in the build instead of the silicon; that is the chapter’s own reading, not a line on the page. At boot, init_kernel receives dtb_addr_p and dtb_size (boot.c:456-457) and, if the size is not 0, copies the blob into the boot-info block for the first user program (boot.c:314-324, SEL4_BOOTINFO_HEADER_FDT). Nothing in the kernel parses it (grep -rnil 'libfdt\|fdt_' src prints nothing). The kernel passes the DTB on, so the party that must read it correctly at run time is the root task, which is user code. The boot entry is the page’s boot code assumption.

So “the DTB is outside the proof” is true, and what follows from it is narrower than it sounds. The kernel’s run-time behaviour does not depend on interpreting a DTB. The build does.

(b) Find the Sv39 level count in vspace.c, and say what the seL4 walk does at a level whose table does not exist, against ember/pt.c’s walk.

Answer

Three. CONFIG_PT_LEVELS defaults to 3 (src/arch/riscv/config.cmake:11; its comment, lines 8–10, ties 2, 3 and 4 to Sv32, Sv39 and Sv48), and lookupPTSlot starts at CONFIG_PT_LEVELS - 1 (vspace.c:396), the same three levels as ember/pt.c:72’s for (level = 2; level >= 0; level--). The difference is the missing level. ember’s walk calls alloc_table() when a slot is not valid (pt.c:77-79). lookupPTSlot never allocates: its loop (vspace.c:407-412) stops at the first slot that is not a page-table entry and returns it with ptBitsLeft saying how big a mapping that slot could take. decodeRISCVFrameInvocation compares that to the frame’s size and, if it differs, fails with seL4_FailedLookup and a lookup_fault_missing_capability (vspace.c:860-863). The caller must first map a page table into the missing level with the RISCVPageTableMap invocation (vspace.c:709), using a capability to a page-table object it already owns. In ember the kernel’s allocator is the policy. In seL4 the policy is the user’s, and the kernel’s allocator is absent: that is the price of having no allocation in the walk that a proof has to cover.

(c) On the non-SMP path, what does traps.S do with the user’s t0 and sp, and what does that say about kernel stacks, against ember/proc.S?

Answer

Mechanism gives the swap; what it leaves behind is the user’s t0, which sits in sscratch and is recovered by csrr x1, sscratch and stored at slot 4 (traps.S:67-73), with the user’s sp stored as data in slot 1 (line 37). Then every trap starts at the same stack top, la sp, (kernel_stack_alloc + BIT(CONFIG_KERNEL_STACK_BITS)) (line 94). ember does not: its user_vec finds the process’s own kernel stack top in sscratch (ember/proc.S:25, parked by proc.c:132), because chapter 8’s swtch can leave a process asleep halfway down it. The frame in seL4 lives in the thread control block, not on a stack, and a trap never resumes a half-run kernel path on an old stack. Whether that is why the proof is tractable is not something this file says; what it says is that the kernel has no per-thread stack to reason about.

(d) A pipe in chapter 10 buffers: a write completes whether or not a reader is there. What does sendIPC do with a non-blocking send to an endpoint nobody is receiving on?

Answer

It drops the message. The state is EPState_Idle and the first case (endpoint.c:28-30) does its work only if (blocking): it marks the sender BlockedOnSend and queues it on the endpoint (lines 32-57). For blocking == false there is no else, and control reaches break (line 60). Nothing was copied and nothing was queued. An endpoint has no buffer. A blocking sender waits with its message still in its own message registers, and the copy happens only in the EPState_Recv case (lines 62-86), at doIPCTransfer (line 86), when both threads are present. Chapter 10’s ring is a third party that holds bytes between a writer and a reader. An endpoint is a rendezvous, and the kernel is never the store.

(e) From the verified-configurations page: on which architectures is binary correctness listed, and is riscv64 one of them at the fetch date? What does the tree say?

Answer

Binary correctness is listed under the AArch32 (ARM) configurations and under no other (Mechanism has the lists; fetched 2026-10-01T01:37Z). So at that date riscv64 is not one, and on riscv64 the compiler and linker are in the trusted base (the assumptions page, above). The tree adds a wrinkle that the page does not resolve. configs/include/RISCV64_verified_include.cmake:14 sets KernelBinaryVerificationBuild ON, but the option’s own help text (config.cmake:177-183) says enabling it “does NOT imply that you are using a verified kernel”. It restricts optimisations that would interfere with a binary proof. The white paper’s description of translation validation names an L3 model of the RISC-V ISA. The tooling for the step exists on RISC-V; the page’s property list is the status. And qemu-riscv-virt is not a platform in the RISCV64 list, and grep -rn 'qemu-riscv-virt\|QEMURiscV' configs finds nothing: configs/RISCV64_verified.cmake builds for hifive. The board this book uses is therefore not a verified configuration, which is why the lab reads it and does not claim it.

(f) State in one sentence what “hearth is not verified” will mean in chapter 51, using the three boxes of the figure.

Answer

hearth has no abstract-specification box and no refinement arrow from its C to one, so what its tests show is the behaviour of a run, and nothing in the book claims the C does only what a specification allows; the side box (its assembly entry and exit, its boot code and the DTB it is handed, the hardware under it) is the part of hearth that a verified hearth would still have to assume. The refusal is in the spec (docs/superpowers/specs/2026-09-29-hp-course-design.md, “Named refusals (ch 51)”: “a verified hearth”) and in the syllabus’s chapter 51 entry; the figure’s dashed rule is the same sentence.

Lab

A reading lab: nothing boots. Fetch the pinned tree (read-only; nothing in this repository builds it):

C=${XDG_CACHE_HOME:-$HOME/.cache}/hp/ch17
mkdir -p $C && git clone --depth 1 --branch 16.0.0 https://github.com/seL4/seL4 $C/seL4-16.0.0

labs/ch17/README.md lists the six files in the order of the Walkthrough. Read them there, and answer the six exercises with the line that answers each. The exception to “labs boot” is recorded in DECISIONS.md (2026-09-30) as one of Part III’s two reading labs. seL4’s build needs its own toolchain and Python environment, and the chapter’s subject is the statement of the proof, which a sel4test run does not show.

Further reading

results matching ""

    No results matching ""