Slide 1

Slide 1 text

ParaFuzz: Fuzzing Multicore OCaml programs “KC” Sivaramakrishna n joint work wit h Sumit Padhiyar and Adharsh Kamath

Slide 2

Slide 2 text

• Adds native support for concurrency and parallelism to OCaml Multicore OCaml

Slide 3

Slide 3 text

• Adds native support for concurrency and parallelism to OCaml Multicore OCaml Overlapped execution A B A C B Time

Slide 4

Slide 4 text

• Adds native support for concurrency and parallelism to OCaml Multicore OCaml Overlapped execution A B A C B Time Simultaneous execution A B C Time

Slide 5

Slide 5 text

• Adds native support for concurrency and parallelism to OCaml Multicore OCaml Overlapped execution A B A C B Time Simultaneous execution A B C Time Effect Handlers

Slide 6

Slide 6 text

• Adds native support for concurrency and parallelism to OCaml Multicore OCaml Overlapped execution A B A C B Time Simultaneous execution A B C Time Effect Handlers Domains

Slide 7

Slide 7 text

• Adds native support for concurrency and parallelism to OCaml Multicore OCaml Overlapped execution A B A C B Time Simultaneous execution A B C Time Effect Handlers Domains using Testing

Slide 8

Slide 8 text

Testing Parallel Programs

Slide 9

Slide 9 text

Testing Parallel Programs • The assertion can fail for a particular input and scheduling combination

Slide 10

Slide 10 text

Testing Parallel Programs • The assertion can fail for a particular input and scheduling combination 10

Slide 11

Slide 11 text

Testing Parallel Programs • The assertion can fail for a particular input and scheduling combination happens before 10

Slide 12

Slide 12 text

Testing Parallel Programs • The assertion can fail for a particular input and scheduling combination happens before happens before 10

Slide 13

Slide 13 text

Testing Parallel Programs • The assertion can fail for a particular input and scheduling combination • Logic bugs are more than just detecting data race s ✦ No data races here happens before happens before 10

Slide 14

Slide 14 text

Testing Parallel Programs • The assertion can fail for a particular input and scheduling combination • Logic bugs are more than just detecting data race s ✦ No data races here • Goal — An effective and pragmatic testing technique for the working OCaml programmer. happens before happens before 10

Slide 15

Slide 15 text

Existing solutions • Testin g ✦ Stress testing — run the program over and over again and hope that the assertion is triggere d ✦ Random testing — generate random inputs, and perturb the OS scheduler (somehow) to trigger bugs

Slide 16

Slide 16 text

Existing solutions • Testin g ✦ Stress testing — run the program over and over again and hope that the assertion is triggere d ✦ Random testing — generate random inputs, and perturb the OS scheduler (somehow) to trigger bugs • Model checking — SPIN, TLC model checker s ✦ Strong guarantees, but not practical with limited time budge t ✦ Often works on a model of the program and not directly on the source code

Slide 17

Slide 17 text

Existing solutions • Testin g ✦ Stress testing — run the program over and over again and hope that the assertion is triggere d ✦ Random testing — generate random inputs, and perturb the OS scheduler (somehow) to trigger bugs • Model checking — SPIN, TLC model checker s ✦ Strong guarantees, but not practical with limited time budge t ✦ Often works on a model of the program and not directly on the source code • Formal veri fi catio n ✦ Requires expert knowledge and lots of time and effort

Slide 18

Slide 18 text

Goal + Approach • Build upon effective pragmatic testing technique s ✦ Ignore concurrency for the moment — only input non-determinism

Slide 19

Slide 19 text

Goal + Approach • Build upon effective pragmatic testing technique s ✦ Ignore concurrency for the moment — only input non-determinism • Property-based testin g ✦ Use a generator to generate random inputs to test a functio n ✦ Quick-check

Slide 20

Slide 20 text

Goal + Approach • Build upon effective pragmatic testing technique s ✦ Ignore concurrency for the moment — only input non-determinism • Property-based testin g ✦ Use a generator to generate random inputs to test a functio n ✦ Quick-check • Fuzzin g ✦ Generate random inputs to crash a progra m ✦ AFL — Extremely effective grey-box (coverage-guided) fuzzer

Slide 21

Slide 21 text

Goal + Approach • Build upon effective pragmatic testing technique s ✦ Ignore concurrency for the moment — only input non-determinism • Property-based testin g ✦ Use a generator to generate random inputs to test a functio n ✦ Quick-check • Fuzzin g ✦ Generate random inputs to crash a progra m ✦ AFL — Extremely effective grey-box (coverage-guided) fuzzer • Crowbar = Fuzzing + QuickChec k ✦ Coverage-guided property-fuzzin g ✦ https://github.com/stedolan/crowbar

Slide 22

Slide 22 text

ParaFuzz Parafuzz = Crowbar (grey-box fuzzing + property-based testing) + Parallelism

Slide 23

Slide 23 text

ParaFuzz • How to control parallel thread scheduling ? ✦ OS controls thread scheduling in parallel program s ✦ Need to force a buggy schedule Parafuzz = Crowbar (grey-box fuzzing + property-based testing) + Parallelism

Slide 24

Slide 24 text

Effect handlers • Mock the parallelism API using effect handler s • Effect Handler s ✦ Modular and composable basis of non-local control- fl ow mechanism s ✤ Exceptions, async/await, lightweight threads, co-routines, etc . ✦ Structured programming with delimited continuations

Slide 25

Slide 25 text

Effect Handlers + Fuzzing • Simulate parallel thread scheduler using effect handler s ✦ OS thread scheduler → user-level thread schedule r ✦ Retain control over the scheduling decisions

Slide 26

Slide 26 text

Effect Handlers + Fuzzing • Simulate parallel thread scheduler using effect handler s ✦ OS thread scheduler → user-level thread schedule r ✦ Retain control over the scheduling decisions • Fuzzing the schedule r ✦ Yield at every synchronisation point ✤ Synchronisation point — context-switch leads to non-determinis m ✦ Use AFL to pick next thread to run from ready queue

Slide 27

Slide 27 text

Effect Handlers + Fuzzing • Simulate parallel thread scheduler using effect handler s ✦ OS thread scheduler → user-level thread schedule r ✦ Retain control over the scheduling decisions • Fuzzing the schedule r ✦ Yield at every synchronisation point ✤ Synchronisation point — context-switch leads to non-determinis m ✦ Use AFL to pick next thread to run from ready queue • Synchronisation point s ✦ Domain (spawn, join), Atomic (get, set, CAS), Mutex (lock, unlock), Condition variable (wait, notify, broadcast)

Slide 28

Slide 28 text

ParaFuzz • System layout

Slide 29

Slide 29 text

ParaFuzz • System layout • Advantage s ✦ Drop-in replacement for Multicore OCaml — separate compiler switc h ✦ No false positive s ✦ Deterministic record-and-replay

Slide 30

Slide 30 text

Evaluation

Slide 31

Slide 31 text

Evaluation

Slide 32

Slide 32 text

Evaluation Effectivenes s fraction of runs that found the bug Ef fi cienc y Mean-time to failure

Slide 33

Slide 33 text

Evaluation Effectivenes s fraction of runs that found the bug Ef fi cienc y Mean-time to failure

Slide 34

Slide 34 text

Evaluation Effectivenes s fraction of runs that found the bug Ef fi cienc y Mean-time to failure

Slide 35

Slide 35 text

Future work: Data races

Slide 36

Slide 36 text

Future work: Data races • ParaFuzz currently assumes that the programs are data-race-free (DRF) ✦ DRF programs in OCaml have SC semantics

Slide 37

Slide 37 text

Future work: Data races • ParaFuzz currently assumes that the programs are data-race-free (DRF) ✦ DRF programs in OCaml have SC semantics • OCaml memory model (PLDI’18) also has a simple operational model for racy program s ✦ Racy reads may return one of a subset of writes performed to a non- atomic location

Slide 38

Slide 38 text

Future work: Data races • ParaFuzz currently assumes that the programs are data-race-free (DRF) ✦ DRF programs in OCaml have SC semantics • OCaml memory model (PLDI’18) also has a simple operational model for racy program s ✦ Racy reads may return one of a subset of writes performed to a non- atomic location • Extend ParaFuzz to racy program s ✦ Use AFL to pick the value that a read should retur n ✦ Force a yield at non-atomic reads and writes

Slide 39

Slide 39 text

Future work: Data races • ParaFuzz currently assumes that the programs are data-race-free (DRF) ✦ DRF programs in OCaml have SC semantics • OCaml memory model (PLDI’18) also has a simple operational model for racy program s ✦ Racy reads may return one of a subset of writes performed to a non- atomic location • Extend ParaFuzz to racy program s ✦ Use AFL to pick the value that a read should retur n ✦ Force a yield at non-atomic reads and writes • Can we make it fast enough for pragmatic use?

Slide 40

Slide 40 text

Summary • ParaFuzz ✦ property-based fuzzing tool for Parallel OCaml program s ✦ Easy to use — drop-in replacement for Multicore OCaml program s ✦ Effective and ef fi cient at fi nding concurrency bug s • Future work — Detecting bugs under data races https://github.com/ocaml-multicore/parafuzz