Download - Automatically Tolerating And Correcting Memory Errors

Transcript
Page 1: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Automatically Tolerating &Correcting Memory Errors

Emery BergerUniversity of Massachusetts Amherst

joint work with Gene Novark (UMass Amherst),Ben Zorn (Microsoft Research)

[PLDI 2006, PLDI 2007]

Page 2: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Problems with Unsafe Languages

C, C++: pervasive apps, but langs.memory unsafe

Numerous opportunities for security vulnerabilities, errors Double free Invalid free Uninitialized reads Dangling pointers Buffer overflows (stack & heap)

Page 3: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Current Approaches

Unsound, may work or abort Windows, GNU libc, etc., Rx [Zhou]

Unsound, will definitely continue Failure oblivious [Rinard]

Sound, definitely aborts (fail-safe) CCured [Necula], CRED [Ruwase & Lam], SAFECode

[Dhurjati, Kowshik & Adve], etc. Slowdowns: 30% - 20X Requires C source, programmer intervention Garbage collection or partially sound (pools)

Good for debugging, less for deployment

Page 4: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Soundness for “Erroneous” Programs

Normally: memory errors ? Consider infinite-heap allocator:

All news fresh;ignore delete

No dangling pointers, invalid frees,double frees

Every object infinitely large No buffer overflows, data overwrites

Transparent to correct program “Erroneous” programs sound

Page 5: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Probabilistic Memory Safety

Approximate with M-heaps (e.g., M=2)

DieHard: fully-randomized M-heap Increases odds of benign errors Probabilistic memory safety

i.e., P(no error) n Errors independent across heaps

E(users with no error) n * |users|

? Efficient implementation…

Page 6: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Implementation Choices

Conventional, freelist-based heaps Hard to randomize, protect from errors

Double frees, heap corruption What about bitmaps? [Wilson90]

– Catastrophic fragmentation Each small object likely to occupy one page

obj obj objobj

pages

Page 7: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Randomized Heap Layout

Bitmap-based, segregated size classes Bit represents one object of given size

i.e., one bit = 2i+3 bytes, etc. Prevents fragmentation

00000001 1010 10

size = 2i+3 2i+

4

2i+

5

metadata

heap

Page 8: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Randomized Allocation

malloc(8): compute size class = ceil(log2 sz) – 3 randomly probe bitmap for zero-bit (free)

Fast: runtime O(1) M=2 E[# of probes] ≈ 2

00000001 1010 10

size = 2i+3 2i+

4

2i+

5

metadata

heap

Page 9: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

malloc(8): compute size class = ceil(log2 sz) – 3 randomly probe bitmap for zero-bit (free)

Fast: runtime O(1) M=2 E[# of probes] ≈ 2

00010001 1010 10

size = 2i+3 2i+

4

2i+

5

metadata

heap

Randomized Allocation

Page 10: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

free(ptr): Ensure object valid – aligned to right address Ensure allocated – bit set Resets bit

Prevents invalid frees, double frees

00010001 1010 10

size = 2i+3 2i+

4

2i+

5

metadata

heap

Randomized Deallocation

Page 11: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Randomized Deallocation

free(ptr): Ensure object valid – aligned to right address Ensure allocated – bit set Resets bit

Prevents invalid frees, double frees

00010001 1010 10

size = 2i+3 2i+

4

2i+

5

metadata

heap

Page 12: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

free(ptr): Ensure object valid – aligned to right address Ensure allocated – bit set Resets bit

Prevents invalid frees, double frees

00000001 1010 10

size = 2i+3 2i+

4

2i+

5

metadata

heap

Randomized Deallocation

Page 13: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Randomized Heaps & Reliability

2 34 5 3 1 6

object size = 2i+4

object size = 2i+3

11 6 3 2 5 4 …

My Mozilla: “malignant” overflow

Your Mozilla: “benign” overflow

Objects randomly spread across heap Different run = different heap

Improves security Errors across heaps independent

Page 14: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

DieHard software architecture

broadcast vote

input output

execute replicas(separate processes)

replica3seed3

replica1seed1

replica2seed2

Optional: replication-based fault-tolerance Requires randomization: errors independent

Page 15: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

DieHard Results

Analytical results (pictures!) Dangling pointer errors Buffer overflows Uninitialized reads

Empirical results Runtime overhead Error avoidance

Injected faults & actual applications

Page 16: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Analytical Results: Dangling Pointers

Free one object too early

Page 17: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Analytical Results: Dangling Pointers

Free one object too early

Object extremely unlikely to be reused soon

Page 18: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Analytical Results: Dangling Pointers

Free one object too early

Object extremely unlikely to be reused soon

Page 19: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Analytical Results: Dangling Pointers

Free one object too early

Object extremely unlikely to be reused soon

Example: F = 1,000,000 P(ok after one malloc) ¼ 1 P(ok after 1000 mallocs) ¸ 99.9%

F = # free objectsA = # mallocs

Page 20: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Analytical Results: Buffer Overflows

Model overflow: random write of live data Heap half full (max occupancy)

Page 21: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Analytical Results: Buffer Overflows

Model overflow: random write of live data Heap half full (max occupancy)

Page 22: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Analytical Results: Buffer Overflows

Model overflow: random write of live data Heap half full (max occupancy)

Page 23: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Analytical Results: Buffer Overflows

Replicas: Increase odds of avoiding overflow in at least one replica

repl

icas

Page 24: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Analytical Results: Buffer Overflows

Replicas: Increase odds of avoiding overflow in at least one replica

repl

icas

Page 25: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Analytical Results: Buffer Overflows

Replicas: Increase odds of avoiding overflow in at least one replica

repl

icas

P(Overflow in all replicas) = (½)3 = 1/8 P(No overflow in ≥ 1 replica) = 1-(½)3 = 7/8

Page 26: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Analytical Results: Buffer Overflows

F = free spaceH = heap sizeN = # objects

worth of overflow

k = replicas

Overflow one object

Page 27: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Empirical Results: Error Avoidance

Injected faults: Dangling pointers (@50%, 10 allocations)

glibc: crashes; DieHard: 9/10 correct Overflows (@1%, 4 bytes over) –

glibc: crashes 9/10, “inf loop”; DieHard: 10/10 correct Real faults:

Avoids Squid web cache overflow Crashes BDW & glibc

Avoids dangling pointer error in Mozilla DoS in glibc & Windows

Page 28: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

DieHard Limitations

Fine for single error But: multiple errors eventually swamp

probabilistic protection Not great for large overflows

Tolerates errors But doesn’t find them

No information for programmer Ideal: point directly to bug…

Page 29: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Exterminator:Automatically Correcting

Memory Errors with High Probability

Page 30: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Diagnosing Buffer Overflows

Canonical buffer overflow: Allocate object – too small Write past end ) nukes object bytes forward

Not necessarily contiguous

char * str = new char[8];strcpy (str, “goodbye cruel world”);

Page 31: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Diagnosing Buffer Overflows

Canonical buffer overflow: Allocate object – too small Write past end ) nukes object bytes forward

Not necessarily contiguous

char * str = new char[8];strcpy (str, “goodbye cruel world”);

Page 32: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Diagnosing Buffer Overflows

Canonical buffer overflow: Allocate object – too small Write past end ) nukes object bytes forward

Not necessarily contiguous

bad object(too small)

char * str = new char[8];strcpy (str, “goodbye cruel world”);

Page 33: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Diagnosing Buffer Overflows

Canonical buffer overflow: Allocate object – too small Write past end ) nukes object bytes forward

Not necessarily contiguous

bad object(too small)

bytes past end

char * str = new char[8];strcpy (str, “goodbye cruel world”);

Page 34: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Diagnosing Buffer Overflows

Canonical buffer overflow: Allocate object – too small Write past end ) nukes object bytes forward

Not necessarily contiguous

bad object(too small)

bytes past end

char * str = new char[8];strcpy (str, “goodbye cruel world”);

Page 35: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Diagnosing Buffer Overflows

Canonical buffer overflow: Allocate object – too small Write past end ) nukes object bytes forward

Not necessarily contiguous

bytes past end

char * str = new char[8];strcpy (str, “goodbye cruel world”);

Page 36: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Diagnosing Buffer Overflows

Canonical buffer overflow: Allocate object – too small Write past end ) nukes object bytes forward

Not necessarily contiguous

bytes past end

char * str = new char[8];strcpy (str, “goodbye cruel world”);

Page 37: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Diagnosing Buffer Overflows

Canonical buffer overflow: Allocate object – too small Write past end ) nukes object bytes forward

Not necessarily contiguous

bytes past end

char * str = new char[8];strcpy (str, “goodbye cruel world”);

Page 38: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Diagnosing Buffer Overflows

Canonical buffer overflow: Allocate object – too small Write past end ) nukes object bytes forward

Not necessarily contiguous

bytes past end

char * str = new char[8];strcpy (str, “goodbye cruel world”);

Page 39: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Diagnosing Buffer Overflows

Canonical buffer overflow: Allocate object – too small Write past end ) nukes object bytes forward

Not necessarily contiguous

bytes past end

char * str = new char[8];strcpy (str, “goodbye cruel world”);

1. Heap provides no useful information

Page 40: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Diagnosing Buffer Overflows

Canonical buffer overflow: Allocate object – too small Write past end ) nukes object bytes forward

Not necessarily contiguous

bytes past end

char * str = new char[8];strcpy (str, “goodbye cruel world”);

2. No way to detect corruption

Page 41: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Isolating Buffer Overflows

8 2 9 3 4 5 1 7

Red =possiblebadobject

Green =notbadobject

Canaries in freed space detect corruption

known random value dead canary = corruption

# = object id (allocation time)

Page 42: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Isolating Buffer Overflows

8 2 9 3 4 5 1 7

Red =possiblebadobject

Green =notbadobject

Canaries in freed space detect corruption Run multiple times with “DieFast” allocator

Page 43: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Canaries in freed space detect corruption Run multiple times with “DieFast” allocator

8 2 9 3 4 5 1 7

Isolating Buffer Overflows

Red =possiblebadobject

Green =notbadobject

1 8 7 5 3 2 9 6 4

Page 44: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Canaries in freed space detect corruption Run multiple times with “DieFast” allocator Key insight: Overflow must be at same

8 2 9 3 4 5 1 7

Isolating Buffer Overflows

Red =possiblebadobject

Green =notbadobject

1 8 7 5 3 2 9 6 4

Page 45: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

8 2 9 4 5 1 7

Isolating Buffer Overflows

Red =possiblebadobject

Green =notbadobject

1 8 7 5 3 2 9 6 4

3

Canaries in freed space detect corruption Run multiple times with “DieFast” allocator Key insight: Overflow must be at same

Page 46: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

8 2 9 3 4 5 1 7

Isolating Buffer Overflows

Red =possiblebadobject

Green =notbadobject

1 8 7 5 3 2 9 6 4

Canaries in freed space detect corruption Run multiple times with “DieFast” allocator Key insight: Overflow must be at same

Page 47: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

8 2 9 3 4 5 1 7

Isolating Buffer Overflows

Red =possiblebadobject

Green =notbadobject

1 8 7 5 3 6 492

Canaries in freed space detect corruption Run multiple times with “DieFast” allocator Key insight: Overflow must be at same

Page 48: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Isolating Buffer Overflows

8 2 9 3 4 5 1 7

Red =possiblebadobject

Green =notbadobject

1 8 7 5 3 2 9 6 4

4 9 6 38 5 72 1

Canaries in freed space detect corruption Run multiple times with “DieFast” allocator Key insight: Overflow must be at same

) object 9 overflowed, with high probability

Page 49: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Buffer Overflow Analysis

Example: H = 1,000,000 objects3 iterations ¼ false positives

Iterations exponentially increase precision

H = # heap objectsK = # iterations

11;000;000

8 2 9 3 4 5 1 7

1 8 7 5 3 2 9 6 4

4 9 6 38 5 72 1

Page 50: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Isolating Dangling Pointers

Dangling pointer error: Allocated object freed too soon Overwritten by some other object

int * v = new int[4];…delete [] v; // oops…char * str = new char[16];strcpy (str, “die, pointer”);v[3] = 12;… use of v[0]

Page 51: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Isolating Dangling Pointers

Unlike buffer overflow: dangling pointer ) same corruption in all

k = 3 ) false negatives ¼P(identical over°ow) ·

µS

H ¡ 1

¶k¡ 1

11;000;000

2

11 2 3 6 4 5 10 1 12 798

1 7 5 3 2 1112 648 9 10

4 6 312 5 72 1410 8 9

Page 52: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Correcting Allocator

Generate runtime patches to correct errors Track object call sites in allocator

Prevent overflows: pad overflowed objects

malloc(8) malloc(8 + δ)

Prevent dangling pointers: defer freesfree(ptr) delay δ mallocs;

free(ptr)

1 1

Page 53: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Exterminator Summary

Three main pieces: DieHard-based allocator (DieFast)

Reveals bugs Error isolator

Finds bugs across multiple heaps w.h.p. Correcting allocator

Fixes bugs Modes suitable for testing (debugging)

or deployment

Page 54: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Exterminator Modes

Iterative Run multiple times Same inputs Debugging

Replicated Run simultaneously Deployable w/limitations Can fix errors on-the-fly

Cumulative Different inputs, nondeterminism Deployable; see paper for details

seed

votebroadcast

input output

DieFast replica1seed

DieFast replica2seed

Error isolator

correcting allocator

correcting allocator

correcting allocator

DieFast replica3

runtime patches

Page 55: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Exterminator Runtime Overhead

25%

Page 56: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Empirical Results: Real Faults

Squid heap overflow Crashes glibc 2.8.0 and BDW collector 3 iterations to fix ) 6 byte pad

Prevents overflow for all subsequent executions

Page 57: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Mozilla 1.7.3 buffer overflow Debug scenario:

repeated load of PoC: 23 runs to fix overflow

Deployed scenario: different browsing sessions: 34 runs to fix

2

Empirical Results: Real Faults

31

1

2

Page 58: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

Conclusion Randomization: enables

probabilistic memory safety (DieHard)& automatic error correction (Exterminator)

Trades hardware resources(RAM,CPU) for reliability Hardware trends

Larger memories, multi-core CPUs Follows in footsteps of

ECC memory, RAID

Page 59: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

The End

www.diehard-software.orgwww.cs.umass.edu/~emery

Page 60: Automatically Tolerating And Correcting Memory Errors

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science • 2007 • 2007

4 3 6 5218

16

allocation space

bitmap

1

object size

2inUse

4inUse

1inUse

6inUse

1inUse

miniheaps

Actual DieHard Heap Layout

Bitmap-based, segregated size classes Bit represents one object of given size

i.e., one bit = 2i+3 bytes, etc.

malloc(): randomly probe bitmap for free space free(): just reset bit