CWE-14: Compiler Removal of Code to Clear Buffers
Description
Sensitive memory is cleared according to the source code, but compiler optimizations leave the memory untouched when it is not read from again, aka dead store removal.
This compiler optimization error occurs when: Secret data are stored in memory. The secret data are scrubbed from memory by overwriting its contents. The source code is compiled using an optimizing compiler, which identifies and removes the function that overwrites the contents as a dead store because the memory is not used subsequently.
- Abstraction
- VariantA weakness tied to a specific language, technology or resource.
- Likelihood of exploit
- Not rated by MITRE
- Status
- Draft
Common consequences
- ConfidentialityAccess Control
Read Memory; Bypass Protection Mechanism
This weakness will allow data that has not been cleared from memory to be read. If this data contains sensitive password information, then an attacker can read the password and use the information to bypass protection mechanisms.
Potential mitigations
- Implementation
Store the sensitive data in a volatile memory location if available.
- Build and Compilation
If possible, configure your compiler so that it does not remove dead stores.
- Architecture and Design
Where possible, encrypt sensitive data that are used by a software system.
Related weaknesses
CAPEC attack patterns that exploit it
CWE 4.20 links no CAPEC attack pattern to this weakness.