OpenSSH regreSSHion (CVE-2024-6387): Async-Signal-Unsafe Heap Corruption & Why Privilege Separation Matters
How a 2020 refactoring accidentally removed a single #ifdef guard in sshd's SIGALRM handler, reintroducing a 2006 signal-race vulnerability across glibc Linux systems.
1. EXECUTIVE SUMMARY
On July 1, 2024, the Qualys Threat Research Unit disclosed CVE-2024-6387 (`regreSSHion`, CVSS 8.1), a signal-handler race condition in OpenSSH's server daemon (`sshd`) versions 8.5p1 through 9.7p1 on glibc-based Linux systems. When a client fails to authenticate within `LoginGraceTime` (120 seconds by default), the privileged `sshd` monitor process delivers `SIGALRM` and invokes `sigdie()`, which calls `syslog()`. On glibc, `syslog()` dynamically allocates memory via `malloc()` and `localtime_r()`—functions that are not async-signal-safe (CWE-479). If `SIGALRM` interrupts the privileged process while it is already midway through a `malloc()` or `free()` call, the signal handler re-enters the allocator with inconsistent heap metadata, enabling heap corruption inside the root-privileged pre-authentication process.
2. TECHNICAL EXPLANATION & EXECUTION CHAIN
In 2006, OpenSSH patched this exact vulnerability class (`CVE-2006-5051`) by guarding the `grace_alarm_handler` logging call with `#ifndef Cannot_call_syslog_from_signal_handler`. However, in October 2020 (commit `752250c`, released in OpenSSH 8.5p1), a logging refactor accidentally removed that `#ifdef` guard. Critically, the impact depends heavily on the C standard library implementation: OpenBSD is immune because its `syslog_r()` is async-signal-safe, and Alpine Linux (`musl` libc) is not exploitable via heap corruption because `musl`'s `syslog()` formats messages into a stack buffer and sends them over the `/dev/log` socket without calling `malloc()`. On glibc Linux systems, `syslog()` lazily allocates an internal `FILE` stream buffer (`__tzfile_read`, `malloc`) on its first invocation, creating a deterministic race window when an attacker shapes the heap via public-key authentication packets and times connection closure to coincide with `LoginGraceTime` expiration.
Client connects to TCP :22 -> Sends crafted SSH packets to groom glibc heap structures -> Holds connection open until `LoginGraceTime` (120s) expires while triggering final `malloc()`/`free()` -> Kernel delivers `SIGALRM` mid-allocator -> `grace_alarm_handler` calls `syslog()` -> Re-entrant `malloc()` corrupts glibc heap arena in privileged `sshd` process.
3. VERIFIED EVIDENCE MATRIX (FACT VS. INTERPRETATION VS. UNCERTAINTY)
OpenSSH versions 8.5p1 through 9.7p1 on glibc Linux call `syslog()` inside `grace_alarm_handler()`, which invokes non-reentrant `malloc()` calls upon `SIGALRM` delivery.
Exploitation is not 'one-packet instant RCE': winning the signal race and defeating ASLR requires thousands of connection attempts taking roughly 6–8 hours against 32-bit targets and significantly longer on 64-bit systems, generating massive noisy log volume.
OpenBSD and musl-based Linux distributions (such as Alpine Linux) are not vulnerable to the glibc `syslog()` heap corruption path.
4. CHRONOLOGICAL TIMELINE
CVE-2006-5051 disclosed by Mark Dowd; OpenSSH adds guard preventing unsafe syslog() calls inside SIGALRM.
Commit 752250c refactors logging in sshd and inadvertently removes the signal-handler guard; ships in OpenSSH 8.5p1 (March 2021).
Qualys TRU discovers the regression during code audit and develops proof-of-concept heap race against 32-bit/64-bit glibc targets.
Coordinated disclosure of CVE-2024-6387 alongside release of OpenSSH 9.8p1, which splits sshd into sshd-session and removes async-signal-unsafe logging.
5. PRACTICAL ENGINEERING LESSONS
- [1]POSIX signal handlers must only invoke async-signal-safe functions (as listed in `man 7 signal-safety`) or set a `volatile sig_atomic_t` flag read by the main event loop.
- [2]Security regressions happen when defensive `#ifdef` guards lack automated regression tests verifying why they were added.
- [3]Exploitability assessments must account for practical constraints: a race requiring 10,000+ timed 120-second connections is trivially detected and blocked by connection rate limiters (`MaxStartups`, `PerSourceMaxStartups`, CrowdSec, or `nftables`) long before ASLR is bypassed.
6. DEFENSIVE RECOMMENDATIONS
- [1]Upgrade OpenSSH to `9.8p1` or distribution-backported patch levels (e.g., Debian `1:9.2p1-2+deb12u3`, Ubuntu `1:8.9p1-3ubuntu0.10`).
- [2]If an immediate binary update is blocked, set `LoginGraceTime 0` in `/etc/ssh/sshd_config` (which disables the `SIGALRM` timer completely, trading DoS connection-slot risk for complete immunity to the signal race) combined with strict `PerSourceMaxStartups`.
- [3]Restrict SSH management port access via WireGuard tunnels, IP allowlists, or behavioral log bouncers (`CrowdSec`).