Zenhammer (CVE-2024-21844): Rowhammer Fault Injection on AMD Zen 4/Zen 5 DDR5 and Target Row Refresh Bypasses

In modern cybersecurity, hardware-level fault injection and microarchitectural side channels represent the ultimate subversion of operating system security guarantees. For nearly a decade, the Rowhammer vulnerability—the physical phenomenon where rapid electrical toggling of DRAM wordlines induces parasitic capacitive charge leakage in adjacent memory cells—was treated as a problem primarily afflicting legacy DDR3 and DDR4 memory modules on Intel x86 platforms. When the JEDEC solid-state technology association finalized the DDR5 memory specification, industry consensus assumed that the combination of mandatory on-die Error Correction Codes (on-die ECC) and proprietary hardware-level Target Row Refresh (TRR) mitigations had permanently relegated Rowhammer to history. Simultaneously, AMD Zen microarchitectures were widely considered structurally resilient against memory controller fault injection due to non-linear physical address interleaving. However, the discovery of Zenhammer (CVE-2024-21844) shattered this security illusion. Building upon speculative timing attacks analyzed in GhostRace speculative race conditions and kernel lock bypasses, microarchitectural data sampling detailed in Downfall AVX gather hardware leaks, and transient execution vectors explored in Branch History Injection (BHI) Spectre-v2 exploits, Zenhammer demonstrates the first successful Rowhammer attack against AMD Zen 3, Zen 4, and Zen 5 microarchitectures operating on commercial DDR5 memory. This deep-dive examines the underlying physical DRAM disturbance mechanisms, the reverse engineering of AMD Zen memory controller XOR hashing functions, multi-sided TRR counter depletion patterns, non-temporal streaming store evasion, and end-to-end Linux kernel Page Table Entry (PTE) privilege escalation.

1. Physical DRAM Disturbance & Why DDR5 On-Die ECC Failed

To understand how Zenhammer compromises DDR5 memory, one must examine the solid-state physics of scaled DRAM storage capacitors and the specific architectural implementation of on-die error correction.

A dynamic random-access memory (DRAM) cell consists of a single access transistor and a microscopic storage capacitor (a 1T-1C architecture). Digital bits (0 or 1) are represented by the presence or absence of electrical charge stored on the capacitor plate:

$$Q = C_{\text{cell}} \cdot V_{\text{cell}}$$

As DRAM manufacturers scaled fabrication nodes down through 1x, 1y, 1z, and into the sub-14nm regime (1α and 1β nodes), the physical spacing between parallel wordlines shrank below 20 nanometers. At this atomic scale, individual storage capacitors possess an exceedingly fragile capacitance of only 8 to 12 femtofarads (\(10^{-15} \text{ F}\)), holding a charge of fewer than 30,000 electrons.

Zenhammer DRAM Rowhammer Activation, On-Die SEC-DED ECC Limits, and Many-Sided TRR Bypass Patterns.
Figure 1: Zenhammer DRAM Rowhammer Activation, On-Die SEC-DED ECC Limits, and Many-Sided TRR Bypass Patterns.

When an attacker toggles a DRAM wordline (known as the “aggressor row”) by issuing rapid, repeated read or write commands, the wordline voltage swings aggressively between \(V_{\text{PP}}\) (wordline high, \(\sim 2.8\text{V}\)) and \(V_{\text{SS}}\) (wordline low, \(\sim 0\text{V}\)). This high-frequency voltage transient induces three distinct electromagnetic disturbance effects on physically adjacent “victim rows”:

  1. Capacitive Cross-Coupling: Parasitic capacitance between the aggressor wordline and the victim storage node induces AC voltage displacement, directly displacing stored electrons.
  2. Electron Injection via Sub-Threshold Leakage: Transient voltage spikes briefly lower the effective barrier height of neighboring pass transistors, allowing electrons to leak from the storage node into the substrate.
  3. Acoustic and Phonon Trap Dynamics: Repeated switching injects hot carriers into the inter-wordline dielectric, creating localized trap states that accelerate steady-state leakage currents.

If an aggressor row is toggled more than a critical threshold number of times (\(N_{\text{hammer}} \approx 100,000 \text{ to } 250,000\) activations) within a standard refresh interval (\(t_{\text{REFI}} = 32\text{ms}\) or \(64\text{ms}\)), the victim capacitor loses enough charge that the sense amplifier misinterprets its logical state during the next precharge cycle—triggering a bit flip.

The False Promise of DDR5 On-Die ECC

When DDR5 was announced, marketing literature emphasized that every DDR5 die includes native On-Die Error Correction Code (on-die ECC). Many practitioners assumed this rendered Rowhammer impossible. In reality, on-die ECC was introduced not as a security primitive, but as a manufacturing yield-enhancement mechanism for sub-14nm lithography.

Standard DDR5 on-die ECC utilizes a Hamming-based Single-Error-Correcting, Double-Error-Detecting (SEC-DED) or Reed-Solomon code operating over a 128-bit internal data word accompanied by 8 parity bits. While on-die ECC seamlessly corrects an isolated single-bit flip during a row read, it exhibits two catastrophic structural vulnerabilities against targeted Rowhammer attacks:

  • Double-Bit Masking Failure: If Rowhammer electromagnetic disturbance flips two bits within the same 128-bit ECC word, the SEC-DED logic cannot correct the error. At best, it signals an error; at worst, it misidentifies the syndrome and inverts a third bit, silently corrupting data without raising a hardware trap!
  • Refresh Transparency: On-die ECC is evaluated only when a row is read across the internal bus. It does NOT operate continuously during background row refresh cycles or while charge is actively draining from victim cells.

2. Deciphering the AMD Zen Memory Controller: Reverse-Engineering Bank XOR Hashing

Historically, academic Rowhammer research was predominantly conducted on Intel processors because Intel memory controllers utilized straightforward, linear address mapping or well-documented XOR hashing polynomials. AMD Zen processors (Zen 1 through Zen 5), by contrast, distribute physical memory addresses across channels, sub-channels, bank groups, and banks using proprietary, unpublished, non-linear hashing functions.

To execute a Rowhammer attack, an attacker cannot simply hammer adjacent virtual memory addresses. Because the memory controller scatters adjacent physical pages across completely different memory banks and DIMM channels to maximize bus parallelism, hammering contiguous physical addresses would activate rows in different banks—dissipating the electromagnetic charge and completely failing to induce bit flips. The attacker must identify addresses that map to the exact same physical bank, on the same sub-channel, with adjacent row coordinates.

The Zenhammer researchers solved this by developing a high-precision microarchitectural timing profiler based on DRAM bank conflict latency. When two memory requests target the same bank in rapid succession, the memory controller must issue a PRECHARGE command followed by an ACTIVATE command, incurring a delay of:

$$t_{\text{RC}} = t_{\text{RAS}} + t_{\text{RP}} \approx 45 \text{ to } 55 \text{ nanoseconds}$$

Conversely, if the two requests target different banks, they can be serviced in parallel without incurring \(t_{\text{RC}}\). By allocating 2MB HugePages and measuring round-trip access latency between thousands of address pairs using the high-resolution timestamp counter (`RDTSC` / `RDPRU`), the researchers systematically extracted the secret XOR hashing matrices governing AMD Zen memory controllers.

For AMD Zen 3 and Zen 4 microarchitectures, the physical bank index (\(\text{Bank}_{\text{ID}}\)) is determined by computing the parity of selected address bits using linear combinations:

$$\text{Bank}_{\text{ID}}[k] = \bigoplus_{i \in S_k} \text{PA}[i]$$

Where \(\text{PA}[i]\) represents physical address bit \(i\), and \(S_k\) is the bitmask index set. The Zenhammer analysis revealed that AMD Zen controllers incorporate physical address bits up to bit 21 into the bank-selection XOR equations. Armed with this reverse-engineered mathematical mapping, an unprivileged user-space process can instantly generate lists of virtual addresses that map to the exact same DRAM bank with absolute mathematical precision!

3. Overcoming Target Row Refresh (TRR): Many-Sided Hammering Patterns

Even with precise bank addressing, an attacker encounters the hardware defense embedded directly within modern DRAM dies: Target Row Refresh (TRR).

AMD Zen Memory Controller Architecture, Non-Temporal Streaming Stores (MOVNT), and Cache Flush Eviction Loops.
Figure 2: AMD Zen Memory Controller Architecture, Non-Temporal Streaming Stores (MOVNT), and Cache Flush Eviction Loops.

Target Row Refresh monitors incoming row activation commands on the memory bus. When internal tracking logic detects that a particular wordline is being activated unusually frequently, the DRAM chip automatically issues proactive refresh pulses to adjacent neighbor rows (aggressor \(N-1\) and \(N+1\)) during idle bus cycles or refresh intervals (tREFI), restoring their capacitive charge before bit flips can materialize.

However, the TRR implementation inside DDR4 and DDR5 modules is severely constrained by die area and power budgets. DRAM chips do not maintain a full associative counter table for all 65,536 or 131,072 rows in a bank. Instead, they rely on small, finite-state tracking buffers—typically holding between 4 and 16 active row entries—managed by heuristic sampling or time-windowed leaky bucket algorithms.

Zenhammer bypasses TRR by executing sophisticated Many-Sided Hammering Patterns (ranging from 6-sided to 12-sided activation loops). Instead of hammering only two adjacent rows (the classic double-sided pattern: \(N-1\) and \(N+1\)), Zenhammer interleaves activations across a carefully orchestrated sequence of aggressor rows (\(A_1, A_2, \dots, A_k\)) combined with dummy rows (\(D_1, D_2, \dots, D_m\)):

$$P_{\text{hammer}} = [A_1, A_2, D_1, A_3, A_4, D_2, \dots, A_k, D_m]$$

This access pattern operates as a counter-exhaustion attack on the TRR state machine:

  1. Sampling Cache Flooding: By introducing dummy activations that map to the same bank group, Zenhammer intentionally overflows the DRAM’s internal TRR sampling buffer.
  2. Victim Eviction: The primary aggressor rows that are actively draining charge from the target victim row are evicted from the TRR tracking registers.
  3. Blind Spot Creation: Because the DRAM’s TRR logic believes the dummy rows are the most critical threats, it directs its limited proactive refresh pulses to harmless dummy neighbors—leaving the true victim row completely unprotected while it undergoes massive capacitive discharge.

4. Cache Eviction Mechanics: Non-Temporal Streaming Stores (MOVNT) vs. CLFLUSHOPT

To deliver hundreds of thousands of activations to a DRAM bank within 32 milliseconds, memory requests must bypass the CPU’s multi-level cache hierarchy. If an address hits in the L1, L2, or 32MB L3 cache, the request is satisfied on-chip, and zero electrical commands are dispatched to the external DDR5 bus.

On Intel x86 processors, attackers historically used the `clflush` or `clflushopt` instructions to evict cache lines. On AMD Zen microarchitectures, however, researchers uncovered a severe timing anomaly: executing `clflushopt` in tight multi-core loops experiences severe instruction serialization bottlenecks and variable pipeline retirement delays within the Zen execution engine, reducing activation throughput below the threshold necessary to overcome DDR5 leakage rates.

Zenhammer overcame this microarchitectural hurdle by weaponizing Non-Temporal Streaming Stores (`MOVNTDQ` / `MOVNTI`).

// Zenhammer High-Throughput Memory Hammering Loop
void hammer_zen_ddr5(uint64_t *aggressor_a, uint64_t *aggressor_b, size_t iterations) {
    __m128i dummy_data = _mm_setzero_si128();
    
    for (size_t i = 0; i < iterations; i++) {
        // Issue non-temporal streaming stores to bypass L1/L2/L3 caches directly
        _mm_stream_si128((__m128i*)aggressor_a, dummy_data);
        _mm_stream_si128((__m128i*)aggressor_b, dummy_data);
        
        // Force memory pipeline serialization and drain write-combining buffers
        _mm_sfence();
        
        // Flush remaining cache lines to force immediate DRAM bus ACTIVATE
        _mm_clflushopt(aggressor_a);
        _mm_clflushopt(aggressor_b);
        
        // Execute synchronized memory barrier
        _mm_mfence();
    }
}

Non-temporal stores notify the Zen load-store unit (LSU) that the written data will not be reused soon. The processor bypasses the L1/L2/L3 cache allocation protocols entirely, routing the write data directly into the CPU's internal Write-Combining (WC) buffers. When paired with `SFENCE` and `CLFLUSHOPT`, these streaming stores force the memory controller to emit an unbroken avalanche of DRAM `ACTIVATE` and `PRECHARGE` commands across the physical DDR5 command bus at maximum bus line rates!

5. End-to-End Exploit: Corrupting Linux Kernel Page Table Entries (PTEs)

Inducing raw bit flips in memory is an impressive physical feat, but turning a single random bit flip into a deterministic root-level shell requires exploiting the memory layout of the Linux virtual memory manager.

Crucially, researchers verified that Zenhammer successfully bypasses AMD Memory Guard (Transparent SME / Secure Memory Encryption). While TSME encrypts DRAM data lines using AES-128 or AES-256 engines embedded inside the memory controller, it operates entirely on data payloads after memory scheduling. Physical row activations, bus command scheduling, and wordline precharge transients occur regardless of whether data is encrypted or plaintext. When a bit flip occurs in a ciphertext word, it decrypts into corrupt plaintext—enabling reliable memory manipulation even on encrypted enterprise virtual machines!

Zenhammer utilizes a classic, devastating privilege escalation technique: Page Table Entry (PTE) Flipping via Memory Grooming.

In x86-64 Linux, virtual memory addresses are translated to physical addresses via a 4-level page table hierarchy (PGD \(\to\) P4D \(\to\) PUD \(\to\) PMD \(\to\) PTE). A Page Table Entry (PTE) is an 8-byte entry that controls the translation and permissions of a single 4KB page:

PTE Bit RangeField NameArchitectural FunctionExploit Impact When Flipped
Bit 0Present (P)Indicates page resides in physical RAMCauses unhandled kernel page fault
Bit 1Read/Write (R/W)0 = Read-Only; 1 = Read-WriteTransforms Read-Only file into Writable memory
Bit 2User/Supervisor (U/S)0 = Supervisor Only; 1 = User-SpaceGrants user-space direct read/write to kernel page
Bits 12 - 51Physical Page Frame Number (PFN)Direct physical memory address baseRedirects mapping to kernel code or `/etc/passwd`

The Zenhammer attack pipeline executes across four synchronized phases:

  1. Memory Profiling & Templating: An unprivileged process allocates large memory buffers via `mmap()` and scans for flippable bits across DRAM banks. It identifies an address where hammering predictably flips a specific bit in a victim row.
  2. Memory Spraying & Grooming: The attacker releases the victim page back to the Linux kernel physical frame allocator (`buddy allocator`). Immediately thereafter, the attacker forks hundreds of processes or allocates thousands of page tables using memory-mapped files. The kernel reallocates the vulnerable physical frame to store a kernel page table page belonging to the attacker.
  3. Rowhammer Triggering: The attacker executes the non-temporal many-sided hammering sequence against the surrounding aggressor rows. The bit flip strikes the kernel PTE.
  4. Arbitrary Physical Memory Overwrite: The flipped bit in the Physical Page Frame Number (PFN) field redirects the user process's virtual page mapping to point directly to an arbitrary physical memory frame—such as the memory caching `/etc/shadow`, the root password hash, or the kernel's own credential structures (`struct cred`). The user process modifies the file in RAM and immediately spawns a root-privileged shell!

6. Empirical Telemetry: Bit Flip Rates Across Zen Microarchitectures

The Zenhammer researchers conducted extensive hardware benchmarking across retail systems running AMD Zen 3 (Ryzen 5000), Zen 4 (Ryzen 7000 / EPYC 9004), and Zen 5 platforms with standard commercial DDR5-4800 and DDR5-5600 modules from major memory manufacturers:

  • DDR5 Susceptibility: Despite active on-die ECC, Zenhammer successfully triggered reproducible bit flips on over 70% of tested DDR5 devices. In multiple instances, bit flips were induced in as few as 160,000 hammer activations per row—well within standard operating thresholds.
  • AMD Zen 4 Architecture Vulnerability: On Zen 4 platforms, Zenhammer achieved bit flips significantly faster than on equivalent Intel 13th/14th Gen systems, largely due to the ultra-high throughput of Zen 4's non-temporal write pipelines and write-combining buffer flushing.
  • End-to-End Root Escalation: In controlled security testing, unprivileged local users obtained full administrative root access in an average of 90 to 240 seconds from exploit launch.

7. Hardware Defenses: Per-Row Activation Counting (PRAC) & JEDEC Mitigations

The realization that TRR and on-die ECC cannot stop Rowhammer on modern DDR5 platforms has triggered urgent architectural revisions within JEDEC and CPU vendors:

  1. Per-Row Activation Counting (PRAC): Standardized in recent JEDEC DDR5 specifications, PRAC replaces heuristic sampling with deterministic hardware counters embedded within the DRAM controller and DRAM die. Whenever any individual row exceeds an activation limit within a refresh window, the memory controller halts external traffic and forcibly executes an immediate adjacent-row refresh pulse.
  2. Sub-Interval Refresh Rate Multiplication (2x / 4x Refresh): Operating systems and BIOS firmware can cut the default refresh interval from \(32\text{ms}\) to \(16\text{ms}\) or \(8\text{ms}\). While this halves the time available for attackers to accumulate charge leakage, it imposes a 3% to 5% continuous memory bandwidth and latency penalty.
  3. Hypervisor & Kernel Memory Isolations: Memory allocators can implement B-Int (Bank-Isolation) algorithms, ensuring that untrusted user-space applications and sensitive kernel page tables are never allocated within the same physical DRAM bank.
Official Engineering Whitepaper

Zenhammer: Rowhammer Fault Injection on AMD Zen 4/5 DDR5

Target Row Refresh Bypass, Non-Temporal Stores, and Kernel PTE Corruption (Complete architectural audit with telemetry tables and schematic breakdowns).

Reference File: whitepaper_batch_20_2_zenhammer_exploit.pdf
Format: Publication-Grade PDF

Explore Advanced Hardware Vulnerability & Kernel Exploit Analyses

Investigate critical microarchitectural vulnerabilities, transient execution exploits, and low-level kernel defenses with these peer-reviewed deep dives:

Zenhammer definitively disproved the assumption that next-generation memory standards are inherently secure. Physical capacitor scaling continues to outpace heuristic hardware mitigations. Until deterministic tracking architectures like PRAC become universal, system administrators and hardware architects must rely on BIOS-level refresh doubling and memory bank isolation to safeguard enterprise infrastructure against physical memory exploitation.

S
Salamo — Senior Hardware & Systems Researcher

Systems architect and technical lead at Lesty Tech. Specializing in semiconductor architecture, neural network hardware efficiency, and embedded device firmware.

Add Comment