Weakness · High

CWE-14: Compiler Removal of Code to Clear Buffers

What it is

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."

MITRE CWE 4.19.1

Severity (our rating)
High
Likelihood of exploit
Not rated by MITRE
Introduced during
Build and Compilation, Implementation
Exploited in the wild
No CVE in CISA's catalog

In more detail

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.

What an attacker can do

  • Read Memory (Confidentiality, Access Control)
  • Bypass Protection Mechanism (Confidentiality, Access Control)

How to prevent it

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.

How to find it

  • Black Box. This specific weakness is impossible to detect using black box methods. While an analyst could examine memory to see that it has not been scrubbed, an analysis of the executable would not be successful. This is because the compiler has already removed the relevant code. Only the source code shows whether the programmer intended to clear the memory or not, so this weakness is indistinguishable from others.
  • White Box. This weakness is only detectable using white box methods (see black box detection factor). Careful analysis is required to determine if the code is likely to be removed by the compiler.

CWE-14 on MITRE's CWE site

H2 Security

Found it in your code?

We review where it appears, fix it with your team, and check it was not already used against you.

Talk to our team

T Academy

Stop writing it in the first place

Learn to build software and systems without weaknesses like this one, with practice on real hosts in your browser, every objective checked on the machine.

Start free

Source: MITRE Common Weakness Enumeration, CWE version 4.19.1. CWE is a trademark of The MITRE Corporation.