An Automated Approach to Re-Hosting Embedded Firmware Through Removing Hardware Dependencies.

Austin Ketterer, Asha Shekar, Edgardo Barsallo Yi, Saurabh Bagchi, Abraham Anthony Clements2022 · DOI

TL;DR

Re-hosting embedded firmware in emulators is often a manual, "trial-and-error" nightmare because of complex hardware dependencies. This paper introduces an automated approach that uses graph-cut algorithms and simulated annealing to identify the optimal boundary where hardware-dependent code can be swapped for high-level models, significantly reducing the manual effort required for firmware security testing.

What Problem Does This Paper Address?

Embedded systems are everywhere, but testing their firmware is difficult. You either need the physical hardware (which doesn't scale) or an emulator like QEMU. While QEMU is great at emulating CPUs, it lacks support for the thousands of unique peripherals (sensors, radios, timers) found in the wild.

To get around this, researchers use "re-hosting"—running the firmware in a virtual environment by replacing hardware-dependent code with high-level software models. However, deciding which functions to replace is currently a slow, manual process: you run the firmware until it crashes, identify the hardware dependency, write a model, and repeat. This paper aims to automate that decision-making process.

Methods

The authors treat the firmware binary as a mathematical graph where nodes are functions and edges are function calls. Their approach follows four main steps:

  1. Graph Construction: Using Ghidra, they perform static binary analysis to build a Control Flow Graph (CFG) and a Data Flow Graph (DFG).
  2. Node Classification: They categorize functions into four groups:
  3. Must Retain: Core logic the user wants to test.
  4. Must Remove: Functions that directly touch hardware (identified via memory-mapped I/O addresses).
  5. Suggested Retain/Remove: Functions in the "middle" that could go either way.
  6. Weighting: They assign a "cost" to each node based on two factors:
  7. Effort: How hard is it to write a proxy for this function? (e.g., functions that write to global memory are harder to model).
  8. Utility: How much of the original code's functionality is preserved if we keep this node?
  9. Optimization: They use a Min-Cut algorithm to find the initial "cheapest" boundary to separate hardware from logic. They then refine this using Simulated Annealing, an iterative optimization technique that helps find "better" solutions by escaping local minima in the graph.

Datasets

The researchers evaluated their approach using several real-world firmware sets:

  • STM32-Cube HAL library: Standard firmware for STM32F4 boards.
  • STM Nucleo programs: A selection of programs previously used in the "Pretender" re-hosting project.
  • Atmel Advanced Software Framework: Firmware for SAM R21 boards.
  • Specific applications included UART-printf, FatFS (file system), and various network stacks (UDP/TCP echo clients and servers).

Key Insights and Ideas

  • The "Effort vs. Utility" Trade-off: The core "aha" moment is that re-hosting isn't just about removing hardware calls; it's about finding the point of least resistance. If a function is "leaky" (affects global state), it's a bad candidate for removal because your manual model would have to be incredibly complex to maintain that state.
  • Scaling the Problem: By targeting the Hardware Abstraction Layer (HAL) rather than individual hardware registers, the problem scales from supporting 10,000+ unique devices to supporting just a few dozen HALs.
  • Policy-Driven Emulation: The system allows users to set a "policy" (via weights), letting them choose whether they want a high-fidelity emulation (more manual work, more original code) or a quick-and-dirty version (less work, more modeled code).

Key Results

  • Monotonic Scaling: The evaluation showed that as the "Utility" weight increases, the proportion of nodes retained increases predictably, proving the algorithm behaves logically across different firmware vendors.
  • Efficiency: The Min-Cut algorithm is extremely fast (under 0.2 seconds), while even the most complex Simulated Annealing runs (100,000 iterations) finished in about 98 seconds.
  • Manual Work Reduction: In a manual example (UDP-echo-client), the algorithm suggested a cut that required implementing only one node on the boundary instead of four, significantly reducing the developer's workload.
  • Static Analysis Limits: The authors quantified how much static analysis misses. For example, they had to write custom scripts to handle "ARM Thumb mode" addressing, which standard tools often misinterpret.

Limitations and Future Work

  • Static Analysis Imperfection: The approach relies heavily on Ghidra. If the binary analysis fails to resolve a pointer or a function call (common in complex C++ or obfuscated code), the resulting graph—and the "cut"—will be inaccurate.
  • Thumb Mode Complexity: Handling the +1 pointer offset in ARM Thumb mode remains a subtle challenge for automated tools.
  • Comparison Difficulties: The authors noted it is difficult to perform a direct head-to-head comparison with the original HALucinator because that tool didn't share the same explicit goal of removing all hardware interactions.
  • Future Direction: Integrating this automated "cutting" directly into an emulation loop to provide real-time suggestions to researchers as they develop hardware models.

Summary updated

Abstract

Enables replacing HALs and other libraries with high level implementations.This transforms the re-hosting scaling problem from supporting 10,000's of devices to dozens of HALs. Contributions of this Paper1. We aid high level emulation in deciding which functions to model.This enables one to partition a firmware such that it is decoupled from its hardware dependencies yet retains its core functionality.2. We provide a policy-driven approach for users to indicate what part of the emulation needs to be performed with fidelity and what parts can be skipped.3. We perform binary analysis on the firmware to determine the types of dependencies present and decide which need to be removed.4. We show that our approach enables high level emulation of various firmware from Atmel and STMicroelectronics using HALucinator. Key Intuition #1-This algorithm is based off of the idea that the firmware can be represented as a graph, where each node is a function and each edge is a call.-In this graph, if we can identify what nodes need to be removed, we can come up with the best way to remove them Functions to be replaced by proxies/models Key Intuition #2 -The difficulty to remove the node is not constant across nodes.-Some nodes are more complex, or have more data dependencies that escape their context.-This means we need both a Control Flow Graph (CFG) for functions and calls, and a Data Flow Graph (DFG) to look at data dependencies.Function to be replaced by proxies/models How difficult is it to model E?
BibTeX
@misc{ketterer2022automated,
  author = {Austin Ketterer and Asha Shekar and Edgardo Barsallo Yi and Saurabh Bagchi and Abraham Anthony Clements},
  title = {{An Automated Approach to Re-Hosting Embedded Firmware Through Removing Hardware Dependencies.}},
  year = {2022},
  doi = {10.2172/2006057},
}

Loading related content...

Figure