Modelresearch
Software testing as species discovery
Also called STADS.
Models fuzzing as sampling species from an ecology and uses the Good-Turing estimator to estimate the chance that the next input finds new behavior.
Software testing as species discovery (STADS) is a statistical model of automated testing that borrows the methods ecologists use to count the species of a forest from a sample of animals. A test generator, such as a fuzzer, produces inputs for a program one after another. STADS treats each input as one sample drawn from a population of program behaviors, and the behavior the input shows, for example the path it takes through the code, is its species. Some behaviors are common and are seen again and again; others are rare and may not have been seen yet. With this view, the species estimators of ecology answer testing questions: Good-Turing estimation estimates the probability that the next input shows a behavior never seen before, and the Chao1 estimator estimates how many behaviors there are in all. Böhme (2018) introduced the model.
For fuzz testing, this gives a statistical answer to an old problem: a campaign that has found no bug does not show that none is left, but the discovery probability bounds the chance that the next input finds an error of a kind not seen yet. This residual risk can be estimated while the campaign runs and used to decide when to stop. The guarantee needs the samples to come from a fixed distribution, which a feedback-driven fuzzer does not satisfy, so for such a fuzzer the estimates are approximations.
The machine
- Inputs as individuals. A fuzzer generates inputs . A dynamic analysis assigns to each input its species: the path it executes, the function where it crashes, or a pair such as (path, crashed or not).
- The multinomial model. Each input belongs to exactly one of species , and each input belongs to with probability , independently of the other inputs, with . The number of species and the probabilities are unknown.
- Fixed abundances. The probabilities do not change during the campaign. This holds for a blackbox fuzzer with a fixed input distribution. A greybox fuzzer adds inputs that found new species to its queue and so raises the probability of their neighbors; Böhme calls this adaptive bias.
- The Bernoulli product model. When one input can belong to several species at once, such as the branches it covers, each species is present in an input with its own probability, independently across inputs. The data are then incidence counts, and the estimators change accordingly.
- What is observed. After inputs, is the number of inputs in species , is the number of species seen so far, and is the number of species seen exactly times. counts the singletons and the doubletons.
What it counts
The discovery probability. is the probability that input belongs to a species not seen in the first inputs, so and . Its expected value over the campaign is
The sample coverage is the probability that the next input belongs to a species already seen, and is the expected number of further inputs to the next discovery while stays as it is.
The Good-Turing estimate. . A species seen once is a species that was nearly missed, and the share of singletons predicts the share of the species still missing.
The residual risk. The residual risk after inputs without a failure is the probability that input is the first input to show a failure. If the analysis is fine enough that every kind of failure is a union of species, then an input that shows a new kind of failure belongs to a species not yet seen, so the residual risk is at most . STADS uses as the estimate of this bound.
Richness and extrapolation. The Chao1 estimate (with when ) gives a lower bound estimate of the number of species, and is the share discovered. Formulas of ecology for rarefaction and extrapolation estimate and after more inputs, which tells how much more fuzzing buys.
Example. A made-up function reads one byte and branches on the number of leading 1 bits, from 0 to 8. With uniform random bytes this gives nine species A to I with probabilities and (I is the byte 255). The first 50 bytes of Python's random.Random(0).randrange(256) give these counts:
| species | A | B | C | D | E | F | G | H | I |
|---|---|---|---|---|---|---|---|---|---|
| probability | 1/2 | 1/4 | 1/8 | 1/16 | 1/32 | 1/64 | 1/128 | 1/256 | 1/256 |
| count in 50 inputs | 23 | 14 | 5 | 2 | 3 | 2 | 1 | 0 | 0 |
So , (species G) and (D and F). The Good-Turing estimate is , and the true discovery probability is . Chao1 gives against the true 9. If byte 255 is the one input that crashes, the residual risk is , below . One sample is noisy: after 100 inputs of the same stream, and the estimate is 0, while . The estimator is right on average: over all samples of size 50, and . A scratch script computed these numbers exactly with fractions.
Relation to other models
- Ecology. The multinomial model is the abundance model of species sampling, and the Bernoulli product model is the incidence model. The estimators of Chao1 and of rarefaction are used without change.
- Language models. Good-Turing estimation of unseen words is the same estimate of the missing mass, with words as species.
- The coupon collector. With equally likely species, the time to see all of them is the coupon collector problem. STADS makes no assumption on the abundances, and real campaigns have many rare species.
- Markov chain model of greybox fuzzing. The model behind power schedules describes how the fuzzer moves between paths and how the choice of seeds changes the probabilities. STADS assumes that the probabilities stay fixed, so it leaves out the change that the chain model describes.
- The exponential cost of discovery. The exponential cost of vulnerability discovery is an empirical law about campaigns that a species model with a heavy tail of rare species explains.
- The rule of succession. For a fixed distribution with no failure in runs, the Laplace estimate of the failure probability is an alternative, related to Laplace smoothing; Böhme, Liyanage and Wüstholz (2021) list it among the blackbox estimators.
Known results in the model
- Bias of the Good-Turing estimate (theorem, fixed distribution). has expected value , so . This is at least 0, and at most , because and for . So the estimate is a little too high on average, by less than . In the example, the gap at is about 0.00057.
- Residual risk bound (theorem). If every kind of failure is a union of species, the residual risk is at most , as shown above. It is a bound on a probability, estimated by ; it is not a proof that no bug is left.
- Other properties of the estimate. The paper cites results of the statistics literature: the Good-Turing estimate is strongly consistent, it is asymptotically normal, and its mean squared error is below (Robbins). All of them assume the fixed-distribution model.
- The djpeg campaign (measurement). In the paper's example of AFL on djpeg, after 12 hours there were 447 singleton species in 63.6 million inputs, so ; after 24 hours there were 95 singletons in 124.8 million inputs, so . Here a species is a pair of a path and whether the input crashed.
- Evaluation under adaptive bias (measurement). Böhme fuzzed six programs with AFL for a total of 8.2 months and reported low bias for the estimates of the discovery probability and of species coverage, and that the bias fell as more inputs were generated, despite AFL's adaptive bias.
- Greybox residual risk (measurement). Böhme, Liyanage and Wüstholz (2021) measured that the classical estimators made for blackbox fuzzing, among them Good-Turing and Laplace, systematically and substantially under-estimate the residual risk of greybox campaigns, because the probability of a bug-revealing input grows as the queue grows. They gave the first probabilistic analysis of adaptive bias and new estimators that correct for it. The fixed-distribution theorems above therefore do not carry over to a greybox fuzzer; for it, the Good-Turing estimate is an approximation.
References
- Marcel Böhme, STADS, software testing as species discovery, ACM Transactions on Software Engineering and Methodology 27(2), Article 7, 2018, pp. 1 to 52, the multinomial model, Section 4 (the discovery probability, its Good-Turing estimate and the guarantee for undiscovered errors), Figure 2 (the djpeg campaign), Section 6 (the evaluation with AFL), Section 7 (the Bernoulli product model) and Section 9.5 (adaptive bias)
- Marcel Böhme, Danushka Liyanage and Valentin Wüstholz, Estimating residual risk in greybox fuzzing, Proceedings of ESEC/FSE 2021, pp. 230 to 241, the definition of residual risk, the discovery probability as its upper bound, and the measured under-estimation by blackbox estimators under adaptive bias
- I. J. Good, The population frequencies of species and the estimation of population parameters, Biometrika 40(3-4), 1953, pp. 237 to 264, the estimate of the total probability of unseen species from the number of species seen once
- Andreas Zeller, Rahul Gopinath, Marcel Böhme, Gordon Fraser and Christian Holler, The Fuzzing Book, chapter When To Stop Fuzzing, the Good-Turing estimate of the discovery probability in a fuzzing campaign
Where this leads
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag WT7TJM Edit this page History Report an error Markdown