VTrust: Regaining Trust on Virtual Calls Chao Zhang , Sco5 A. Carr, - - PowerPoint PPT Presentation

vtrust regaining trust on virtual calls
SMART_READER_LITE
LIVE PREVIEW

VTrust: Regaining Trust on Virtual Calls Chao Zhang , Sco5 A. Carr, - - PowerPoint PPT Presentation

Title VTrust: Regaining Trust on Virtual Calls Chao Zhang , Sco5 A. Carr, Tongxin Li, Yu Ding, Chengyu Song, Mathias Payer, Dawn Song UC Berkeley, Purdue University, Peking University, Georgia Tech Title Virtual Call Hijacking in real world A


slide-1
SLIDE 1

Title

VTrust: Regaining Trust on Virtual Calls

Chao Zhang, Sco5 A. Carr, Tongxin Li, Yu Ding, Chengyu Song, Mathias Payer, Dawn Song

UC Berkeley, Purdue University, Peking University, Georgia Tech

slide-2
SLIDE 2

Title

Virtual Call Hijacking in real world

use aEer free format string heap

  • verflow

… Virtual Call Hijacking

plenty of vulnerabiliMes:

Google: "80% a5acks exploit use-aEer-free...” Microso-: 50% CVEs targeted Winows7 are UAF

  • wri5en in C++
  • heavy use of virtual funcMons and virtual calls

A common way to exploit:

2

slide-3
SLIDE 3

Title

Virtual Calls

§ How to resolve the virtual funcMon of an object at runMme?

  • VTable pointers in objects

class B{ virtual void foo(); } class D1: public B{ virtual void foo(); int data1; } class D2: public B{ virtual void foo(); int data2; }

Class Hierarchy: void test ( B* obj ) {

  • bjàfoo(); // virtual call site

} B::foo, D1::foo, or D2::foo?

writable section read-only section D1::foo() ... vfptr

  • bj1 of Class D1

VTable of Class D1

data1 vfptr

  • bj2 of Class D2

data2 D2::foo() ...

VTable of Class D2

RunMme Memory: Resolve virtual funcMons: Step 1: read VTable pointer from obj Step 2: read funcMon pointer from VTable

3

slide-4
SLIDE 4

Title

Virtual Call Hijacking

§ A5acks: breaking the integrity of VTable pointers

§ VTable injecMon a5ack: vfptr points to forged VTables Resolve virtual funcMons: Step 1: read VTable pointer from obj Step 2: read funcMon pointer from VTable RunMme Memory:

writable section read-only section D1::foo() ... vfptr

  • bj1 of Class D1

VTable of Class D1

data1

writable section read-only section D1::foo() ... vfptr

  • bj1 of Class D1

VTable of Class D1

data1 ROP() ...

forged VTable

PracAcal and reliable: virtual call hijacking + ROP

4

slide-5
SLIDE 5

Title

Virtual Call Hijacking (2)

§ A5acks: breaking the integrity of VTable pointers

§ VTable injecMon a5ack: vfptr points to forged VTables § VTable reuse a5ack: vfptr points to exisAng but out-of-context VTables

Resolve virtual funcMons: Step 1: read VTable pointer from obj Step 2: read funcMon pointer from VTable RunMme Memory:

writable section read-only section D1::foo() ... vfptr

  • bj1 of Class D1

VTable of Class D1

data1

writable section read-only section D1::foo() ... vfptr

  • bj1 of Class D1

VTable of Class D1

data1 fp() ...

  • ther VTable or data

COOP aEack [S&P’15]

5

slide-6
SLIDE 6

Title

Outline

§ MoMvaMon § Related Work § Design § ImplementaMon § EvaluaMon § Conclusion

6

slide-7
SLIDE 7

Title

Binary Level Defenses

§ VTint [NDSS’15] § T-VIP [ACSAC’14]

  • enforce read-only

§ Pro:

  • binary-compaMble
  • could defat popular VTable injecMon a5acks

§ Con:

  • false posiMves
  • cannot defeat VTable reuse a5acks,e.g., COOP

writable section read-only? vf() ... vfptr

  • bject

VTable

data 7

slide-8
SLIDE 8

Title

Source Level Defense: Forward Edge CFI

§ GCC-VTV [Usenix’14], whitelist-based

  • compute an incomplete set of legiMmate targets at compile-Ame
  • merge this set by using iniMalizer funcMons at load Ame
  • validate runMme target against this set at runAme

§ Pro:

  • support incremental building

§ Con:

  • heavy runMme operaMon, i.e., hash table lookups

8

slide-9
SLIDE 9

Title

Source Level Defense: RockJIT

§ CCS’15, CFI-based

  • collect type informaAon at compile-Ame
  • compute equivalence classes of transfer targets at load Ame,

based on the collected type informaMon.

  • update the CFI checks to only allow indirect transfers

(including virtual calls) to one equivalence class at load-Ame § Pro:

  • support incremental building

§ Con:

  • heavy load Mme operaMons

9

slide-10
SLIDE 10

Title

Outline

§ MoMvaMon § Related Work § Design:

  • Virtual FuncMon Type Enforcement
  • VTable Pointer SaniMzaMon

§ ImplementaMon § EvaluaMon § Conclusion

10

slide-11
SLIDE 11

Title

Virtual FuncMon Type

§ A virtual funcMon is allowed at a virtual call site if and only if it has:

  • a matching funcMon name
  • a matching argument type list
  • matching qualifiers (constant, volaMle, reference)
  • a compaMble class

void test ( B* obj, int arg1, void* arg2) { // virtual call site

  • bjàfoo(arg1, arg2);

} class D: public B { // virtual funcMons virtual void foo(int arg1, void* arg2); }

11

slide-12
SLIDE 12

Title

Virtual FuncMon Type Enforcement

// virtual call site: expected type

  • bjàfoo(arg1, arg2);

// virtual funcMons definiMons: target type virtual void foo(int arg1, void* arg2);

§ How to encode the type informaMon, to enable fast

type lookup and comparison?

  • RTTI-based soluMons are too slow

ASSERT( expected_type == target_type )

  • bjàfoo(arg1, arg2);

12

slide-13
SLIDE 13

Title

Virtual FuncMon Type Enforcement

// virtual call site: expected type

  • bjàfoo(arg1, arg2);

// virtual funcMons definiMons: target type virtual void foo(int arg1, void* arg2);

§ Our soluMon: compute a signature for the type § All signatures can be computed staMcally and independently.

  • support incremental building
  • don’t need extra link-Mme,load-Mme or runMme support
  • fast and easy to deploy

ASSERT( expected_type == target_type )

  • bjàfoo(arg1, arg2);

signature = hash ( funcName, typeList, qualifiers, classInfo )

ASSERT( expected_signature == target_signature )

  • bjàfoo(arg1, arg2);

13

slide-14
SLIDE 14

Title

Security Analysis

§ No ma5er what VTables are used, target virtual

funcMons must have matching signatures.

§ A5ackers can forge signatures if and only if

  • target applicaMons have dynamic generated code.

Virtual Func Type Enforcement

Target Applications

VTable Reuse VTable Injection

14

slide-15
SLIDE 15

Title

VTable Pointer SaniMzaMon

§ SoluMon: limit the target funcMons to staMc code § How?

  • saniMze VTable pointers, to only allow legiMmate VTables used for

virtual funcMon lookup.

writable section read-only section D1::foo() ... vfptr

  • bj1 of Class D1

VTable of Class D1

data1

writable section read-only section D1::foo() ... vt_idx

  • bj1 of Class D1

VTable of Class D1

data1 D1::vfptr ...

Translation Table

15

slide-16
SLIDE 16

Title

Outline

§ MoMvaMon § Related Work § Design § ImplementaMon § EvaluaMon § Conclusion

16

slide-17
SLIDE 17

Title

Virtual FuncMon Type Enforcement

§ Compute signatures

  • funcMon name:

§ destructor funcMons § member funcMon pointers

  • class info:

§ top-most primary class’ name

§ Instrument signatures

  • hard-coded before virtual call sites
  • hard-coded before virtual funcMon bodies

ASSERT( expected_signature == target_signature )

  • bjàfoo(arg1, arg2);

signature = hash ( funcName, typeList, qualifiers, classInfo )

17

slide-18
SLIDE 18

Title

VTable Pointer SaniMzaMon

§ A centralized translaMon table is impracMcal

  • merge this table at load-Mme
  • update vt_idx in constructor funcMons

§ Our soluMon: distributed translaMon table

  • each library has its own translaMon table

writable section read-only section D1::foo() ... vt_idx

  • bj1 of Class D1

VTable of Class D1

data1 D1::vfptr ...

Translation Table

writable section read-only section D1::foo() ... idx_pair

  • bj1 of Class D1

D1's VTable

data1 D1::vfptr ...

Translation Table for lib1

D2::vfptr ...

Translation Table for lib2

D1::foo() ...

D2's VTable

lib1 lib2 ...

Global Translation Table

  • constant library

translaMon tables.

  • constant idx_pair

18

slide-19
SLIDE 19

Title

Overall Workflow

LLVM Opt *.cpp LLVM IR (metadata) Clang/ Clang++ LLVM IR (checks) LLVMgold.so *.obj LLVM CodeGen VTLib.so *.cpp VTable metadata Collector VTLib.cpp executable/ libraries ld.gold

layer 1: VFunc Type Enforcement (part 2) layer 2: VTable Pointer Sanitization layer 1: VFunc Type Enforcement (part 1)

19

slide-20
SLIDE 20

Title

Outline

§ MoMvaMon § Related Work § Design § ImplementaMon § EvaluaMon § Conclusion

20

slide-21
SLIDE 21

Title

Performance Overhead

§ SPEC 2006

  • avg (two layers together): 2.2% (~ 0.72% + 1.4%)
  • worst: 8.0%

0.00%$ 1.00%$ 2.00%$ 3.00%$ 4.00%$ 5.00%$ 6.00%$ x a l a n c . $ a s t a r $

  • m

n e t p p $ s

  • p

l e x $ d e a l I I $ n a m d $ p

  • v

r a y $ G e

  • .

M e a n $ TypeEnforce$ VTableSanCze$

The 1st layer defense is much faster than the 2nd layer, sufficient for programs without dynamic generated code.

21

slide-22
SLIDE 22

Title

Performance Overhead

§ Firefox

  • avg (two layers together): 2.2% (~ 0.4% + 1.8%)
  • worst: 4.3%

!0.50%& 0.00%& 0.50%& 1.00%& 1.50%& 2.00%& 2.50%& 3.00%& 3.50%& L i t e B r i t e & K r a k e n & S u n s p i d e r & B r

  • w

s e r m a r k & O c t a n e & P e a c e K e e p e r & G e

  • .

M e a n . & TypeEnforce& VTableSaniHze&

22

slide-23
SLIDE 23

Title

ProtecMon Effects

§ VTable injecMon a5acks § VTable reuse a5acks (few in real world)

  • BCTF challenge “zhongguancun”

23

slide-24
SLIDE 24

Title

Corner cases

§ Custom virtual funcMon definiMons

  • e.g., nsXPTCStubBase::StubNN() in Firefox
  • will cause false posiMves

§ Custom virtual call sites

  • e.g., NS_InvokeByIndex() in Firefox
  • will leave extra a5ack surface

§ VTrust could idenMfy all these corner cases

automaMcally, and provides a precise protecMon.

24

slide-25
SLIDE 25

Title

Conclusion

§ VTrust provides two layers of defenses against all virtual

call hijacking a5acks.

§ Virtual funcAon type enforcement introduces a very low

performance overhead, able to defeat all this type of a5acks if no dynamic code exists in target applicaMons.

§ VTable pointer saniAzaAon could help defeat all a5acks

even if target applicaMons have dynamic code.

§ The performance and security evaluaMon show that

VTrust has a low performance overhead, and provides a strong protecMon.

25

slide-26
SLIDE 26

Title

Thanks!

Q&A