Race Conditions: When Correct Steps Happen in the Wrong Order
A booking site might promise the last place in a workshop to two people. One request checks availability and finds the place open. Before it records a reservation, another request makes the same check. The site lets both requests proceed.
Each check made sense when it happened. The error came from what happened between the check and the reservation.
A race condition occurs when a program's outcome depends on an ordering of operations that the program hasn't properly controlled. The requests don't need to arrive at precisely the same instant. Their steps only need to overlap in a way the software handles incorrectly.
When Timing Becomes a Security Hole
The gap between looking and changing
The booking example can fail in this order:
- Request A reads the number of available places: one.
- Request B reads the number before A changes it: also one.
- A records a reservation.
- B records another reservation based on its earlier check.
The two requests share information about the available place. Neither waits for the other to finish checking and changing it. A correct answer can therefore become out of date before the software uses it.
Running several activities during overlapping periods is called concurrency. It is not inherently a bug. The problem arises when concurrent activities need coordinated access to something shared and the program doesn't provide it.
MITRE's description of improperly synchronized access explains that another sequence of work can change a resource during a vulnerable timing window. Even a short operation can contain several steps that other work interrupts.
Keeping the decision and the change together
For the workshop, the software needs to preserve a rule: one available place can produce no more than one new reservation. Checking and reserving must be coordinated so another request cannot rely on an out-of-date answer.
One approach is an atomic operation. Competing operations treat it as one indivisible step: they cannot interrupt it halfway through the work that needs protection.
Another approach uses a lock to control access to the shared information while the critical work takes place. The critical section is the part of the program that needs this protection.
Both approaches require the programmer to identify exactly which work needs protection. The protection has to cover the operations and shared resources that can conflict. A lock taken after both requests have already checked availability would arrive too late for this example.
- Try both Arm and RISC-V processors on a single board and compare them yourself.
- Skip the soldering: the header pins arrive already attached.
- Follow the step-by-step tutorial in MicroPython or C at your own pace.
A security decision can go stale, too
Now consider a program that checks whether it may safely use a file, then acts on that file later. If the relevant file or its condition changes between those steps, the earlier approval may no longer apply to what the program actually uses.
This pattern is called a time-of-check to time-of-use race, often shortened to TOCTOU. The name describes the gap: something was true when checked, but the software assumed it would remain true until used.
MITRE's TOCTOU entry describes consequences including unauthorized access and changes. A timing bug becomes a security vulnerability when someone can use it to cross a boundary the system should enforce.
Not every race condition follows this pattern, and not every race creates a security problem. The effect depends on the work being interrupted and the rule that fails.
Doing the check more quickly can reduce the opportunity for interference. It doesn't remove the assumption that nothing will change afterward. The check must remain valid when the program acts on it.
Symbolic Links: A Filename That Leads Somewhere Else

Synchronization: Getting Clocks—and Work—in Agreement

System Integrity: Is the Computer Still Doing Its Intended Job?

QUOTE:
"Amateurs hack systems, professionals hack people."
