Definition
Reachability is the question whether a system, started in one of its allowed initial states and moving only by allowed steps, can arrive at a chosen target: a state, a set of states or a program point. A state is a complete description of the system at one moment, such as the current instruction and the values of all variables. The target is reachable when some finite sequence of allowed steps leads from an initial state to it. The answer depends on which initial states and steps the model allows.
The idea
A program copies len bytes into a 64-byte buffer, and the copy runs past the end of the buffer when len is above 64. Whether this is a security defect turns on one question: can any execution reach that copy with len above 64? If the only route passes through a debug command that the product build removes, the copy is unreachable in the product. If a network packet can set len, it is reachable, and such a packet is an attack. Asked about an error state, the same question checks a safety property §1.11: “the lock never opens without a valid code” holds exactly when no state in which the lock is open without a valid code is reachable.
Picture a building: rooms are states, doors are steps, and some rooms are entrances. The question is whether someone who comes in through an entrance can get to one particular room. Two differences from a real building matter. A door in a program can depend on values: the door from the test x < 1 into its true branch opens only for some values of x, so a route that looks connected on the floor plan can be impossible to walk. And the analyst draws the floor plan: which entrances exist, which doors the environment can open (a library function that may fail, a device that may return an unexpected value), and which outside events, such as an interrupt §6.11 or an incoming packet, can happen between two steps. A different plan can give a different answer.
How it works
Reachability is asked of a model with three parts, together called a transition system.
The states.
The initial states, where the system may start. For a program, these are its first instruction together with every allowed input and every allowed initial content of memory and storage.
The transition relation, which says for each state which states can follow it in one step. A step can have several possible successors: one for each value an input may take, for each result a library function or device may return (failures included), and for each way the threads and interrupts may be interleaved.
Four methods answer the question.
Explicit search. Start from the initial states, and in each round add every successor of every state found so far, as in a breadth-first search §14.18. If the target appears, the sequence of steps that led to it is a witness, called a counterexample when the target is an error. If a round adds no new state, the set found contains all reachable states, and the target is unreachable if it is not in that set. On a model with finitely many states, the search always ends.
Symbolic search. When there are too many states to list one by one, the analysis represents sets of states by formulas, such as , and computes the successors of a whole set at once. Symbolic model checking §3.30 tools work this way. The number of states can grow exponentially with the number of variables, which is called state explosion §3.26.
Overapproximation §19.2.5. An analysis can compute a superset of the reachable states, for example by keeping only a range of values for each variable. If the target lies outside the superset, the target is unreachable. If the target lies inside, it may be reachable, or the superset may be too coarse, so the path that the analysis offers must be checked. A path through the control-flow graph §3.13 (the diagram of which statement can follow which) is feasible when some input satisfies every branch condition along it. An SMT solver §3.28 (satisfiability modulo theories solver, a program that decides whether a set of such conditions can hold together) can check this. If the path is infeasible, the analysis is made more precise and run again; counterexample-guided abstraction refinement §15.13 automates this loop.
Underapproximation. Testing, fuzzing §10.9 and bounded model checking §3.29 explore only part of the behavior, for example the executions of at most steps. A target that they reach is reachable, and the run is the witness. A target that they do not reach may still be reachable.
Worked example
Exploring a small model. A controller has four states: A (idle), B (receiving), C (processing) and D (error). The allowed steps are A to B, B to C, and C back to A. The only initial state is A. Write for the set of states found after rounds, and for the set of states one step after some state in the set .
.
.
.
, the same as , so the search stops.
State C is reachable, with the witness A, B, C of two steps. State D is unreachable, because no step leads into it.
Now the model of the environment changes. The processing in state C calls a library function, and the model now allows that call to fail, which adds a step from C to D. The rounds are the same up to , and then . The error state D is now reachable, with the witness A, B, C, D of three steps. The program did not change; the assumption about the library function did.
An input assumption. The code x = sensor(); if (x == 2) error(); reaches error only if the sensor returns 2. If the model says that the sensor returns only 0 or 1, error is unreachable. If the real sensor can return any byte value from 0 to 255, error is reachable with x equal to 2.
A path in the graph that no execution takes. In if (x < 1) { if (x > 3) error(); }, the control-flow graph contains a path to error: the true edge of x < 1, then the true edge of x > 3. Along that path x does not change, so an execution would need an integer with , that is , and also , that is . No integer is both, so the node error is reachable in the graph, but no state at error is reachable in the program.
Stated precisely
A transition system is a triple : is the set of states, is the set of initial states, and means that state can follow state in one step. For a set of states, . Define and . The set of reachable states is which is the set of states at the end of some finite sequence with . A target set is reachable when . The index counts rounds of exploration, not elapsed time.
is the least fixed point §3.22 of : the smallest set of states that contains the initial states and every successor of its members. If is finite, each round either adds at least one state or changes nothing, and once a round changes nothing no later round does, so the iteration stops after at most rounds, where is the number of states. A safety property that forbids the states in holds exactly when is unreachable.
For programs with unbounded memory, reachability is undecidable §19.2.1: deciding whether the end of a program is reachable is the halting problem §19.2.2. For finite-state models it is decidable, although the number of states can be exponential in the size of the model’s description.
Each kind of result proves one thing. An overapproximation is a computed set with ; finding proves that is unreachable. An underapproximation is a computed set with ; finding proves that is reachable. The other two outcomes, and , prove nothing. Both proofs are about the model. An unreachability proof carries over to the real system only if the initial states and steps of the model include every behavior of the real system that the claim covers. A reachability proof carries over only if every step of the witness can really happen.
Limits and common mistakes
Not observed is not unreachable: tests and fuzzing that never reach a state show only that the inputs tried did not reach it. Inside an overapproximation is not reachable: a target inside the superset is a possible problem until a feasible witness is found. Reachable in the control-flow graph is not reachable in the program: a path in the graph is a real execution only if some input satisfies all of its branch conditions together.
An assumption that removes behavior must be enforced by something real. A model in which a library function never fails, an input never exceeds 64 bytes, or no interrupt arrives during a section of code proves unreachability only for a system with that property. The property must come from a check earlier in the code, from the guaranteed contract of the function, or from the hardware. Otherwise the proof is about a system that does not exist.
Faults outside the fault model §1.30 break unreachability claims. A bit flipped in memory, a voltage glitch that makes the processor skip an instruction, or a reset in the middle of a write can lead to states that no model of correct execution contains.
Reachable is not exploitable. Reaching a faulty instruction is necessary for an attack, but whether an attacker controls the values there is a further question, which taint analysis §3.19 addresses.
A bounded search proves a bounded claim. “Unreachable within 20 steps” says nothing about step 21.
Reachability answers whether something bad can happen. Whether something good eventually happens, such as every request eventually getting an answer, is a liveness property §1.12 and needs different methods.
Questions answered
Reachable under which input and environmental assumptions?
A reachability result holds only for the model it was computed in, so every claim must state the assumptions of that model:
inputs: which values, lengths and sequences of inputs are allowed, and who can send them;
initial state: the starting content of memory, stored data and configuration;
environment: what each library function, device and communication partner may return, failures and timeouts §9.34 included;
concurrency §9.1: which thread schedules and interrupt arrivals are allowed;
faults: which hardware faults, resets and power losses are included;
bounds: any limit on steps, loop iterations or input size that the analysis used.
Then read the result by its direction. “Reachable” means that the model contains a witness path; it is a real finding when every step of that path can happen in the real system. “Unreachable”, proved with an overapproximation of the behavior of the model, is a proof about the model. It carries over to the real system only if each assumption that excluded behavior is enforced there, by a check in the code, by the hardware or by the guaranteed contract of a function. A target that testing or a bounded search did not reach has not been shown unreachable. For example, if a program reaches its error branch only when a sensor reads 2, the branch is unreachable under the assumption that the sensor returns only 0 or 1, and reachable if the sensor can return any byte value.
Related entries: Control-flow graph (CFG) (§3.13), Fixed point (§3.22), Bounded model checking (§3.29), Symbolic execution (§3.27), Model checking (§3.30), Safety property (§1.11), Overapproximation versus underapproximation (§19.2.5), Counterexample-guided abstraction refinement (CEGAR) (§15.13).