fuzzchick: coverage-guided, specification-based testingbcpierce/papers/fuzzchick... ·...

35
FuzzChick: Coverage-Guided, Specification-Based Testing Leonidas Lampropoulos Michael Hicks Benjamin C. Pierce HCSS April 29, 2019

Upload: others

Post on 26-Jul-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: FuzzChick: Coverage-Guided, Specification-Based Testingbcpierce/papers/fuzzchick... · 2019-04-30 · •We introduced coverage guided, property based testing (CGPT), a novel combination

FuzzChick: Coverage-Guided, Specification-Based Testing

Leonidas LampropoulosMichael HicksBenjamin C. Pierce

HCSSApril 29, 2019

Page 2: FuzzChick: Coverage-Guided, Specification-Based Testingbcpierce/papers/fuzzchick... · 2019-04-30 · •We introduced coverage guided, property based testing (CGPT), a novel combination

Q: Is it a good idea to combine specification-based testing a la QuickCheck with fuzzing?

A: Yes

Page 3: FuzzChick: Coverage-Guided, Specification-Based Testingbcpierce/papers/fuzzchick... · 2019-04-30 · •We introduced coverage guided, property based testing (CGPT), a novel combination

Fuzz Testing

Page 4: FuzzChick: Coverage-Guided, Specification-Based Testingbcpierce/papers/fuzzchick... · 2019-04-30 · •We introduced coverage guided, property based testing (CGPT), a novel combination

Basic Idea

• Start with a sample input to a System-Under-Test• Use bit-level mutations to

generate lots of similar inputs• See if any of them lead to

crashes

Page 5: FuzzChick: Coverage-Guided, Specification-Based Testingbcpierce/papers/fuzzchick... · 2019-04-30 · •We introduced coverage guided, property based testing (CGPT), a novel combination

Some Flavors of Fuzzing

Bug-Finding Efficiency

User Effort

Completely Random Fuzzing

Fuzzing with Custom Input Generators / Grammars

(e.g., libfuzzer, IMF, FuzzM)

Coverage-Guided Fuzzing

(e.g. AFL)“Smart” Coverage-

Guided Fuzzing (e.g. Driller, VUzzer)

Page 6: FuzzChick: Coverage-Guided, Specification-Based Testingbcpierce/papers/fuzzchick... · 2019-04-30 · •We introduced coverage guided, property based testing (CGPT), a novel combination

Coverage-Guided Fuzzing

Crash

Program Under Test

Report to User

Fuzzer

Binary InputSeed Pool

New Paths?

Yes

Mutator

Mutated seed

NoThrow away

Coverage info

Inst

rum

enta

tion

Initial seedRandom bits

RNG

Initial Seed

Page 7: FuzzChick: Coverage-Guided, Specification-Based Testingbcpierce/papers/fuzzchick... · 2019-04-30 · •We introduced coverage guided, property based testing (CGPT), a novel combination

Random Specification-Based

Testing

Page 8: FuzzChick: Coverage-Guided, Specification-Based Testingbcpierce/papers/fuzzchick... · 2019-04-30 · •We introduced coverage guided, property based testing (CGPT), a novel combination

Basic Idea

• Programmer writes a formal specificationof software system or component as a function from sample inputs to Booleans• Executable “property” of S-U-T

• Tool generates many random inputs and applies the function to each one• If a counterexample is found, a greedy shrinking

process is used to find a minimal one

• Attractive midpoint between unit tests and full-scale formal verification• Famously embodied in Haskell

QuickCheck

Koen Claessen

John Hughes

Page 9: FuzzChick: Coverage-Guided, Specification-Based Testingbcpierce/papers/fuzzchick... · 2019-04-30 · •We introduced coverage guided, property based testing (CGPT), a novel combination

An Example Property

Definition prop_sort_correct (l : list nat) : bool :=is_sorted (sort l).

QuickCheck uses the type of this function to automatically generate random inputs of the appropriate form (lists of numbers)

Page 10: FuzzChick: Coverage-Guided, Specification-Based Testingbcpierce/papers/fuzzchick... · 2019-04-30 · •We introduced coverage guided, property based testing (CGPT), a novel combination

Random Specification-Based Testing

Failure

Generator

SUT + Property

Report to User

Randombits

Random structured

data

RNG

Success/Discard

Page 11: FuzzChick: Coverage-Guided, Specification-Based Testingbcpierce/papers/fuzzchick... · 2019-04-30 · •We introduced coverage guided, property based testing (CGPT), a novel combination

• A variant of Haskell’s QuickChecktool…• ported to the Coq proof assistant…• and fed on steroids• e.g., a mechanically verified

coretness proof for the testing framework itself

Page 12: FuzzChick: Coverage-Guided, Specification-Based Testingbcpierce/papers/fuzzchick... · 2019-04-30 · •We introduced coverage guided, property based testing (CGPT), a novel combination

A Harder Property

Definition prop_insert_correct (x : nat) (l : list nat) : bool :=is_sorted l ==> is_sorted (insert x l).

QuickChick’s default behavior:• Generate many random input lists• Evaluate is_sorted on each one• Discard the ones for which is_sorted returns

false• Evaluate is_sorted (insert x l) on those that are left

Page 13: FuzzChick: Coverage-Guided, Specification-Based Testingbcpierce/papers/fuzzchick... · 2019-04-30 · •We introduced coverage guided, property based testing (CGPT), a novel combination

Flavors of Random Specification-Based Testing

Bug-Finding Efficiency

User Effort

Naïve Random Testing

Hand-Written

Generators

?

Page 14: FuzzChick: Coverage-Guided, Specification-Based Testingbcpierce/papers/fuzzchick... · 2019-04-30 · •We introduced coverage guided, property based testing (CGPT), a novel combination

Key Insight

Use coverage information to guide the mutation of complex structured data just like AFL uses it to mutate bit strings!

“Semantic Mutation”

Page 15: FuzzChick: Coverage-Guided, Specification-Based Testingbcpierce/papers/fuzzchick... · 2019-04-30 · •We introduced coverage guided, property based testing (CGPT), a novel combination

Coverage-Guided,Specification-Based

Testing

Page 16: FuzzChick: Coverage-Guided, Specification-Based Testingbcpierce/papers/fuzzchick... · 2019-04-30 · •We introduced coverage guided, property based testing (CGPT), a novel combination

FuzzChick

Failure

Generator

SUT + Property

Report to User

FuzzChick

Seed Pool

New Paths?

Yes

“Semantic Mutator”

Randombits

Success/Discard

NoThrow away

RNG

Coverage info

Inst

rum

enta

tion

Randomstructured

data

Mutatedstructured

data

Structureddata

Page 17: FuzzChick: Coverage-Guided, Specification-Based Testingbcpierce/papers/fuzzchick... · 2019-04-30 · •We introduced coverage guided, property based testing (CGPT), a novel combination

Semantic Mutators

1

2 3

4

All “stepwise variants”*

* Actually, a probability distribution over all stepwise variants…

Page 18: FuzzChick: Coverage-Guided, Specification-Based Testingbcpierce/papers/fuzzchick... · 2019-04-30 · •We introduced coverage guided, property based testing (CGPT), a novel combination

Semantic Mutators: Modification

1

2 3

4

0

2 3

4

1

2 3

5

Etc.

Page 19: FuzzChick: Coverage-Guided, Specification-Based Testingbcpierce/papers/fuzzchick... · 2019-04-30 · •We introduced coverage guided, property based testing (CGPT), a novel combination

Semantic Mutators: Deletion

1

2 3

4

1

2

4

1

3

132

4Etc.

Page 20: FuzzChick: Coverage-Guided, Specification-Based Testingbcpierce/papers/fuzzchick... · 2019-04-30 · •We introduced coverage guided, property based testing (CGPT), a novel combination

Semantic Mutators: Addition

1

2 3

4

1

2 3

4

1

2 3

4

Etc.

5 5

1

2 3

4 5

Page 21: FuzzChick: Coverage-Guided, Specification-Based Testingbcpierce/papers/fuzzchick... · 2019-04-30 · •We introduced coverage guided, property based testing (CGPT), a novel combination

Evaluation

Page 22: FuzzChick: Coverage-Guided, Specification-Based Testingbcpierce/papers/fuzzchick... · 2019-04-30 · •We introduced coverage guided, property based testing (CGPT), a novel combination

Case Study: Dynamic IFC

• System under test: • Simple machine with built-in dynamic information-flow monitor• Sensitive data is tagged “Secret”• Monitor detects illicit flows from Secret inputs to Public outputs

• i.e. violations of noninteference

• Evaluation setup:• Manually create many buggy “variants” of correct monitor• See how long it takes to find a counterexample for each bug, under various testing

regimes • Purely random• FuzzChick• Hand-crafted test input generators

Page 23: FuzzChick: Coverage-Guided, Specification-Based Testingbcpierce/papers/fuzzchick... · 2019-04-30 · •We introduced coverage guided, property based testing (CGPT), a novel combination

Noninterference – Abstract Machines

r0: 0

r1: 42

r2: 1…

Register File

17

Heap

32

Page 24: FuzzChick: Coverage-Guided, Specification-Based Testingbcpierce/papers/fuzzchick... · 2019-04-30 · •We introduced coverage guided, property based testing (CGPT), a novel combination

Noninterference – Security Labels

r0: 0 @Public

r1: 42 @Public

r2: 1 @Secret…

Register File

17 @Secret

Heap

3 @Public2 @Public

Page 25: FuzzChick: Coverage-Guided, Specification-Based Testingbcpierce/papers/fuzzchick... · 2019-04-30 · •We introduced coverage guided, property based testing (CGPT), a novel combination

Noninterference – Indistinguishability

r0: 0 @Public

r1: 42 @Public

r2: 1 @Secret…

Register File

17 @Secret

Heap

3 @Public2 @Public

r0: 0 @Public

r1: 42 @Public

r2: 1 @Secret…

Register File

17 @Secret

Heap

3 @Public2 @Public

~

Page 26: FuzzChick: Coverage-Guided, Specification-Based Testingbcpierce/papers/fuzzchick... · 2019-04-30 · •We introduced coverage guided, property based testing (CGPT), a novel combination

Noninterference – Indistinguishability

r0: 0 @Public

r1: 42 @Public

r2: 1 @Secret…

Register File

17 @Secret

Heap

3 @Public2 @Public

r0: 0 @Public

r1: 42 @Public

r2: 0 @Secret…

Register File

17 @Secret

Heap

3 @Public2 @Public

~

Page 27: FuzzChick: Coverage-Guided, Specification-Based Testingbcpierce/papers/fuzzchick... · 2019-04-30 · •We introduced coverage guided, property based testing (CGPT), a novel combination

Noninterference – Property

Definition prop_noninterference (m1 m2 : machine) : bool :=indistinguishable m1 m2 ==> indistinguishable (step m1) (step m2).

• Generate many random input machines• Register file, heap, and program

• Evaluate indistinguishable on each one• Discard the ones for which indistinguishable

returns false• Step the machines• Evaluate indistinguishable on the result

Page 28: FuzzChick: Coverage-Guided, Specification-Based Testingbcpierce/papers/fuzzchick... · 2019-04-30 · •We introduced coverage guided, property based testing (CGPT), a novel combination

Noninterference – Property

Definition prop_noninterference (m1 m2 : machine) : bool :=indistinguishable m1 m2 ==> indistinguishable (step m1) (step m2).

Three approaches:1. Naïve automatic generate-and-test2. FuzzChick with an almost trivial random seed generator3. Optimized handwritten generators (ICFP 2013)

Page 29: FuzzChick: Coverage-Guided, Specification-Based Testingbcpierce/papers/fuzzchick... · 2019-04-30 · •We introduced coverage guided, property based testing (CGPT), a novel combination

Results

0.01

0.1

1

10

100

1000

10000

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33

MTT

F (S

ECO

ND

S)

HandWritten FuzzChick Pure Random

Numbers on x axis denote buggy variants of a correct IFC enforcement mechanism, sorted by height of the orange bar (effectiveness of FuzzChick)

Log scale!

Page 30: FuzzChick: Coverage-Guided, Specification-Based Testingbcpierce/papers/fuzzchick... · 2019-04-30 · •We introduced coverage guided, property based testing (CGPT), a novel combination

Definition prop_noninterference (m1 m2 : machine) : bool :=indistinguishable m1 m2 ==> indistinguishable (step m1) (step m2).

What does “almost automatic” mean?

Failure

Generator

SUT + Property

Report to User

FuzzChick

Seed Pool

New Paths?

Yes

“Semantic Mutator”

Randombits

Success/Discard

NoThrow away

RNG

Coverage info

Inst

rum

enta

tion

Randomstructured

data

Mutatedstructured

data

Structureddata

Page 31: FuzzChick: Coverage-Guided, Specification-Based Testingbcpierce/papers/fuzzchick... · 2019-04-30 · •We introduced coverage guided, property based testing (CGPT), a novel combination

Initial random seed = Pair of machines

Approaches to finding “interesting” pairs of low-indistinguishable machine states:

1. Generate two random states. Mutate them until they become low-indistinguishable.

2. Generate one random state. Copy it. Mutate until it becomes interesting.

Page 32: FuzzChick: Coverage-Guided, Specification-Based Testingbcpierce/papers/fuzzchick... · 2019-04-30 · •We introduced coverage guided, property based testing (CGPT), a novel combination

Conclusion

Page 33: FuzzChick: Coverage-Guided, Specification-Based Testingbcpierce/papers/fuzzchick... · 2019-04-30 · •We introduced coverage guided, property based testing (CGPT), a novel combination

Bug-Finding Efficiency

User Effort

Naïve Random Testing

Hand-Written

Generators

FuzzChick

Page 34: FuzzChick: Coverage-Guided, Specification-Based Testingbcpierce/papers/fuzzchick... · 2019-04-30 · •We introduced coverage guided, property based testing (CGPT), a novel combination

Future work: Import more ideas from fuzzing!

Bug-Finding Efficiency

User Effort

Completely Random Fuzzing

Fuzzing with Custom Input Generators / Grammars

(e.g., libfuzzer, IMF)

Coverage-Guided Fuzzing

(e.g. AFL)“Smart” Coverage-

Guided Fuzzing (e.g. Driller, VUzzer)

lots of other interesting points in this space…!

Page 35: FuzzChick: Coverage-Guided, Specification-Based Testingbcpierce/papers/fuzzchick... · 2019-04-30 · •We introduced coverage guided, property based testing (CGPT), a novel combination

• We introduced coverage guided, property based testing (CGPT), a novel combination of specification-based random testing and coverage-guided fuzzing• We implemented this technique in FuzzChick, a redesign of QuickChick• We evaluated FuzzChick by using it to test an existing formalized

development of low-level information-flow tracking• On this challenging application domain, FuzzChick significantly outperforms

QuickChick• not nearly as good as carefully hand-written generators• but requires almost no effort to use

Summary