precise and accurate patch presence test for binaries · commit history. a real-world example ......

106
Usenix Security’18 Hang Zhang, Zhiyun Qian University of California, Riverside 1 Precise and Accurate Patch Presence Test for Binaries

Upload: others

Post on 05-Jan-2020

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Usenix Security’18

Hang Zhang, Zhiyun QianUniversity of California, Riverside

1

Precise and Accurate Patch Presence Test for Binaries

Page 2: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

What’s the problem?1

Page 3: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

What’s the problem?1

Short Answer: Given an Android image (or other binary), how do we decide whether a CVE has been patched?

Page 4: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

A real-world example3

Page 5: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

A real-world example3

Page 6: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

A real-world example3

Page 7: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

A real-world example3

Open Source

Page 8: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

A real-world example3

Open Source ???

Page 9: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

A real-world example3

Open Source ???

Few source “snapshots” w/o commit history.

Page 10: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

A real-world example

Are the mainstream linux/AOSP patches propagated?

3

Open Source ???

Few source “snapshots” w/o commit history.

Page 11: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Open vs. Closed

Open-source is the trend.

4

Code reuse in closed-source software.

Page 12: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Open vs. Closed

Open-source is the trend.

4

Code reuse in closed-source software.

Is the open-source security patch applied in the binary?

Page 13: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Why challenging?2

Page 14: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

#1: Needle in the (changing) haystack6

Security patch as a needle: small, subtle.

Page 15: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

#1: Needle in the (changing) haystack6

Security patch as a needle: small, subtle.

- if (a > 0)+ if (a >= 0)

Page 16: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

#1: Needle in the (changing) haystack6

Security patch as a needle: small, subtle.

- if (a > 0)+ if (a >= 0)

…+ a = 0;…

Page 17: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

#1: Needle in the (changing) haystack6

Security patch as a needle: small, subtle.

- if (a > 0)+ if (a >= 0)

…+ a = 0;…

Patched function as a changing haystack.

Page 18: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

#1: Needle in the (changing) haystack6

Security patch as a needle: small, subtle.

- if (a > 0)+ if (a >= 0)

…+ a = 0;…

Patched function as a changing haystack.

Func():......AAAAAA+ the lineAAAAAA......

Func():......BBBBBB+ the lineBBBBBB......

Func():......CCCCCC+ the lineCCCCCC......

Func():......DDDDDD+ the lineDDDDDD......

backport evolve evolve

Page 19: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

#1: Needle in the (changing) haystack6

Security patch as a needle: small, subtle.

- if (a > 0)+ if (a >= 0)

…+ a = 0;…

Patched function as a changing haystack.

Func():......AAAAAA+ the lineAAAAAA......

Func():......BBBBBB+ the lineBBBBBB......

Func():......CCCCCC+ the lineCCCCCC......

Func():......DDDDDD+ the lineDDDDDD......

backport evolve evolve

Page 20: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

#1: Needle in the (changing) haystack6

Security patch as a needle: small, subtle.

- if (a > 0)+ if (a >= 0)

…+ a = 0;…

Patched function as a changing haystack.

Func():......AAAAAA+ the lineAAAAAA......

Func():......BBBBBB+ the lineBBBBBB......

Func():......CCCCCC+ the lineCCCCCC......

Func():......DDDDDD+ the lineDDDDDD......

backport evolve evolve

Page 21: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

#1: Needle in the (changing) haystack6

Security patch as a needle: small, subtle.

- if (a > 0)+ if (a >= 0)

…+ a = 0;…

Patched function as a changing haystack.

Func():......AAAAAA+ the lineAAAAAA......

Func():......BBBBBB+ the lineBBBBBB......

Func():......CCCCCC+ the lineCCCCCC......

Func():......DDDDDD+ the lineDDDDDD......

backport evolve evolve

Page 22: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

#2: Haystack is a binary…7

Find the needle in a binary.

Page 23: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Related work8

Page 24: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Related work8

Category 1: Source-source matching.

Page 25: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Related work8

Category 1: Source-source matching.

Cannot deal with binary haystack.

Page 26: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Related work8

Category 1: Source-source matching.

Category 2: Binary-binary matching.

Cannot deal with binary haystack.

Page 27: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Related work8

Category 1: Source-source matching.

Category 2: Binary-binary matching.

Cannot deal with binary haystack.

Lack of knowledge about the needle (i.e. the patch).

Page 28: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

How does a human expert work?

How does FIBER work?3

Page 29: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

-+...-+...+

-+

Patch change site analysis. (Source level)

Binary signature translation.

Match in binary.

Page 30: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Change Site Analysis: What will human do?11

Given an open-source security patch, you need to locate it in a binary. What will you do at first?

Page 31: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Change Site Analysis: What will human do?11

Given an open-source security patch, you need to locate it in a binary. What will you do at first?

Pick those most obvious, unique and representativechange sites.

Page 32: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Change Site Analysis12

Unique – Exists only in the patched version.

Page 33: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Change Site Analysis12

Unique – Exists only in the patched version.

Solution: token-based string search to test uniqueness, add contexts if not unique.

Page 34: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Change Site Analysis13

Stable – Not affected by other irrelevant changes.

Page 35: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Change Site Analysis13

Stable – Not affected by other irrelevant changes.

Func():......AAAAAA+ the lineAAAAAA......

Func():......BBBBBB+ the lineBBBBBB......

Func():......CCCCCC+ the lineCCCCCC......

Func():......DDDDDD+ the lineDDDDDD......

backport evolve evolve

Page 36: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Change Site Analysis13

Stable – Not affected by other irrelevant changes.

Func():......AAAAAA+ the lineAAAAAA......

Func():......BBBBBB+ the lineBBBBBB......

Func():......CCCCCC+ the lineCCCCCC......

Func():......DDDDDD+ the lineDDDDDD......

backport evolve evolve

Page 37: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Change Site Analysis13

Stable – Not affected by other irrelevant changes.

Func():......AAAAAA+ the lineAAAAAA......

Func():......BBBBBB+ the lineBBBBBB......

Func():......CCCCCC+ the lineCCCCCC......

Func():......DDDDDD+ the lineDDDDDD......

backport evolve evolve

Page 38: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Change Site Analysis13

Stable – Not affected by other irrelevant changes.

Func():......AAAAAA+ the lineAAAAAA......

Func():......BBBBBB+ the lineBBBBBB......

Func():......CCCCCC+ the lineCCCCCC......

Func():......DDDDDD+ the lineDDDDDD......

backport evolve evolve

Page 39: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Change Site Analysis13

Stable – Not affected by other irrelevant changes.

Solution: keep the change site as small as possible (always start from a single line), add contexts only when necessary.

Func():......AAAAAA+ the lineAAAAAA......

Func():......BBBBBB+ the lineBBBBBB......

Func():......CCCCCC+ the lineCCCCCC......

Func():......DDDDDD+ the lineDDDDDD......

backport evolve evolve

Page 40: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Change Site Analysis14

Easy-to-recognize – Imagine what a human prefers.

Page 41: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Change Site Analysis14

Easy-to-recognize – Imagine what a human prefers.

+ func_noinline()

Page 42: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Change Site Analysis14

Easy-to-recognize – Imagine what a human prefers.

+ func_noinline()

Perfect: easily located by call instruction and function name (Android images have symbol table).

Page 43: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Change Site Analysis14

Easy-to-recognize – Imagine what a human prefers.

+ func_noinline()

+ if(cond)

Perfect: easily located by call instruction and function name (Android images have symbol table).

Page 44: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Change Site Analysis14

Easy-to-recognize – Imagine what a human prefers.

+ func_noinline()

+ if(cond)

Perfect: easily located by call instruction and function name (Android images have symbol table).

Good: both syntax structure and semantic change.

Page 45: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Change Site Analysis14

Easy-to-recognize – Imagine what a human prefers.

+ func_noinline()

+ if(cond)

+ a = b * c

Perfect: easily located by call instruction and function name (Android images have symbol table).

Good: both syntax structure and semantic change.

Page 46: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Change Site Analysis14

Easy-to-recognize – Imagine what a human prefers.

+ func_noinline()

+ if(cond)

+ a = b * c

Perfect: easily located by call instruction and function name (Android images have symbol table).

Good: both syntax structure and semantic change.

Meh: only semantic change without syntax change.

Page 47: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Change Site Analysis14

Easy-to-recognize – Imagine what a human prefers.

+ func_noinline()

+ if(cond)

+ a = b * c

Perfect: easily located by call instruction and function name (Android images have symbol table).

Good: both syntax structure and semantic change.

Meh: only semantic change without syntax change.

Solution: we rank the change sites based on statement types involved, according to our domain knowledge.

Page 48: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

-+...-+...+

-+

Patch change site analysis. (Source level)

Binary signature translation.

Match in binary.

Page 49: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

What if we do it manually?16

How to connect the source change with binary code?

Page 50: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

What if we do it manually?16

if (a > 1) do A;else do B;

How to connect the source change with binary code?

Page 51: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

What if we do it manually?16

Syntax

if (a > 1) do A;else do B;

…cond jmp

… …

How to connect the source change with binary code?

Page 52: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

What if we do it manually?16

Syntax Semantics

if (a > 1) do A;else do B;

…cond jmp

… …

…a > 1?

A B

How to connect the source change with binary code?

Page 53: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

What if we do it manually?16

Correlate both its syntax and semantics to the binary code.

Syntax Semantics

if (a > 1) do A;else do B;

…cond jmp

… …

…a > 1?

A B

How to connect the source change with binary code?

Page 54: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Binary Signature Translation17

Identify and organize correlated instructions in the reference binary.

Page 55: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Binary Signature Translation17

Identify and organize correlated instructions in the reference binary.

foo(a,b,c){ ... if (a+b > c) bar(a+b); ...

Page 56: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Binary Signature Translation17

Identify and organize correlated instructions in the reference binary.

foo(a,b,c){ ... if (a+b > c) bar(a+b); ...

foo:...MOV X3,X0MOV X4,X1...

AArch64 calling convention:a -> X0 b -> X1 c -> X2

ADD X0,X3,X4CMP X0,X2BGT label1

label1:BL bar

...

DWARF Debug Information

Page 57: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Binary Signature Translation17

Identify and organize correlated instructions in the reference binary.

foo(a,b,c){ ... if (a+b > c) bar(a+b); ...

foo:...MOV X3,X0MOV X4,X1...

AArch64 calling convention:a -> X0 b -> X1 c -> X2

ADD X0,X3,X4CMP X0,X2BGT label1

label1:BL bar

...

DWARF Debug Information

Page 58: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Binary Signature Translation18

Find the “root” instructions.

ADD X0,X3,X4CMP X0,X2BGT label1

label1:BL bar

Page 59: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Binary Signature Translation18

Find the “root” instructions.

ADD X0,X3,X4CMP X0,X2BGT label1

label1:BL bar

X0 = X3 + X4

Page 60: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Binary Signature Translation18

Find the “root” instructions.

ADD X0,X3,X4CMP X0,X2BGT label1

label1:BL bar

X0 = X3 + X4

(X3 + X4) > X2

Page 61: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Binary Signature Translation18

Find the “root” instructions.

ADD X0,X3,X4CMP X0,X2BGT label1

label1:BL bar

X0 = X3 + X4

(X3 + X4) > X2

Page 62: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Binary Signature Translation18

Find the “root” instructions.

ADD X0,X3,X4CMP X0,X2BGT label1

label1:BL bar

X0 = X3 + X4

(X3 + X4) > X2

ADD X0,X3,X4CMP X0,X2BGT label1

Page 63: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Binary Signature Translation18

Find the “root” instructions.

ADD X0,X3,X4CMP X0,X2BGT label1

label1:BL bar

X0 = X3 + X4

(X3 + X4) > X2

ADD X0,X3,X4CMP X0,X2BGT label1

Root instructions: whose outputs will no longer be consumed by other instructions.

Page 64: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Binary Signature Translation18

Find the “root” instructions.

ADD X0,X3,X4CMP X0,X2BGT label1

label1:BL bar

X0 = X3 + X4

(X3 + X4) > X2

ADD X0,X3,X4CMP X0,X2BGT label1

Root instructions: whose outputs will no longer be consumed by other instructions.

Solution: we perform a basic-block level data-flow analysis to identify root instructions.

Page 65: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Binary Signature Translation19

Extract semantic formulas for root instructions.

foo:...MOV X3,X0MOV X4,X1...

AArch64 calling convention:a -> X0 b -> X1 c -> X2

ADD X0,X3,X4CMP X0,X2BGT label1

label1:BL bar

...

Page 66: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Binary Signature Translation19

Extract semantic formulas for root instructions.

foo:...MOV X3,X0MOV X4,X1...

AArch64 calling convention:a -> X0 b -> X1 c -> X2

ADD X0,X3,X4CMP X0,X2BGT label1

label1:BL bar

...

X0 > X2

Page 67: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Binary Signature Translation19

Extract semantic formulas for root instructions.

foo:...MOV X3,X0MOV X4,X1...

AArch64 calling convention:a -> X0 b -> X1 c -> X2

ADD X0,X3,X4CMP X0,X2BGT label1

label1:BL bar

...

X0 > X2

(X3 + X4) > X2

Page 68: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Binary Signature Translation19

Extract semantic formulas for root instructions.

foo:...MOV X3,X0MOV X4,X1...

AArch64 calling convention:a -> X0 b -> X1 c -> X2

ADD X0,X3,X4CMP X0,X2BGT label1

label1:BL bar

...

X0 > X2

(X3 + X4) > X2

(X0 + X1) > X2

Page 69: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Binary Signature Translation19

Extract semantic formulas for root instructions.

foo:...MOV X3,X0MOV X4,X1...

AArch64 calling convention:a -> X0 b -> X1 c -> X2

ADD X0,X3,X4CMP X0,X2BGT label1

label1:BL bar

...

X0 > X2

(X3 + X4) > X2

(X0 + X1) > X2

(a + b) > cfoo(a,b,c){ ... if (a+b > c) bar(a+b); ...

Page 70: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Binary Signature Translation19

Extract semantic formulas for root instructions.

foo:...MOV X3,X0MOV X4,X1...

AArch64 calling convention:a -> X0 b -> X1 c -> X2

ADD X0,X3,X4CMP X0,X2BGT label1

label1:BL bar

...

X0 > X2

(X3 + X4) > X2

(X0 + X1) > X2

(a + b) > c

Solution: we use function-level, intra-procedure and under-constrained symbolic execution to obtain formulas.

foo(a,b,c){ ... if (a+b > c) bar(a+b); ...

Page 71: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

-+...-+...+

-+

Patch change site analysis. (Source level)

Binary signature translation.

Match in binary.

Page 72: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Matching21

Quick Pass.

Page 73: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Matching21

Quick Pass.

Cond. jmp

Call bar

foo(a,b,c){ ... if (a+b > c) bar(a+b); ...

Page 74: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Matching21

Quick Pass.

Cond. jmp

Call bar

Call barCond. jmp

Store

Call bar

Cond. jmp

Call sth

foo(a,b,c){ ... if (a+b > c) bar(a+b); ...

Page 75: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Matching21

Quick Pass.

Cond. jmp

Call bar

Call barCond. jmp

Store

Call bar

Cond. jmp

Call sth

foo(a,b,c){ ... if (a+b > c) bar(a+b); ...

Page 76: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Matching21

Quick Pass.

Cond. jmp

Call bar

Call barCond. jmp

Store

Call bar

Cond. jmp

Call sth

foo(a,b,c){ ... if (a+b > c) bar(a+b); ...

Page 77: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Matching21

Quick Pass.

Solution: look at easy-to-match attributes, e.g. topology, root instruction type, etc.

Cond. jmp

Call bar

Call barCond. jmp

Store

Call bar

Cond. jmp

Call sth

foo(a,b,c){ ... if (a+b > c) bar(a+b); ...

Page 78: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Matching22

Slow Pass.

Cond. jmp

Call bar

Call barCond. jmp

Store

Call bar

Cond. jmp

Call sth

foo(a,b,c){ ... if (a+b > c) bar(a+b); ...

Page 79: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Matching22

Slow Pass.

(a + b) > c

(a + b) > c

a != bCond. jmp

Call bar

Call barCond. jmp

Store

Call bar

Cond. jmp

Call sth

foo(a,b,c){ ... if (a+b > c) bar(a+b); ...

Page 80: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Matching22

Slow Pass.

(a + b) > c

(a + b) > c

a != bCond. jmp

Call bar

Call barCond. jmp

Store

Call bar

Cond. jmp

Call sth

foo(a,b,c){ ... if (a+b > c) bar(a+b); ...

Page 81: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Matching22

Slow Pass.

(a + b) > c

(a + b) > c

a != bCond. jmp

Call bar

Call barCond. jmp

Store

Call bar

Cond. jmp

Call sth

Solution: basically we strictly compare two formulas simplified by Z3 solver , with necessary relaxations. (e.g. commutative operators)

foo(a,b,c){ ... if (a+b > c) bar(a+b); ...

Page 82: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

23

Special (and Interesting) Cases

Page 83: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

23

Func():............+ uniq_func_noinline()............

Page 84: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

23

Func():............+ uniq_func_noinline()............

Simply test the function call presence, no semantic formulas needed.

Page 85: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

23

Func():............- f(a,b)+ f(a,c)............

Page 86: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

23

Func():............- f(a,b)+ f(a,c)............

That line matters? No, that parameter matters!

Page 87: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

In evaluation: 107 security patches crawled from Android Bulletin (Jun 2016 – May 2017)8 Android kernel images from 3 mainstream vendors.

How well does FIBER work?4

Page 88: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Accuracy25

Page 89: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Accuracy25

Accuracy: excellent, on average 94% accuracy w/o FP.

Page 90: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Accuracy25

Accuracy: excellent, on average 94% accuracy w/o FP.

FP: we wrongly believe the patch is present. Dangerous!FN: we wrongly believe the patch is not there. Extra time to confirm.

Page 91: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Why FN?26

Function inline. Function prototype change. Code customization. Patch adaptation. Other engineering issues.

Refer to section 6.2 in the paper for more details.

Page 92: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Why FN?26

Function inline:Added new callee function in the change site is inlined in different ways across reference and target binaries.

Page 93: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Why FN?26

Patch adaptation:The change site itself has been customized during patch porting.

Page 94: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Performance27

Page 95: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Performance27

Performance: acceptable, some cases may take long time to match, overall still much more efficient than manual work. Parallelization is also easily possible.

Page 96: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Un-ported patches28

Page 97: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Un-ported patches28

Lag (month) Cnt.1 22 56 2

Page 98: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Un-ported patches28

Some critical patches were not propagated even after 6 months (confirmed)!

Lag (month) Cnt.1 22 56 2

Page 99: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

CVE-2016-791029

diff --git a/block/genhd.c b/block/genhd.cindex 3c9dede..0ad8796 100644--- a/block/genhd.c+++ b/block/genhd.c@@ -856,6 +856,7 @@ static void disk_seqf_stop( , void *v)

if (iter) {class_dev_iter_exit(iter);kfree(iter);

+ seqf->private = NULL;}

}

0x0 [ + offset]X0struct seq_file *seqf

Page 100: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

CVE-2016-791029

diff --git a/block/genhd.c b/block/genhd.cindex 3c9dede..0ad8796 100644--- a/block/genhd.c+++ b/block/genhd.c@@ -856,6 +856,7 @@ static void disk_seqf_stop( , void *v)

if (iter) {class_dev_iter_exit(iter);kfree(iter);

+ seqf->private = NULL;}

}

0x0 [ + offset]X0struct seq_file *seqf

Page 101: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

How much code do you write?4

Page 102: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

We use Angr as our symbolic execution engine. (w/ modifications)

How much code do you write?4

Page 103: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

We use Angr as our symbolic execution engine. (w/ modifications)

How much code do you write?4

#code of Fiber: 5,097 LOC Python.

Page 104: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

We use Angr as our symbolic execution engine. (w/ modifications)

How much code do you write?4

#code of Fiber: 5,097 LOC Python.

Still under improvement.

Page 105: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

We use Angr as our symbolic execution engine. (w/ modifications)

How much code do you write?4

#code of Fiber: 5,097 LOC Python.

Still under improvement.

Now fully open-sourced on Github!https://fiberx.github.io

Page 106: Precise and Accurate Patch Presence Test for Binaries · commit history. A real-world example ... – Exists only in the patched version. Solution: token-based string search to test

Thanks!Q & A

https://fiberx.github.io