Section 19.5.4

Microkernel, monolithic kernel, and service isolation

Definition

A monolithic kernel and a microkernel are two designs for the kernel, the part of an operating system that runs with full control of memory and hardware. A monolithic kernel runs almost every service in that privileged part, including device drivers §6.38, file systems and network protocols. A microkernel keeps there only what needs full control, such as memory separation, scheduling and message passing, and runs every other service as an ordinary program. Service isolation is the result: each service has its own protected memory and only the rights it needs.

The idea

A device driver is the code that operates one piece of hardware, and it often handles data that an outsider controls. Suppose a USB storage driver copies a descriptor, the short record in which a plugged-in device describes itself, into a fixed-size buffer without checking its length, and a malicious memory stick sends a long descriptor.

In a monolithic kernel the driver runs with full privilege in the kernel’s single memory space, so the excess bytes can overwrite any kernel data, such as the table of running programs or the record of which user owns which program: one driver bug hands over the whole machine. In a microkernel the same driver is an ordinary program in its own address space, the set of memory addresses a program can use. The processor’s memory-protection hardware stops the driver’s writes at the edge of that space, so the overflow corrupts only the driver. A driver taken over by the attacker can do only what the driver’s rights allow: operate its own USB controller and send messages on the channels it was given.

Watertight compartments in a ship are a fair picture: a breach floods one compartment instead of the whole hull. The picture stops being accurate in two respects. If the flooded compartment holds the engine, the ship stops anyway: a service that other services depend on still takes them down when it fails, although it cannot overwrite them. And a compromised service can still give wrong answers to the services that ask it, which no wall prevents.

Monolithic kernels, such as Linux, remain common because one kernel part calls another with an ordinary function call, while a microkernel turns that call into a message between programs, which costs time. Jochen Liedtke, who designed the L4 microkernel, stated the guiding rule in 1995 [443]: a concept belongs inside the microkernel only if moving it outside, so that competing implementations become possible, would prevent the system from providing its required function.

How it works

  1. Two privilege levels §6.10. The processor runs kernel code at a privileged level and all other code at an unprivileged level. Only privileged code may change the memory-protection settings, and unprivileged code reaches only the memory and device registers that those settings allow.

  2. One address space per service. For each service the kernel programs the memory management unit §6.9 (MMU), the hardware that translates and checks every address a program uses, so that the service reaches only its own memory. A microcontroller §6.1 usually has a simpler memory protection unit §6.8 (MPU), which checks addresses against a few regions without translating them. A driver also gets access to the control registers of its own device, which appear at fixed addresses (memory-mapped input/output §4.35).

  3. Messages through the kernel. A service that needs another service sends it a message by interprocess communication §19.5.5 (IPC): the kernel delivers the message to an endpoint, a kernel object that works as a mailbox, switches to the receiver’s address space and runs the receiver, which replies the same way.

  4. Rights as capabilities. The kernel delivers a message only if the sender holds a capability for the endpoint, an unforgeable reference that names the endpoint and grants the right to use it. The kernel thus acts as a reference monitor §1.17, the component that checks every access. The first program that runs after start-up hands each service only the capabilities its job needs: the principle of least privilege §1.15, applied to the whole system.

  5. Faults stop at the boundary. When a service makes an access that its address space does not allow, the hardware raises a fault and the kernel stops that service. A supervising service can restart it: MINIX 3, a small Unix-like microkernel operating system whose name comes from “mini-Unix”, restarts failed drivers in this way.

A monolithic kernel has only step 1. Its drivers, file systems and network code call one another as functions in one privileged address space, and the hardware cannot tell one kernel part from another.

Two things cross every software boundary. The kernel itself runs with full privilege, so a bug in the kernel breaks every isolation. And with direct memory access §4.36 (DMA), a device copies data to and from memory itself, and those accesses do not pass through the MMU or MPU. A driver that programs such a device can tell the device to write anywhere, unless an IOMMU (input-output memory management unit) checks the device’s own accesses. Many microcontrollers have no IOMMU, and their MPU checks only the processor’s accesses.

Worked example

Take a hypothetical system with five software parts, sized in lines of source code, a rough measure of how much code could hold a bug: core kernel functions (scheduling, memory management and message passing), 12,000 lines; a disk driver, 6,000; a file system, 40,000; a network card driver, 9,000; and a network protocol stack, 60,000. The hardware, the boot code and the initial configuration of rights belong to the trusted computing base §1.4 (TCB), the set of parts a security property depends on, of every property below, and are not counted. Assume that an IOMMU confines every device that uses DMA.

Monolithic design. All five parts run with full privilege in one address space. A stray write in any part can change any kernel data, so every part is in the TCB of every property: 12,000+6,000+40,000+9,000+60,000=127,00012{,}000 + 6{,}000 + 40{,}000 + 9{,}000 + 60{,}000 = 127{,}000 lines.

Microkernel design. The microkernel itself has 10,000 lines, and every other part runs as a separate service.

Compared with the 127,000 lines of the monolithic design, the microkernel design relies on 10,000/127,000≈0.0810{,}000 / 127{,}000 \approx 0.08, about 8%, of that code for property 1; on 56,000/127,000≈0.4456{,}000 / 127{,}000 \approx 0.44, about 44%, for property 2; and on 116,000/127,000≈0.91116{,}000 / 127{,}000 \approx 0.91, about 91%, for property 3. Without the IOMMU, the driver of every device that uses DMA would join all three sets. The TCB shrank; it did not disappear, and it differs from property to property.

Stated precisely

Let PP be a security property of a system whose components are the hardware, the boot code, the kernel, the services and the initial configuration of rights. A set TT of components is a trusted computing base for PP when PP holds in every run in which each component in TT behaves as its specification says, whatever the components outside TT do. Designers try to make TT small, because every member of TT must be correct for PP to hold.

A microkernel design claims the following. For the isolation property, that the memory and rights of a service change only through kernel operations authorized by capabilities, the trusted computing base is Tiso={hardware,boot code,kernel,initial configuration}∪D,T_{\text{iso}} = \{\text{hardware},\ \text{boot code},\ \text{kernel},\ \text{initial configuration}\} \cup D, where DD is the set of drivers for devices that use DMA and that no IOMMU confines. For any other property PP, the trusted computing base is Tiso∪SPT_{\text{iso}} \cup S_P, where SPS_P is the set of services whose behavior PP depends on. TisoT_{\text{iso}} is never empty, so no kernel design removes the TCB.

The seL4 microkernel, a member of the L4 family, shows how far the kernel’s own share can be checked. Machine-checked proofs show that seL4’s C code behaves as its abstract specification says, a relation called refinement, and that the specification enforces integrity, meaning a component changes only what its capabilities allow, and confidentiality §1.8, meaning one component learns nothing about another through the kernel unless the configuration allows it. On processor architectures that the project’s binary verification supports, the result extends to the compiled machine code, so the compiler need not be trusted. The seL4 project lists what the proofs assume:

The proofs say nothing about the services that run on the kernel, and they hold only for the verified platforms and configurations.

Limits and common mistakes

A microkernel moves services out of the privileged part; it does not make them trustworthy. A file system that runs as an ordinary program is still in the TCB of every property about files.

Memory isolation is not isolation of effects. A compromised service can still return wrong data, stop answering, use up the resources it was given and misuse every capability it holds. A service that acts for a client with its own broader rights, instead of the client’s, is a confused deputy §1.25.

A service that crashes cleanly still stops the work that depends on it. Restarting it restores availability only if its state can be rebuilt and its clients repeat their requests.

Isolation costs time and memory. Every request between services becomes interprocess communication, with kernel entries, address-space switches and copying, and every service needs its own stack and memory regions. An MPU has few regions, typically 8 or 16, and the MPU of the Armv7-M architecture, used in many microcontrollers, requires each region’s size to be a power of two and its start address a multiple of that size, which wastes memory and limits how many services can be separated at once.

A wrong configuration undoes the design: a service that receives capabilities for everything is isolated in name only. And microkernel names an architecture, not a guarantee: the seL4 proofs do not carry over to another microkernel.

Questions answered

Does a microkernel eliminate the TCB?

No. A microkernel shrinks the privileged part of an operating system, but the trusted computing base (TCB), the set of hardware, software and configuration that a security property depends on, never becomes empty. The kernel, the hardware, the boot code and the configuration that hands out rights are in the TCB of every property. The TCB is also defined per property, and it includes every service that the property depends on, whether that service runs inside the kernel or as an isolated program: a property about stored files depends on the file system and the disk driver. The driver of a device that writes memory by direct memory access (DMA), with no IOMMU (input-output memory management unit) to confine the device, stays in the TCB as well.

What a microkernel does is make the part trusted for isolation small, small enough to verify formally, as was done for the seL4 microkernel, and keep services that a property does not depend on out of that property’s TCB. Even the seL4 proofs rest on stated assumptions, including correct hardware, correct boot and assembly code, and devices that do not misuse DMA.

Related entries: Trusted computing base (TCB) (§1.4), Trust boundary (§1.3), Least privilege (§1.15), Capability security (§1.40), Memory protection unit (MPU) (§6.8), Memory management unit (MMU) (§6.9), Direct memory access (DMA) (§4.36), Interprocess communication and authority transfer (§19.5.5). Further reading: [156, 443].