Time-of-check to time-of-use (TOCTOU)

A race condition in which a program checks a resource and uses it a moment later, leaving a window in which an attacker can change or replace the resource so the check no longer holds.

Full guide: TOCTOU Explained: Time of Check Time of Use Race Conditions for CISSP

Time-of-check to time-of-use (TOCTOU) is a class of race condition. A program checks something about a resource, such as whether a file exists, who owns it or whether a user may open it, and then acts on that resource a moment later. If the resource can change in between, the decision is made about one thing and applied to another. In the classic case a privileged program checks a user’s permission on a file path, then opens it, while the attacker swaps in a symbolic link to a protected file. MITRE catalogues the weakness as CWE-367.

The fix is to remove the gap rather than to shorten it. Common approaches are a single atomic check-and-use operation, opening the resource once and checking the same handle, locking the resource, or letting the operating system enforce the permission at the moment of use. That last approach reflects the reference monitor principle of complete mediation, in which access is checked when it happens. The TOCTOU guide walks through it.

Exam relevance: a scenario in which a condition was valid when checked but had changed by the time it was acted on is likely to be describing TOCTOU. Candidates are expected to recognise that atomic operations and locking address it, while faster hardware does not.