DieHard: Probabilistic Memory Safety for Unsafe Programming - - PowerPoint PPT Presentation

diehard probabilistic memory safety for unsafe
SMART_READER_LITE
LIVE PREVIEW

DieHard: Probabilistic Memory Safety for Unsafe Programming - - PowerPoint PPT Presentation

DieHard: Probabilistic Memory Safety for Unsafe Programming Languages Emery Berger Ben Zorn University of Massachusetts Microsoft Research Amherst Presented by: Brian Norris PLDI 2006 PLDI 2006 Frivolity Happy Leap Day! PLDI 2006


slide-1
SLIDE 1

PLDI 2006 PLDI 2006

DieHard: Probabilistic Memory Safety for Unsafe Programming Languages

Emery Berger

University of Massachusetts Amherst

Ben Zorn

Microsoft Research

Presented by:

Brian Norris

slide-2
SLIDE 2

PLDI 2006 PLDI 2006

Frivolity

 Happy Leap Day!

slide-3
SLIDE 3

PLDI 2006 PLDI 2006

Frivolity

 Happy Leap Day!  die-hard

 (adj.) strongly or fanatically determined or devoted

slide-4
SLIDE 4

PLDI 2006 PLDI 2006

Frivolity

 Happy Leap Day!  die-hard

 (adj.) strongly or fanatically determined or devoted

slide-5
SLIDE 5

PLDI 2006 PLDI 2006

Frivolity

 Happy Leap Day!  die-hard

 (adj.) strongly or fanatically determined or devoted

slide-6
SLIDE 6

PLDI 2006 PLDI 2006

Problems with Unsafe Languages

 C, C++: pervasive apps, but memory unsafe  Numerous opportunities for security vulnerabilities,

errors

 Double free  Invalid free  Uninitialized reads  Dangling pointers  Buffer overflows (stack & heap)

slide-7
SLIDE 7

PLDI 2006 PLDI 2006

Current Approaches

 Unsound, may work or abort

 Windows, GNU libc, etc., Rx

 Unsound, will definitely continue

 Failure oblivious (Rinard) **

 Sound, definitely aborts (fail-safe)

 CCured, CRED, SAFECode

 Requires C source, programmer intervention  30% to 20X slowdowns

 Good for debugging, less for deployment

slide-8
SLIDE 8

PLDI 2006 PLDI 2006

DieHard

 Sound execution (with high probability)  Fully-randomized memory manager

 Increases odds of benign memory errors  Ensures different heaps across users

 Replication

 Run multiple replicas simultaneously, vote on

results

 Detects crashing & non-crashing errors

 Trades space (and CPU?) for increased reliability

slide-9
SLIDE 9

PLDI 2006 PLDI 2006

Soundness for “Erroneous” Programs

 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

slide-10
SLIDE 10

PLDI 2006 PLDI 2006

Approximating Infinite Heaps

 Infinite ) M-heaps: probabilistic soundness  Option 1: Pad allocations & defer deallocations

+ Simple – No protection from larger overflows

– pad = 8 bytes, overflow = 9 bytes…

– Deterministic: overflow crashes everyone

 Better: randomize heap

+ Probabilistic protection against errors

+Independent across heaps

? Efficient implementation…

slide-11
SLIDE 11

PLDI 2006 PLDI 2006

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

slide-12
SLIDE 12

PLDI 2006 PLDI 2006

Randomized Allocation

00000001 1010 10

size = 2i+3 2i+4 2i+5

metadata heap

malloc(sz):

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

 Fast: runtime O(1)

 M=2 ) E[# of probes] · 2

slide-13
SLIDE 13

PLDI 2006 PLDI 2006

Randomized Allocation

00010001 1010 10

size = 2i+3 2i+4 2i+5

metadata heap

malloc(sz):

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

 Fast: runtime O(1)

 M=2 ) E[# of probes] · 2

slide-14
SLIDE 14

PLDI 2006 PLDI 2006

Randomized Deallocation

00010001 1010 10

size = 2i+3 2i+4 2i+5

metadata heap

free(ptr):

 Ensure object valid (aligned)  Check bitmap  Reset bit

 Prevents invalid frees, double frees

slide-15
SLIDE 15

PLDI 2006 PLDI 2006

Randomized Deallocation

00010001 1010 10

size = 2i+3 2i+4 2i+5

metadata heap

free(ptr):

 Ensure object valid (aligned)  Check bitmap  Reset bit

 Prevents invalid frees, double frees

slide-16
SLIDE 16

PLDI 2006 PLDI 2006

Randomized Deallocation

00000001 1010 10

size = 2i+3 2i+4 2i+5

metadata heap

free(ptr):

 Ensure object valid (aligned)  Check bitmap  Reset bit

 Prevents invalid frees, double frees

slide-17
SLIDE 17

PLDI 2006 PLDI 2006

Randomized Heaps & Reliability

2 3 4 5 3 1 6

  • bject size = 2i+4
  • bject size = 2i+3

 Objects randomly spread across heap  Different run = different heap

 Errors across heaps independent

slide-18
SLIDE 18

PLDI 2006 PLDI 2006

Randomized Heaps & Reliability

2 3 4 5 3 1 6

  • bject size = 2i+4
  • bject size = 2i+3

1 1 6 3 2 5 4

 Objects randomly spread across heap  Different run = different heap

 Errors across heaps independent

slide-19
SLIDE 19

PLDI 2006 PLDI 2006

Randomized Heaps & Reliability

2 3 4 5 3 1 6

  • bject size = 2i+4
  • bject size = 2i+3

1 1 6 3 2 5 4

… My Mozilla: “malignant” overflow

 Objects randomly spread across heap  Different run = different heap

 Errors across heaps independent

slide-20
SLIDE 20

PLDI 2006 PLDI 2006

Randomized Heaps & Reliability

2 3 4 5 3 1 6

  • bject size = 2i+4
  • bject size = 2i+3

1 1 6 3 2 5 4

… My Mozilla: “malignant” overflow

Your Mozilla: “benign” overflow

 Objects randomly spread across heap  Different run = different heap

 Errors across heaps independent

slide-21
SLIDE 21

PLDI 2006 PLDI 2006

DieHard software architecture

 Each replica has different allocator  “Output equivalent” – kill failed replicas

broadcast vote

input

  • utput

execute replicas

replica3

seed3

replica1

seed1

replica2

seed2

slide-22
SLIDE 22

PLDI 2006 PLDI 2006

Results

 Analytical results

 Buffer overflows  Dangling pointer errors  Uninitialized reads

 Empirical results

 Runtime overhead  Error avoidance

 Injected faults & actual applications

slide-23
SLIDE 23

PLDI 2006 PLDI 2006

Analytical Results: Buffer Overflows

 Model overflow as write of live data

 Heap half full (max occupancy)

slide-24
SLIDE 24

PLDI 2006 PLDI 2006

Analytical Results: Buffer Overflows

 Model overflow as write of live data

 Heap half full (max occupancy)

slide-25
SLIDE 25

PLDI 2006 PLDI 2006

Analytical Results: Buffer Overflows

 Model overflow as write of live data

 Heap half full (max occupancy)

slide-26
SLIDE 26

PLDI 2006 PLDI 2006

Analytical Results: Buffer Overflows

 Replicas: Increase odds of avoiding overflow in at

least one replica

replicas

slide-27
SLIDE 27

PLDI 2006 PLDI 2006

Analytical Results: Buffer Overflows

 Replicas: Increase odds of avoiding overflow in at

least one replica

replicas

slide-28
SLIDE 28

PLDI 2006 PLDI 2006

Analytical Results: Buffer Overflows

 Replicas: Increase odds of avoiding overflow in at

least one replica

replicas

 P(Overflow in all replicas) = (1/2)3 = 1/8  P(No overflow in ¸ 1 replica) = 1-(1/2)3 = 7/8

slide-29
SLIDE 29

PLDI 2006 PLDI 2006

Analytical Results: Buffer Overflows

F = free space

H = heap size

N = # objects worth of overflow

k = replicas

Overflow one object

slide-30
SLIDE 30

PLDI 2006 PLDI 2006

Empirical Results: Runtime

slide-31
SLIDE 31

PLDI 2006 PLDI 2006

Empirical Results: Runtime

slide-32
SLIDE 32

PLDI 2006 PLDI 2006

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

slide-33
SLIDE 33

PLDI 2006 PLDI 2006

Conclusion

 Randomization + replicas = probabilistic

memory safety

 Useful point between absolute soundness (fail-stop)

and unsound

 Trades hardware resources (RAM, CPU) for

reliability

 Hardware trends

 Larger memories, multi-core CPUs

 Follows in footsteps of ECC memory, RAID

slide-34
SLIDE 34

PLDI 2006 PLDI 2006

Major Weakness

 Excessive memory, CPU usage  Fallacy: we can forfeit extra memory and CPU

resources because they are becoming cheaper

 For production use (seriously?)  Inconsistent comparisons

slide-35
SLIDE 35

PLDI 2006 PLDI 2006

Related Work

 Unsound, will definitely continue

 Failure oblivious (Rinald) [30, 32] **

 Introduced idea of “boundless memory blocks”  Same benefits with less memory?

 DieHarder