Section 17.18

Why fuzzing cannot certify universal safety

Question

What does no failure after many fuzz executions establish?

Short answer

No failure after many fuzz executions establishes only that the inputs actually run, in the harness and build actually tested, produced no failure that the test oracle §10.5 could detect. It does not establish safety for every input: the fuzzer may never generate the failing input, the oracle may miss a failure that did occur, and the tested setup may differ from the deployed one. Even a statistical bound on the failure rate needs independent random inputs from one fixed distribution, which a coverage-guided fuzzer does not supply.

Terms in the question

Full answer

Step 1: the claim that a program is safe is universal. Let DD be the input domain, the set of all inputs the program can receive. “The program is safe” means: for every input xx in DD, the run on xx is correct. One failing run refutes the claim. Passing runs confirm it only for the inputs they used. Testing can establish the claim only by running every input in DD, which is exhaustive enumeration §10.33, and that is possible only for small domains: a function of one 16-bit argument has 216=65,5362^{16} = 65{,}536 inputs. A 64-byte input already has 25664=2512256^{64} = 2^{512}, about 1.3×101541.3 \times 10^{154}, possible values. At 10910^9 runs per second, running them all would take about 1.3×101451.3 \times 10^{145} seconds.

Step 2: what is established. Let SS be the set of inputs the fuzzer actually ran. Zero failures establish one fact: for every input in SS, in the tested build and environment, the oracle flagged nothing. Three gaps separate this fact from safety, described in Steps 3 to 5.

Step 3: the fuzzer may never reach the failing input. A fuzzer produces inputs from a model: a grammar, a set of example inputs (the seed corpus §10.14) and the changes it applies to them, or a hand-written generator. An input that this model cannot produce is never tried, however long the fuzzer runs. Other inputs are possible but improbable. A test of a 4-byte field against one fixed value passes for 1 of 2322^{32} values, so a 4-byte value chosen uniformly at random passes the test with probability 2−32≈2.3×10−102^{-32} \approx 2.3 \times 10^{-10}. In 10610^6 runs, the expected number of inputs that pass the test is 106×2.3×10−10≈0.0002310^6 \times 2.3 \times 10^{-10} \approx 0.00023. Coverage-guided fuzzing §10.12, which keeps the inputs that reach new code, and input dictionaries §10.16, lists of values worth inserting into inputs, exist to shrink this gap; they do not close it.

Step 4: the oracle may miss a failure. A failure counts only if the oracle notices it. Without a sanitizer, a write one byte past the end of an array §14.5 often changes a neighboring variable and crashes nothing. A wrong result, such as a parser that accepts a malformed message or a function that returns the wrong decision, is not a crash at all. An oracle that detects only crashes sees only the failures that crash. Sanitizers and assertions widen the oracle. Differential testing §10.6, which compares the outputs of two implementations, and property checks, which test a stated relation between input and output, catch wrong results.

Step 5: the tested setup may differ from the deployed one. The harness may enter the code through a different function than the deployed system does, replace hardware with stand-ins, run one thread where the device runs several, or reset state that the device keeps from one message to the next. The build may differ as well: sanitizers, optimization level, compiler, or a 64-bit desktop processor in place of a 32-bit microcontroller §6.1. A failure that depends on any of these differences lies outside the claim.

Step 6: coverage does not close the gaps. A coverage metric §10.18 records which code ran, not with which values. A copy loop runs the same branches for a length of 16 and a length of 17, and only one of the two lengths overflows a 16-byte buffer. Full branch coverage §10.20 with zero failures still leaves every bug that depends on a value rather than on a branch.

Step 7: a statistical bound needs its own assumptions. Suppose the nn inputs were drawn from one fixed probability distribution QQ over DD, each draw independent of the others, so that they are independent and identically distributed samples §11.5, and all nn runs passed. Let pp be the probability that one input drawn from QQ fails. The probability of nn passes in a row is (1−p)n(1 - p)^n, which is small when pp is large. The values of pp for which that probability is at least 0.05 are those with p≤1−0.051/np \le 1 - 0.05^{1/n}; this is the 95% upper confidence bound on pp. Because −ln0.05≈3.0-\ln 0.05 \approx 3.0, where ln\ln is the natural logarithm, the bound is close to 3/n3/n for large nn, an approximation called the rule of three §18.5.8. The bound rests on three assumptions.

  1. Independence: each input is chosen without regard to the results of earlier runs.

  2. One distribution: every input comes from the same QQ.

  3. The right distribution: QQ is the distribution that the claim is about.

A coverage-guided fuzzer breaks the first two on purpose: it keeps the inputs that reached new code and changes them further, so each input depends on earlier results and the distribution shifts during the run. The third fails for security claims, because an attacker does not draw inputs from QQ; the attacker sends the failing input. Even when all three assumptions hold, the bound limits how often failures occur under QQ. It says nothing about whether a failing input exists.

Step 8: what the result is good for, and how to report it. Zero failures over many runs is evidence that failures reachable by this fuzzer, and visible to this oracle, are absent or rare, and the saved inputs make a useful regression test §10.4, a test rerun after every change to catch a bug that comes back. A report should state the fuzzer and its version, the harness, the build options, the seed corpus, the oracle including the sanitizers that were enabled, the number of executions, the duration, the coverage reached and when coverage stopped growing, and every input that crashed or timed out. A claim about all inputs needs a method that reasons about all inputs, such as the program checker of the extended Berkeley Packet Filter §2.1 (eBPF), called the eBPF verifier §3.3, which examines every path of a program before the program runs, or model checking §3.30. Each such method is correct only for its own model of the program and its environment.

Worked example

A parser copies a message’s payload into a 16-byte buffer. The first byte of the message, LL, gives the payload length, and the parser copies LL bytes without checking that L≤16L \le 16. Every value of LL from 17 to 255 writes past the end of the buffer.

  1. The generator. The tester wrote the input generator from the format documentation, which says that payloads hold at most 16 bytes. The generator draws LL uniformly from 0 to 16 and appends LL random bytes.

  2. The campaign. The fuzzer runs n=1,000,000n = 1{,}000{,}000 inputs, and none fails.

  3. Reach. The probability that the generator produces L≥17L \ge 17 is 0, so every one of the 10610^6 inputs lies in the safe part of the domain.

  4. The bound. These runs do satisfy the first two assumptions of Step 7, with QQ the generator’s distribution. The bound gives p≤1−0.051/1000000≈2.996×10−6p \le 1 - 0.05^{1/1000000} \approx 2.996 \times 10^{-6}, close to 3/1063 / 10^6. The bound is true: the actual failure probability under this generator is 0. Yet an attacker who sends L=17L = 17 makes the parser write 17−16=117 - 16 = 1 byte past the buffer.

  5. A wider generator, a blind oracle. Replace the generator with a mutation-based fuzzer that sets a randomly chosen byte to a random value. When it changes the first byte, L≥17L \ge 17 with probability (255−17+1)/256=239/256≈0.93(255 - 17 + 1) / 256 = 239 / 256 \approx 0.93, so overflowing inputs now appear quickly. If the parser was built without a sanitizer, a 1-byte overflow may overwrite only unused padding next to the buffer; nothing crashes, and an oracle that detects only crashes still reports no failure. Built with AddressSanitizer §10.22, a sanitizer that marks the bytes around each buffer as forbidden, the first overflowing input is reported.

The program had the same bug in every campaign. Whether zero failures were reported depended only on the generator’s domain and on what the oracle could detect, and those two are what a zero-failure claim must state.

Follow-up questions and limits

How many executions are enough? No number of executions turns into a claim about all inputs. A practical stopping point is that coverage has stopped growing for a long time with the oracle the claim needs. That shows that the fuzzer’s exploration has saturated, not that the program is correct.

Do timeouts §9.34 and rejected inputs count as passes? No. A run that the harness stopped at a time limit is a hang, a possible failure. An input that the harness rejected before calling the code, or a run that never started, tested nothing. Count each kind separately from the runs that completed and passed.

How does a proof differ? A verifier or a model checker establishes a property for every input of a model of the program, relative to the assumptions of that model, such as the meaning of each instruction and the behavior of the environment. Boundary-value testing §10.31 runs the inputs at the edges of each range, here L=16L = 16 and L=17L = 17, chosen by reading the specification, and would have found this bug in two runs. The methods give different evidence and are used together.

Can fuzzing ever establish a universal claim? Only by running every input of a finite domain, at which point it has become exhaustive enumeration rather than fuzzing. For a domain of 2162^{16} inputs at 10610^6 runs per second, this takes 65,536/106≈0.0765{,}536 / 10^6 \approx 0.07 seconds.

This answer does not cover how to design a harness or how to choose a seed corpus.

Fullest treatment: Fuzzing (§10.9).

Related entries: Test oracle (§10.5), Exhaustive enumeration (§10.33), Coverage versus correctness (§10.40), eBPF verifier (§3.3).