Minimal Virtual Machines on IoT Microcontrollers: The Case of Berkeley Packet Filters with rBPF

Koen Zandberg, Emmanuel Baccelli

TL;DR

This paper explores using minimal virtual machines (VMs) on resource-constrained IoT microcontrollers for secure code isolation. They introduce rBPF, a register-based VM derived from eBPF, and compare its performance and memory footprint against a WebAssembly (Wasm) VM. The findings suggest rBPF offers a compelling solution for isolating small, updatable IoT modules with significantly lower memory overhead than Wasm.

What Problem Does This Paper Address?

The proliferation of Internet of Things (IoT) devices, built on low-power, memory-limited microcontrollers, presents a growing security challenge. While virtual machines (VMs) are a standard approach for isolating software modules and enhancing security in larger systems, their substantial memory and processing requirements have historically made them impractical for these tiny embedded devices. This paper addresses the need for lightweight, software-only VM solutions that can provide process isolation on microcontrollers, enabling secure execution of potentially untrusted or updatable code without requiring specialized hardware. This is crucial for mitigating various IoT attacks and establishing a root of trust.

Methods

The authors investigate two minimal VM approaches:

  • WebAssembly (Wasm): They use the WASM3 interpreter, a stack-based VM designed for portability and sandboxing. Wasm applications are compiled from various languages (like C/C++, Rust) to Wasm bytecode, which is then interpreted.
  • rBPF (register-based Berkeley Packet Filter): This is a novel VM designed by the authors, based on the extended Berkeley Packet Filter (eBPF) architecture. Unlike Wasm's stack-based model, rBPF is register-based, aiming for a minimal memory footprint. They adapted eBPF to be ISA-compatible and integrated it into the RIOT IoT operating system, providing bindings for OS facilities and event triggers.

Both VMs were implemented and tested on commercial off-the-shelf IoT hardware (Nordic nRF52840 Development Kit). They designed two benchmarks: a computational benchmark (Fletcher32 checksum) to assess basic VM performance and memory impact, and a networked benchmark simulating a CoAP-based sensor reading application to evaluate real-world IoT use cases.

Datasets

Not discussed in the paper. The evaluation uses custom benchmarks and real-world IoT application scenarios rather than pre-existing datasets.

Key Insights and Ideas

  • Memory Footprint is King for IoT: The most striking insight is the dramatic difference in memory requirements. While Wasm VMs can double the firmware size for a simple IoT application, rBPF adds only a negligible amount of memory overhead (less than 10%). This is a critical differentiator for resource-constrained devices.
  • rBPF's Register-Based Architecture Pays Off: The register-based design of rBPF, in contrast to Wasm's stack-based approach, significantly reduces the pressure on RAM. This is a key factor in its superior memory efficiency.
  • Tolerable Performance for Specific IoT Tasks: While both VMs introduce execution time overhead compared to native code, this overhead is deemed tolerable for low-throughput, low-energy IoT applications. rBPF is about twice as slow as Wasm for the tested checksum algorithm, but both are orders of magnitude slower than native execution.
  • rBPF Offers a Promising Software-Only Isolation: rBPF provides a viable software-only solution for isolating small, updatable modules without requiring specialized hardware, making it more accessible and adaptable than hardware-based solutions.
  • Script Size Matters for Updates: For over-the-air updates, the size of the code to be transferred is important. While Wasm scripts were slightly smaller than rBPF scripts in their tests, the overall firmware size increase with Wasm makes rBPF more attractive for frequent updates.

Key Results

  • Flash Memory: The WASM3 interpreter is 15 times larger than the rBPF interpreter in terms of ROM size. Adding an rBPF VM to a typical IoT application adds less than 10% to the firmware size, while a Wasm VM more than doubles it.
  • RAM Memory: For a simple networked IoT application, Wasm requires doubling the memory budget, whereas rBPF requires only a negligible increase (e.g., 16B for additional memory access regions).
  • Execution Time: For the Fletcher32 checksum, rBPF execution was approximately 2 times slower than Wasm. Both VMs were significantly slower than native C code (Wasm ~35x, rBPF ~70x slower). However, rBPF still achieves around 1.3 million instructions per second, sufficient for many IoT tasks.
  • Script Size for Updates: Wasm scripts were about 30% smaller than rBPF scripts for the Fletcher32 example.
  • Networked Application: A sensor reading application compiled to rBPF bytecode was 296 B, with an execution overhead of 94 µs. The full firmware image with the rBPF interpreter was 69 KiB. This is significantly smaller than a comparable JavaScript solution mentioned in prior work, which required a 156 KiB engine.

Limitations and Future Work

  • Execution Time Overhead: The authors acknowledge that VMs inherently introduce execution overhead, impacting power consumption. While they argue this is manageable for low-throughput tasks, they suggest future work could involve hardware acceleration (MPU/MMU) or ahead-of-time transpilation to native code for performance-critical scenarios.
  • Wasm RAM Usage: The significant RAM requirements of Wasm (64 KiB pages) are a major limitation for microcontrollers. Future work could explore alternative Wasm interpreters (e.g., WAMR, WARDuino) or adaptations to reduce memory page sizes.
  • rBPF Script Size: While rBPF excels in memory footprint, its script sizes can be larger than Wasm. The authors suggest using compression algorithms like Heatshrink to reduce script size by up to 60%.
  • CPU Time Capping: The current rBPF design does not limit the CPU time a single VM invocation can consume, potentially draining batteries. Capping CPU time is identified as a crucial next step for extending sandboxing guarantees.
  • Generalizability: While the paper uses RIOT OS, the approach is presented as applicable to other similar OSes. Further validation on a wider range of IoT hardware and operating systems would be beneficial.

Summary updated

Abstract

Virtual machines (VM) are widely used to host and isolate software modules. However, extremely small memory and low-energy budgets have so far prevented wide use of VMs on typical microcontroller-based IoT devices. In this paper, we explore the potential of two minimal VM approaches on such low-power hardware. We design rBPF, a register-based VM based on extended Berkeley Packet Filters (eBPF). We compare it with a stack-based VM based on We-bAssembly (Wasm) adapted for embedded systems. We implement prototypes of each VM, hosted in the IoT operating system RIOT. We perform measurements on commercial off-the-shelf IoT hardware. Unsurprisingly, we observe that both Wasm and rBPF virtual machines yield execution time and memory overhead, compared to not using a VM. We show however that this execution time overhead is tolerable for low-throughput, low-energy IoT devices. We further show that, while using a VM based on Wasm entails doubling the memory budget for a simple networked IoT application using a 6LoWPAN/CoAP stack, using a VM based on rBPF requires only negligible memory overhead (less than 10% more memory). rBPF is thus a promising approach to host small software modules, isolated from OS software, and updatable on-demand, over low-power networks.
BibTeX
@inproceedings{zandberg2020minimal,
  author = {Koen Zandberg and Emmanuel Baccelli},
  title = {{Minimal Virtual Machines on IoT Microcontrollers: The Case of Berkeley Packet Filters with rBPF}},
  booktitle = {PEMWN},
  year = {2020},
  url = {https://openreview.net/forum?id=YXFHKhTpEP},
}
Figure