Race condition

A flaw in which the outcome depends on the relative timing or order of concurrent operations, so an attacker who influences that timing can change what the program does.

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

A race condition arises when two or more threads, processes or systems use a shared resource at the same time without proper coordination, and the result depends on which one gets there first. MITRE catalogues the general weakness as CWE-362. A simple case is two withdrawals that each read the same account balance before either writes the new one, so both succeed and the account pays out twice. Because the fault depends on timing, it may appear only under load and can pass ordinary testing.

Time-of-check to time-of-use (TOCTOU, CWE-367) is the best-known security form: a program checks a condition, such as a file’s permissions, and then acts on the resource, and an attacker changes the resource in the gap between the two. Every TOCTOU flaw is a race condition, but many race conditions are not TOCTOU flaws. Defences aim to make the check and the action one indivisible step: atomic operations, locks, database transactions with the isolation property of ACID, and acting on an opened file handle rather than a file name.

Exam relevance: a scenario in which a check passes but the resource changes before it is used is likely to point to TOCTOU, while a broader timing-dependent fault points to a race condition. Candidates are expected to reach for atomicity and locking as the fix.