Why Memory Safety Dominates Serious CVEs
Most software vulnerabilities are logic mistakes: a missing permission check, a query built by concatenation, a secret in a log. Memory-safety bugs are different in kind. A web bug lets an attacker do something the application can already do, to data the application can already reach. A memory bug can let an attacker change what the program is: overwrite a pointer, redirect the next function return, read the private key next to the buffer. That is why they rank among the most severe findings, why vendors patch them out of cycle, and why governments now publish policy about programming languages.
The numbers, briefly
The headline figures are collected in Programming for Security's Go and Rust: What Memory Safety Buys: about 70 % of the CVEs Microsoft assigns each year (2019) and about 70 % of Chrome's high-severity security bugs are memory-safety bugs, and Android's share fell from 76 % (2019) to 24 % (2024) as new code moved to memory-safe languages. MITRE's CWE Top 25 has been computed from real CVE data since 2019, and memory bugs are always on it: out-of-bounds writes (CWE-787) were 12th in 2019, first or second from 2020 to 2024 and fifth in 2025, with use-after-free (CWE-416) and out-of-bounds reads (CWE-125) close behind.
Those figures come from large C and C++ code bases. A Java, Python or Go service has very few memory bugs of its own; it inherits them from the runtime, the kernel, the TLS library and the image decoders it links. Every program sits on C somewhere.
Spatial and temporal safety
Researchers split memory safety into a few properties. Each bug class in this course breaks one of them:
| Property | The rule | Broken by | CWE |
|---|---|---|---|
| Spatial | every access stays inside the object it was derived from | stack and heap overflows, out-of-bounds reads, off-by-one | 121, 122, 125, 787, 193 |
| Temporal | an object is only used between its allocation and its free | use-after-free, double free, returning a pointer to a local | 416, 415, 562 |
| Initialisation | memory is written before it is read | uninitialised variables, padding leaks | 457, 908 |
| Type | memory is read as the type it holds | type confusion, bad casts, union misuse | 843 |
| Thread | shared memory is accessed under a rule (locks, atomics) | data races | 362 |
| Resource | what is allocated is eventually freed | memory leaks (availability, not corruption) | 401 |
Integer overflow (CWE-190) and format strings (CWE-134) are not memory bugs by themselves. They become memory bugs when the wrong number is used as a size or an index, or when user data is used as a format, which is why they have their own lessons in the bug-class section.
Why these bugs are so valuable to an attacker
A bug gives an attacker a primitive: "read 64 KB past this buffer", "write 8 chosen bytes after this array", "use this freed object". The program's surroundings decide what that primitive is worth. With no mitigations, a single stack overflow was enough for code execution in the 1990s. Today the same bug usually only crashes the program, because canaries, NX, ASLR and control-flow integrity each block a step; serious attacks chain two or three bugs. That is still routinely achieved against browsers and phones, which is why the fix, not the mitigation, is the goal.
Classifying findings by property
Security teams tag every memory-safety finding with its CWE so they can count trends. The model below sorts a small, invented list of fuzzer findings (the kind a CI fuzzing job produces in a week) into the properties of the table and computes the share of each. It runs in your browser:
from collections import Counter
PROPERTY = {
121: "spatial", 122: "spatial", 125: "spatial", 787: "spatial", 193: "spatial",
416: "temporal", 415: "temporal", 562: "temporal",
457: "initialisation", 908: "initialisation",
843: "type", 362: "thread", 401: "resource",
}
# Invented findings: (id, sanitizer, CWE)
findings = [
("F1", "ASan heap-buffer-overflow", 122), ("F2", "ASan heap-use-after-free", 416),
("F3", "ASan stack-buffer-overflow", 121), ("F4", "LSan direct leak", 401),
("F5", "ASan heap-buffer-overflow (read)", 125), ("F6", "MSan use-of-uninitialized-value", 457),
("F7", "ASan double-free", 415), ("F8", "UBSan vptr", 843),
("F9", "ASan heap-buffer-overflow", 122), ("F10", "TSan data race", 362),
("F11", "ASan heap-use-after-free", 416), ("F12", "ASan heap-buffer-overflow (read)", 125),
]
by_prop = Counter(PROPERTY[cwe] for _, _, cwe in findings)
corrupting = sum(n for p, n in by_prop.items() if p != "resource")
for prop, n in by_prop.most_common():
print(f"{prop:15} {n:2} {'#' * n}")
print(f"memory-corruption findings: {corrupting}/{len(findings)} = {corrupting / len(findings):.0%}")
print("most common CWE:", Counter(c for _, _, c in findings).most_common(1)[0])spatial 5 #####
temporal 3 ###
resource 1 #
initialisation 1 #
type 1 #
thread 1 #
memory-corruption findings: 11/12 = 92%
most common CWE: (122, 2)
The invented numbers are not a statistic. The shape is typical, though: spatial bugs (overflows and out-of-bounds reads) are the largest group, use-after-free the next. Note the tie-break in the last line: CWE-122, CWE-416 and CWE-125 each appear twice, and most_common returns the first one it counted. A real triage report should show all tied entries.
How the industry responds
The response has three layers, and this course has a section for each:
- Find the bugs before release: compiler warnings, static analysis, sanitizers in tests, and continuous fuzzing (Google's OSS-Fuzz, running since 2016, reports more than 13,000 vulnerabilities and 50,000 bugs found and fixed in about 1,000 open-source projects as of May 2025). See Finding Bugs.
- Make the survivors hard to exploit with mitigations in the compiler, the loader, the kernel and the CPU. See Mitigations Compared.
- Stop writing new bugs by writing new code in memory-safe languages and by hardening the C and C++ that remains. This is what memory-safety roadmaps ask vendors to plan: CISA, the NSA, the FBI and partner agencies published The Case for Memory Safe Roadmaps in December 2023, and the US Office of the National Cyber Director's report Back to the Building Blocks (February 2024) made the same argument. See Rust: Ownership, unsafe, FFI and Migration.
Pitfalls
- "We use a safe language, so this doesn't concern us." Your dependencies, runtime and kernel are C and C++;
unsafeblocks and FFI calls reintroduce the bugs. - Counting crashes instead of root causes. One heap overflow can produce dozens of different crash sites. Deduplicate by the allocation and the faulting line in the sanitizer report.
- Treating a crash as "only a DoS". A crash proves the program lost control of its memory. Until the root cause is understood, assume it is exploitable.
Practice
1. A finding says "READ of size 8 at address 16 bytes after a 32-byte region". Which property does it break, and which CWE fits?
Spatial safety: the read is outside the object. An out-of-bounds read is CWE-125 (the more general CWE-119 also fits; prefer the most specific one).
2. Why is a memory leak listed as "resource", not as a corruption bug?
A leak never touches memory it doesn't own; it only fails to return memory. Its impact is availability (the process grows until it is killed), not confidentiality or integrity. LeakSanitizer finds it; CWE-401.
3. Change the model so that ties in the last line are all printed.
counts = Counter(c for _, _, c in findings)
top = max(counts.values())
print("most common CWEs:", sorted(c for c, n in counts.items() if n == top))This prints [122, 125, 416].
Test yourself
Which property does a use-after-free break?
- Spatial safety
- Temporal safety
- Type safety
- Thread safety
Why can a memory bug be worse than an SQL injection in the same program?
- It is always remote
- It can change the program's own control data (pointers, return addresses), not only the data the program is allowed to use
- Databases are safe
- Memory bugs are easier to find
What do mitigations such as canaries and ASLR do to a memory bug?
- They remove it
- They make exploitation harder, often turning the bug into a crash, but the bug remains
- They make the program faster
- They report it to the vendor
In the model, what share of the 12 invented findings were memory corruption?
- 50%
- 75%
- 92%
- 100%