Who we are Eshard - Embedded Security Company Software & - - PowerPoint PPT Presentation

who we are eshard embedded security company software
SMART_READER_LITE
LIVE PREVIEW

Who we are Eshard - Embedded Security Company Software & - - PowerPoint PPT Presentation

Who we are Eshard - Embedded Security Company Software & Hardware Security What do we do: @eshardNews Tools: Side Channel / Code Analysis Consultancy https://www.eshard.com Audit contact@eshard.com Training


slide-1
SLIDE 1

Who we are

1

Eshard - Embedded Security Company

  • Software & Hardware Security

What do we do:

  • Tools: Side Channel / Code Analysis
  • Consultancy
  • Audit
  • Training

@eshardNews https://www.eshard.com contact@eshard.com Bordeaux + Marseille

slide-2
SLIDE 2

Attack TrustZone with Rowhammer

2

Pierre Carru - eshard pierre.carru@eshard.com

GreHack 2017

slide-3
SLIDE 3

Presentation Summary

3

  • 1. Rowhammer → Corrupt Mem
  • 2. TrustZone→ Secure enclave ~25 min
  • 3. Attack: Corrupt TrustZone Mem
  • 4. Questions
slide-4
SLIDE 4

Context - Existing Rowhammer-based Exploitations

4

  • Intel

○ clflush instruction (2014 original attack) ○ cache eviction (rowhammer.js 2015) ○ non-temporal instructions (2016) ○

  • ne location hammering (few days ago)
  • Mobile (arm):

no direct way for unprivileged user ○ Drammer (end 2016) uses uncached memory region → exploit gains root privilege ○ No cache eviction method working yet → not enough access/second (yet)?

slide-5
SLIDE 5

Context - Existing TrustZone Attacks

5

  • Software Bugs in Qualcomm’s TEE, and Widevine TA:

○ Dan Rosenberg (2014): Integer overflow No exploitation ○ Gal Beniamini (2015 - 2016):

  • 1. Missing parameter validation in Secure Kernel Call

→ Shellcode execution in Secure Kernel

  • 2. Buffer Overflow in Widevine TA

→ Shellcode execution in TA, and then in Secure Kernel

  • CLKSCREW (Tang 2017):

Faults in microarchitecture using frequency and voltage scaling → Retrieve private key, Load self-signed TA

  • Other ARM Plaforms: undisclosed / unknown?

⇒ Few TrustZone Attack

slide-6
SLIDE 6

Rowhammer attack against TrustZone

6

Assumption:

  • Rowhammer vulnerable device
  • Kernel Privilege in Normal OS

Objectives:

  • Corrupt Memory marked Secure
  • If possible, exploit corruptions in order to gain more privileges

We focus on the Secure / Non-Secure border → We use maximum privilege in Non-Secure Side

Linx Kernel TEE Kernel NS S User TEE User

slide-7
SLIDE 7

Realization - Example Exploitation

7

Platform: Any Cortex-A based ARM Development board with TrustZone Support

  • Linux in Non-Secure Side
  • Custom Trusty based TEE

PoC attack: 1. TEE provides an RSA-CRT signing mechanism 2. Secret Key stored in S Memory 3. Linux uses Rowhammer to fault the Secret Key (crosses the TrustZone border) 4. Linux uses faulty signature to recover Secret Key “Bellcore” (Boneh, DeMillo, Lipton)

slide-8
SLIDE 8

Exploitation Principle (1)

8

Linux TEE Non-Secure World “NS” Secure World “S” RSA key

  • public: n, e
  • private: d, p, q
  • precomputed private: dp,dq, qInv

Please sign m=“Hello”

Compute using RSA key c ← RSA-CRT(key, m)

Return signature c=0x24A96… and public key (n,e)

slide-9
SLIDE 9

Exploitation Principle (2)

9

Linux TEE Non-Secure World “NS” Secure World “S” RSA key

  • public: n, e
  • private: d, p, q
  • precomputed private: dp

’,dq, qInv

Please sign m=“Hello”

Compute using RSA key c’ ← RSA-CRT(key’, m)

Return signature c’=0x68F6… and public key (n,e) Rowhammer attack targeted at key area Faults dp — its value is now dp

Recovers private RSA key Using m and c’ values

slide-10
SLIDE 10

Rowhammer

10

slide-11
SLIDE 11

System Architecture

11

SoC Processor Processor Processor Processor DRAM Controller DRAM Chip AXI DDR Protocol DRAM Chip L1 Cache L2 Cache AXI

Need to Go through the caches! May reorder accesses usually only 1 PoP

  • n mobile
slide-12
SLIDE 12

How to generate faults in DRAM

12

slide-13
SLIDE 13

DRAM Storage Cell

13

Capacitor as storage mechanism Capacitor either:

  • charged → logic 1
  • discharged → logic 0

Capacitors lose their charge over time ⇒ have to be recharged periodically “refreshed”

slide-14
SLIDE 14

A DRAM Chip contains multiple Banks

14

Usually on Mobile: 1 PoP LPDDR3/4 Chip Image: Onur Mutlu

slide-15
SLIDE 15

x8 DRAM Bank

15

Image: Memory Systems - Cache, DRAM, Disk

slide-16
SLIDE 16

DRAM Array

16

ACTIVATE Open Row → Row Buffer READ/WRITE R or W Column (in buffer) PRECHARGE Close Row REFRESH

Row Buffer Row 3 Row 2 Row 1 Row 0 Cell Bitline Wordline Row Decoder Sense Amplifier Address Column Decoder MS LS Data Out

slide-17
SLIDE 17

Row Access

17

Access to an opened row:

  • No need to ACTIVATE
  • Just READ/WRITE to access row buffer

Access to a closed row:

  • PRECHARGE current row
  • ACTIVATE new row
  • READ/WRITE
slide-18
SLIDE 18

Simple-Sided Rowhammer

18

Need to ACTIVATE two distinct Rows in the same Array Because accessing the same Row consecutively ⇒ hit the row buffer

ROW BUFFER ROW 4 ROW 3 ROW 2 ROW 1

May generate 0 → 1 or 1 → 0 flips

slide-19
SLIDE 19

Double-Sided Rowhammer

19

Hammer rows adjacent to the target Row → generates more flips Flips are reproducible on a particular RAM chip → due to manufacturing?

ROW BUFFER ROW n+1 ROW n ROW n-1

slide-20
SLIDE 20

How to address rows from CPU

20

slide-21
SLIDE 21

Memory Mapping - How to address adjacent rows (1)

21

Bank 0 Bank 1 4 Banks, x8 Bus Width No Bank Interleaving

8 A r r a y s

. . .

Byte [0x00]

Row 0 Col 0: 8 bits (1 bit per Array)

Byte [0x01] Byte [n_col - 1] Byte [n_col] Bottom and Top rows can’t be attacked with double sided technique

slide-22
SLIDE 22

Memory Mapping - How to address adjacent rows (2)

22

Bank 0 Bank 1 4 Banks, x8 Bus Width With Bank Interleaving

8 A r r a y s

Byte [0x00]

Row 0 Col 0: 8 bits (1 bit per Array)

Byte [0x01] Byte [n_col - 1] Byte [n_col]

. . .

Byte [n_col×n_banks]

slide-23
SLIDE 23

Deduce Memory Characterics & Configuration using Timing Characterization

23

Pseudo code (simplified)

base = 0x…; for (i = start; i < end; i += step) { ts = start() read_at(base) read_at(i) time[i] = end(ts) }

Can be crossed checked with datasheets if DRAM Chip is identified

slide-24
SLIDE 24

Rowhammer Implementation (2)

24

Need to map region around target physical location → ioremap [target_pa - Δ, target_pa + Δ] Need to bypass the caches: “uncacheable” region → ioremap_nocache

SoC Processor Processor Processor Processor DMC DRAM L1 L2 Kernel TEE Kernel NS S User TEE User Timer

slide-25
SLIDE 25

Rowhammer Implementation (1)

25

/* row before */ addrs[0] = target_va - (mem->n_banks * mem->row_size); /* row after */ addrs[1] = target_va + (mem->n_banks * mem->row_size); for (int j = 0; j < iterations; j++) { *row_before = pattern; /* write or read */ *row_after = pattern; }

In Kernel Module for simplicity Code Simplified:

slide-26
SLIDE 26

TrustZone

26

slide-27
SLIDE 27

TrustZone Rationale

27

Want:

  • Secure processor runs OS with manageable Security

≠ Android

  • Some hardware resources only accessible to Secure OS

Do not want to:

  • Waste silicon space on separate processor
  • Hardware duplication

→ TrustZone:

  • Time sharing of processor, ≈ virtually 2 distinct processors
  • Some resources available only to the Secure processor
slide-28
SLIDE 28

System Bus - AXI

28

Masters:

  • Read from slaves
  • Write to slaves

TrustZone Introduces a new transaction attribute: NS ∈ {0, 1}

CPU DRAM Controller AXI interface

Image: ARM

S read to 0x1234 NS read to 0x1234 ex: DMA Controller, Modem, ...

slide-29
SLIDE 29

Adaptations to IPs AXI slave responsible to enforce S/NS logic L1, L2 Caches Memory controller Touchscreen DMA controller MMU Interrupt controller … Existing devices can be modified to become aware of TrustZone Or an extra adapter IP can wrap a device to provide S/NS logic

29

slide-30
SLIDE 30

ARM Gadget2008

30

slide-31
SLIDE 31

ARM Procesor Architecture extensions Principles: Only “secure software” can make S transactions. NS OS calls “secure software” which checks if call request is legal Implementation: New state dimension: NS is {0, 1} New processor mode: monitor (in addition to usr, svc, …) PL1 New instruction: SMC, similar to SVC but for: PL1 → monitor New system controls (SCR, …), CP15 Register banking

31

slide-32
SLIDE 32

Modes, privilege levels, Security States (Simplified, ARMv7-A)

32

slide-33
SLIDE 33

Modes, privilege levels, Security States (Simplified, ARMv7-A)

SMC SVC SMC SVC ERET ERET ERET ERET

33

slide-34
SLIDE 34

In one state at a time (per core)

Start linux

Execution

34

Bootloader Non-Secure Secure Time Startup

Init

Context Switches through monitor

S Interrupt

Linux TEE OS

Offer services to linux

slide-35
SLIDE 35

Attack

35

slide-36
SLIDE 36

RSA-CRT - Fast implementation of the RSA signature based on CRT

36

Signature s of the message m is defined as: Some constants precalculated at key generation The signature can be calculated:

exponents and modulus are smaller ⇒ faster

slide-37
SLIDE 37

RSA-CRT Fault Attack - “Bellcore”

37

On the Importance of Checking Cryptographic Protocols for Faults Boneh, DeMillo, Lipton 1997 If dq is faulted and becomes dq’ The signature calculation become s’ instead of s p can then be calculated and is: The whole private key can then be derived

slide-38
SLIDE 38

PoC - Implemented System Overview

38

Trusty generates random RSA key in secure memory at boot Offers signature mechanism to Linux “row” module used to generate faults to a target address using Rowhammer “sign” tool uses Trusty’s signature service and calculates gcd

sign userspace tool Linux Trusty NS S row

ioctl

Shared mem + context switch

slide-39
SLIDE 39

Memory Setup

39

Unused Linux 256M 512M 768M 1G 0x1000_0000 DRAM

U A R T G I C

0x1000_0000 0x5000_0000 0xFFFF_FFFF 0x5000_0000 0x2000_0000 0x3000_0000 0x4000_0000 Board physical address space Offset in DRAM 1G

Keys

Trusty DRAM Physical addresses 0x4800_0000

slide-40
SLIDE 40

Example Session - Sign Message - No Fault in Key

40

[root@alarm ~]# ./sign hello message: 0x68656c6c6f00000000000000000000000000… [ 5326.601784] row: ROW_IOCTL_SIGNATURE sign_crt:88: s = 0x7c1a8306e5a4910b3d94d06e62174f4669… public key: e = 0x3 n = 0xc2c617ed42871bfc97b83cc1e392f0b03323858… signature: 0x7c1a8306e5a4910b3d94d06e62174f4669… gcd == n, no fault have happened in the key area

Kernel Trusty Userspace

slide-41
SLIDE 41

Example Session - Hammer

41

[root@alarm ~]# echo 1 > /sys/module/row/params/do_hammer [ 5343.279638] row: addr[0]=a17f0000 (pa 400F0000) [ 5343.284277] row: addr[1]=a1810000 (pa 40110000) [ 5346.779417] dmc: R=2MB nR=0M 0 MnR/s (29) @ ~0 MB/s [ 5346.779417] W=128MB nW=32M 9 MnW/s (4) @ ~36 MB/s [ 5346.790429] row: elapsed=42294

Memory Controller Counters

slide-42
SLIDE 42

Example Session - Sign Message - Key Faulted

42

[root@alarm ~]# ./sign hello message: 0x68656c6c6f00000000000000000000000000… [ 5355.711724] row: ROW_IOCTL_SIGNATURE sign_crt:88: s = 0x657eb547c65344406a9d7f44a58d… public key: e = 0x3 n = 0xc2c617ed42871bfc97b83cc1e392f0b03323858… signature: 0x657eb547c65344406a9d7f44a58da72860… Success: found private factor f: 0xc5d85c20911b6fb56e795d857ea927f28112f7321e713…

  • ther factor of n: n/f = 0xfc069e141107cf589b9464d8341ea18b4c2769513331f…

Calculated Signature has changed Found a factor!

slide-43
SLIDE 43

Cannot Access Secure Areas - Protected by TZASC

43

[root@alarm ~]# cat /sys/module/row/params/do_dump_target_pa [ 5372.191371] Unhandled fault: imprecise external abort (0x406) at 0x76e15004 [ 5372.198354] pgd = 8ced0000 [ 5372.201071] [76e15004] *pgd=1cdd5831, *pte=1b3c175f, *ppte=1b3c1c7f [ 5372.207400] Internal error: : 406 [#1] SMP ARM

slide-44
SLIDE 44

Conclusion

44

  • Proof of attackability
  • Limitation: Attack memory along S/NS border
  • Need to study current TrustZone implementations to determine if exploitable
  • Mitigation is simple
  • Intern positions open: LLVM Obfuscator / Side-Channel Analysis

Distributed Computing

slide-45
SLIDE 45

Questions

45

slide-46
SLIDE 46

Remarks (1)

46

Different point of view compared to other Rowhammer applications: We are at kernel level, so:

  • Easy to access memory using physical addresses
  • Easy to bypass caches

This is how drivers for memory mapped devices work See /proc/iomem

slide-47
SLIDE 47

Remarks (2)

47

Do real world TEE implementations use S regions where Rowhammer is possible? → Need to make a mapping of the address space Easily done from NS space, access to S regions ⇒ external abort

slide-48
SLIDE 48

Why Trusty?

48

Simple & Clean implementation (but no docs)

  • Based on LK, nearly vanilla

○ Multiple kernel tasks, preemptive scheduler ○ Memory Management primitives (page tables, ...) ○ Usual primitives: mutexes, timers, …

  • Trusty additions in another repo (extensible build system)

○ TrustZone Monitor ○ Userspace applications + syscall interface ○ High Level IPC between S / NS

slide-49
SLIDE 49

Trusty - Board Support

49

  • New platform lk/trusty/platform/
  • Cortex-A9 Support (rough):

○ GICv1 ○ Private Timer

  • Drivers

○ UART ○ TZASC ○ ...

slide-50
SLIDE 50

Annex

50

slide-51
SLIDE 51

Trusty Source Code Organization

51

  • external/lk: Nearly “normal” LK
  • lk/trusty: additions to LK

○ lib/sm: TrustZone Monitor ○ lib/uthread: Userspace threads ○ lib/trusty: Various ○ platform/generic-arm64: Support for qemu arm64 virtual board. ○ platform/vexpress-a15: Support for ARM’s reference board

  • app: Userspace trusty applications “Trustlets”.
slide-52
SLIDE 52

Stdcall / Fastcall calling conventions

52

SMC, parameters in registers:

  • Fastcall: atomic
  • Yielding call “stdcall”: can be preempted by a NS interrupt (needs resume)

In Trusty an SMC Number is defined as:

#define SMC_FASTCALL_NR(entity, fn) SMC_NR((entity), (fn), 1, 0) #define SMC_NR(entity, fn, fastcall) ((fastcall) & 0x1) << 31) | \ ((entity) & 0x3F) << 24) | \ ((fn) & 0xFFFF) \ )

slide-53
SLIDE 53

Trusty fastcall

53

Trusty: register handler to trusty int callback(args) { … } register_fastcall(call number, callback) Linux: use trusty library in order to issue an SMC with particular call number int ret = trusty_fastcall(call number, args)

slide-54
SLIDE 54

References

54 DRAM

  • Memory Systems - Cache, DRAM, Disk
  • Computer Architecture - Main Memory, Onur Mutlu
  • Rajeev Balasubramonian
  • Main Memory - Christos Kozyrakis

Rowhammer

  • Flipping Bits in Memory Without Accessing Them: An Experimental Study of DRAM Disturbance Errors, Yoongu Kim
  • Exploiting the DRAM rowhammer bug to gain kernel privileges, Mark Seaborn and Thomas Dullien
  • Rowhammer.js: A Remote Software-Induced Fault Attack in JavaScript, Daniel Gruss, Clémentine Maurice, and Stefan Mangard
  • Drammer: Deterministic Rowhammer Attacks on Mobile Platforms, Victor van der Veen

TrustZone

  • Reflections on Trusting TrustZone, Dan Rosenberg
  • https://bits-please.blogspot.com, Gal Beniamini

RSA-CRT Fault Attack

  • On the Importance of Checking Cryptographic Protocols for Faults, Boneh, DeMillo, Lipton 1997

Trusty

  • https://source.android.com/security/trusty/