Meaning
Software execution vulnerabilities occur when concurrent tasks or hardware interrupts alter the value of a shared register or memory location between the read and write phases of a modification sequence. In embedded software, a read-modify-write hazard arises when an interrupt service routine preempts a background thread that has read a register but not yet written back the updated value. This disruption causes the background thread to overwrite the change made by the interrupt handler, resulting in lost updates and unstable hardware behavior.
Interrupt Concurrency
Race conditions are common in systems where peripheral registers contain individual bits that control different hardware functions. When a low-priority driver attempts to set a bit, it must first load the entire register into a CPU workspace. If an interrupt occurs and changes a different bit in the same register, the subsequent write by the low-priority driver will erase that change, illustrating a classic read-modify-write hazard in action.
Mitigation Strategy
Prevention of these software errors requires the use of atomic operations, such as disabling interrupts before the sequence or using bit-banding if supported by the processor. Another approach utilizes exclusive load and store instructions that monitor the register for any intervening writes. When the hardware detects a write to the monitored address, it fails the store operation, forcing the software to re-evaluate and execute the sequence again.
Diagnostics Method
Finding these bugs is difficult because they are highly timing-dependent. Developers rely on static analysis tools.