THE L33T VULN JOURNAL
Read-only was a lie — CVE-2016-5195 / Dirty COW

// CASE FILE 004 · CVE-2016-5195

Read-only was a lie

// THIS CASE ON SOCIAL POST LINKS WILL APPEAR HERE

In October 2016, a Linux kernel race showed how local code could cross a file-permission boundary. Dirty COW let a write reach a protected backing file instead of remaining in a private copy.

Result
Local privilege escalation
Entry point
Local code and copy-on-write handling
Affected component
Linux kernel; distribution patch status determines exposure
Public disclosure
October 2016

// PEOPLE BEHIND THIS CASE

Phil Oester reported exploitation; Linus Torvalds authored the upstream fix, with review from Michal Hocko and Hugh Dickins. Linux vendors distributed corrected kernels. Verified attribution and source links are collected below.

01 / THE CASE

The short version

How the story began

Linux said the mapping was read-only. The attacker said:

we'll see.

In 2016, researchers disclosed a race condition inside the Linux kernel's memory management code. An unprivileged local user could exploit a flaw in copy-on-write handling to write into memory mappings that were supposed to be read-only. That could turn ordinary local access into root. The bug had existed for years. It had even been partially addressed long before — then effectively returned.

And by the time the security community caught up, exploitation had already been observed in the wild. The vulnerability became known as Dirty COW.

The Short Version

Dirty COW was a Linux kernel race condition. It affected how the kernel handled:

  • private memory mappings
  • copy-on-write
  • concurrent write behavior

Under the right timing conditions, a local unprivileged process could gain write access to data that should remain read-only. That could be abused to modify protected files or binaries and escalate privileges. The name comes from:

Dirty COW: COW stands for copy-on-write.

What Is Copy-On-Write?

Copy-on-write is a performance optimization. Imagine two processes need to use the same data. Instead of immediately creating two copies, the operating system can let both reference the same physical memory. As long as nobody changes it:

  • PROCESS A ─┐
  • > SAME MEMORY PAGE
  • PROCESS B ─┘

When one process tries to modify the data, the kernel creates a private copy. Hence:

  • COPY
  • ON
  • WRITE

After the write:

Process A keeps the original page; process B uses a private copy.

That mechanism saves memory and avoids unnecessary copying. But it depends on the kernel enforcing the transition correctly. Dirty COW found a race in that enforcement.

A few terms before we continue

Kernel

The kernel is the privileged core of an operating system. It manages:

  • memory
  • processes
  • devices
  • filesystems
  • permissions
  • system calls

Breaking a kernel security boundary can be much more serious than breaking a normal application.

Memory mapping

A process can map a file into memory using mechanisms such as mmap(). That means file contents can be accessed through memory addresses.

Race condition

A race condition happens when security or correctness depends on the exact timing and ordering of multiple operations. If two threads repeatedly perform operations at the same time, a tiny timing window can sometimes expose a state the developer never intended.

02 / DISCOVERY

How the case became public

The Discovery

The Linux kernel fix credits Phil Oester with reporting and testing the bug. Oester had captured evidence of an exploit being used in the wild. That detail changes the tone of the story. Dirty COW was not simply a researcher creating an elegant proof of concept for a theoretical kernel race. There was evidence that someone else had already figured it out and was using the technique.

The issue was publicly disclosed in October 2016. Then came another remarkable detail from the kernel fix. Linus Torvalds described it as an ancient bug and noted that he had attempted to fix the underlying race years earlier. That earlier fix had been reverted because it caused problems on another architecture. The vulnerability survived.

Years later, changes in the virtual memory subsystem made the race easier to trigger reliably. A theoretical-looking flaw had become practical.

The Bug That Came Back

One of the most interesting parts of Dirty COW is its history. The kernel fix notes that an attempt had been made to address a related race roughly eleven years earlier. That fix was later reverted because of compatibility problems. The kernel evolved. The memory subsystem evolved. And eventually the old race became easier to trigger. This is a powerful engineering lesson:

A reverted security-relevant fix is not the same thing as a solved problem.

Technical debt can remain dormant for years.

Timeline

  • 2000s
  • Earlier attempt to address related COW race
  • Fix later reverted because of architecture problems
  • 2007+
  • Vulnerable kernel behavior persists across many releases
  • 2016
  • Exploitation observed in the wild
  • Phil Oester reports/tests issue
  • Kernel fix prepared
  • Public disclosure — CVE-2016-5195

03 / MECHANISM

Where the boundary broke

How Can Read-Only Memory Become Writable?

Suppose an unprivileged process maps a protected file privately and read-only. Conceptually:

ROOT-OWNED FILE → READ-ONLY PRIVATE MAPPING → UNPRIVILEGED PROCESS

The process should not be able to modify the real file. Copy-on-write is supposed to preserve that boundary. Dirty COW exploited a race between kernel operations involved in invalidating and writing those mappings. Red Hat summarized the issue as a race involving copy-on-write breakage of private read-only mappings. The result:

read-only → race → unexpected write access

What Was Actually Wrong?

The technical core involved Linux memory management and get_user_pages() behavior. A common explanation of the exploit race involves two operations repeatedly fighting over the same mapping:

  • THREAD A
  • madvise(..., MADV_DONTNEED)
  • THREAD B
  • attempt write through memory access path

The attacker tries to win a timing race during copy-on-write handling. Conceptually:

PRIVATE READ-ONLY MAPPING → thread A invalidates / discards page state → thread B races write handling → COW state confusion → protected data altered

This is why Dirty COW was not a simple one-shot bug. Reliability depended on racing kernel operations many times until the vulnerable timing window was hit.

How Dirty Cow Worked

At a high level:

attacker has local unprivileged access → maps protected file read-only → creates a race around COW handling → kernel reaches inconsistent state → write reaches protected mapping → privilege boundary can be bypassed

A common high-impact target was a privileged executable or other root-owned data. The vulnerability itself was local. It did not magically provide remote access. But once an attacker had a low-privileged shell, Dirty COW could become the second stage:

foothold → Dirty COW → root

04 / SCOPE

Who was affected?

Dirty COW affected a broad range of Linux kernels and therefore many Linux distributions. Red Hat documented affected versions across multiple RHEL generations. The NVD description covers Linux kernel 2.x through 4.x before the upstream fix line around 4.8.3. But vendor backports make raw upstream version comparisons unreliable. The correct question is:

Has my distribution shipped the CVE-2016-5195 fix for this exact kernel package?

05 / LAB · CONTROLLED VERIFICATION

Inspect it. Test it. Compare.

Lab / Proof Of Concept

Dirty COW is a kernel privilege-escalation bug. For a public educational article, the lab focuses on safe identification and understanding rather than providing a weaponized root exploit.

PoC 1 — Identify kernel version

uname -a
uname -r

Do not decide vulnerability status from the version number alone. Linux distributions often backport security fixes into older kernel version lines.

PoC 2 — Check distribution security state

RPM systems

rpm -q kernel

Debian / Ubuntu family

dpkg -l 'linux-image*' | grep '^ii'

openSUSE

rpm -q kernel-default
zypper patches --category security

Compare the installed build against your vendor's CVE-2016-5195 advisory.

PoC 3 — Understand normal copy-on-write behavior

A safe conceptual lab can use a private mapping of a file you own. The expected security model is:

file on disk → MAP_PRIVATE → process changes private page → original file remains unchanged

That is the boundary Dirty COW violated under a race.

PoC 4 — Verify after patching

After installing the vendor kernel update:

uname -r

Then reboot if required:

sudo reboot

After reboot:

uname -r

The important operational lesson is:

installing new kernel ≠ running new kernel

until the machine actually boots into the fixed build.

Executable private-copy demonstration

Save this as cow-demo.py and run python3 cow-demo.py. It creates only a temporary file owned by the current process.

import mmap
import tempfile
with tempfile.TemporaryFile() as f:
    f.write(b"DATA")
    f.flush()
    with mmap.mmap(f.fileno(), 4, access=mmap.ACCESS_COPY) as page:
        page[:] = b"EDIT"
        f.seek(0)
        disk = f.read()
        print("private:", bytes(page).decode())
        print("disk:", disk.decode())
        assert disk == b"DATA"

This was executed successfully: the private mapping read EDIT, while the file remained DATA. It demonstrates normal copy-on-write isolation; it neither exploits nor detects Dirty COW. A writable private copy is expected behavior. The security failure was modification of a protected backing file through the kernel race. No privilege-escalation exploit was executed for this article.

06 / SCOPE & RESPONSE

Patch and verify

The correct fix is a patched kernel. Generic workflow:

  • # update package metadata
  • # install vendor kernel security update
  • # reboot
  • # verify running kernel

Examples:

Debian / Ubuntu family

sudo apt update
sudo apt full-upgrade
sudo reboot

Fedora / RHEL-like systems

sudo dnf upgrade
sudo reboot

openSUSE

sudo zypper patch
sudo reboot

Then verify:

uname -r

Temporary mitigations should not be treated as substitutes for the kernel fix.

07 / TAKEAWAY

What this case teaches

What Happened Next?

Dirty COW rapidly became a standard Linux privilege-escalation case study. Public exploit implementations appeared. Security teams had to assess enormous fleets of Linux systems. Android devices were also relevant because Android uses the Linux kernel. The vulnerability became a reminder that local bugs can matter enormously in real attack chains. An attacker rarely needs one perfect vulnerability.

A more realistic chain is:

remote foothold → low-privilege shell → local kernel exploit → root

Dirty COW fit that second stage extremely well.

Why This Matters

Dirty COW teaches several things.

Read-only is a policy enforced by code

The label itself provides no protection if the implementation can be raced.

Reliability changes vulnerability severity

A race that is nearly impossible to win may be interesting. A race that can be repeated thousands of times until it succeeds becomes operationally useful.

Old kernel code can remain attackable for years

The bug survived across a rapidly evolving kernel.

Local privilege escalation is not "just local"

In a real intrusion, local privilege escalation often converts:

limited access

into:

complete system control

That is why kernel LPEs matter.

08 / THE PEOPLE

The people behind the case

Reporter / tester credited in the Linux kernel fix

Phil Oester

The upstream fix contains:

Reported-and-tested-by: Phil "not Paul" Oester

Oester also reported evidence of exploitation observed in network capture data.

Linux kernel maintainer / upstream fix author

Linus Torvalds

The fix commentary is especially notable because Torvalds described the issue as an old race that had been unsuccessfully addressed years earlier.

Sources & further reading