Finding bugs in microcontroller (MCU) firmware is challenging, even for device manufacturers who own the source code. The MCU runs different instruction sets than x86 and exposes a very different development environment. This invalidates many existing sophisticated software testing tools on x86. To maintain a unified developing and testing environment, a straightforward way is to re-compile the source code into the native executable for a commodity machine (called rehosting). However, ad-hoc re-hosting is a daunting and tedious task and subject to many issues (library-dependence, kernel-dependence and hardware-dependence). In this work, we systematically explore the portability problem of MCU software and propose pararehosting to ease the porting process. Specifically, we abstract and implement a portable MCU (PMCU) using the POSIX interface. It models common functions of the MCU cores. For peripheral specific logic, we propose HAL-based peripheral function replacement, in which high-level hardware functions are replaced with an equivalent backend driver on the host. These backend drivers are invoked by well-designed para-APIs and can be reused across many MCU OSs. We categorize common HAL functions into four types and implement templates for quick backend development. Using the proposed approach, we have successfully rehosted nine MCU OSs including the widely deployed Amazon FreeRTOS, ARM Mbed OS, Zephyr and LiteOS. To demonstrate the superiority of our approach in terms of security testing, we used off-the-shelf dynamic analysis tools (AFL and ASAN) against the rehosted programs and discovered 28 previously-unknown bugs, among which 5 were confirmed by CVE and the other 19 were confirmed by vendors at the time of writing.
翻译:在微控制器(MCU)固件中查找错误是具有挑战性的,即使是拥有源代码的设备制造商也是如此。 MCU运行不同的指令组而不是x86, 并暴露出一个非常不同的开发环境。 这使得在x86上的许多现有尖端软件测试工具失效。 为了保持统一的开发和测试环境, 一种直截了当的方法是将源代码重新编译成本地可操作的商品机器( 称为重新托管) 。 然而, 自动重新托管是一项艰巨和棘手的任务, 并且存在许多问题( library- 依赖性、 内脏依赖性和硬件依赖性 )。 在这项工作中, 我们系统地探索了 MCUC软件的可移动性问题, 并提议利用 POS 界面将一个便携式 MCUCU (PCU) 的可操作性 MCUC 软件重新编译为本地功能。 关于基于 HAL 特定逻辑, 我们建议基于 HAL 的外围功能替换功能, 由主机的等效后端驱动器取代高端硬件功能。 这些后端驱动器被精心操作器被设计好的 AS AS AS- areal- reli- laft laft laft laft laft laft 。