Section 19.2.5

Overapproximation versus underapproximation

Definition

An overapproximation of a program’s behavior is a computed set that contains every state the program can really reach, and possibly more; a state is a complete snapshot of the running program. An underapproximation is a computed set that contains only states the program can really reach, possibly not all of them. The difference that matters: an overapproximation that contains no bad state proves that no run reaches one, while a bad state inside an underapproximation proves that some real run reaches one.

Where it fits

Main entry: Abstract interpretation (§3.4).

Let RR be the set of states the program can really reach, fixed by the semantics, the exact definition of what every instruction does. A computed set OO is an overapproximation when R⊆OR \subseteq O, and a computed set UU is an underapproximation when U⊆RU \subseteq R. Abstract interpretation, which runs a program on summaries of its values, computes overapproximations, and soundness §3.7 is the name of that guarantee. Testing, fuzzing §10.9, symbolic execution §3.27 and bounded model checking §3.29 run or explore some real executions, so the states they visit form an underapproximation. The four possible outcomes mean different things:

Suppose the values that xx can really hold at one point are R={0,2}R = \{0, 2\}, and xx is used as an index into an array §14.5 of 2 elements, so the value 2 is out of bounds. The interval [0,2][0, 2], which stands for {0,1,2}\{0, 1, 2\}, is an overapproximation: it keeps both real values and adds 1. A test that only ever produced x=0x = 0 gives the underapproximation {0}\{0\}. The interval reports the real bug at 2; the test misses it. Had the forbidden value been 1 instead, the interval would report a false alarm, since no run produces 1, and the test would rightly report nothing. An overapproximation errs only by adding states; an underapproximation errs only by leaving states out.

Limits and common mistakes

Both guarantees hold only relative to the model of each instruction. An overapproximation built from a wrong model of one instruction, a helper function §2.19 or the machine’s overflow behavior covers a different program. A run reported by an underapproximating tool is real only if every step of it matches what the real instructions do. A bad run found in an overapproximation may be spurious; only replaying it on the real system confirms it.

The kind of tool does not fix the direction; the inclusion it establishes does. A static analyzer that drops the cases it cannot handle no longer overapproximates, and a tester that runs a simplified copy of the program no longer underapproximates.

Questions answered

What if an analyzer silently skips an unknown instruction?

If an analyzer silently skips an unknown instruction, its verdict that the program is safe stops being a proof, because the analysis no longer covers every behavior of the real program. Skipping treats the instruction as if it did nothing. If the real instruction can write a register or memory, or send execution elsewhere, real runs reach states that the computed set lacks. The computed set is then not an overapproximation of the real program, and “no bad state found” may hide a real bug.

There are two sound responses. The first is a conservative model: assume the instruction may change every location it could affect to any value and may jump to any target it could reach. An analyzer that knows nothing about the instruction must assume it can change anything and jump anywhere, which usually forces rejection anyway. The second is conservative refusal §3.36: reject the program with an explicit error, the fail-closed §1.13 choice. A tool that explores real runs is not rescued by skipping either: a failing run it reports may not exist in the real program, because the run was computed for a program without that instruction.

Related entries: Conservative refusal (§3.36), Coverage versus correctness (§10.40), Refinement (§3.32), Soundness (§3.7).