SyzTrust - State-Aware Fuzzing On Trusted OS Designed For IoT Devices
SyzTrust - State-Aware Fuzzing On Trusted OS Designed For IoT Devices
Qinying Wang∗† , Boyu Chang∗ , Shouling Ji∗( ), , Yuan Tian‡ , Xuhong Zhang∗ , Binbin Zhao§ , Gaoning Pan∗ ,
Chenyang Lyu∗ , Mathias Payer† , Wenhai Wang∗ , Raheem Beyah§
∗ Zhejiang
University, † EPFL, ‡ University of California, Los Angelos, § Georgia Institute of Technology
E-mails: {wangqinying, bychang, sji}@zju.edu.cn, [email protected], [email protected], [email protected],
{pgn, puppet}@zju.edu.cn, [email protected], [email protected], [email protected]
arXiv:2309.14742v1 [cs.CR] 26 Sep 2023
Abstract—Trusted Execution Environments (TEEs) embedded Samsung have designed TEEs for low-end Microcontroller
in IoT devices provide a deployable solution to secure IoT Units (MCUs) [20], [57], [61] and device manufacturers
applications at the hardware level. By design, in TEEs, the have embedded the TEE in IoT devices such as unmanned
Trusted Operating System (Trusted OS) is the primary com- aerial vehicles and smart locks, to protect sensitive data and
ponent. It enables the TEE to use security-based design tech- to provide key management services. A TEE is composed of
niques, such as data encryption and identity authentication. Client Applications (CAs), Trusted Applications (TAs), and
Once a Trusted OS has been exploited, the TEE can no a Trusted Operating System (Trusted OS). Among them, the
longer ensure security. However, Trusted OSes for IoT devices Trusted OS is the primary component to enable the TEE
have received little security analysis, which is challenging using security-based design techniques, and its security is
from several perspectives: (1) Trusted OSes are closed-source the underlying premise of a reliable TEE where the code and
and have an unfavorable environment for sending test cases data are protected in terms of confidentiality and integrity.
and collecting feedback. (2) Trusted OSes have complex data Unfortunately, implementation flaws in Trusted OSes violate
structures and require a stateful workflow, which limits existing the protection guarantees, bypassing confidentiality and in-
vulnerability detection tools. tegrity guarantees. These flaws lead to critical consequences,
To address the challenges, we present S YZ T RUST, the including sensitive information leakage (CVE-2019-25052)
first state-aware fuzzing framework for vetting the security of
and code execution within the Trusted OS context [13],
[42]. Once attackers gain control of Trusted OSes, they can
resource-limited Trusted OSes. S YZ T RUST adopts a hardware-
launch critical attacks, such as creating a backdoor to the
assisted framework to enable fuzzing Trusted OSes directly
Linux kernel [12], and extracting full disk encryption keys
on IoT devices as well as tracking state and code coverage
of Android’s KeyMaster service [11].
non-invasively. S YZ T RUST utilizes composite feedback to guide
While TEEs are increasingly embedded in IoT devices,
the fuzzer to effectively explore more states as well as to
the security of Trusted OS for IoT devices remains under
increase the code coverage. We evaluate S YZ T RUST on Trusted
studied. Considering the emerging amount of diversified
OSes from three major vendors: Samsung, Tsinglink Cloud, MCUs and IoT devices, manual analysis, such as reverse
and Ali Cloud. These systems run on Cortex M23/33 MCUs, engineering, requires significant expert efforts and is there-
which provide the necessary abstraction for embedded TEEs. fore infeasible at scale. Recent academic works use fuzzing
We discovered 70 previously unknown vulnerabilities in their to automate TEE testing. However, unlike Trusted OSes
Trusted OSes, receiving 10 new CVEs so far. Furthermore, for Android devices, Trusted OSes for IoT devices are
compared to the baseline, S YZ T RUST has demonstrated sig- built on TrustZone-M with low-power and cost-sensitive
nificant improvements, including 66% higher code coverage, MCUs, including NuMicro M23. Thus, Trusted OSes for
651% higher state coverage, and 31% improved vulnerability- IoT devices are more hardware-dependent and resource-
finding capability. We report all discovered new vulnerabilities constrained, complicating the development of scalable and
to vendors and open source S YZ T RUST. usable testing approaches with different challenges. In the
following, we conclude two challenges for fuzzing IoT
1. Introduction Trusted OSes.
Challenge I: The inability of instrumentation and re-
Trusted Execution Environments (TEEs) are essential stricted environment. Most Trusted OSes are closed-
to securing important data and operations in IoT devices. source. Additionally, TEE implementations, especially the
GlobalPlatform, the leading technical standards organiza- Trusted OSes are often encrypted by IoT vendors, which
tion, has reported a 25-percent increase in the number implies the inability to instrument and monitor the code ex-
of TEE-enabled IoT processors being shipped quarterly, ecution in the secure world. Accordingly, classic feedback-
year-over-year [29]. Recently, major IoT vendors such as driven fuzzing cannot be directly applied to the scenario
of testing TEEs including TAs and Trusted OSes. Existing
Shouling Ji is the corresponding author. works either rely on on-device binary instrumentations [15]
1
or require professional domain knowledge and rehosting IoT devices is resource constrained, which makes storing
through proprietary firmware emulation [32] to enable test- ETM traces on board difficult and limits the fuzzing speed.
ing and coverage tracking. However, as for the Trusted OSes Additionally, the TEE internals are complicated and have
designed for IoT devices, the situation is more challenging multiple components, which generate noisy trace packets.
due to the following two reasons. First, IoT devices are Therefore, we offload heavy-weight tasks to a PC and care-
severely resource-limited, while existing binary instrumen- fully scheduled the fuzzing subprocesses in a more parallel
tations are heavy-weight for them and considerably limit way. We also present an event- and address-based trace filter
their execution speed. Second, as for rehosting, IoT devices to handle the noisy trace packets that are not executed by
are mostly hardware-dependent, rendering the reverse en- the Trusted OS. Additionally, we adopt an efficient code
gineering and implementation effort for emulated software coverage calculation algorithm directly on the raw packets.
and hardware components unacceptable. In addition, rehost- Second, as for the Challenge II, the vulnerability detec-
ing faces the limitation of the inaccuracy of modeling the tion capability of coverage-based fuzzers is limited, and a
behavior of hardware components. To our best knowledge, more effective fuzzing strategy is required. Therefore, we
the only existing TEE rehosting solution PartEmu [32] is propose a composite feedback mechanism, which enhances
not publicly available and does not support the mainstream code coverage with state feedback. To be specific, we utilize
TEE based on Cortex-M MCUs designed for IoT devices. state variables that control the execution contexts to present
Challenge II: Complex structure and stateful work- the states of a Trusted OS. However, such state variables are
flow. Trusted OSes for IoT devices are surprisingly com- usually stored in closed-source and customized data struc-
plex. Specifically, Trusted OSes implement multiple cryp- tures within Trusted OSes. Existing state variable inference
tographic algorithms, such as AES and MAC, without un- methods either use explicit protocol packet sequences [45]
derlying hardware support for these algorithms as would or require source codes of target software [35], [68], which
be present on Cortex-A processors. To implement these are unavailable for Trusted OSes. Therefore, to identify the
algorithms in a secure way, Trusted OSes maintain several state-related members from those complex data structures,
state diagrams to store the execution contexts and guide the S YZ T RUST collects some heuristics for Trusted OS and
execution workflow. To explore more states of a Trusted utilizes them to perform an active state variable inference
OS, a fuzzer needs to feed syscall sequences in several algorithm. After that, S YZ T RUST monitors the state variable
specific orders with different specific state-related argument values during the fuzzing procedure as the state feedback.
values. Without considering such statefulness of Trusted Finally, S YZ T RUST is the first end-to-end solution ca-
OSes, coverage-based fuzzers are unlikely to explore further pable of fuzzing Trusted OSes for IoT devices. Moreover,
states, causing the executions to miss the vulnerabilities the design of the on-device fuzzing framework and modular
hidden in a deep state. Unfortunately, existing fuzzing tech- implementation make S YZ T RUST more extensible. With
niques lack state-awareness for Trusted OSes. Specifically, several MCU-specific configurations, S YZ T RUST scales to
they have trouble understanding which state a Trusted OS Trusted OSes on different MCUs from different vendors.
reaches since there are no rich-semantics response codes to
Evaluation. We evaluate S YZ T RUST on real-world Trusted
indicate it. In addition, due to the lack of source code and
OSes from three leading IoT vendors Samsung, Tsinglink
the inability of instrumentation, it is hard to infer and extract
Cloud, and Ali Cloud. The evaluation result shows that
the state variables by program analysis.
S YZ T RUST is effective at discovering new vulnerabilities
Our solution. To address the above key challenges, we pro-
and exploring new states and codes. As a result, S YZ T RUST
pose and implement S YZ T RUST, the first fuzzing framework
has discovered 70 new vulnerabilities. Among them, vendors
targeting Trusted OSes for IoT devices, supporting state and
confirmed 28, and assigned 10 CVE IDs. The vendors
coverage-guided fuzzing. Specifically, we propose an on-
are still investigating others. Compared to state-of-the-art
device fuzzing framework and leverage a hardware-in-the-
approaches, S YZ T RUST finds more vulnerabilities, hits 66%
loop approach. To support in-depth vulnerability detection,
higher code branches, and 651% higher state coverage.
we propose a composite feedback mechanism that guides the
fuzzer to explore more states and increase code coverage. Summary and contributions.
S YZ T RUST necessitates diverse contributions. First, to • We propose S YZ T RUST, the first fuzzing framework
tackle Challenge I, we propose a hardware-assisted fuzzing targeting Trusted OSes for IoT devices, supporting effective
framework to execute test cases as well as collect code state and code coverage guided fuzzing. With a carefully
coverage feedback. Specifically, we decouple the execution designed hardware-assisted fuzzing framework and a com-
engine from the rest of the fuzzer to enable directly exe- posite feedback mechanism, S YZ T RUST is extensible and
cuting test cases in the protective TEE secure world on the configurable to different IoT devices.
resource-limited MCU. To support coverage tracking, we • With S YZ T RUST, we evaluate three popular Trusted
present a selective trace collection approach instead of costly OSes on three leading IoT vendors and detect several
code instrumentation to enable tracing instructions on a previously unknown bugs. We have responsibly reported
target MCU. In particular, we leverage the ARM Embedded these vulnerabilities to the vendors and got acknowledged
Trace Macrocell (ETM) feature to collect raw trace packets from vendors such as Samsung. We release S YZ T RUST
by monitoring instruction and data buses on MCU with as an open-source tool for facilitating further studies at
a low-performance impact. However, the Trusted OS for https://github.com/SyzTrust.
2
Normal World Secure World 2.2. Debug Probe
Client Applications (CAs) Trusted Applications (TAs) A debug probe is a special hardware device for low-
CA CA CA TA TA TA level control of ARM-based MCUs, using DAP (Debug
Access Port) provided by the ARM CoreSight Architecture
[25]. It bridges the connection between a computer and an
TEE Client API TEE Internal API MCU and provides full debugging functionality, including
Rich OS Switch
watchpoints, flash memory breakpoints, memory, as well as
Trusted OS
(e.g., FreeRTOS) Instructions register examination or editing. In addition, a debug probe
can record data and instruction accesses at runtime through
Figure 1: Structure of TrustZone-M based TEE. the ARM ETM feature. ETM is a subsystem of ARM
Coresight Architecture and allows for traceability, whose
function is similar to Intel PT. The ETM generates trace
elements for executed signpost instructions that enable
2. Background reconstruction of all the executed instructions. Utilizing the
above features, the debug probe has shown its effectiveness
in tracing and debugging malware [49], unpacking Android
apps [65], or fuzzing Linux peripheral drivers [37].
2.1. TEE and Trusted OS
3. Threat Model
A TEE is a secure enclave on a device’s main processor Our attacker tries to achieve multiple goals: gaining
that is separated from the main OS. It ensures the confiden- control over, extracting confidential information from, and
tiality and integrity of code and data loaded inside it [64]. causing crashes in other Trusted Applications (TAs) hosted
For standardizing the TEE implementations, GlobalPlatform on the same Trusted OS or the Trusted OS itself. We
(GP) has developed a number of specifications. For instance, consider two practical attack scenarios. First, an attacker can
it specifies the TEE Internal Core API implemented in the exploit our discovered vulnerabilities by providing carefully
Trusted OS to enable a TA to perform its security functions crafted data to a TA. They can utilize a malicious Client
[30]. However, it is difficult for vendors to implement a Application (CA) to pass the crafted data to a TA. For
Trusted OS correctly since there are lots of APIs with instance, in mTower, CVE-2022-38511 (ID 1 in Table 1)
complex and stateful functions defined in the GP TEE spec- can be triggered by passing a large key size value from a
ifications. For instance, the TEE Internal Core API defines CA to a TA. Second, an attacker can exploit our discovered
six types of APIs, including cryptographic operations APIs vulnerabilities by injecting a malicious TA into the secure
supporting more than 20 complex cryptographic algorithms. world. They can do this through rollback attacks or electro-
In addition, the TEE Internal Core API also requires that a magnetic fault injections (CVE-2022-47549).
Trusted OS shall implement state diagrams to manage the
operation. The two aforementioned factors make it challeng- 4. Design
ing for device vendors to develop a secure Trusted OS.
ARM TrustZone has become the de-facto hardware tech- Figure 2 gives an overview of S YZ T RUST’s design.
nology to implement TEEs in mobile environments [17] and S YZ T RUST includes two modules: the fuzzing engine on the
has been deployed in servers [33], low-end IoT devices [8], Personal Computer (PC) and the execution engine on the
[53], and industrial control systems [27]. For IoT devices, MCU. The fuzzing engine generates and sends test cases
the Cortex-M23/33 MCUs, introduced by the ARM Commu- to the MCU via the debug probe. The execution engine
nity in 2016, are built on new TrustZone for ARMv8-M as executes the received test case on the target Trusted OS.
security foundations for billions of devices [22]. TrustZone At a high level, we propose a hardware-assisted fuzzing
for ARMv8-M Cortex-M has been optimized for faster con- framework and a composite feedback mechanism to guide
text switch and low-power applications and is designed from the fuzzer. Given the inaccessible environment of Trusted
the ground up instead of being reused from Cortex-A [54]. OSes, we design a TA and CA pair as a proxy to the
As Figure 1 shows, instead of utilizing a secure monitor Trusted OS and utilize a debug probe to access the MCU for
in TrustZone for Cortex-A, the division of the secure and feedback collection. To handle the challenge of limited re-
normal world is memory-based, and transitions take place sources, we decouple the execution engine from S YZ T RUST
automatically in the exception handle mode. Based on the and only run it on the MCU. This allows S YZ T RUST,
TrustZone-M, IoT vendors provide Trusted OS binaries to with its resource-demanding core components, to run more
the device manufacturers and then the device manufacturers effectively on a PC. To handle the statefulness of Trusted
produce devices with device-specific TAs for the end users. OSes, we include state feedback with code coverage in the
This paper focuses on the Trusted OSes from different IoT composite feedback. State variables represent internal states,
vendors and provides security insights for device manufac- and our inference method identifies them in closed-source
turers and end users. Trusted OSes.
3
State Variable Fuzzing Loop
Trusted OS State Variables
Inference
Debug Probe
Initial Seeds Hardware-assisted Controller Test cases
Proxy CA & TA
Code coverage Trace
A Collector
Syscall composite
State coverage Feedback Feedback
feedback State Variables Trusted OS
Templates
Monitor
Figure 2: Overview of S YZ T RUST. S YZ T RUST consists of a fuzzing engine running on a PC, an execution engine running
on an MCU, and a debug probe to bridge the fuzzing engine and the execution engine.
The main workflow is as follows. First, S YZ T RUST a target Trusted OS by mutating them. However, there is
accepts two inputs, including initial seeds and syscall tem- no off-the-shelf seed corpus for testing Trusted OSes, and
plates. Second, the manager generates test cases through constructing one is not trivial, as the syscall sequences
two fuzzing tasks, including generating a new test case from with arguments should follow critical crypto constraints,
scratch based on syscall templates or by mutating a selected and manually constructing valid sequences will need much
seed. Then, the generated test cases are delivered to the effort. For example, a valid seed includes a certain order
execution engine on MCU through the debug probe. The of syscall sequences to initiate an encryption operation, and
execution engine executes these test cases to test the Trusted the key and the encryption mode should be consistent with
OS. Meanwhile, the debug probe selectively records the supporting encryption. Fortunately, OP-TEE [39], an open-
executed instruction trace, which is processed by our trace source TEE implementation for Cortex-A, offers a test suite,
collector as an alternative to code coverage. Additionally, which can be utilized to construct seeds for most Trusted
the state variable monitor tracks the values of a set of target OSes. Specifically, we automatically inject codes in TAs
state variables to calculate state coverage via the debug provided by the test suite to log the syscall names and
probe. Finally, the code and state coverage is fed to the their arguments. Then we automatically convert those logs
manager as composite feedback to guide the fuzzer. The into seeds following the format required by S YZ T RUST. In
above procedures are iteratively executed and we denote the addition, we automatically add data dependencies between
iterative workflow as the fuzzing loop. syscalls in the seed corpus. Accordingly, we identify the
return values from syscalls that are input arguments of other
4.1. Inputs syscalls and add helper syscalls for the identified values.
Although the syscall template and seed corpus construc-
Syscall templates and initial seeds are fed to S YZ T RUST. tion require extra work, it is a one-shot effort and can be
Syscall templates. Provided syscall templates, used in the further study of Trusted OS security.
S YZ T RUST is more likely to generate valid test cases
by following the format defined by the templates. Syscall 4.2. A Hardware-assisted Framework
templates define the syscalls with their argument types
as well as special types that provide the semantics of an Now our hardware-assisted fuzzing framework enables
argument. For instance, resources represent the values the generated test cases to be executed in protective and
that need to be passed from an output of one syscall resource-constrained trusted environments on IoT devices.
to an input of another syscall, which refers to the data To handle the constrained resources in Challenge I, we
dependency between syscalls. We manually write syscall decouple the execution engine from the other components
templates for the Internal Core API for the GP TEE in of S YZ T RUST to ease the execution overhead of the MCU.
Syzlang (S YZKALLER’s syscall description language [31]). As shown in Figure 2, the fuzzing engine, which includes
However, a value with a complex structure type, which is most core components of S YZ T RUST and requires more
common in Trusted OSes, cannot be used as a resource computing resources and memory space, runs on a PC,
value due to the design limitation of Syzlang. To handle while only the execution engine runs on the MCU. Thus,
this limitation, we extend the syscall templates with helper S YZ T RUST does the heavy tasks, including seed preserva-
syscalls, which accept values of complex structures and tion, seed selection, type-aware generation, and mutation.
output their point addresses as resource values. In As for the protected execution environment in Challenge
total, we have 37 syscall templates and 8 helper syscalls, I, we design a pair of CA and TA as the execution engine
covering all the standard cryptographic APIs. that executes the test cases to test the Trusted OSes. We
Initial seeds. Since syscall templates are used to gen- utilize a debug probe to bridge the connection between the
erate syntactically valid inputs, S YZ T RUST requires initial fuzzing engine and the execution engine. In the following,
seeds to collect some valid syscall sequences and argu- we introduce the design of delivering test cases and the pair
ments and speed up the fuzzing procedure. Provided initial of CA and TA. First, as shown in Figure 2, the debug probe
seeds, S YZ T RUST continuously generates test cases to test transfers test cases and feedback between the fuzzing engine
4
and the execution engine. Specifically, a debug probe can 10 InvokeOneSyscall ( ) ;
directly access the memory of the target MCU. Thus, the 11 / / Data a c c e s s e v e n t i s t r i g g e r e d , s t o p t r a c i n g
12 s t o p e v e n t ++;
debug probe accepts generated test cases from the manager 13 i f ( AllSyscallsExecuted () ){
engine and writes them to a specific memory of the target 14 break ;
15 }
MCU. As for test case transportation, we design a serializer 16 } while (1) ;
to encode the test cases into minimum binary data denoted 17 }
as payloads before sending them to the MCU. A payload 18
includes a sequence of syscalls with their syscall names, Listing 1: A code snippet containing the main execution
syscall argument types, and syscall argument values. In ad- logic from our designed TA.
dition, S YZ T RUST denotes syscall names as ordinal numbers
to minimize the transportation overhead. Second, the pair of However, the IoT Trusted OSes are highly resource-
CA and TA plays the role of a proxy to handle the test cases. constrained, making locally storing ETM traces infeasi-
Accordingly, the CA monitors the specific memory in the ble and limiting the speed of local fuzzing. Therefore,
MCU. If a payload is written, the CA reads the binary data S YZ T RUST utilizes the debug probe (see Section 4.2) to
from the specific memory and delivers them to the TA. Then stream all ETM trace data to the host PC in real time while
the TA deserializes the received binary data and executes the target system is running. Moreover, S YZ T RUST enables
them one by one to test a Trusted OS implementation. parallel execution of test case generation, transmission, and
Accordingly, the TA invokes specific syscalls according execution, as well as coverage calculation, thereby boosting
to the ordinal numbers and fills them in with arguments the speed of fuzzing.
extracted from the payload. To this end, the TA hardcodes For code coverage, we cannot directly use the raw
the syscalls declaration codes that are manually prepared. instruction trace packets generated by the ETM as a re-
The manual work to prepare the declaration codes is a one- placement for branch coverage due to two issues. First,
shot effort that can be easily done by referring to the GP there is a gap between the raw ETM trace packets and
TEE Internal Core API specification. the instruction traces generated by the Trusted OS. The
TEE internals are complicated and the ETM component
4.3. Selective Instruction Trace Tracking records instruction traces generated by the software running
on the MCU, including the CA, rich OS, the TA, and the
This section introduces how to obtain the code coverage Trusted OS. Thus, we design a selective instruction trace
feedback in S YZ T RUST when testing the Trusted OSes. collection strategy to generate fine-grained traces. ARM
To handle the inability of instrumentation in Challenge ETM allows enabling/disabling trace collection when cor-
I, we present a selective instruction trace track, which is responding events occur. We configure the different events
implemented in the trace collector in the fuzzing engine. via the Data Watchpoint and Trace Unit (DWT) hardware
The trace collector controls the debug probe to collect traces feature to filter out noisy packets. In S YZ T RUST, we aim to
synchronously when the test cases are being executed. After calculate the code coverage triggered by every syscall in a
completing a test case, it calculates the code coverage and test case and generated by Trusted OS. Thus, as shown in
delivers it to the manager as feedback. Listing 1, we configure the event-based filters by adding two
In the selective instruction trace track, we utilize the data write access event conditions. The two event conditions
ETM component to enable non-invasive monitoring of the start ETM tracing before invoking a syscall and stop ETM
execution context of target Trusted OSes. The overall work- tracing after completing the syscall, respectively. In addition,
flow is as follows. (1) Before each payload is sent to we specify the address range of the secure world shall be
the MCU, the hardware-assisted controller resets the target included in the trace stream to filter noisy trace packets
MCU via the debug probe. (2) Once the execution engine generated from the normal world.
reads a valid payload from the specific memory space and Second, there is a gap between the raw ETM trace pack-
starts to execute it, the hardware-assisted controller starts ets to the quantitive coverage results. To precisely recover
the ETM component to record the instruction trace for each the branch coverage information, we have to decode the raw
syscall from the payload. Specifically, in the meanwhile trace packets and map them to disassembled binary instruc-
of executing the syscalls, the generated instruction trace is tion address. After that, we can recover the instruction traces
synchronously recorded and delivered to the fuzzing engine and construct the branch coverage information [69] [65].
via the debug probe. (3) After completing a payload, the However, disassembling code introduces significant run-time
hardware-assisted controller computes the coverage based overhead as it incurs high computation cost [18]. Thus, we
on the instruction traces for the manager. calculate the branch coverage directly using the raw trace
1 extern int32 t start event ; packets [37]. At a high level, this calculation mechanism
2 extern int32 t stop event ; utilizes a special basic block generated with Linear Code
3 void TA ProcessEachPayload ( ) { Sequence and Jump (LCSAJ) [66] to reflect any change in
4 RecvPayloadFromCA ( ) ;
5 DecodePayload ( ) ; basic block transitions. LCSAJ basic blocks consist of the
6 / / S t a r t i n v o k i n g s y s c a l l s one by one basic address of a raw ETM branch packet and a sequence of
7 do {
8 / / Data a c c e s s e v e n t i s t r i g g e r e d , s t a r t t r a c i n g branch conditions. The branch conditions indicate whether
9 s t a r t e v e n t ++; the instructions followed by the basic address are executed.
5
This mechanism performs several hash operations on the Test Cases
TEE_AllocateOperation
LCSAJ basic blocks to transform them into random IDs, (TEE_OperationHandle *operation,
uint32_t algorithm, uint32_t mode,
which we utilize as branch coverage feedback. uint32_t maxKeySize)
TEE_ResetOperation(…)
…
Test Harness
4.4. State Variable Inference and Monitoring Output Buffer
0000 0000 00c0 0000 0000 0008 0000
0000 0000 00a8 2d00 2000 0000 0000 Trusted OS
Here we introduce how to identify the internal state State Variable …
Inferer
of the Trusted OS and how to obtain the state coverage
feedback through the state variable monitor component. In
particular, the state variable inference provides the state struct __TEE_OperationHandle{
[0:3] algorithm: 0000 0000 00c0 0000 …
variable monitor with the address ranges of the inferred state … Hardware-assisted State
[40:43] operationState: 0001
Variables Monitor
variables. Then the state variable monitor tracks the values }
…
6
Hit Times 𝐻𝑖𝑡 𝐻𝑖𝑡 ... 𝐻𝑖𝑡
preserves and prioritizes seeds that trigger new code or
HitMap
states. We design two maps as the seed corpus to preserve
seeds according to code coverage and state feedback. With
State Hashes 𝑆𝑡 𝑆𝑡 ... 𝑆𝑡
such seed corpus, S YZ T RUST then periodically selects seeds
SeedMap
from the hash table to explore new codes and new states.
𝑆𝑑 This section introduces how S YZ T RUST fine-tunes the evo-
𝑆𝑑 lution through a novel composite feedback mechanism, in-
Seed A Seed Node cluding seed preservation and seed selection strategy.
𝑆𝑑
Buckets • A Syscall Sequence
with Arguments
Seed preservation. Given the composite feedback
...
• Branch Coverage mechanism, we thus provide two maps as the seed corpus
𝑆𝑑
to store seeds that discover new state values and new code,
respectively. As shown in Figure 4, in two maps, S YZ T RUST
Figure 4: Seed corpus in S YZ T RUST. calculates the hash of combination values of state variables
as the keys. S YZ T RUST maps the state hashes to their hit
times in the HitMap and maps the state hashes to seed
S YZ T RUST outputs the address ranges of these byte se-
buckets in the SeedMap. In the SeedMap, for a certain
12/3 quences and feeds them to the hardware-assisted controller. 11
state hash, the mapping seed bucket contains one or several
State variable monitor. The identified state variables
seeds that can produce the matching state variable values. To
and their address ranges are then used as configurations
construct the SeedMap, S YZ T RUST handles the following
of the hardware-assisted controller. S YZ T RUST utilizes the
two situations. First, if a syscall from a test case triggers a
debug probe to monitor the state variables. When a new
new value combination of state variables, S YZ T RUST adds
TEE_OperationHandle or TEE_ObjectHandle is
a new state hash in the SeedMap. Then, S YZ T RUST maps
allocated, S YZ T RUST records its start address. Given the
the new state hash to a new seed bucket. To construct the
start address of the two handles and address ranges of state
seed bucket, S YZ T RUST utilizes the test case with its branch
variables, S YZ T RUST calculates the memory ranges of state
coverage to construct a seed node and appends the seed
variables and directly reads the memory via the debug probe.
bucket with the newly constructed seed node. Second, if
In the fuzzing loop, for each syscall, beside the branch cov-
a syscall from a test case triggers a new code coverage,
erage, S YZ T RUST records the hash of combination values
S YZ T RUST adds a new seed node in a seed bucket. Specifi-
of the state variables as the state coverage.
cally, S YZ T RUST calculates the hash of combination values
of state variables produced by the syscall. Then, S YZ T RUST
4.5. Fuzzing Loop looks up the seed bucket that is mapped to the state hash
and appends a new seed node that contains the test case
After collecting code and state coverage feedback, the
and its branch coverage to the seed bucket. Noted, a test
fuzzer enters the main fuzzing loop implemented in the
case could be stored in multiple seed buckets if it triggers
manager. S YZ T RUST has a similar basic fuzzing loop to
multiple feedbacks at the same time. As for the HitMap,
S YZKALLER. It schedules two tasks for test case gener-
each time after completing a test case, S YZ T RUST calculates
ation: generating a new test case from syscall templates
all the state hashes it triggers and updates the hit times for
or mutating an existing one based on selected seeds. As
these state hashes according to their hit times.
for the generation task, S YZ T RUST faithfully borrows the
Seed selection. Given the preserved seed corpus,
generation strategy from S YZKALLER. As for the muta-
S YZ T RUST applies a special seed selection strategy to
tion task, S YZ T RUST utilizes a composite feedback mech-
improve the fuzzing efficiency. Algorithm 1 shows how
anism to explore rarely visited states while increasing code
S YZ T RUST selects seeds from the corpus. First, S YZ T RUST
coverage. Notably, S YZ T RUST does not adopt the Triage
chooses a state and then chooses a seed from the map-
scheduling tasks from S YZKALLER due to two key reasons.
ping seed buckets according to the state. In state selection,
First, S YZ T RUST fuzzes directly on the MCU, enabling
S YZ T RUST is more likely to choose a rarely visited state
swift MCU resets after each test case, thus mitigating false
by a weighted random selection algorithm. The probability
positives in branch coverage. Branch coverage validation
of choosing a seed is negatively correlated with its hit
through triaging is, therefore, unnecessary. Second, exe-
times. Thus, we assign each seed a weight value, which
cuting test cases for Trusted OSes (averaging 30 syscalls)
is the reciprocal of its hit times. Finally, The probability of
is time-consuming, incurring a significant overhead for
choosing a seed is equal to the proportion of its weight in
S YZ T RUST to minimize a syscall sequence by removing
the sum of all weights. In seed selection, S YZ T RUST is more
syscalls one by one. Appendix A further experimentally
likely to choose a seed with high branch coverage. To this
demonstrates our intuition for the new scheduling tasks.
end, S YZ T RUST chooses a seed based on a weighted random
selection algorithm, and the probability of choosing a certain
4.6. Composite Feedback Mechanism seed is equal to the proportion of its branch coverage in all
S YZ T RUST adopts a novel composite feedback mecha- coverages. Notably, the probabilities of choosing a state and
nism, leveraging both code and state coverage to guide mu- seed are dynamically updated since the hit times and the sum
tation tasks within the fuzzing loop. Specifically, S YZ T RUST of coverage is updated in the fuzzing procedure.
7
Algorithm 1: Seed Selection Algorithm structures in the Trusted OS and the use of our state variable
Input: C , SeedMap that maps state hashes to a set inference to collect address ranges. These structures can
of seeds be extracted from the documents and header files. We rely
Input: H , HitMap that maps state hashes to hit on two heuristics to help extract them. First, state-related
times data structures usually have common names, e.g., related to
Output: s, the selected seed context or state. Second, the state structures will be the in-
1 Sum W ← 0;
puts and outputs of several crypto operation-related syscalls.
2 M ap W = initMap() //maps state hashes to their
For example, on Link TEE Air, a pointer named context
weights ; is used among cryptographic syscalls such as tee aes init
3 for each key ∈ H do
and tee aes update, and can be further utilized to infer
4 t ← getValue(H, key ); state variables. This information can be obtained from the
5 Sum W ← Sum W + t−1 ; crypto.h header file.
6 end
7 for each key ∈ H do 5. Implementation
8 t ← getValue(H, key );
9 M ap W ← M ap W ∪ (key, t−1 /Sum W );
We have implemented a prototype of S YZ T RUST on
10 end
top of S YZKALLER. We replaced S YZKALLER’s execution
11 St ← WeightedRandom StateSelection(M ap W );
engine with our custom CA and TA pair, integrating our
12 seedSets ← getValue(C, St);
extended syscall templates, eliminating S YZKALLER’s triage
13 s ← WeightedRandom SeedSelection(seedSets);
scheduling task, and implementing our own seed preserva-
tion and selection strategy. Sections 4.2, 4.5, and 4.6 detail
these adaptations.
4.7. Scope and Scalability of S YZ T RUST. Below are details about our implementations. (1) As for
the overall fuzzing framework, we use the SEGGER J-Trace
S YZ T RUST targets Trusted OSes provided by IoT ven- Pro debug probe to control the communication between
dors and assumes that (i) a TA can be installed in the the fuzzing engine and the execution engine, as shown in
Trusted OS, and (ii) target devices have ETM enabled. Figure 5. The pair of CA and TA is developed following
These assumptions align with typical IoT Trusted OS sce- the GP TEE Internal Core API specification and is loaded
narios. First, given that IoT device manufacturers often into the MCU following the instructions provided by the
need to implement device-specific TAs, Trusted OS binaries IoT vendors. To control the debug probe, we developed a
supplied by IoT vendors generally allow TA installation. hardware-assisted controller based on the SEGGER J-Link
Second, S YZ T RUST tests IoT Trusted OSes by deploying SDK. The hardware-assisted controller receives commands
them on development boards where ETM is enabled by from the manager and sends feedback collected on the MCU
default. Moreover, S YZ T RUST can directly test the Trusted to the manager via socket communications. (2) For the selec-
OSes following the GP TEE Internal Core API specification tive instruction trace track, S YZ T RUST integrates the ETM
with MCU-specific configurations. It has built-in support for tracing component of the SEGGER J-Trace Pro and records
testing on alternative Trusted OSes, including proprietary the instruction traces from Trusted OSes non-invasively. The
ones. Appendix B extends discussion with concrete data. raw ETM packets decoder and branch coverage calculation
S YZ T RUST can support other Trusted OSes. To test a are accomplished in the hardware-assisted controller. (3)
new Trusted OSes on a different MCU, S YZ T RUST requires For the state variable inference and monitoring, S YZ T RUST
MCU configurations, including the address ranges of spe- follows the testing strategy in Section 4.4 and utilizes an
cific memory for storing payloads, the addresses of the data RTT component [2] from the SEGGER J-Trace Pro to
events for the event-based filter, and the address ranges of record related state variable values and deliver them to the
secure memory for the address-based filter. We developed fuzzing engine. The RTT component accesses memory in
tooling in the CA and TA to automatically help the analyst the background with high-speed transmission.
obtain all required addresses. In addition, by following the Several tools help us analyze the root cause of detected
development documents from IoT TEE vendors, the CA crashes. We utilize CmBacktrace, a customized backtrace
and TA may require slight adjustments to meet the format tool [70], to track and locate error codes automatically. Ad-
required by the new Trusted OSes and loaded into the Rich ditionally, we develop TEEKASAN based on KASAN [34]
OS and Trusted OS. and MCUASAN [59] to help identify out-of-bound and use-
To extend S YZ T RUST to proprietary Trusted OSes, we after-free vulnerabilities. We integrate TEEKASAN with
augment the syscall templates and the API declarations in lightweight compiler instrumentation and develop shadow
our designed TA and test harness with the new version memory checking for bug triaging on the open source
of these customized APIs. This can be done by referring Trusted OSes. Since TEEKASAN only analyzed a small
to the API documents provided by IoT vendors, which is number of vulnerabilities due to the limitation of the instru-
simple and requires minimum effort. To enable the state- mentation tool and most Trusted OSes are closed-source, we
aware feature, we need expert analysis of the state-related manually triage the remaining vulnerabilities.
8
Power interface
USB
interface
MCU
(connected to
computer)
7 L P H P V
SWD/ETM
interface
Debug
probe
5 H V H W 7 U D Q V I H U ( [ H F X W L R Q &