remix: on-demand live randomizationww2.cs.fsu.edu/~ychen/paper/remix_slides.pdf · •live...

46
Remix: On-demand Live Randomization Yue Chen, Zhi Wang, David Whalley, Long Lu* Florida State University, Stony Brook University*

Upload: others

Post on 08-Jul-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

Remix: On-demand Live Randomization

Yue Chen, Zhi Wang, David Whalley, Long Lu*

Florida State University, Stony Brook University*

Page 2: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

Background

• Buffer Overflow -> Code Injection Attack

Page 3: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

Background

• Buffer Overflow -> Code Injection Attack

– Defense: Data Execution Prevention (DEP)

• Write XOR Execute: a block (page) of memory cannot be marked as both writable and executable at the same time.

Page 4: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

Background

• Buffer Overflow -> Code Injection Attack

– Defense: Data Execution Prevention (DEP)

• Write XOR Execute: a block (page) of memory cannot be marked as both writable and executable at the same time.

• Return-oriented Programming (ROP) Attack

– Discover gadgets from existing code, and chain them by ret instructions

– Can be Turing complete

Page 5: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

Code Reuse Attack

Existing Code

Chained Gadgets

Page 6: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

ROP Defense Strategy

• ROP is one example of a broad class of attacks that require attackers to know or predict the locations of binary features.

Page 7: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

ROP Defense Strategy

• ROP is one example of a broad class of attacks that require attackers to know or predict the locations of binary features.

Defense Goal Frustrate such attacks by randomizing feature

space, or remove features

Page 8: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

ASLR Address Space Layout Randomization

Executable

Library1

Library1

Executable

First-time Second-time

Page 9: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

ASLR - Problem

Library1

Executable

Pointer Leak

Page 10: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

ASLR - Problem

Library1

Executable

Pointer Leak

De-randomized

Page 11: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

ASLR - Problem

Brute force attacks are still possible (When the entropy is small. E.g., 32-bit systems.) Randomized only once.

Page 12: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

Goal

• Live randomization during runtime

• Finer-grained randomization unit

• Low performance overhead

• Highly composable – Can and should be combined with other defenses

(traditional ASLR, function randomization, etc.)

Page 13: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

Remix

Live basic block (BB) (re-)randomization within functions

A basic block is a straight-line code without

jumps in or out of the middle of the block.

Page 14: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

Remix

Live basic block (BB) (re-)randomization within functions

Advantages: • No function pointer migration • Good spatial locality

A basic block is a straight-line code without

jumps in or out of the middle of the block.

Page 15: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

Remix

Basic Block 1

Basic Block 2

Basic Block 3

Basic Block 4

Basic Block 5

Space for Alignment

Other Functions …

Function A

Page 16: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

Remix

Basic Block 1

Basic Block 2

Basic Block 3

Basic Block 4

Basic Block 5

Space for Alignment

Other Functions …

Function A

Basic Block 1

Basic Block 2

Basic Block 3

Basic Block 4

Basic Block 5

Other Functions …

Function A

After 0.46 seconds

Page 17: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

Remix

Basic Block 1

Basic Block 2

Basic Block 3

Basic Block 4

Basic Block 5

Space for Alignment

Other Functions …

Function A

Basic Block 1

Basic Block 2

Basic Block 3

Basic Block 4

Basic Block 5

Other Functions …

Function A

Basic Block 1

Basic Block 2

Basic Block 3

Basic Block 4

Basic Block 5

Other Functions …

Function A

After 0.46 seconds

After 2.13 seconds

Page 18: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

Challenges

• Chain randomized basic blocks together – Need extra space to chain basic blocks

– Need to update instructions

• Stale pointer migration

Page 19: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

Extra Space Case 1: Extra Jmp

Basic Block 1

Basic Block 2

Basic Block 3

Jmp to BB1

(1) At the beginning of a function

Page 20: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

Extra Space Case 1: Extra Jmp

Basic Block 1

Basic Block 2

Basic Block 3

Jmp to BB1

(1) At the beginning of a function (2) At the end of a basic block that does not end with an instruction like jmp/ret

mov … add … mov …

mov … add … jle …

Page 21: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

Extra Space Case 2: Larger Displacement

Basic Block 1

Basic Block 2

Basic Block 3

Basic Block 4

Basic Block 5

Jump to BB3

Before Remix

Page 22: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

Extra Space Case 2: Larger Displacement

Basic Block 1

Basic Block 2

Basic Block 3

Basic Block 4

Basic Block 5

Basic Block 1

Basic Block 2

Basic Block 3

Basic Block 4

Basic Block 5

Jump to BB3 Jump to BB3

Before Remix After Remix

Page 23: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

Extra Space Case 2: Larger Displacement

One-byte displacement: jmp +0x10

Basic Block 1

Basic Block 2

Basic Block 3

Basic Block 4

Basic Block 5

Basic Block 1

Basic Block 2

Basic Block 3

Basic Block 4

Basic Block 5

Jump to BB3 Jump to BB3

Four-byte displacement: jmp +0x00001000

Before Remix After Remix

Page 24: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

Extra Space Solution

With Source Code:

Modify the compiler to:

1. Insert an extra 5-byte NOP

instruction after each basic block

2. Only generate instructions with

4-byte displacement Enough Space Guaranteed!

Page 25: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

Extra Space Solution

With Source Code:

Modify the compiler to:

1. Insert an extra 5-byte NOP

instruction after each basic block

2. Only generate instructions with

4-byte displacement Enough Space Guaranteed!

Without Source Code:

Leverage existing NOP paddings: • Function alignment • Loop alignment

Can insert random bytes into NOP space after randomization, making attack even harder.

Page 26: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

Instruction Update

Q: Which instructions need updating ?

A: Control-flow related ones, to adjust displacement

Page 27: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

Instruction Update

Two-step update (e.g., unconditional direct jmp):

Basic Block 1

Basic Block 2

Basic Block 3

Original After BB reordering Step one: Jumps to original address of BB 3

Step two: Jumps to current address of BB 3

Basic Block 1

Basic Block 2

Basic Block 3

Basic Block 1

Basic Block 2

Basic Block 3

Basic Block 1

Basic Block 2

Basic Block 3

jmp

Page 28: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

Instruction Update

• Direct call: step-one update

• Indirect call: no update needed

• Direct jump: step-one and step-two update

• Indirect jump: discussed later

• PC-relative addressing: step-one update

Page 29: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

Indirect Jump

• Jump to functions – unchanged

– PLT/GOT

– Tail/Sibling Call

• Jump to basic blocks – see next

Page 30: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

Basic Block Pointer Conversion

• Why?

- Migrate stale pointers to basic blocks, to ensure correctness

Page 31: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

Basic Block Pointer Conversion

• Why?

- Migrate stale pointers to basic blocks, to ensure correctness

• Where?

- Return address

- Jump table (switch/case)

- Saved context (e.g., setjmp/longjmp)

- Kernel exception table

Page 32: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

Call Foo

Return Site

main

Foo

Illustration - Return Address

Page 33: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

Call Foo

Return Site

main

Foo

Illustration - Return Address

Page 34: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

Call Foo

Return Site

main

Foo

Illustration - Return Address

Page 35: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

Optimization

To Speed up the randomization procedure:

• Pre-store the required information

– Basic block information (e.g., locations)

– Code/data that need updating

Page 36: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

Optimization To speed up execution:

• Probabilistic loop bundling

Basic Block 1

Basic Block 2

Basic Block 3

Basic Block 4

Basic Block 5

Loop

Page 37: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

Bundle

Optimization To speed up execution:

• Probabilistic loop bundling

Basic Block 1

Basic Block 2

Basic Block 3

Basic Block 4

Basic Block 5

Loop

Basic Block 1

Bundled BB

Basic Block 4

Basic Block 5

Page 38: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

Bundle

Optimization To speed up execution:

• Probabilistic loop bundling

Basic Block 1

Basic Block 2

Basic Block 3

Basic Block 4

Basic Block 5

Loop

Basic Block 1

Bundled BB

Basic Block 4

Basic Block 5

Basic Block 1

Bundled BB

Basic Block 4

Basic Block 5

Randomize

Page 39: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

Bundle

Optimization To speed up execution:

• Probabilistic loop bundling

Basic Block 1

Basic Block 2

Basic Block 3

Basic Block 4

Basic Block 5

Loop

Basic Block 1

Bundled BB

Basic Block 4

Basic Block 5

The bundling layout is different from time to time. – Unpredictable!

Basic Block 1

Bundled BB

Basic Block 4

Basic Block 5

Randomize

Page 40: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

Implementation

• Can work on source code using a slightly

modified LLVM, or work directly on binaries.

• Can work on Linux user-space applications, and

FreeBSD kernel modules.

Page 41: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

Evaluation - Security

• Finer-grained randomization:

– Adds about four bits of entropy to each instruction.

• Live randomization during runtime:

– Destroy discovered gadgets immediately after each re-randomization.

Software Apache nginx lighttpd

Average Basic Block Number per Function

15.3 18.8 14.4

Average NOP Space (bytes) per Function

19.3 26.2 22.1

Want more entropy? – Insert more NOP space!

Page 42: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

Evaluation - Performance

SPEC CPU 2006 Performance Overhead (randomized once)

Page 43: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

Evaluation - Performance

SPEC CPU 2006 Size Increase

Page 44: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

Evaluation - Performance

Apache Web Server Performance Overhead (by ApacheBench)

Randomization Time Interval

Randomization time interval can be random ! Performance depends on hardware speed.

Page 45: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

Evaluation - Performance

ReiserFS Performance Overhead (by IOZone)

Randomization Time Interval

Randomization time interval can be random ! Performance depends on hardware speed.

Page 46: Remix: On-demand Live Randomizationww2.cs.fsu.edu/~ychen/paper/Remix_slides.pdf · •Live randomization during runtime •Finer-grained randomization unit ... –Can and should be

Q&A