Dongseok Jang Zachary Tatlock Sorin Lerner UC San - - PowerPoint PPT Presentation

dongseok jang zachary tatlock sorin lerner uc san diego
SMART_READER_LITE
LIVE PREVIEW

Dongseok Jang Zachary Tatlock Sorin Lerner UC San - - PowerPoint PPT Presentation

Dongseok Jang Zachary Tatlock Sorin Lerner UC San Diego University of UC San Diego Washington Vulnerable Control Flow Hijacking Lead Program to


slide-1
SLIDE 1

¡

Dongseok ¡Jang ¡ Zachary ¡Tatlock ¡ Sorin ¡Lerner ¡

UC ¡San ¡Diego ¡ University ¡of ¡ Washington ¡ UC ¡San ¡Diego ¡

slide-2
SLIDE 2

Vulnerable ¡

slide-3
SLIDE 3

Control ¡Flow ¡Hijacking ¡

Lead ¡Program ¡to ¡Jump ¡to ¡Unexpected ¡Code ¡

That ¡does ¡what ¡a7acker ¡wants ¡ ¡

Example: ¡Stack ¡Buffer ¡Overflow ¡ALacks ¡

Well ¡studied ¡and ¡hard ¡to ¡be ¡cri=cal ¡by ¡itself ¡ ¡ ¡

New ¡FronNer ¡: ¡Vtable ¡Hijacking ¡

slide-4
SLIDE 4

Vtable ¡Pointers ¡

Mechanism ¡for ¡Virtual ¡FuncNons ¡

class C { virtual int foo(); virtual int bar(); int fld; }; ... C *x = new C();

vptr ¡ fld ¡ foo ¡ bar ¡

x ¡

foo’s ¡impl ¡ bar’s ¡impl ¡ heap ¡obj ¡ vtable ¡

slide-5
SLIDE 5

Vtable ¡Pointers ¡

Virtual ¡Call ¡: ¡2-­‑Step ¡Dereferencing ¡for ¡Callee ¡

x->foo();

vptr ¡ fld ¡ foo ¡ bar ¡

x ¡

foo’s ¡impl ¡ bar’s ¡impl ¡ heap ¡obj ¡ vtable ¡

vptr = *((FPTR**)x); f = *(vptr + 0); f(x);

slide-6
SLIDE 6

Vtable ¡Hijacking ¡

bad ¡ fld ¡ foo ¡ bar ¡

x ¡

foo’s ¡impl ¡ bar’s ¡impl ¡ heap ¡obj ¡ vtable ¡ Arbitrary ¡ Code ¡ fake ¡vtable ¡

x->foo();

vptr = *((FPTR**)x); f = *(vptr + 0); f(x);

slide-7
SLIDE 7

Vtable ¡Hijacking ¡via ¡Use-­‑aSer-­‑Free ¡

C *x = new C(); x->foo(); delete x; // forget x = NULL; ... D *y = new D(); y->buf[0] = input(); ... x->foo();

C::vptr ¡ x’s ¡fld ¡

x ¡ y ¡

candidate ¡for ¡ ¡ realloca3on ¡ buf[0] ¡ buf[1] ¡ corrupted ¡ buf[1] ¡

x ¡

Use ¡Corrupted ¡Data ¡for ¡x’s ¡vptr

slide-8
SLIDE 8

Vtable ¡Hijacking: ¡Real ¡Case ¡

Vtable ¡Hijacking ¡of ¡Chrome ¡via ¡Use-­‑aSer-­‑Free ¡

Pinkie ¡Pie’s ¡demonstra=on ¡at ¡Pwn2Own ¡ Used ¡to ¡trigger ¡ROP ¡for ¡sandbox ¡escaping ¡of ¡Chrome ¡

Found ¡in ¡IE, ¡Firefox, ¡ Chrome

slide-9
SLIDE 9

¡

How ¡to ¡Prevent ¡Vtable ¡Hijacking? ¡

¡

¡With ¡Accuracy ¡& ¡Low ¡Overhead? ¡

slide-10
SLIDE 10

Code ¡InstrumentaNon ¡

C *x = ... Check(x); x->foo();

slide-11
SLIDE 11

Code ¡InstrumentaNon ¡

C *x = ... ASSERT(VPTR(x) ∈ Valid(C)); x->foo();

Valid(C) ¡= ¡{ ¡vptr ¡of ¡C ¡or ¡C’s ¡subclasses ¡} ¡

Obtained ¡by ¡class ¡hierarchy ¡analysis ¡(CHA) ¡

slide-12
SLIDE 12

Code ¡InstrumentaNon ¡

C *x = ... ASSERT(VPTR(x) ∈ Valid(C)); x->foo();

Simple ¡ImplementaNon ¡Can ¡Be ¡Slow ¡

Involved ¡data ¡structure ¡lookup/func=on ¡calls ¡

slide-13
SLIDE 13

Inlining ¡OpNmizaNon ¡

C *x = ... ASSERT(VPTR(x) ∈ Valid(C)); x->foo(); vptr = *((FPTR**)x); f = *(vptr + 0); f(x); x->foo()

slide-14
SLIDE 14

Inlining ¡OpNmizaNon ¡

C *x = ... ASSERT(VPTR(x) ∈ Valid(C)); vptr = *((FPTR**)x); f = *(vptr + 0); f(x); ASSERT(vptr ∈ Valid(C)); //

slide-15
SLIDE 15

Inlining ¡OpNmizaNon ¡

C *x = ... ASSERT(VPTR(x) ∈ Valid(C)); vptr = *((FPTR**)x); ASSERT(vptr ∈ Valid(C)); f = *(vptr + 0); f(x);

Say ¡that ¡C ¡has ¡only ¡one ¡subclass ¡D ¡ à à ¡SpecializaNon ¡of ¡Checks

// ASSERT(vptr ∈ {C::vptr, D::vptr}); //

slide-16
SLIDE 16

Inlining ¡OpNmizaNon ¡

C *x = ... ASSERT(VPTR(x) ∈ Valid(C)); vptr = *((FPTR**)x); ASSERT(vptr ∈ Valid(C)); ASSERT(vptr ∈ {C::vptr, D::vptr}); // f = *(vptr + 0); f(x); SAFE: // //

slide-17
SLIDE 17

Inlining ¡OpNmizaNon ¡

C *x = ... ASSERT(VPTR(x) ∈ Valid(C)); vptr = *((FPTR**)x); ASSERT(vptr ∈ Valid(C)); ASSERT(vptr ∈ {C::vptr, D::vptr}); // f = *(vptr + 0); f(x); SAFE: if (vptr == C::vptr) goto SAFE; if (vptr == D::vptr) goto SAFE; exit(-1); // //

slide-18
SLIDE 18

Inlining ¡OpNmizaNon ¡

C *x = ... ASSERT(VPTR(x) ∈ Valid(C)); vptr = *((FPTR**)x); ASSERT(vptr ∈ Valid(C)); ASSERT(vptr ∈ {C::vptr, D::vptr}); // f = *(vptr + 0); f(x); SAFE: if (vptr == C::vptr) goto SAFE; if (vptr == D::vptr) goto SAFE; exit(-1); // //

How ¡to ¡Order ¡Inlined ¡Checked? ¡ à à ¡Profile-­‑guided ¡Inlining ¡

slide-19
SLIDE 19

Method ¡Pointer ¡Checking ¡

C *x = ... vptr = *((FPTR**)x); ASSERT(vptr ∈ {C::vptr, D::vptr}); f = *(vptr + 0); x->foo() f(x)

slide-20
SLIDE 20

Method ¡Pointer ¡Checking ¡

C *x = ... vptr = *((FPTR**)x); ASSERT(vptr ∈ {C::vptr, D::vptr}); f = *(vptr + 0); f(x) ASSERT(f ∈ ValidM(C,foo)); //

Checking ¡Callee ¡Before ¡It ¡Is ¡Called ¡

Provides ¡same ¡security ¡as ¡vtable ¡checking ¡

slide-21
SLIDE 21

Method ¡Pointer ¡Checking ¡

C *x = ... vptr = *((FPTR**)x); ASSERT(vptr ∈ {C::vptr, D::vptr}); f = *(vptr + 0); f(x) ASSERT(f ∈ ValidM(C,foo)); //

Say ¡that ¡C ¡has ¡one ¡subclass ¡D ¡ and ¡D ¡doesn’t ¡override ¡C::foo() ¡

// ASSERT(f ∈ {C::foo});

Save ¡Checks ¡for ¡Shared ¡Methods ¡

slide-22
SLIDE 22

Member ¡Pointers ¡in ¡C++ ¡

A *x = ... // m: index into a vtable // x->*m can be any methods of A (x->*m)()

Say ¡that ¡A ¡has ¡1000 ¡methods ¡ à à ¡Up ¡to ¡1000 ¡method ¡ptr ¡checks! ¡ Vtable ¡Checking ¡Can ¡Be ¡Faster ¡

slide-23
SLIDE 23

Method ¡Pointer ¡Checking ¡

Fewer ¡Checks ¡for ¡Usual ¡Virtual ¡Calls ¡ ¡ More ¡Checks ¡for ¡Member ¡Pointer ¡Calls ¡

slide-24
SLIDE 24

Hybrid ¡Checking ¡

Method ¡Checking ¡for ¡Usual ¡Virtual ¡Calls ¡ ¡ Vtable ¡Checking ¡for ¡Member ¡Pointer ¡Calls ¡

slide-25
SLIDE 25

Tamper ¡Resistance ¡

Inserted ¡Checks ¡in ¡Read-­‑Only ¡Memory ¡ ¡ Checking ¡Data ¡in ¡Read-­‑Only ¡Memory ¡

slide-26
SLIDE 26

Performance: ¡Benchmark ¡

Chromium ¡Browser ¡

Realis=c ¡: ¡≈ ¡3 ¡millions ¡of ¡C++/C ¡LOC ¡ Popular ¡target ¡of ¡vtable ¡hijacking ¡

¡ Running ¡On ¡JS, ¡HTML5 ¡Benchmark ¡

slide-27
SLIDE 27

Performance ¡

UnopNmized ¡(Avg: ¡23%) ¡

0 ¡ 5 ¡ 10 ¡ 15 ¡ 20 ¡ 25 ¡ 30 ¡ 35 ¡

JS ¡ HTML ¡

RunNme ¡Overhead(%) ¡

slide-28
SLIDE 28

Performance ¡

Profile-­‑Guided ¡Inlining ¡(Avg: ¡6%) ¡

0 ¡ 5 ¡ 10 ¡ 15 ¡ 20 ¡ 25 ¡ 30 ¡ 35 ¡

JS ¡ HTML ¡

RunNme ¡Overhead(%) ¡ 0 ¡ 5 ¡ 10 ¡ 15 ¡ 20 ¡ 25 ¡ 30 ¡ 35 ¡

JS ¡ HTML ¡

RunNme ¡Overhead(%) ¡

slide-29
SLIDE 29

Performance ¡

Inlined ¡Method ¡Ptr ¡Checking ¡(3%) ¡

0 ¡ 5 ¡ 10 ¡ 15 ¡ 20 ¡ 25 ¡ 30 ¡ 35 ¡

JS ¡ HTML ¡

RunNme ¡Overhead(%) ¡ 0 ¡ 5 ¡ 10 ¡ 15 ¡ 20 ¡ 25 ¡ 30 ¡ 35 ¡

JS ¡ HTML ¡

RunNme ¡Overhead(%) ¡ 0 ¡ 5 ¡ 10 ¡ 15 ¡ 20 ¡ 25 ¡ 30 ¡ 35 ¡

JS ¡ HTML ¡

RunNme ¡Overhead(%) ¡

slide-30
SLIDE 30

Performance ¡

Hybrid ¡Checking ¡(Avg: ¡2%) ¡

0 ¡ 5 ¡ 10 ¡ 15 ¡ 20 ¡ 25 ¡ 30 ¡ 35 ¡

JS ¡ HTML ¡

RunNme ¡Overhead(%) ¡

slide-31
SLIDE 31

Code ¡Size ¡Overhead ¡

7% ¡Code ¡Size ¡Increase ¡

8.3 ¡MB ¡out ¡of ¡119 ¡MB ¡ Checking ¡Data ¡+ ¡Inlined ¡Checks ¡

slide-32
SLIDE 32

Future ¡Work ¡

Separate ¡CompilaNon ¡

Link-­‑=me ¡CHA ¡/ ¡inlining ¡

¡

Dynamic ¡Link ¡Library ¡

Run=me ¡update ¡of ¡checking ¡data ¡

slide-33
SLIDE 33

Summary ¡

Vtable ¡Hijacking ¡

O\en ¡happening ¡in ¡web ¡browsers ¡

Compiler-­‑based ¡Approach ¡

Code ¡Instrumenta=on ¡/ ¡sta=c ¡Analysis ¡

RealisNc ¡Overhead ¡

Careful ¡compiler ¡op=miza=ons ¡

slide-34
SLIDE 34

Thank ¡you! ¡ ¡

hLp://goto.ucsd.edu/safedispatch ¡