Race conditions occur when the proper functioning of a security function depends upon the timing of activities performed by the computer. In this video, Mike Chapple explains how to prevent race conditions in your code.
- [Announcer] Race conditions are a particularly dangerous security flaw, and require careful attention from software developers and security professionals in order to prevent them. A race condition occurs when the proper functioning of a security control depends upon the timing of activities performed by the computer or the user. If the timing doesn't occur as expected, the software may behave in an unexpected manner. A common example of a race condition is a Time of Check to Time of Use, or TOCTOU vulnerability.
In a TOCTOU vulnerability, software first checks to see whether an activity is authorized, and then waits some time before performing the action that is authorized. The catch is that the authorization status might have changed during the time that elapsed. Let's take a look at an example of a bank account. Imagine an ATM machine that dispenses cash. The algorithm for the machine might work something like this: First the user inserts an ATM card. Then the user enters a personal identification number.
The machine verifies that personal identification number and also checks the available balance in the account. Then the user requests an amount of money, and the machine dispenses the money if it is less than the available balance. Now, that sounds good, right? In fact, if there were only one ATM machine in the world, this might work fine. But, what if two users are standing next to each other and they both go through this process at the same time, accessing the same account? User One and User Two might both get to step 3, and both ATM machines would learn that there is $1,000 available in the account.
Then, both users request at the same time to withdraw $750 from the account. The ATM machines have already learned that the account balance is $1,000, so when they do their check, they each give the user the requested $750, and the account is now overdrawn by $500. We could easily modify this algorithm to prevent the TOCTOU race condition. We do this by adding a lock that prevents two users from accessing the same account at the same time.
When the first user accesses the account at the first ATM, that ATM will put a lock on the account, preventing the second user from starting a transaction before the first transaction completes. Race conditions can have a significant impact on application security. Developers must understand the security risks involved and plan their code to avoid these issues.
- Comparing viruses, worms, and Trojans
- Backdoors and logic bombs
- Understanding the attacker
- Attack types: from denial of service to brute force attacks
- Preventing insider threats
- Wireless attacks
- Understanding cross-site scripting
- Preventing SQL injection
- Social engineering
- Scanning for vulnerabilities
- Penetration testing
- Assessing the impact of vulnerabilities