Heartbleed OpenSSL Vulnerability
CVE-2014-0160: Missing buffer bounds check in TLS Heartbeat
Incident Overview
Discovered in April 2014, Heartbleed was a catastrophic vulnerability in OpenSSL 1.0.1. An attacker could craft a 1-byte payload with a claimed length of 65,535 bytes, prompting OpenSSL to copy 64KB of secret memory back to the client.
Real-World Impact
Exposed private RSA keys, user passwords, session tokens, and credit card numbers from over 17% of secured internet web servers.
Technical Root Cause Analysis
OpenSSL failed to check whether the payload length declared in an incoming TLS Heartbeat request matched the actual buffer size, echoing back up to 64KB of contiguous process heap memory.
- Missing Bounds Check: `memcpy(bp, pl, payload)` executed without checking if `payload <= actual_buffer_bytes`.
- Memory Exposure: OpenSSL used a custom freelist memory pool (`freelist`), so heap allocations contained recently freed private keys, passwords, and cookies.
- Silent Exploitation: Attacks left no footprint in server error logs because valid Heartbeat responses were sent without crashing the process.
Vulnerable OpenSSL Heartbeat Implementation (C)
/* Vulnerable code in ssl/t1_lib.c */
hbtype = *p++;
n2s(p, payload); // Unchecked 16-bit payload length provided by attacker!
ptls2 = p;
/* Missing check: if (1 + 2 + payload + 16 > s->s3->rrec.length) return 0; */
buffer = OPENSSL_malloc(1 + 2 + payload + padding);
bp = buffer;
/* Over-reads 64KB of server heap memory! */
memcpy(bp, pl, payload);Incident Timeline
TLS Heartbeat extension RFC 6520 implemented in OpenSSL source code.
Vulnerability discovered independently by Codenotary / Neel Mehta (Google Security).
Public disclosure of CVE-2014-0160 and emergency OpenSSL 1.0.1g patch release.
Mass revocation of SSL/TLS certificates worldwide.
Key Engineering Takeaway & Defensive Guidance
Always validate memory allocation bounds and payload length fields against actual buffer sizes. Use memory-safe programming languages (Rust) or rigorous static analysis.