Section 21.4

Femto-Containers: small functions rather than whole process containers

Full name: Femto-Containers is a coined name, not an abbreviation. Femto is the metric prefix for one quadrillionth, 10−1510^{-15}; container refers to the software containers of larger computers, such as those that Docker runs, which the paper names among the tools that do not fit microcontrollers §6.1.

What it is

Femto-Containers is a runtime, software that loads, isolates and runs other code, for small functions on microcontrollers: single-chip computers with tens to hundreds of kilobytes of memory. Each function is compiled to eBPF §2.1 (extended Berkeley Packet Filter) bytecode §2.4, instructions for a virtual machine §2.3, and the runtime executes it when a chosen event occurs, checking every memory access. Koen Zandberg, Emmanuel Baccelli, Shenghao Yuan, Frédéric Besson and Jean-Pierre Talpin published it at the Middleware conference in 2022. It addresses installing, updating and isolating such functions over a network.

Basis of this account

This account rests on the authors’ preprint, the version they posted on the public arXiv server: arXiv:2210.03432, version 1 of 7 October 2022. The preprint asks to be cited as the paper in the proceedings of the 23rd ACM/IFIP Middleware conference, November 2022, where ACM is the Association for Computing Machinery and IFIP the International Federation for Information Processing. The published text was not compared. The parts read were the abstract and the sections on use cases, threat model §1.2, design requirements, the comparison of candidate runtimes, the implementation, the example applications and the formal verification, together with the measurements of hook cost and of several containers on one device. The related work, the other measurements and the appendix were not examined. Nothing was run.

What the paper claims

The authors make these claims.

How it works

The firmware of RIOT contains fixed points at events such as the arrival of a network packet, a sensor reading, a timer or a switch between threads. The paper calls them hooks or launch pads §14.26. A hook fills a small context structure, for example with the identifiers of the previous and the next thread, and calls the hosting engine, the part of Femto-Containers that runs every function attached to that hook. Where the hook allows it, the function’s result changes what the firmware does next. A new function can be attached without changing the firmware; a new hook needs a firmware update.

One function goes through these steps.

  1. Install. The bytecode arrives over CoAP (Constrained Application Protocol), a lightweight web protocol for small devices. It comes with a SUIT (Software Updates for Internet of Things) manifest §13.4, a signed description of the update that lets the device check its authenticity and integrity §1.9. The manifest names the hook by a unique identifier. The device downloads the new function into RAM before updating the hook to use it.

  2. Pre-flight check. Before the first run, a checker reads every instruction. Each register field must name one of the eleven registers. Register r10, which points to the function’s stack, must never be written. Every jump target must lie inside the function’s own code; the instruction set has no computed jumps, so every target is known before the run.

  3. Run. When the hook fires, the interpreter executes the instructions through a jump table §2.39 that holds one handler per operation code §2.8. The function has eleven 64-bit registers, a 512-byte stack and no heap. Nothing can break into the function’s own control flow, because the virtual machine offers no interrupts §6.11.

  4. Memory check. A load or store computes its address at run time, so the interpreter compares every address with the function’s stack and with an allow list: memory regions that the host grants to this function, each marked readable, writable or both. A packet filter, for example, can be given read-only access to the packet. An access outside these regions aborts the run.

  5. Limits. The engine limits the number of instructions in a function, NiN_i, and the number of branch instructions that a run may execute, NbN_b. The paper states that this bounds a run to Ni×NbN_i \times N_b instructions.

  6. Host access. The function reaches peripherals and operating system services only through system calls, made with the eBPF call instruction. The paper calls the agreement between host and function a contract: the operating system offers a set of permissions at each hook, the function asks for a set, and the engine grants their intersection.

  7. State. Values that must outlive a run, that is, guest persistent state §2.36, go into key-value stores, also reached through system calls. One store is private to the function, one is shared by all functions, and an optional third is shared by the functions of one tenant.

Worked example

The numbers are invented for teaching; the mechanism is the paper’s. A function attached to the packet hook may read a 64-byte packet that starts at address 0x20000400. Its allow list therefore holds one read-only region, addresses 0x20000400 to 0x2000043F.

Now take Ni=200N_i = 200 instructions and Nb=100N_b = 100 branch instructions, again invented values. Between two branch instructions the interpreter only moves forward, so one stretch of straight-line execution runs each of the at most 200 instructions at most once. A run has at most Nb+1=101N_b + 1 = 101 such stretches: one ending at each of the 100 permitted branches and one after the last. It therefore executes at most 101×200=20,200101 \times 200 = 20{,}200 instructions. This is the paper’s product, 200×100=20,000200 \times 100 = 20{,}000, plus the final stretch. If one interpreted instruction took 1 microsecond, an invented figure, the run would end within about 20.2 milliseconds. Time spent inside system calls comes on top: a system call is one counted instruction, but its native code runs outside the count.

What this account does not establish

The results are the authors’ measurements, and this account did not reproduce them.

Isolation rests on correct allow lists, as the paper itself notes. A region granted by mistake is open to the function.

The verification covers the interpreter and the pre-flight checker. In the parts read, the paper does not extend it to the system calls, the hooks, the key-value stores or the installation path, which are ordinary operating system code.

The limits on instructions are an instruction budget §2.32, not a time limit. The time per instruction on a given processor and the time of every system call must be added before a deadline can be checked.

Permissions are coarse. The paper names as a limitation that each hook has one fixed set of permissions, so two tenants who need different permissions at the same event need two hooks, and hooks are fixed when the firmware is built.

The functions and the key-value stores of the measured system live in RAM. The parts read do not describe keeping them across a restart.

The isolation guarantee concerns memory and faults: a function cannot reach memory it was not granted. It says nothing about whether the function computes the right result, or about what a permitted system call does with the arguments it receives.

Questions answered

Why is a tiny function runtime different from a Linux container?

A tiny function runtime differs from a Linux container because it isolates one short function by checking each of its instructions in software, while a Linux container isolates a group of ordinary programs with the operating system kernel and the processor’s memory hardware. A Linux container is a set of processes, running programs, to which the Linux kernel gives separate namespaces, meaning their own view of process numbers, files, network interfaces and host name, and which it places in a cgroup §13.20 (control group) that limits processor time and memory. A tiny function runtime such as Femto-Containers (Zandberg and others, 2022) runs one small function, compiled to eBPF (extended Berkeley Packet Filter) bytecode, inside the operating system of a microcontroller. The two differ in six respects.

The difference cuts both ways. A small instruction set with checked memory accesses keeps the isolating code small enough to verify formally: the interpreter and checker of Femto-Containers are about 500 lines of C with a machine-checked proof. But the function gets none of the abstractions that an operating system gives a container, such as files, processes and network connections. Whatever it needs must be offered as a host service, and every such service lies outside that proof and must be checked on its own.

Related entries: Virtual machine (VM) (§2.3), Overflow-safe range check (§4.17), CertrBPF: connecting a VM specification to generated C (§21.3), Sandbox (§2.30), Software fault isolation (SFI) (§2.41), Instruction budget (fuel) (§2.32), Guest persistent state (§2.36), cgroup (§13.20), Memory management unit (MMU) (§6.9), Probe and hook (§14.26). Further reading: [206].