Section 20.11

Tree 11: “What changes on an MCU without process isolation?”

Setting

A sensor gateway is a small device that collects readings from sensors and passes them on. The gateway in this invented example is built on a microcontroller unit §6.1 (MCU): a single chip that holds a processor, its memory and peripherals such as a radio. It accepts a small decision program, delivered through a phone from a publisher, the one party authorized to change the gateway’s rules. The gateway’s own software, the host, runs the decision program, the guest, inside a virtual machine §2.3 (VM), a part of the host that carries out the guest’s instructions one at a time and checks each guest memory access.

The host is one compiled program. It contains a small real-time operating system (RTOS) kernel, which schedules threads, the independently scheduled sequences of execution; a Bluetooth Low Energy (BLE) §7.1 protocol stack, which runs the radio protocol; the VM; and the helper functions §2.19, host routines that the guest may call. All of it runs in one address space, meaning that every part can name every memory address, and all of it runs at the processor’s privileged level, which may configure the hardware. The MCU has no memory management unit §6.9 (MMU), the hardware that gives each process on a desktop computer its own address space. It has a memory protection unit §6.8 (MPU), which can restrict access to a few address ranges, but here the MPU is not configured. A direct memory access §4.36 (DMA) engine copies radio data into memory, and interrupts §6.11, hardware signals that make the processor suspend the current code and run a handler, can arrive at any time.

Short answer

Without process isolation, every native part of the host can read and write all memory, so all of it must be trusted. The guest stays confined only because the VM checks each guest access in software. No boundary stops a bug in the radio stack, the kernel, the VM or a helper; separate threads isolate nothing; and DMA engines and interrupt handlers §6.12 act outside the VM’s checks. Hardware faults and power loss lie outside any software proof and need their own arguments.

Follow-up questions

First answer

The downloaded program can still be isolated, but nothing else is: the only boundary is the checking done by the virtual machine (VM) that runs the program, and every native component is trusted. On a desktop operating system each program runs as a process with its own address space, enforced by a memory management unit (MMU), so a bug in one process cannot write another’s memory. A microcontroller unit (MCU) that runs all its software as one program, in one address space and at one privilege level §6.10, has no such boundary.

Hardware can restore some boundaries if it is configured. A memory protection unit (MPU) can make code read-only, place a protected region beyond the end of each stack, or let selected threads run at the unprivileged level with access to their own regions only. Only boundaries that are configured and enforced count.

Can a guest jump to arbitrary native code?

Not if the virtual machine (VM) controls every transfer of control that the downloaded program, the guest, can make. The guest has two kinds of transfer.

The guest reaches arbitrary native code only through a flaw in design or implementation:

Native code itself is outside this model. On a microcontroller where all native code runs at the privileged level, a compromised native component can rewrite the vector table or switch the memory protection hardware off.

What about DMA and interrupts?

Both act on memory without passing through the checks of the virtual machine (VM) that runs the downloaded program, so both must be modeled as separate actors. A check on the program’s loads and stores mediates neither.

Direct memory access (DMA) is done by a hardware engine that copies data between a peripheral, such as the radio, and memory without the processor executing each transfer. After the software starts a transfer into a buffer, the engine writes that buffer on its own schedule until the transfer completes.

The rule is that a buffer belongs either to the engine or to the software, never to both, and passes back to the software only when the transfer is known to be complete.

An interrupt service routine (ISR) is the function that runs when an interrupt, a hardware signal that suspends the current code, arrives. It can start between any two instructions of the thread it interrupts. If the thread has written an object’s new length but not yet its new data address, the ISR sees a half-updated object. A mutex §9.5, a lock that threads take in turn, does not help: an ISR must not wait, so it cannot take a mutex, and a mutex excludes only code that also takes it. The usual defenses are to disable that interrupt briefly around the update, or to prepare a complete new object and then publish it with a single indivisible write of one pointer. A compiler barrier §4.37 between the two steps keeps the compiler from moving the pointer write ahead of the writes that fill the object.

The model must therefore say, for every buffer, who owns it at each moment and when completion is signaled, and for every shared object, which actors can interrupt an update.

What if hardware faults or power fails?

Then a software proof no longer applies, because it assumes a processor and memory that behave as specified. A bounds proof says that, if every instruction executes as written, no access by the downloaded program leaves its region. It says nothing about:

Each admitted fault belongs in a fault model §1.30, a written list of the faults that the claims cover, and needs its own mechanism. Example: a record holds 8 bytes of data and a 4-byte cyclic redundancy check §4.32 (CRC), a checksum computed from the data. It is written as three 4-byte words, the CRC last, and power fails after the first word. The record now holds the new first half of the data, the old second half and the old CRC. Each half looks valid on its own, but the old CRC was computed from the old data, so it almost certainly does not match the mixture, and the boot code detects the torn record. Keeping two copies with a sequence number lets the boot code choose the newest complete copy. A brownout detector that holds the processor in reset while the voltage is too low, and a watchdog timer §6.16 that restarts a device that stops responding, cover further faults.

A clean software reset and a power loss are different tests. A software reset happens at a point the code chose, with no write in progress unless the code started one. A power loss can strike at any instruction, including in the middle of a flash write. Passing one test says nothing about the other.

Does fail-closed §1.13 always keep the device safe?

No. Fail closed means that when a check fails or cannot be completed, the system takes the restrictive outcome: it refuses the request, or keeps the old state instead of applying a change. It preserves one named property, that the protected action never happens without a successful check, and no other goal.

Before calling a default safe, state three things: which effect it protects, what refusing costs in each situation, and who keeps the authority to recover, by a path that the failing component cannot block.

Related entries: Memory protection unit (MPU) (§6.8), Memory management unit (MMU) (§6.9), Privilege level (§6.10), Interrupt (§6.11), Direct memory access (DMA) (§4.36).