+ All Categories
Home > Documents > vTZ: Virtualizing ARM TrustZone - USENIX · vTZ: Virtualizing ARM TrustZone...

vTZ: Virtualizing ARM TrustZone - USENIX · vTZ: Virtualizing ARM TrustZone...

Date post: 13-Aug-2020
Category:
Upload: others
View: 5 times
Download: 0 times
Share this document with a friend
34
vTZ: Virtualizing ARM TrustZone IPADS, Shanghai Jiao Tong University Zhichao Hua, Jinyu Gu, Yubin Xia, Haibo Chen, Binyu Zang, Haibing Guan
Transcript
Page 1: vTZ: Virtualizing ARM TrustZone - USENIX · vTZ: Virtualizing ARM TrustZone IPADS,ShanghaiJiaoTongUniversity Zhichao Hua, Jinyu Gu, Yubin Xia, Haibo Chen, Binyu Zang, HaibingGuan

vTZ: Virtualizing ARM TrustZone

IPADS, Shanghai Jiao Tong University

Zhichao Hua, Jinyu Gu, Yubin Xia, Haibo Chen, Binyu Zang, Haibing Guan

Page 2: vTZ: Virtualizing ARM TrustZone - USENIX · vTZ: Virtualizing ARM TrustZone IPADS,ShanghaiJiaoTongUniversity Zhichao Hua, Jinyu Gu, Yubin Xia, Haibo Chen, Binyu Zang, HaibingGuan

OTP

fTPM

Security systems with TrustZone

Server SoCWith Virtualization

Can VMs useTrustZone?

2

Page 3: vTZ: Virtualizing ARM TrustZone - USENIX · vTZ: Virtualizing ARM TrustZone IPADS,ShanghaiJiaoTongUniversity Zhichao Hua, Jinyu Gu, Yubin Xia, Haibo Chen, Binyu Zang, HaibingGuan

ARM TrustZone3

Normal World Secure World

Monitor Mode

OST-OS

(Trust OS)

TA(Trusted APP)

APP DRAM

CPU core

smcsmc

APP

Devices

• Two isolated execution environments

• Different worlds switch to each other by “smc” instruction

• Hardware resources can be partitioned into secure/non-secure part dynamically

– Secure world can access all

– Normal world can only access non-secure part

Bus

Page 4: vTZ: Virtualizing ARM TrustZone - USENIX · vTZ: Virtualizing ARM TrustZone IPADS,ShanghaiJiaoTongUniversity Zhichao Hua, Jinyu Gu, Yubin Xia, Haibo Chen, Binyu Zang, HaibingGuan

TrustZone Usage

• TrustZone on mobile phone– Secure storage, key protection, kernel integrity checker,

malware detector, etc.

• TrustZone on ARM server– Has similar scenarios and requirements

4

Page 5: vTZ: Virtualizing ARM TrustZone - USENIX · vTZ: Virtualizing ARM TrustZone IPADS,ShanghaiJiaoTongUniversity Zhichao Hua, Jinyu Gu, Yubin Xia, Haibo Chen, Binyu Zang, HaibingGuan

TrustZone + Virtualization5

Requirements Ideal Reality

Each guest VM has a secure world ✓

Guest VM can choose its own trust OS ✓

Isolation between different guests’ secure worlds ✓

Hardware resources partition between guest’s

normal world and secure world✓

Page 6: vTZ: Virtualizing ARM TrustZone - USENIX · vTZ: Virtualizing ARM TrustZone IPADS,ShanghaiJiaoTongUniversity Zhichao Hua, Jinyu Gu, Yubin Xia, Haibo Chen, Binyu Zang, HaibingGuan

TrustZone + Virtualization5

Requirements Ideal Reality

Each guest VM has a secure world ✓ ✗

Guest VM can choose its own trust OS ✓ ✗

Isolation between different guests’ secure worlds ✓ ✗

Hardware resources partition between guest’s

normal world and secure world✓ ✗

The OS in secure world becomes single point of failure– cve-2015-4421, cve-2015-4422, cve-2015-6639

Page 7: vTZ: Virtualizing ARM TrustZone - USENIX · vTZ: Virtualizing ARM TrustZone IPADS,ShanghaiJiaoTongUniversity Zhichao Hua, Jinyu Gu, Yubin Xia, Haibo Chen, Binyu Zang, HaibingGuan

Goals

• Multiplexing the secure world for guest VMs– Each guest VM can choose its own trust OS

– Isolate each guest’s secure world

– Provide hardware resources partition for each guest

• Compatibility for existing software in secure world– Provide same functionalities and interfaces with real TrustZone

– Support existing trust OS

• Minimizing TCB of the new architecture

6

Page 8: vTZ: Virtualizing ARM TrustZone - USENIX · vTZ: Virtualizing ARM TrustZone IPADS,ShanghaiJiaoTongUniversity Zhichao Hua, Jinyu Gu, Yubin Xia, Haibo Chen, Binyu Zang, HaibingGuan

Alternative Designs

Normal World

VMM

T-VMMOS

VMN VMS

T-OSuser

svc

hyp

SecureWorld

Design Choice I

mon

: TCB

APP TA

• Large TCB

• No compatibility

• Bad performance

• T-VMM (trusted VMM) in the secure world– Virtualize guest secure world with VMS

• VMM in the normal world

– Virtualize guest normal world with VMN

• No virtualization extension in secure world– Both guest’s trust OS and TA run in user mode

– ARM has virtualization unfriendly instructions• Trust OS needs to be modified

• System TCB– T-VMM (~10K of LoC)

– VMM (millions of LoC)

7

Page 9: vTZ: Virtualizing ARM TrustZone - USENIX · vTZ: Virtualizing ARM TrustZone IPADS,ShanghaiJiaoTongUniversity Zhichao Hua, Jinyu Gu, Yubin Xia, Haibo Chen, Binyu Zang, HaibingGuan

Alternative Designs

Normal World

VMM

T-VMMOS

VMN VMS

user

svc

hyp

SecureWorld

Normal World

OS

VMN

SecureWorld

VMS

T-OS

Design Choice I Design Choice II

monVMM

: TCB

APP TAAPP TA

• Large TCB

• No compatibility

• Bad performance

• Large TCB

• Has compatibility

• Good performance

• Virtualize guest secure world in real normal world

• Secure world is not used

• System TCB

– VMM (millions of LoC)

7

T-OS

Page 10: vTZ: Virtualizing ARM TrustZone - USENIX · vTZ: Virtualizing ARM TrustZone IPADS,ShanghaiJiaoTongUniversity Zhichao Hua, Jinyu Gu, Yubin Xia, Haibo Chen, Binyu Zang, HaibingGuan

Alternative Designs

Normal World

VMM

T-VMMOS

VMN VMS

user

svc

hyp

SecureWorld

Normal World

OS

VMN

SecureWorld

VMS

T-OS

Design Choice I Design Choice II

monVMM

: TCB

APP TAAPP TA

• Large TCB

• No compatibility

• Bad performance

• Large TCB

• Has compatibility

• Good performance

Normal World

VMM

OS

VMN

SecureWorld

VMS

T-OS

Design Choice III

CIEEs

SecuredModules

CFLock

• Small TCB

• Has compatibility

7

T-OS

Page 11: vTZ: Virtualizing ARM TrustZone - USENIX · vTZ: Virtualizing ARM TrustZone IPADS,ShanghaiJiaoTongUniversity Zhichao Hua, Jinyu Gu, Yubin Xia, Haibo Chen, Binyu Zang, HaibingGuan

Threat Model

• Any guest may be an attacker

• VMM is buggy, can be compromised

• Code integrity is protected during system boot by secure boot technology

• Side-channel attacks and physical attacks are not considered

8

VMN VMS

Normal World

VMM

OS

Secure World

T-OS

Control Flow Lock

CIEEs SecuredModules

SMM SWS

usermode

svcmode

hypmode

monmode

APP TA

Page 12: vTZ: Virtualizing ARM TrustZone - USENIX · vTZ: Virtualizing ARM TrustZone IPADS,ShanghaiJiaoTongUniversity Zhichao Hua, Jinyu Gu, Yubin Xia, Haibo Chen, Binyu Zang, HaibingGuan

VMN VMS

Overview

Normal World

VMM

OS

Secure World

T-OS

Control Flow Lock

CIEEs SecuredModules

SMM SWS

• Emulate guest normal world/secure world with different VMs

– World switching is performed by switching between two VMs

• SMM (Secured Memory Mapping)– Memory mapping

• SWS (Secured World Switching)– CPU Context

• CIEE (Constrained Isolated Execution Environment)

– Protect critical logic in hyp mode

• CFLock (Control Flow Lock)

usermode

svcmode

hypmode

monmode

9

APP TA

Page 13: vTZ: Virtualizing ARM TrustZone - USENIX · vTZ: Virtualizing ARM TrustZone IPADS,ShanghaiJiaoTongUniversity Zhichao Hua, Jinyu Gu, Yubin Xia, Haibo Chen, Binyu Zang, HaibingGuan

TrustZone Features System Properties

Secure Boot SW must boot before NW.

Boot image of SW must be checked.

SW cannot be replaced.

CPU States Protection “smc” must switch to the correct world.

Protect the integrity of NW CPU states during switching.

Protect SW CPU states.

Memory Isolation Only SW can access secure memory.

Only SW can configure memory partition.

Peripheral Assignment Secure interrupts must be injected into SW.

NW cannot access secure peripherals.

Secure peripherals are trusted for SW

Only SW can partition interrupt/peripherals.

Properties need to be enforced by vTZ

10

Page 14: vTZ: Virtualizing ARM TrustZone - USENIX · vTZ: Virtualizing ARM TrustZone IPADS,ShanghaiJiaoTongUniversity Zhichao Hua, Jinyu Gu, Yubin Xia, Haibo Chen, Binyu Zang, HaibingGuan

TrustZone Features System Properties

Secure Boot SW must boot before NW.

Boot image of SW must be checked.

SW cannot be replaced.

CPU States Protection “smc” must switch to the correct world. Protect the integrity of NW CPU states during switching.

Protect SW CPU states.

Memory Isolation Only SW can access secure memory.

Only SW can configure memory partition.Peripheral Assignment Secure interrupts must be injected into SW.

NW cannot access secure peripherals.

Secure peripherals are trusted for SW

Only SW can partition interrupt/peripherals.

Properties need to be enforced by vTZ.

10

Page 15: vTZ: Virtualizing ARM TrustZone - USENIX · vTZ: Virtualizing ARM TrustZone IPADS,ShanghaiJiaoTongUniversity Zhichao Hua, Jinyu Gu, Yubin Xia, Haibo Chen, Binyu Zang, HaibingGuan

P1. Only secure world can access secure memory

• Challenge – Untrusted VMM controls all memory mappings

– Map one guest’s secure memory to its normal world or to another guest

– Map one guest’s secure memory to VMM’s address space

• Solution– SMM exclusively controls all memory mappings to physical memory

– SMM checks memory mappings

11

Page 16: vTZ: Virtualizing ARM TrustZone - USENIX · vTZ: Virtualizing ARM TrustZone IPADS,ShanghaiJiaoTongUniversity Zhichao Hua, Jinyu Gu, Yubin Xia, Haibo Chen, Binyu Zang, HaibingGuan

• Two kinds of mappings to the physical memory– Stage-2 page table maps guest physical address to

physical address

– Hyp page table maps virtual address to physical address for VMM

• Three ways memory mapping can be modified– Enabling a page table

– Disabling the address translation

– Changing the entries of page table

P1. Only secure world can access secure memory

.textenable_guest_pt:ldr x1, [x0] // load page tableMSR VTTBR_EL2, x1// enable table table

enable_hyp_pt:ldr x1, [x0] // load page tableMSR TTBR0_EL2, x1// enable table table

set_pte:str x1, [x0]// change table entry

hypervisorpage table

Stage-2page table

12

Page 17: vTZ: Virtualizing ARM TrustZone - USENIX · vTZ: Virtualizing ARM TrustZone IPADS,ShanghaiJiaoTongUniversity Zhichao Hua, Jinyu Gu, Yubin Xia, Haibo Chen, Binyu Zang, HaibingGuan

SMM (Secured Memory Mapping)

• SMM exclusively controls the mapping– Replace all page table maintain instructions

– Enforce hypervisor’s code as read-only (R.O.)

– Enforce page table as read-only

• SMM enforces memory mapping policy– E.g., one guest’s secure memory can only be

mapped to its own secure world

P1. Only secure world can access the secure memory

.textenable_guest_pt:ldr x1, [x0] // load page tableMSR VTTBR_EL2, x1// enable table table

enable_hyp_pt:ldr x1, [x0] // load page tableMSR TTBR0_EL2, x1// enable table table

set_pte:str x1, [x0]// change table entry

hypervisorpage table

Stage-2page table

Invoke_SMM

Invoke_SMM

Invoke_SMM

13

Page 18: vTZ: Virtualizing ARM TrustZone - USENIX · vTZ: Virtualizing ARM TrustZone IPADS,ShanghaiJiaoTongUniversity Zhichao Hua, Jinyu Gu, Yubin Xia, Haibo Chen, Binyu Zang, HaibingGuan

P2. “smc” must switch to the correct world

• Challenge– Untrusted VMM controls the scheduleing of all VMs

– “smc” may switch to a malicious VM

– “smc” may switch to a wrong entry of guest secure world

– Untrusted VMM may tamper with the CPU context during switching

• Solution– SWS hooks all switching between a VM and the VMM

– SWS checks all switching

14

Page 19: vTZ: Virtualizing ARM TrustZone - USENIX · vTZ: Virtualizing ARM TrustZone IPADS,ShanghaiJiaoTongUniversity Zhichao Hua, Jinyu Gu, Yubin Xia, Haibo Chen, Binyu Zang, HaibingGuan

SWS (Secured World Switching)

• SWS Interposes switching between a VM and the VMM– VM_exit is triggered by exception, hooked by CFLock

– VM_enter is performed by special instructions, replacing all of them

• E.g., eret

• SWS binds each guest’s secure world and normal world– Identify VMs presenting guest’s two worlds by VMID

15

Page 20: vTZ: Virtualizing ARM TrustZone - USENIX · vTZ: Virtualizing ARM TrustZone IPADS,ShanghaiJiaoTongUniversity Zhichao Hua, Jinyu Gu, Yubin Xia, Haibo Chen, Binyu Zang, HaibingGuan

• CFLock: hooks the control flow of exception handling

• Ensure the integrity of vector table containing exception handlers– Replace instructions which modify

vector table base register

– Mark vector table as read-only

• Add hook in each exception handler

CFLock (Control Flow Lock)

.textInit_vector:ldr x1, [x0] // load vector tableMSR VBAR_EL2, x1// enable vector table

handler1:…

b handler1

vector table

Invoke_SMMb handler2b handler3b handler4b handler5

…b CFLock…

16

Page 21: vTZ: Virtualizing ARM TrustZone - USENIX · vTZ: Virtualizing ARM TrustZone IPADS,ShanghaiJiaoTongUniversity Zhichao Hua, Jinyu Gu, Yubin Xia, Haibo Chen, Binyu Zang, HaibingGuan

P2. “smc” must switch to the correct world

• Untrusted VMM registers guest’s two VMs in SWS– SWS only allows entering a registered VM

• Untrusted VMM schedules all VMs

• SWS checks all VM_enter / VM_exit operations

17

Page 22: vTZ: Virtualizing ARM TrustZone - USENIX · vTZ: Virtualizing ARM TrustZone IPADS,ShanghaiJiaoTongUniversity Zhichao Hua, Jinyu Gu, Yubin Xia, Haibo Chen, Binyu Zang, HaibingGuan

P3. Only secure world can partition memory

• Guest configures memory partition in its secure world by accessing a memory partition device (TZASC)

• Challenge– There is only one TZASC

– Cannot control TZASC by the untrusted VMM

• Solution– Providing trusted virtual TZASC by “trap and emulate”

18

Page 23: vTZ: Virtualizing ARM TrustZone - USENIX · vTZ: Virtualizing ARM TrustZone IPADS,ShanghaiJiaoTongUniversity Zhichao Hua, Jinyu Gu, Yubin Xia, Haibo Chen, Binyu Zang, HaibingGuan

P3. Only secure world can partition memory

• CFLock traps memory accesses of virtual TZASC– Memory mapped device

– Accessing triggers page fault exception

• SWS identifies current VM– Only guest secure world can do the partitioning

• Need an isolated execution environment to emulate device

– Reuse some structure of the VMM

– Protected from VMM

– Not included in system TCB

19

Page 24: vTZ: Virtualizing ARM TrustZone - USENIX · vTZ: Virtualizing ARM TrustZone IPADS,ShanghaiJiaoTongUniversity Zhichao Hua, Jinyu Gu, Yubin Xia, Haibo Chen, Binyu Zang, HaibingGuan

P3. Only secure world can partition memory

• CIEE (Constrained Isolated Execution Environment)

• Protects a piece of code in the hyp mode

• Excluded from system TCB

20

Page 25: vTZ: Virtualizing ARM TrustZone - USENIX · vTZ: Virtualizing ARM TrustZone IPADS,ShanghaiJiaoTongUniversity Zhichao Hua, Jinyu Gu, Yubin Xia, Haibo Chen, Binyu Zang, HaibingGuan

CIEE (Constrained Isolated Execution Environment)

• Located in the hyp mode

• Prevent against the untrusted VMM– Single entry point

– Run-to-completion

– No dependence on the hypervisor’s data

– No data exposure to the hypervisor

– Unforgeable to the secure world

• Exclude CIEE from system TCB– Isolated privilege

20

Page 26: vTZ: Virtualizing ARM TrustZone - USENIX · vTZ: Virtualizing ARM TrustZone IPADS,ShanghaiJiaoTongUniversity Zhichao Hua, Jinyu Gu, Yubin Xia, Haibo Chen, Binyu Zang, HaibingGuan

CIEE (Constrained Isolated Execution Environment)

• CIEE components– CIEE-Code

– Stack page

– Secure object

• Enforce five security policies

• Isolated privilege– Diff privilege for each CIEE

– Diff copy of secure obj. for each guest

smc

smc

stack page

r/w

CIEE-code

CIEE

write

request

Normal World Secure World

secure obj.

securedmodules

read

21

Page 27: vTZ: Virtualizing ARM TrustZone - USENIX · vTZ: Virtualizing ARM TrustZone IPADS,ShanghaiJiaoTongUniversity Zhichao Hua, Jinyu Gu, Yubin Xia, Haibo Chen, Binyu Zang, HaibingGuan

P3. Only secure world can partition memory

• CFLock traps memory accesses of virtual TZASC– Memory mapped device

– Accessing triggers page fault exception

• SWS identifies current VM– Only guest secure world can do the partitioning

• Emulate TZASC in an CIEE

22

Page 28: vTZ: Virtualizing ARM TrustZone - USENIX · vTZ: Virtualizing ARM TrustZone IPADS,ShanghaiJiaoTongUniversity Zhichao Hua, Jinyu Gu, Yubin Xia, Haibo Chen, Binyu Zang, HaibingGuan

Evaluation

• Can vTZ support existing trust OS?

• How is the performance of server applications on vTZ?

• How is the performance of application with multiple VMs?

23

Page 29: vTZ: Virtualizing ARM TrustZone - USENIX · vTZ: Virtualizing ARM TrustZone IPADS,ShanghaiJiaoTongUniversity Zhichao Hua, Jinyu Gu, Yubin Xia, Haibo Chen, Binyu Zang, HaibingGuan

Evaluation

• Hardware platform– Hikey (ARMv8) with eight 1.2 GHz cores

– Exynos (ARMv7) with one 1.7GHz core

• Software environment– Xen 4.4 + Linux 4.1

24

Page 30: vTZ: Virtualizing ARM TrustZone - USENIX · vTZ: Virtualizing ARM TrustZone IPADS,ShanghaiJiaoTongUniversity Zhichao Hua, Jinyu Gu, Yubin Xia, Haibo Chen, Binyu Zang, HaibingGuan

Compatibility

• Port two existing trust OSes on vTZ– seL4 [SOSP’2009]

– OP-TEE [https://github.com/OP-TEE/]

• Porting effort– Add description file to describe the device base addresses

• Base addresses of memory and devices

• Same as porting an OS on an ARM SoC

25

Page 31: vTZ: Virtualizing ARM TrustZone - USENIX · vTZ: Virtualizing ARM TrustZone IPADS,ShanghaiJiaoTongUniversity Zhichao Hua, Jinyu Gu, Yubin Xia, Haibo Chen, Binyu Zang, HaibingGuan

Application Overhead

12

13

14

15

16

17

4k 8k 16k 32k

Thro

ughp

ut o

f Apa

che

(MB/

s)

Size of TCP buffer (Bytes)

NativeTZ

XenvTZ

1

2

3

4

5

6

128 256 512 1k 2k 4k 8k

Thro

ughp

ut o

f Mon

goD

B (K

ops/

s)

Size of item value (Bytes)

NativeTZ

XenvTZ

26

Page 32: vTZ: Virtualizing ARM TrustZone - USENIX · vTZ: Virtualizing ARM TrustZone IPADS,ShanghaiJiaoTongUniversity Zhichao Hua, Jinyu Gu, Yubin Xia, Haibo Chen, Binyu Zang, HaibingGuan

Application Overhead

(a) (b)

GoHttps on ARMv7(a) and ARMv8(b) with different VMs.

N. :NativeTZ :TrustZoneX :XenvTZ :Our system

27

Page 33: vTZ: Virtualizing ARM TrustZone - USENIX · vTZ: Virtualizing ARM TrustZone IPADS,ShanghaiJiaoTongUniversity Zhichao Hua, Jinyu Gu, Yubin Xia, Haibo Chen, Binyu Zang, HaibingGuan

Conclusion• Analyze security properties of TrustZone

• Combine TrustZone and virtualization to multiplex secure world for each guest– SMM exclusively controls the memory mapping

– CFLock hooks all exceptions in the hyp mode

– SWS checks all switching between a VM and the VMM

– CIEEs to protect pieces of code in the hyp mode and exclude them from system TCB

• Small system TCB

• Compatible with existing trust OS– Porting two trust OSes on vTZ

• Acceptable performance overhead

28

Page 34: vTZ: Virtualizing ARM TrustZone - USENIX · vTZ: Virtualizing ARM TrustZone IPADS,ShanghaiJiaoTongUniversity Zhichao Hua, Jinyu Gu, Yubin Xia, Haibo Chen, Binyu Zang, HaibingGuan

29

Thanks

InstituteofParallelAndDistributedSystems(IPADS)http://ipads.se.sjtu.edu.cn


Recommended