Section 3.8

Completeness

Definition

Completeness is the property of a program analysis or verifier that it confirms every case that really has the property it checks. For a verifier that accepts the programs it can show to be safe, completeness means that every safe program is accepted. It is the counterpart of soundness §3.7, which means that every accepted program is safe. A sound but incomplete verifier rejects some safe programs; a complete but unsound one accepts some unsafe programs. Both properties are judged against one semantics, the exact definition of what each instruction does.

The idea

An operating system kernel lets users load small extension programs and checks each one before running it. Accepting an unsafe program can crash the kernel or let an attacker read memory that should stay secret. Rejecting a safe program costs a developer a rewrite. Ideally the checker would accept exactly the safe programs, being sound and complete at once.

For a language with unrestricted loops, no checker that always finishes can do that. Deciding whether an arbitrary program is safe includes deciding whether it ever halts, which no algorithm §14.1 can do; this is the halting problem §19.2.2. For a language with bounded loops and fixed-size values the question can be decided in principle, but exact checking may have to consider an astronomical number of states. So designers keep soundness, the property whose loss is dangerous, and give up completeness: the checker accepts what it can prove and rejects the rest. Simplicity points the same way: every extra reasoning rule is code that can itself be wrong, and an error in the checker is a security hole.

A strict passport officer is a fair picture: the officer stamps only documents that can be verified on the spot, so some honest travelers are turned away, but no forged document passes as long as the checks themselves are right. The picture stops at one point. An officer can ask further questions, while a verifier’s rejection is final: the developer must rewrite the program so that its safety becomes provable, for example by adding an explicit bounds check.

How it works

A sound but incomplete verifier rejects a safe program for one of four reasons.

  1. The summaries cannot express the needed fact. The verifier’s abstract domain §3.6, its vocabulary of summaries, has no way to state the fact on which safety depends, such as x=yx = y when it keeps only one range per variable.

  2. Merging loses the fact. Where two paths meet, or where a loop is summarized, the verifier merges summaries, and the merged summary may no longer imply safety.

  3. The feature is not modeled. The verifier refuses constructs whose meaning it does not model, such as unbounded loops or calls through a computed address. This is conservative refusal §3.36.

  4. The work limit is reached. The verifier stops after a fixed amount of work and rejects. Linux checks every eBPF §2.1 (extended Berkeley Packet Filter) program, a small program loaded into the kernel, with the eBPF verifier §3.3, which rejects a program once it has processed one million instructions along the paths it explores.

A check therefore has three outcomes, not two: proved safe; violation found, when the verifier can show an execution that breaks the property; and unknown, when it could neither prove nor refute. A sound verifier must treat unknown as a rejection. A verifier that can tell the two kinds of rejection apart should report them apart, because they ask the developer for different things: fix a bug, or restate correct code in a form the verifier can prove.

Worked example

A verifier keeps one interval, a lower and an upper bound, for each variable. The array §14.5 t has one element, so its only valid index is 0. The input xx is an unknown integer from 0 to 3. Four candidate programs read from t.

Under the real semantics P1P_1, P2P_2 and P3P_3 are safe; P3P_3 always computes i=0i = 0. P4P_4 is unsafe: with x=1x = 1 it reads past the end of t. The verifier proves P1P_1 at once, and P2P_2 because the test narrows xx to [0,0][0, 0] on the path that reaches the read. For P3P_3 it knows only x∈[0,3]x \in [0, 3] and y∈[0,3]y \in [0, 3], computes i∈[0−3,3−0]=[−3,3]i \in [0 - 3, 3 - 0] = [-3, 3], cannot prove i=0i = 0, and rejects. It rejects P4P_4 because xx can be 1, 2 or 3.

Let SS be the set of safe programs and AA the set of accepted ones: S={P1,P2,P3}S = \{P_1, P_2, P_3\} and A={P1,P2}A = \{P_1, P_2\}. Every accepted program is safe, A⊆SA \subseteq S, so the verifier is sound on these four programs. The safe program P3P_3 is rejected, so S⊈AS \not\subseteq A, and the verifier is incomplete: it rejected 1 of the 3 safe programs. A verifier that accepted all four would satisfy S⊆AS \subseteq A and be complete, but it would be unsound, because it accepts P4P_4. A verifier that rejected all four would be sound, since the empty set is a subset of SS, and useless.

The two rejections mean different things. For P4P_4 the verifier can name an input, x=1x = 1, that breaks safety. For P3P_3 it has only failed to find a proof. Rewriting P3P_3 to read t[0], or adding a test that returns early unless i=0i = 0, turns it into a program the verifier accepts.

Stated precisely

Let PP be the set of all programs of a language, S⊆PS \subseteq P the programs that have the property in every execution that the semantics allows, and A⊆PA \subseteq P the programs that the verifier accepts. Then sound: A⊆S,complete: S⊆A,sound and complete: A=S.\text{sound: } A \subseteq S, \qquad \text{complete: } S \subseteq A, \qquad \text{sound and complete: } A = S. These are statements about which programs are accepted, not about speed, and not about the share of test programs that pass.

For a language that can express any computation, no verifier that always terminates has A=SA = S for the property “never accesses memory out of bounds”. Take any program QQ written so that it never accesses memory out of bounds; this safe part of the language can still express any computation. Build Q′Q': run QQ, then perform one out-of-bounds access. Q′Q' is unsafe exactly when QQ halts. A terminating verifier with A=SA = S would therefore decide whether an arbitrary QQ halts, which the halting problem shows to be impossible. Rice’s theorem generalizes the argument: every property of the function that a program computes, its input-output behavior, is undecidable §19.2.1 unless all programs have it or none do.

For a language whose programs have finitely many states, for example with bounded loops, fixed-width registers and bounded memory, safety is decidable by examining every reachable state §3.21. The number of states can still be out of reach: two 64-bit registers alone have 21282^{128}, about 3.4×10383.4 \times 10^{38}, combinations of values. Decidable does not mean practical.

Limits and common mistakes

Completeness is relative to a property, a semantics and a convention about what an answer means. Some authors of bug-finding tools reverse the words: they call a tool sound when every bug it reports is real, which in a verifier’s terms is completeness. State the convention before comparing tools.

A rejection is not a bug report. A count of rejections mixes real violations with programs the verifier could not prove, so report the two separately.

Incompleteness shapes how programs are written. Developers add checks that are logically redundant so that the verifier can follow them. A compiler can also rearrange correct code so that a bounds check and the access it protects use different registers; a verifier that tracks each register separately then loses the connection and rejects the program.

In abstract interpretation §3.4 the word also describes a single abstract operation: the operation is complete when applying it to the summary of a set of states gives exactly the summary of the true results. As a formula, α(f(S))=f♯(α(S))\alpha(f(S)) = f^\sharp(\alpha(S)), where α\alpha gives the most precise summary of a set of states SS, f(S)f(S) is the set of results of the real operation on SS, and f♯f^\sharp is the abstract operation.

Testing can show incompleteness, by finding a safe program that is rejected, and unsoundness, by finding an unsafe program that is accepted. Testing cannot show that either property holds.

Questions answered

Why might a practical safety verifier deliberately sacrifice completeness?

A practical safety verifier sacrifices completeness, which means that it rejects some programs that are in fact safe, because it cannot also be sound and always finish quickly, and soundness, never accepting an unsafe program, is the property it must keep. For a language that can express any computation, no checker that always terminates accepts exactly the safe programs, since deciding safety would decide the halting problem. For a restricted language with bounded loops the question can be decidable, but exact checking may need to examine more states than any machine can, while the check must finish within a fixed limit when the program is loaded.

Two further reasons are engineering ones. A smaller set of reasoning rules is easier to get right, and an error in the verifier is itself a security hole. The two kinds of error also cost different amounts: accepting one unsafe program can compromise the whole system, while rejecting a safe one costs the developer a rewrite, such as adding an explicit bounds check that the verifier can follow. The verifier therefore accepts what it can prove in bounded time and rejects everything else, including safe programs whose safety depends on facts its summaries cannot express.

Related entries: eBPF verifier (§3.3), Conservative refusal (§3.36), Soundness (§3.7), State explosion (§3.26), Halting problem, Rice’s theorem, and restricted verifiers (§19.2.2). Further reading: [159].