893
Suppose the balance is initially 100.00. An attack could be constructed as follows:
Example Language: Other (Attack)
In the following pseudocode, the attacker makes two simultaneous calls of the program, CALLER-1 and CALLER-2. Both
callers are for the same user account.
CALLER-1 (the attacker) is associated with PROGRAM-1 (the instance that handles CALLER-1). CALLER-2 is associated
with PROGRAM-2.
CALLER-1 makes a transfer request of 80.00.
PROGRAM-1 calls GetBalanceFromDatabase and sets $balance to 100.00
PROGRAM-1 calculates $newbalance as 20.00, then calls SendNewBalanceToDatabase().
Due to high server load, the PROGRAM-1 call to SendNewBalanceToDatabase() encounters a delay.
CALLER-2 makes a transfer request of 1.00.
PROGRAM-2 calls GetBalanceFromDatabase() and sets $balance to 100.00. This happens because the previous
PROGRAM-1 request was not processed yet.
PROGRAM-2 determines the new balance as 99.00.
After the initial delay, PROGRAM-1 commits its balance to the database, setting it to 20.00.
PROGRAM-2 sends a request to update the database, setting the balance to 99.00
At this stage, the attacker should have a balance of 19.00 (due to 81.00 worth of transfers), but the
balance is 99.00, as recorded in the database.
To prevent this weakness, the programmer has several options, including using a lock to prevent
multiple simultaneous requests to the web application, or using a synchronization mechanism that
includes all the code between GetBalanceFromDatabase() and SendNewBalanceToDatabase().
Example 2:
The following function attempts to acquire a lock in order to perform operations on a shared
resource.
Example Language: C (Bad)
void f(pthread_mutex_t *mutex) {
pthread_mutex_lock(mutex);
/* access shared resource */
pthread_mutex_unlock(mutex);
}
However, the code does not check the value returned by pthread_mutex_lock() for errors. If
pthread_mutex_lock() cannot acquire the mutex for any reason, the function may introduce a race
condition into the program and result in undefined behavior.
In order to avoid data races, correctly written programs must check the result of thread
synchronization functions and appropriately handle all errors, either by attempting to recover from
them or reporting them to higher levels.
Example Language: C (Good)
int f(pthread_mutex_t *mutex) {
int result;
result = pthread_mutex_lock(mutex);
if (0 != result)
return result;
/* access shared resource */
return pthread_mutex_unlock(mutex);
}
Example 3:
Suppose a processor's Memory Management Unit (MMU) has 5 other shadow MMUs to distribute
its workload for its various cores. Each MMU has the start address and end address of "accessible"
memory. Any time this accessible range changes (as per the processor's boot status), the main
MMU sends an update message to all the shadow MMUs.
CWE Version 4.14
CWE-362: Concurrent Execution using Shared Resource with Improper Synchronization ('Race
Condition')
CWE-362: Concurrent Execution using Shared Resource
with Improper Synchronization ('Race Condition') 894
Suppose the interconnect fabric does not prioritize such "update" packets over other general traffic
packets. This introduces a race condition. If an attacker can flood the target with enough messages
so that some of those attack packets reach the target before the new access ranges gets updated,
then the attacker can leverage this scenario.
Observed Examples
Reference Description
CVE-2022-29527 Go application for cloud management creates a world-writable sudoers file that
allows local attackers to inject sudo rules and escalate privileges to root by
winning a race condition.
https://www.cve.org/CVERecord?id=CVE-2022-29527
CVE-2021-1782 Chain: improper locking (CWE-667) leads to race condition (CWE-362), as
exploited in the wild per CISA KEV.
https://www.cve.org/CVERecord?id=CVE-2021-1782
CVE-2021-0920 Chain: mobile platform race condition (CWE-362) leading to use-after-free
(CWE-416), as exploited in the wild per CISA KEV.
https://www.cve.org/CVERecord?id=CVE-2021-0920
CVE-2020-6819 Chain: race condition (CWE-362) leads to use-after-free (CWE-416), as
exploited in the wild per CISA KEV.
https://www.cve.org/CVERecord?id=CVE-2020-6819
CVE-2019-18827 chain: JTAG interface is not disabled (CWE-1191) during ROM code
execution, introducing a race condition (CWE-362) to extract encryption keys
https://www.cve.org/CVERecord?id=CVE-2019-18827
CVE-2019-1161 Chain: race condition (CWE-362) in anti-malware product allows deletion of
files by creating a junction (CWE-1386) and using hard links during the time
window in which a temporary file is created and deleted.
https://www.cve.org/CVERecord?id=CVE-2019-1161
CVE-2015-1743 TOCTOU in sandbox process allows installation of untrusted browser add-ons
by replacing a file after it has been verified, but before it is executed
https://www.cve.org/CVERecord?id=CVE-2015-1743
CVE-2014-8273 Chain: chipset has a race condition (CWE-362) between when an interrupt
handler detects an attempt to write-enable the BIOS (in violation of the lock
bit), and when the handler resets the write-enable bit back to 0, allowing
attackers to issue BIOS writes during the timing window [REF-1237].
https://www.cve.org/CVERecord?id=CVE-2014-8273
CVE-2008-5044 Race condition leading to a crash by calling a hook removal procedure while
other activities are occurring at the same time.
https://www.cve.org/CVERecord?id=CVE-2008-5044
CVE-2008-2958 chain: time-of-check time-of-use (TOCTOU) race condition in program allows
bypass of protection mechanism that was designed to prevent symlink attacks.
https://www.cve.org/CVERecord?id=CVE-2008-2958
CVE-2008-1570 chain: time-of-check time-of-use (TOCTOU) race condition in program allows
bypass of protection mechanism that was designed to prevent symlink attacks.
https://www.cve.org/CVERecord?id=CVE-2008-1570
CVE-2008-0058 Unsynchronized caching operation enables a race condition that causes
messages to be sent to a deallocated object.
https://www.cve.org/CVERecord?id=CVE-2008-0058
CVE-2008-0379 Race condition during initialization triggers a buffer overflow.
https://www.cve.org/CVERecord?id=CVE-2008-0379
CVE-2007-6599 Daemon crash by quickly performing operations and undoing them, which
eventually leads to an operation that does not acquire a lock.
https://www.cve.org/CVERecord?id=CVE-2007-6599
CVE-2007-6180 chain: race condition triggers NULL pointer dereference
https://www.cve.org/CVERecord?id=CVE-2007-6180
CWE Version 4.14
CWE-362: Concurrent Execution using Shared Resource with Improper Synchronization ('Race
Condition')
CWE-362: Concurrent Execution using Shared Resource
with Improper Synchronization ('Race Condition')