PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone...

80
PartEmu: Enabling Dynamic Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox, Samsung Research America Rohan Padhye, Koushik Sen EECS Department, University of California, Berkeley

Transcript of PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone...

Page 1: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

PartEmu: Enabling Dynamic Analysis of Real-World

TrustZone Software Using Emulation

Lee Harrison, Hayawardh Vijayakumar, Michael Grace

Samsung Knox, Samsung Research America

Rohan Padhye, Koushik Sen

EECS Department, University of California, Berkeley

Page 2: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

The “Hidden” Software Stack: TrustZone

Android apps

Android framework

Android apps

OS: Linux kernel

Secure Monitor

Trusted App (TA)

Trusted App (TA)

TrustZone OS (TZOS)

Page 3: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

The “Hidden” Software Stack: TrustZone

Android apps

Android framework

Android apps

OS: Linux kernel

Secure Monitor

Trusted App (TA)

Trusted App (TA)

TrustZone OS (TZOS)

• Separate software stack• Trusted applications (TAs)

• TrustZone OS (TZOS)

Page 4: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

The “Hidden” Software Stack: TrustZone

Android apps

Android framework

Android apps

OS: Linux kernel

Secure Monitor

Normal World/REE

Trusted App (TA)

Trusted App (TA)

TrustZone OS (TZOS)

Secure World/TEE • Separate software stack• Trusted applications (TAs)

• TrustZone OS (TZOS)

• TEE/REE

Page 5: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

The “Hidden” Software Stack: TrustZone

Android apps

Android framework

Android apps

OS: Linux kernel

Secure Monitor

Normal World/REE

Trusted App (TA)

Trusted App (TA)

TrustZone OS (TZOS)

Secure World/TEE

HW Crypto Keys

SecurePeripherals

• Separate software stack• Trusted applications (TAs)

• TrustZone OS (TZOS)

• TEE/REE

• Basis for security: Has access to hardware keys

Page 6: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

The “Hidden” Software Stack: TrustZone

Android apps

Android framework

Android apps

OS: Linux kernel

Secure Monitor

Normal World/REE

Trusted App (TA)

Trusted App (TA)

TrustZone OS (TZOS)

Secure World/TEE

HW Crypto Keys

SecurePeripherals

• Separate software stack• Trusted applications (TAs)

• TrustZone OS (TZOS)

• TEE/REE

• Basis for security: Has access to hardware keys

• Access to TZ locked down: Only signed software can run

Page 7: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Problem: Dynamic analysis of TZ is hard!

Approach

Results: What did we learn?

Page 8: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Problem: Dynamic Analysis of TZ is Hard

Android apps

Android framework

Android apps

OS: Linux kernel

Secure Monitor

Normal World/REE

Trusted App (TA)

Trusted App (TA)

TrustZone OS (TZOS)

Secure World/TEE

HW Crypto Keys

SecurePeripherals

Page 9: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Problem: Dynamic Analysis of TZ is Hard

Android apps

Android framework

Android apps

OS: Linux kernel

Secure Monitor

Normal World/REE

Trusted App (TA)

Trusted App (TA)

TrustZone OS (TZOS)

Secure World/TEE

HW Crypto Keys

SecurePeripherals

• Dynamic analysis needs ability to monitor target

Page 10: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Problem: Dynamic Analysis of TZ is Hard

Android apps

Android framework

Android apps

OS: Linux kernel

Secure Monitor

Normal World/REE

Trusted App (TA)

Trusted App (TA)

TrustZone OS (TZOS)

Secure World/TEE

HW Crypto Keys

SecurePeripherals

• Dynamic analysis needs ability to monitor target• Debugging – needs

memory/registers

• Feedback-driven fuzz testing – needs list of basic blocks covered

Page 11: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Problem: Dynamic Analysis of TZ is Hard

Android apps

Android framework

Android apps

OS: Linux kernel

Secure Monitor

Normal World/REE

Trusted App (TA)

Trusted App (TA)

TrustZone OS (TZOS)

Secure World/TEE

HW Crypto Keys

SecurePeripherals

• Dynamic analysis needs ability to monitor target• Debugging – needs

memory/registers

• Feedback-driven fuzz testing – needs list of basic blocks covered

• However, cannot instrument TZ software or monitor TZ memory due to signing!

Page 12: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Problem: Dynamic Analysis of TZ is Hard

Android apps

Android framework

Android apps

OS: Linux kernel

Secure Monitor

Normal World/REE

Trusted App (TA)

Trusted App (TA)

TrustZone OS (TZOS)

Secure World/TEE

HW Crypto Keys

SecurePeripherals

• Prior dynamic analysis approaches limited!• TA/TZOS binary reverse

engineering

• Fuzz testing without feedback

Page 13: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Solution: Dynamic Analysis By Emulation

• We build an emulator that runs real-world TZOSes and TAs

Page 14: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Solution: Dynamic Analysis By Emulation

• We build an emulator that runs real-world TZOSes and TAs

• Emulation enables dynamic analysis• Allows introspection and monitoring of TZ execution

Page 15: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Solution: Dynamic Analysis By Emulation

• We build an emulator that runs real-world TZOSes and TAs

• Emulation enables dynamic analysis• Allows introspection and monitoring of TZ execution

• We support four widely-used real-world TZOSes:• Qualcomm’s QSEE• Trustonic’s Kinibi• Samsung’s TEEGRIS• Linaro’s OP-TEE

Page 16: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Problem: Dynamic analysis of TZ is hard!

Approach: How did we run TZ in an emulator?

Results: What did we learn?

Page 17: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Challenge: Large Number of Components

Page 18: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Linux OS TEE Driver

Hypervisor

Android FW

Android Apps

TEE Userspace

Software

Challenge: Large Number of Components

Page 19: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

TrustZone OS

Secure Monitor

Linux OS TEE Driver

Hypervisor

Android FW

Android Apps

TEE Userspace

Bootldr

Trusted Apps

Software

Challenge: Large Number of Components

Page 20: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

TrustZone OS

Secure Monitor

Linux OS TEE Driver

Hypervisor

Android FW

Android Apps

TEE Userspace

Bootldr

Trusted Apps

Touch-screen

Camera

GPS

Finger-print

StorageCrypto HW

TZASC/TZPC

System-on-Chip

Software

Hardware

Challenge: Large Number of Components

Page 21: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

TrustZone OS

Secure Monitor

Linux OS TEE Driver

Hypervisor

Android FW

Android Apps

TEE Userspace

Bootldr

Trusted Apps

Touch-screen

Camera

GPS

Finger-print

StorageCrypto HW

TZASC/TZPC

System-on-Chip

Software

Hardware

Challenge: Large Number of Components

Page 22: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

TrustZone OS

Secure Monitor

Linux OS TEE Driver

Hypervisor

Android FW

Android Apps

TEE Userspace

Bootldr

Trusted Apps

Software

Hardware

Traditional Approach: Emulate all HW

ReuseUnmodified

SoftwareComponents

Page 23: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

TrustZone OS

Secure Monitor

Linux OS TEE Driver

Hypervisor

Android FW

Android Apps

TEE Userspace

Bootldr

Trusted Apps

Touch-screen

Camera

GPS

Finger-print

StorageCrypto HW

TZASC/TZPC

System-on-Chip

Software

Hardware

Traditional Approach: Emulate all HW

ReuseUnmodified

SoftwareComponents

Emulate AllHardware

Components

Page 24: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

TrustZone OS

Secure Monitor

Linux OS TEE Driver

Hypervisor

Android FW

Android Apps

TEE Userspace

Bootldr

Trusted Apps

Touch-screen

Camera

GPS

Finger-print

StorageCrypto HW

TZASC/TZPC

System-on-Chip

Software

Hardware

Traditional Approach: Emulate all HW

ReuseUnmodified

SoftwareComponents

Emulate AllHardware

Components

Impractical to emulate all hardware

Page 25: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Our Approach: Emulate Subset of HW and SW

Page 26: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

TrustZone OS

Secure Monitor

Linux OS TEE Driver

Hypervisor

Android FW

Android Apps

TEE Userspace

Bootldr

Trusted Apps

Touch-screen

Camera

GPS

Finger-print

StorageCrypto HW

TZASC/TZPC

System-on-Chip

Software

Hardware

Our Approach: Emulate Subset of HW and SW

StudyComponent

Dependencies

Page 27: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

TrustZone OS

Secure Monitor

Linux OS TEE Driver

Hypervisor

Android FW

Android Apps

TEE Userspace

Bootldr

Trusted Apps

Touch-screen

Camera

GPS

Finger-print

StorageCrypto HW

TZASC/TZPC

System-on-Chip

Our Approach: Emulate Subset of HW and SW

StudyComponent

Dependencies

Page 28: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

TrustZone OS

Secure Monitor

Linux OS TEE Driver

Hypervisor

Android FW

Android Apps

TEE Userspace

Bootldr

Trusted Apps

Touch-screen

Camera

GPS

Finger-print

StorageCrypto HW

TZASC/TZPC

System-on-Chip

Our Approach: Emulate Subset of HW and SW

StudyComponent

Dependencies

Page 29: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

TrustZone OS

Secure Monitor

Linux OS TEE Driver

Hypervisor

Android FW

Android Apps

TEE Userspace

Bootldr

Trusted Apps

Touch-screen

Camera

GPS

Finger-print

StorageCrypto HW

TZASC/TZPC

System-on-Chip

Our Approach: Emulate Subset of HW and SW

Tighty coupled,difficult to emulate

dependency

StudyComponent

Dependencies

Page 30: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

TrustZone OS

Secure Monitor

Linux OS TEE Driver

Hypervisor

Android FW

Android Apps

TEE Userspace

Bootldr

Trusted Apps

Touch-screen

Camera

GPS

Finger-print

StorageCrypto HW

TZASC/TZPC

System-on-Chip

Our Approach: Emulate Subset of HW and SW

Tighty coupled,difficult to emulate

dependency

StudyComponent

Dependencies

Page 31: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

TrustZone OS

Secure Monitor

Linux OS TEE Driver

Hypervisor

Android FW

Android Apps

TEE Userspace

Bootldr

Trusted Apps

Touch-screen

Camera

GPS

Finger-print

StorageCrypto HW

TZASC/TZPC

System-on-Chip

Our Approach: Emulate Subset of HW and SW

Loosely coupled,easy to emulate

dependency

Tighty coupled,difficult to emulate

dependency

Page 32: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

TrustZone OS

Secure Monitor

Linux OS TEE Driver

Hypervisor

Android FW

Android Apps

TEE Userspace

Trusted Apps

Touch-screen

Camera

GPS

Finger-print

StorageCrypto HW

TZASC/TZPC

System-on-Chip

Our Approach: Emulate Subset of HW and SW

Bootldr

EmulateBootloaderUsing Stub

ExcludeStorage

Page 33: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

TrustZone OS

Secure Monitor

Linux OS TEE Driver

Hypervisor

Android FW

Android Apps

TEE Userspace

Trusted Apps

Touch-screen

Camera

GPS

Finger-print

StorageCrypto HW

TZASC/TZPC

System-on-Chip

Our Approach: Emulate Subset of HW and SW

Bootldr

EmulateBootloaderUsing Stub

ExcludeStorage

Page 34: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

TrustZone OS

Secure Monitor

Linux OS TEE Driver

Hypervisor

Android FW

Android Apps

TEE Userspace

Trusted Apps

Touch-screen

Camera

GPS

Finger-print

StorageCrypto HW

TZASC/TZPC

System-on-Chip

Our Approach: Emulate Subset of HW and SW

Bootldr

EmulateBootloaderUsing Stub

ExcludeStorage

Page 35: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Emulation Effort Feasible Using Patterns

Page 36: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Emulation Effort Feasible Using Patterns

• Patterns to Emulate Hardware (MMIO Loads and Stores)

Page 37: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Emulation Effort Feasible Using Patterns

• Patterns to Emulate Hardware (MMIO Loads and Stores)

Page 38: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Emulation Effort Feasible Using Patterns

• Patterns to Emulate Hardware (MMIO Loads and Stores)

Page 39: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Emulation Effort Feasible Using Patterns

• Patterns to Emulate Software APIs

Page 40: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Emulation Effort Feasible Using Patterns

• Patterns to Emulate Software APIs

Page 41: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Emulation Effort Feasible Using Patterns

• Patterns to Emulate Software APIs

Page 42: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Implementation

QEMU

Page 43: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Implementation

QEMU

HW Emulation

Page 44: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Implementation

QEMU

HW Emulation

AFL Fuzz Module

Debug Module

PartEmu Module

API

Page 45: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Implementation

QEMU

HW Emulation

AFL Fuzz Module

Debug Module

PartEmu Module

API

Guest

SW Emulation TAs

TZOS

Page 46: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Implementation

QEMU

HW Emulation

AFL Fuzz Module

Debug Module

PartEmu Module

API

PartEmu Run Management API

Guest

SW Emulation

Driver

TAs

TZOS

Page 47: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Problem: Dynamic analysis of TZ is hard!

Approach: How did we run TZ in an emulator?

Results: What did we learn?

Page 48: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Fuzz Testing TAs Using AFL

16 Firmware Images

Page 49: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Fuzz Testing TAs Using AFL

16 Firmware Images

12 Smartphone / IoT vendors

Page 50: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Fuzz Testing TAs Using AFL

16 Firmware Images

12 Smartphone / IoT vendors

196 Unique TAs

Page 51: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Fuzz Testing TAs Using AFL

16 Firmware Images

12 Smartphone / IoT vendors

196 Unique TAsAFL Crashed

48 TAs

Page 52: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Fuzz Testing TAs Using AFL

16 Firmware Images

12 Smartphone / IoT vendors

196 Unique TAsAFL Crashed

48 TAs

• Found TZ-specific coding anti-patterns that led to crashes

Page 53: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Anti-Pattern 1: Assumptions about Request Sequence

Page 54: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Anti-Pattern 1: Assumptions about Request Sequence• TAs split work into small units receive a sequence of requests

Page 55: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Anti-Pattern 1: Assumptions about Request Sequence• TAs split work into small units receive a sequence of requests

char *ptr = NULL; // global

switch (request) {

case INIT:

init(ptr);

break;

case DO_ACTION:

do_action(ptr);

break;

case UNINIT:

uninit(ptr);

break;

};

Page 56: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Anti-Pattern 1: Assumptions about Request Sequence• TAs split work into small units receive a sequence of requests

char *ptr = NULL; // global

switch (request) {

case INIT:

init(ptr);

break;

case DO_ACTION:

do_action(ptr);

break;

case UNINIT:

uninit(ptr);

break;

};

1.

Page 57: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Anti-Pattern 1: Assumptions about Request Sequence• TAs split work into small units receive a sequence of requests

char *ptr = NULL; // global

switch (request) {

case INIT:

init(ptr);

break;

case DO_ACTION:

do_action(ptr);

break;

case UNINIT:

uninit(ptr);

break;

};

1.

2.

Page 58: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Anti-Pattern 1: Assumptions about Request Sequence• TAs split work into small units receive a sequence of requests

char *ptr = NULL; // global

switch (request) {

case INIT:

init(ptr);

break;

case DO_ACTION:

do_action(ptr);

break;

case UNINIT:

uninit(ptr);

break;

};

1.

2.

3.

Page 59: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Anti-Pattern 1: Assumptions about Request Sequence• TAs split work into small units receive a sequence of requests

char *ptr = NULL; // global

switch (request) {

case INIT:

init(ptr);

break;

case DO_ACTION:

do_action(ptr);

break;

case UNINIT:

uninit(ptr);

break;

};

1.

2.

3.

1.

Page 60: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Anti-Pattern 1: Assumptions about Request Sequence• TAs split work into small units receive a sequence of requests

char *ptr = NULL; // global

switch (request) {

case INIT:

init(ptr);

break;

case DO_ACTION:

do_action(ptr);

break;

case UNINIT:

uninit(ptr);

break;

};

1.

2.

3.

1.

Null-pointerdereference

Page 61: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Anti-Pattern 1: Assumptions about Request Sequence• TAs split work into small units receive a sequence of requests

char *ptr = NULL; // global

switch (request) {

case INIT:

init(ptr);

break;

case DO_ACTION:

do_action(ptr);

break;

case UNINIT:

uninit(ptr);

break;

};

1.

2.

3.

1.

Null-pointerdereference

TA should properly handle any sequence of requests from CA

Page 62: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Anti-Pattern 2:Unvalidated Normal-World Pointers

Client App (CA)

Normal World/REE

Trusted App (TA)

Secure World/TEE

Page 63: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Anti-Pattern 2:Unvalidated Normal-World Pointers

Client App (CA)

Normal World/REE

Trusted App (TA)

Secure World/TEE

Shared Memory

Page 64: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Anti-Pattern 2:Unvalidated Normal-World Pointers

Client App (CA)

Normal World/REE

Trusted App (TA)

Secure World/TEE

shm_ta_base

Shared Memory

Page 65: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Anti-Pattern 2:Unvalidated Normal-World Pointers

Client App (CA)

Normal World/REE

Trusted App (TA)

Secure World/TEE

shm_ta_base

Shared Memory

Page 66: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Anti-Pattern 2:Unvalidated Normal-World Pointers

Client App (CA)

Normal World/REE

Trusted App (TA)

Secure World/TEE

shm_ta_base

Shared Memory

ptr = off +

shm_ta_base

Page 67: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Anti-Pattern 2:Unvalidated Normal-World Pointers

Client App (CA)

Normal World/REE

Trusted App (TA)

Secure World/TEE

shm_ta_base

Shared Memory

ptr = off +

shm_ta_base

ptr

Page 68: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Anti-Pattern 2:Unvalidated Normal-World Pointers

Client App (CA)

Normal World/REE

Trusted App (TA)

Secure World/TEE

shm_ta_base

Shared Memory

ptr = off +

shm_ta_base

ptr mal_ptr

Page 69: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Anti-Pattern 2:Unvalidated Normal-World Pointers

Client App (CA)

Normal World/REE

Trusted App (TA)

Secure World/TEE

shm_ta_base

Shared Memory

ptr = off +

shm_ta_base

ptr

TA Memory leak/ corruption

mal_ptr

Page 70: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Anti-Pattern 2:Unvalidated Normal-World Pointers

Client App (CA)

Normal World/REE

Trusted App (TA)

Secure World/TEE

shm_ta_base

Shared Memory

ptr = off +

shm_ta_base

ptr

TA Memory leak/ corruption

mal_ptr

TA should check that CA-supplied pointers point to shared memory

Page 71: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Anti-Pattern 3:Unvalidated Parameter Types

• GlobalPlatform TEE API allows 4 parameters in TA calls• Each parameter can be either a value or a pointer to a buffer

TEE_Result TA_InvokeCommandEntryPoint(void *session, uint32_t cmd,

uint32_t paramTypes, TEE_Params params[4])

{

// Use params[0] as a buffer

request_ptr = (struct request_struct *) params[0];

switch (request_ptr->request) {

}

}

Page 72: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Anti-Pattern 3:Unvalidated Parameter Types

• GlobalPlatform TEE API allows 4 parameters in TA calls• Each parameter can be either a value or a pointer to a buffer

TEE_Result TA_InvokeCommandEntryPoint(void *session, uint32_t cmd,

uint32_t paramTypes, TEE_Params params[4])

{

// Use params[0] as a buffer

request_ptr = (struct request_struct *) params[0];

switch (request_ptr->request) {

}

}

Page 73: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Anti-Pattern 3:Unvalidated Parameter Types

• GlobalPlatform TEE API allows 4 parameters in TA calls• Each parameter can be either a value or a pointer to a buffer

TEE_Result TA_InvokeCommandEntryPoint(void *session, uint32_t cmd,

uint32_t paramTypes, TEE_Params params[4])

{

// Use params[0] as a buffer

request_ptr = (struct request_struct *) params[0];

switch (request_ptr->request) {

}

}

paramType(0) =

TEEC_MEMREF;

Page 74: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Anti-Pattern 3:Unvalidated Parameter Types

• GlobalPlatform TEE API allows 4 parameters in TA calls• Each parameter can be either a value or a pointer to a buffer

TEE_Result TA_InvokeCommandEntryPoint(void *session, uint32_t cmd,

uint32_t paramTypes, TEE_Params params[4])

{

// Use params[0] as a buffer

request_ptr = (struct request_struct *) params[0];

switch (request_ptr->request) {

}

}

paramTypes(0) =

TEEC_MEMREF;

paramTypes(0) =

TEEC_VALUE;

Page 75: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Anti-Pattern 3:Unvalidated Parameter Types

• GlobalPlatform TEE API allows 4 parameters in TA calls• Each parameter can be either a value or a pointer to a buffer

TEE_Result TA_InvokeCommandEntryPoint(void *session, uint32_t cmd,

uint32_t paramTypes, TEE_Params params[4])

{

// Use params[0] as a buffer

request_ptr = (struct request_struct *) params[0];

switch (request_ptr->request) {

}

}

paramTypes(0) =

TEEC_MEMREF;

paramTypes(0) =

TEEC_VALUE;

TA Memory leak/ corruption

Page 76: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Anti-Pattern 3:Unvalidated Parameter Types

• GlobalPlatform TEE API allows 4 parameters in TA calls• Each parameter can be either a value or a pointer to a buffer

TEE_Result TA_InvokeCommandEntryPoint(void *session, uint32_t cmd,

uint32_t paramTypes, TEE_Params params[4])

{

// Use params[0] as a buffer

request_ptr = (struct request_struct *) params[0];

switch (request_ptr->request) {

}

}

paramTypes(0) =

TEEC_MEMREF;

paramTypes(0) =

TEEC_VALUE;

TA Memory leak/ corruption

TA should check CA-supplied parameter types

Page 77: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Conclusion

• We showed that it is practically feasible to run real-world TZOSes and TAs in an emulator

Page 78: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Conclusion

• We showed that it is practically feasible to run real-world TZOSes and TAs in an emulator

• Large-scale fuzz testing of TAs using the emulator found several previously unknown vulnerabilities in TAs with high reproducibility

Page 79: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Conclusion

• We showed that it is practically feasible to run real-world TZOSes and TAs in an emulator

• Large-scale fuzz testing of TAs using the emulator found several previously unknown vulnerabilities in TAs with high reproducibility

• We identified vulnerability patterns unique to TA development• Pointing to the need for TZ-specific developer education

Page 80: PartEmu: Enabling Dynamic Analysis of Real-World TrustZone ...Analysis of Real-World TrustZone Software Using Emulation Lee Harrison, Hayawardh Vijayakumar, Michael Grace Samsung Knox,

Conclusion

• We showed that it is practically feasible to run real-world TZOSes and TAs in an emulator

• Large-scale fuzz testing of TAs using the emulator found several previously unknown vulnerabilities in TAs with high reproducibility

• We identified vulnerability patterns unique to TA development• Pointing to the need for TZ-specific developer education

Thank you!