39
1 EPOXY: Shielding Bare-Metal Embedded Systems Mathias Payer (@gannimo), Purdue University Jointly with Abraham Clements and Saurabh Bagchi http://hexhive.github.io

EPOXY: Shielding Bare-Metal Embedded Systems · 1 day ago · 4 Software is unsafe and insecure* Low-level languages (C/C++) trade type safety and memory safety for performance –

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: EPOXY: Shielding Bare-Metal Embedded Systems · 1 day ago · 4 Software is unsafe and insecure* Low-level languages (C/C++) trade type safety and memory safety for performance –

1

EPOXY: Shielding Bare-Metal Embedded Systems

Mathias Payer (@gannimo), Purdue UniversityJointly with Abraham Clements and Saurabh Bagchihttp://hexhive.github.io

Page 2: EPOXY: Shielding Bare-Metal Embedded Systems · 1 day ago · 4 Software is unsafe and insecure* Low-level languages (C/C++) trade type safety and memory safety for performance –

2https://en.wikipedia.org/wiki/Pwn2Own

Bugs are everywhere?

Page 3: EPOXY: Shielding Bare-Metal Embedded Systems · 1 day ago · 4 Software is unsafe and insecure* Low-level languages (C/C++) trade type safety and memory safety for performance –

3

Trends in Memory Errors*

* Victor van der Veen, https://www.vvdveen.com/memory-errors/, updated Feb. 2017

Page 4: EPOXY: Shielding Bare-Metal Embedded Systems · 1 day ago · 4 Software is unsafe and insecure* Low-level languages (C/C++) trade type safety and memory safety for performance –

4

Software is unsafe and insecure*

● Low-level languages (C/C++) trade type safety and memory safety for performance– Our systems are implemented in C/C++– Too many bugs to find and fix manually

* SoK: Eternal War in Memory. Laszlo Szekeres, Mathias Payer, Tao Wei, and Dawn Song. In IEEE S&P'13

Google Chrome: 76 MLoCglibc: 2 MLoCLinux kernel: 14 MLoC

Page 5: EPOXY: Shielding Bare-Metal Embedded Systems · 1 day ago · 4 Software is unsafe and insecure* Low-level languages (C/C++) trade type safety and memory safety for performance –

5

Control-FlowHijack Attack

Page 6: EPOXY: Shielding Bare-Metal Embedded Systems · 1 day ago · 4 Software is unsafe and insecure* Low-level languages (C/C++) trade type safety and memory safety for performance –

6

Attack scenario: code injection

● Force memory corruption to set up attack● Redirect control-flow to injected code

Code Heap Stack

Page 7: EPOXY: Shielding Bare-Metal Embedded Systems · 1 day ago · 4 Software is unsafe and insecure* Low-level languages (C/C++) trade type safety and memory safety for performance –

7

Attack scenario: code reuse

● Find addresses of gadgets● Force memory corruption to set up attack● Redirect control-flow to gadget chain

Code Heap Stack

Page 8: EPOXY: Shielding Bare-Metal Embedded Systems · 1 day ago · 4 Software is unsafe and insecure* Low-level languages (C/C++) trade type safety and memory safety for performance –

8

Defenses protect desktops/servers

● Address Space Layout Randomization– Shuffles address space, requires information leak

● Data Execution Prevention– Prohibits code injection, requires ROP

● Stack Canaries– Prohibits stack smashing, requires direct write

Page 9: EPOXY: Shielding Bare-Metal Embedded Systems · 1 day ago · 4 Software is unsafe and insecure* Low-level languages (C/C++) trade type safety and memory safety for performance –

9

Control-Flow Integrity

Page 10: EPOXY: Shielding Bare-Metal Embedded Systems · 1 day ago · 4 Software is unsafe and insecure* Low-level languages (C/C++) trade type safety and memory safety for performance –

10

Control-Flow Integrity (CFI)*

● Restrict a program’s dynamic control-flow to the static control-flow graph– Requires static analysis– Dynamic enforcement mechanism

● Forward edge: virtual calls, function pointers● Backward edge: function returns

* Control-Flow Integrity. Martin Abadi, Mihai Budiu, Ulfar Erlingsson, Jay Ligatti. CCS ‘05* Control-Flow Integrity: Protection, Security, and Performance. Nathan Burow, Scott A. Carr, Joseph Nash, Per Larsen, Michael Franz, Stefan Brunthaler, Mathias Payer. ACM CSUR ‘18, preprint: https://nebelwelt.net/publications/files/18CSUR.pdf

Page 11: EPOXY: Shielding Bare-Metal Embedded Systems · 1 day ago · 4 Software is unsafe and insecure* Low-level languages (C/C++) trade type safety and memory safety for performance –

11

Control-Flow Integrity (CFI)

CHECK(fn);(*fn)(x);

CHECK_RET();return 7Attacker may corrupt memory,

code ptrs. verified when used

Page 12: EPOXY: Shielding Bare-Metal Embedded Systems · 1 day ago · 4 Software is unsafe and insecure* Low-level languages (C/C++) trade type safety and memory safety for performance –

12

CFI: limitations

● CFI provides incremental security– Attacker can choose between valid targets– Data-flow attacks are out of scope

● Strength of CFI depends on static analysis– Coarse-grained: all functions are allowed– Fine-grained: arity or function prototype

Page 13: EPOXY: Shielding Bare-Metal Embedded Systems · 1 day ago · 4 Software is unsafe and insecure* Low-level languages (C/C++) trade type safety and memory safety for performance –

13

Are we making progress?

2007

2017

Page 14: EPOXY: Shielding Bare-Metal Embedded Systems · 1 day ago · 4 Software is unsafe and insecure* Low-level languages (C/C++) trade type safety and memory safety for performance –

14

The State of the IoT

Page 15: EPOXY: Shielding Bare-Metal Embedded Systems · 1 day ago · 4 Software is unsafe and insecure* Low-level languages (C/C++) trade type safety and memory safety for performance –

15

Defenses deployed on IoT devices

Page 16: EPOXY: Shielding Bare-Metal Embedded Systems · 1 day ago · 4 Software is unsafe and insecure* Low-level languages (C/C++) trade type safety and memory safety for performance –

16

Bare-metal devices

(c) dekuNukem, hackaday.io(c) Felix, lowpowerlab.com

(c) bunnie, bunniestudios.com

(c) yenra

Page 17: EPOXY: Shielding Bare-Metal Embedded Systems · 1 day ago · 4 Software is unsafe and insecure* Low-level languages (C/C++) trade type safety and memory safety for performance –

17

Security challenges

● Single application– No separate privilege levels (kernel/user)

● No MMU (virtual memory)– Defenses limited to physical memory space

● Tight constraints– Runtime, memory, battery

Page 18: EPOXY: Shielding Bare-Metal Embedded Systems · 1 day ago · 4 Software is unsafe and insecure* Low-level languages (C/C++) trade type safety and memory safety for performance –

18

IoT security stack

Security Hardware

Global Data

Stack

Code

Bare-metal ApplicationUnused or trivially

bypassed

Vulnerable to:Stack smashingCode injection

Global data corruption

IOAlways accessible

Single (Root)execution domain

No ROP defenses

Sensitive IO

RAM

Flash

Page 19: EPOXY: Shielding Bare-Metal Embedded Systems · 1 day ago · 4 Software is unsafe and insecure* Low-level languages (C/C++) trade type safety and memory safety for performance –

19

Let’s exploit like in ‘99

(c) MGM

Page 20: EPOXY: Shielding Bare-Metal Embedded Systems · 1 day ago · 4 Software is unsafe and insecure* Low-level languages (C/C++) trade type safety and memory safety for performance –

20

EPOXY** Embedded Privilege Overlay across (X)

hardware for anY software

Page 21: EPOXY: Shielding Bare-Metal Embedded Systems · 1 day ago · 4 Software is unsafe and insecure* Low-level languages (C/C++) trade type safety and memory safety for performance –

21

EPOXY design

EPOXYLLVM-based

compiler

Sensitive IO

HardenedApplication

Source Code

● LLVM-based compiler● Protects against

– Code injection– IO manipulation– Control-flow hijack*– Data corruption*

* Probabilistic, strength may vary (tm)

Page 22: EPOXY: Shielding Bare-Metal Embedded Systems · 1 day ago · 4 Software is unsafe and insecure* Low-level languages (C/C++) trade type safety and memory safety for performance –

22

Embedded systems: opportunities

● No separation between “apps” or user/kernel– Only few instructions require privileges

● Small memory size: MBs of Flash, KBs of RAM– Memory is dedicated, may reuse all slack space

● Tight runtime constraints– Execution is interrupt driven, use slack

● Low power requirements– Limit overhead to few instructions

Page 23: EPOXY: Shielding Bare-Metal Embedded Systems · 1 day ago · 4 Software is unsafe and insecure* Low-level languages (C/C++) trade type safety and memory safety for performance –

23

Mission 1: privilege separation

(c) AMC, Walking Dead

Page 24: EPOXY: Shielding Bare-Metal Embedded Systems · 1 day ago · 4 Software is unsafe and insecure* Low-level languages (C/C++) trade type safety and memory safety for performance –

24

Before EPOXY

Code

Global Data

Stack

IO

Application

Security HW

Sensitive IO

Privileged Execution

Page 25: EPOXY: Shielding Bare-Metal Embedded Systems · 1 day ago · 4 Software is unsafe and insecure* Low-level languages (C/C++) trade type safety and memory safety for performance –

25

Privilege separation

● Static analysis identifies restricted operations– Specific instructions per ISA– Sensitive memory-mapped registers (MPU, IO)

● Instrumentation to– Configure MPU to drop privileges– Raise privileges selectively

● Enable security hardware– Enforce W^X code, RW data– Protect access to security hardware, I/O

Page 26: EPOXY: Shielding Bare-Metal Embedded Systems · 1 day ago · 4 Software is unsafe and insecure* Low-level languages (C/C++) trade type safety and memory safety for performance –

26

Privilege overlay: benefits

Code

Global Data

Stack

IO

Security HW

Sensitive IO

Enabled,Access Restricted

Access Restricted

Unprivileged Execution

Privileged Execution

Set to RX, EnforcesCode Integrity

Set to RW, StopsCode Injection

Page 27: EPOXY: Shielding Bare-Metal Embedded Systems · 1 day ago · 4 Software is unsafe and insecure* Low-level languages (C/C++) trade type safety and memory safety for performance –

Evaluation: privileged instructions

Application Tool Exe Priv Priv %

PinLock EPOXY 823K 1.4K 0.17%

FreeRTOS-MPU 823K 813K 98.78%

FatFS-uSD EPOXY 33.3M 3.9K 0.01%

FreeRTOS-MPU 34.1M 33.0M 96.77%

TCP-Echo EPOXY 310M 1.5K <0.001%

FreeRTOS-MPU 322M 307.0M 95.34%

Page 28: EPOXY: Shielding Bare-Metal Embedded Systems · 1 day ago · 4 Software is unsafe and insecure* Low-level languages (C/C++) trade type safety and memory safety for performance –

28

Mission 2: stop stack smashing

(c) Nintendo

Page 29: EPOXY: Shielding Bare-Metal Embedded Systems · 1 day ago · 4 Software is unsafe and insecure* Low-level languages (C/C++) trade type safety and memory safety for performance –

* V. Kuznetsov et al., Code Pointer Integrity, OSDI 2014

RAM

Stack .data .bss heapStack UnSafeStack

Guard Region

Stack integrity through SafeStack

● Split stack into safe stack and unsafe stack*● Move unsafe objects to unsafe stack● Protects against stack smashing

Page 30: EPOXY: Shielding Bare-Metal Embedded Systems · 1 day ago · 4 Software is unsafe and insecure* Low-level languages (C/C++) trade type safety and memory safety for performance –

Mission 3: shuffle

Page 31: EPOXY: Shielding Bare-Metal Embedded Systems · 1 day ago · 4 Software is unsafe and insecure* Low-level languages (C/C++) trade type safety and memory safety for performance –

EPOXY

● Shuffle globals, stack, and code– Protects against ROP– Protects against global data corruption

Seed

Binary 1

Binary 2

Binary 3

Binary 4

Seed 1

Seed 2

Seed 3

Seed 4

Diversification

Sources

Page 32: EPOXY: Shielding Bare-Metal Embedded Systems · 1 day ago · 4 Software is unsafe and insecure* Low-level languages (C/C++) trade type safety and memory safety for performance –

RAM

.data .bss heapStack UnSafeStackA B D A B C D

.data

B b dca a cb d

.bss

C 12 4 3

Flash

foo bar baz bar2 foo2 handler Jumps to handler

Binary 1

invalid execution

E

Padding

Stack UnSafeStackheap

handler foo foo2 bar2 bar baz

Diversification

Page 33: EPOXY: Shielding Bare-Metal Embedded Systems · 1 day ago · 4 Software is unsafe and insecure* Low-level languages (C/C++) trade type safety and memory safety for performance –

EPOXY: full feature set

Code

Global Data

Stack

IO

Hardened Application

Security HW

Sensitive IO

Enabled,Access Restricted

Access Restricted

UnSafeStack Isolate Unsafe Data

Protected stack, ROP Protections

Global Data Protected

ROP Protections

Unprivileged Execution

Privileged Execution

Set to RX, EnforcesCode Integrity

Set to RW, StopsCode Injection

Page 34: EPOXY: Shielding Bare-Metal Embedded Systems · 1 day ago · 4 Software is unsafe and insecure* Low-level languages (C/C++) trade type safety and memory safety for performance –

Evaluation: ROP gadgets

# Surviving Across

App Total 2 5 25 50 Last

PinLock 294K 14K 8K 313 0 48

FatFS-uSD 1,009K 39K 9K 39 0 32

TCP-Echo 676K 22K 9K 985 700 107

Using ROPgadget compiler to identify surviving gadgets across # diversified binaries

Page 35: EPOXY: Shielding Bare-Metal Embedded Systems · 1 day ago · 4 Software is unsafe and insecure* Low-level languages (C/C++) trade type safety and memory safety for performance –

Performance impact (BEEP)

Runtime SS PO All

Min -7.3% -1.3% -11.7%

Ave -3.5% 0.1% 1.1%

Max 4.4% 2.1% 14.2%

Energy SS PO All

Min -4.2% -10.3% -10.2%

Ave 0.2% -0.2% 2.5%

Max 7.3% 2.8% 17.9%

SS: SafeStack, PO: Privilege Overlay

Page 36: EPOXY: Shielding Bare-Metal Embedded Systems · 1 day ago · 4 Software is unsafe and insecure* Low-level languages (C/C++) trade type safety and memory safety for performance –

Performance impact

Pin

Lo

ck

Fa

tFS

-uS

D

TC

P-E

ch

o

1 5

1 0

5

0

5

1 0

1 5

% I

nc

rea

se

En

erg

y

S SP O

Pin

Lo

ck

FatF

S-u

SD

TC

P-E

ch

o

1 5

1 0

5

0

5

1 0

1 5

% I

nc

rea

se

Ru

nti

me

S SP O

IoT Apps Runtime IoT Apps Energy

Page 37: EPOXY: Shielding Bare-Metal Embedded Systems · 1 day ago · 4 Software is unsafe and insecure* Low-level languages (C/C++) trade type safety and memory safety for performance –

37

Conclusion

Page 38: EPOXY: Shielding Bare-Metal Embedded Systems · 1 day ago · 4 Software is unsafe and insecure* Low-level languages (C/C++) trade type safety and memory safety for performance –

38

● Embedded systems need protection– Currently no defenses, easy target

● Fast forward embedded security by 3 decades– Privilege separation, mitigate code injection– Safe stack protects against stack smashing– Diversification instead of ASLR

● Meets runtime, memory, energy requirements

Source: https://github.com/HexHive/EPOXY

Conclusion

Page 39: EPOXY: Shielding Bare-Metal Embedded Systems · 1 day ago · 4 Software is unsafe and insecure* Low-level languages (C/C++) trade type safety and memory safety for performance –

39

Thank you!

Questions?

Mathias Payer (@gannimo), Purdue Universityhttp://hexhive.github.io