Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Rowhammer Explained: How RAM Access Flips Bits

· 6 min read · Home Tech

In this article
  1. Background: The DRAM Architecture
  2. How Rowhammer Works: The Charge Leakage Mechanism
  3. Who Is Affected: Real-World Impact
  4. Mitigations and Defenses
  5. How to Test if Your System Is Vulnerable
  6. Common Misconceptions
  7. Frequently Asked Questions

Rowhammer is a hardware vulnerability in modern DRAM (Dynamic Random-Access Memory) where repeatedly accessing a specific memory row can cause electrical interference that flips bits in neighboring rows, altering data without any software error. This can lead to privilege escalation, data corruption, or even remote code execution, as demonstrated by various proof-of-concept attacks.

Background: The DRAM Architecture

To understand Rowhammer, you need a basic picture of how DRAM stores data. Each bit is a tiny capacitor that holds a charge, representing a 1 or a 0. These capacitors are arranged in a grid of rows and columns. A row is a horizontal line of capacitors that share a wordline, and a column is a vertical line sharing a bitline. When the CPU needs to read or write data, the memory controller activates a specific row, which dumps the charges of all its capacitors onto the bitlines, where sense amplifiers detect the values. That row is then "closed" and restored.

This process is called row activation. In older DRAM designs, rows were refreshed (recharged) frequently to prevent data loss. However, as memory densities increased, manufacturers reduced the refresh rate to save power, and the physical distance between rows shrank. These two factors—closer rows and less frequent refreshing—create the conditions for Rowhammer.

How Rowhammer Works: The Charge Leakage Mechanism

When a row is activated repeatedly, the wordline that controls its access transistors is driven to a high voltage. This voltage pulse induces a small electrical disturbance in the adjacent wordlines. Over time, this disturbance causes the capacitors in neighboring rows to lose charge faster than normal. If enough charge leaks before the next refresh cycle, the stored bit flips: a 1 becomes a 0, or vice versa.

The key is that the attack targets rows that are physically adjacent, not logically adjacent. The memory controller maps physical addresses to logical addresses, but the attacker can discover this mapping through a technique called "row hammering"—accessing two rows (called aggressor rows) at high speed, while a victim row sits between them. The repeated activation of the aggressors causes the victim row to lose charge, leading to bit flips.

Modern DRAM has mitigations, but they are not perfect. For example, the "pseudo-target row refresh" (pTRR) feature automatically refreshes rows that are frequently accessed, but attackers have found ways to bypass it by using more aggressor rows or by exploiting the fact that pTRR only refreshes a limited number of rows.

Who Is Affected: Real-World Impact

Rowhammer is not just a theoretical curiosity. In 2015, researchers at Google's Project Zero and other institutions demonstrated that it could be used to gain kernel privileges on a laptop. They used a JavaScript program that triggered Rowhammer via the browser, proving that a remote attacker could potentially exploit it. Since then, several other attacks have been developed, including:

  • Drammer: An Android attack that uses Rowhammer to gain root access.
  • Flip Feng Shui: A technique that flips bits in a targeted way to corrupt data or inject malicious code.
  • RAMBleed: An attack that reads data from other processes by observing bit flips.

These attacks highlight that Rowhammer is a serious security concern, especially for cloud providers where multiple users share the same physical hardware. If a malicious tenant can flip bits in another tenant's memory, they could potentially steal data or take over the system.

Mitigations and Defenses

Hardware and software defenses have been developed to counter Rowhammer. Here are the main ones:

  • Increased refresh rate: Some memory controllers can be configured to refresh rows more frequently, which reduces the chance of bit flips but increases power consumption.
  • Error-correcting code (ECC) memory: ECC RAM can detect and correct single-bit errors, but it does not prevent the flip itself. It can also be bypassed if the attacker flips multiple bits in the same word.
  • Pseudo-target row refresh (pTRR): This hardware feature tracks frequently accessed rows and refreshes their neighbors. However, it is not always effective against advanced attacks.
  • Software-based mitigations: Operating systems can use memory isolation techniques, such as guard pages, to prevent an attacker from easily accessing the same physical memory region. However, these are not foolproof.

Despite these defenses, Rowhammer remains a practical threat, especially on older hardware or devices that lack the latest mitigations.

How to Test if Your System Is Vulnerable

If you are curious whether your computer is vulnerable, you can run a test. There are open-source tools like rowhammer-test that attempt to trigger bit flips. However, these tests are not 100% reliable, and a negative result does not guarantee safety. The test works by repeatedly accessing two memory addresses that are physically close, then checking for changes in a third address. If a flip occurs, the test reports it.

Keep in mind that running such a test can cause system instability or crashes, as it deliberately stresses the memory. It is best to do it on a machine that does not hold critical data. Also, the test requires root privileges to access physical memory, so you will need to run it with sudo on Linux or as an administrator on Windows.

Common Misconceptions

One common misconception is that Rowhammer only affects old DDR3 memory. While DDR3 is more vulnerable, DDR4 and even DDR5 have been shown to be susceptible, though to a lesser extent. Another misconception is that ECC memory is a complete defense. ECC can correct single-bit errors, but if an attacker flips two bits in the same 64-bit word, the error goes undetected. Some Rowhammer attacks have been specifically designed to do just that.

Another myth is that Rowhammer is only a local attack. In reality, it can be triggered remotely via JavaScript in a browser, as demonstrated in 2015. This makes it a significant threat for any system that runs untrusted code, such as websites with ads or cloud VMs.

Frequently Asked Questions

Can Rowhammer happen by accident?

Yes, but it is extremely rare. The conditions for a bit flip require a very high rate of row activation, which typically only occurs under deliberate stress. Accidental flips are more likely to be caused by other factors like cosmic rays or manufacturing defects.

Does Rowhammer affect SSDs or other storage?

Rowhammer is specific to DRAM, not SSDs. However, similar charge-leakage issues can affect NAND flash memory, but they are not called Rowhammer. NAND flash has its own wear-leveling and error-correction mechanisms.

Can I fix Rowhammer with a software update?

Software updates can mitigate some attacks, but the root cause is in the hardware. If your CPU and memory controller lack hardware defenses, a software patch can only reduce the attack surface, not eliminate it. Upgrading to newer hardware with better mitigations is the most reliable fix.

Is my smartphone vulnerable to Rowhammer?

Yes, smartphones use the same DRAM technology, and attacks like Drammer have shown that Android devices can be exploited. However, many modern phones have mitigations in the memory controller or use ECC, but not all.

How can I protect my cloud VM from Rowhammer?

You cannot directly control the physical hardware in a cloud environment. The cloud provider is responsible for deploying mitigations. As a customer, you can use ECC memory if offered, but ultimately you rely on the provider's security measures.