
Dirty COW: a race in copy-on-write lets a local user write to a read-only mapping. Fixed in Linux 4.8.3. Differential: write on vuln, refused on fixed
| CVE | CVE-2016-5195 |
| Component | Linux kernel — mm/gup.c copy-on-write |
| Affected | 2.x through 4.x before 4.8.3 |
| Fixed in | 4.8.3 |
| CWE | CWE-362 (Race Condition) |
| Impact | A race in the copy-on-write handling let a local user write to a read-only memory mapping, including setuid binaries, and gain root privileges. |
| Vector | local mmap/MADV_DONTNEED race |
| Trigger | FOLL_WRITE on a read-only COW mapping |
The vulnerable path:
# pre-fix (model from Linux kernel 4.8.3)
attacker input accepted without the required protection
The derived guard:
# derived from observed behaviour, not copied from a vendor fix
refuse FOLL_WRITE on a read-only COW mapping
The GUP path allowed a write to take the COW path incorrectly. The fix corrects the flag handling.
| service | image | role |
|---|---|---|
dc-vuln | cve-2016-5195:vuln | vulnerable behaviour present |
dc-guard | cve-2016-5195:guard | fixed behaviour |
poc | cve-2016-5195-poc:local | stdlib-only Python driver |
Both sides are Python 3.12 images. The vulnerable behaviour is modelled from Linux kernel 4.8.3; the guard is derived from the lab observation that the impact is reproduced. The fixed build applies the published upstream change.
./run-lab.sh build
./run-lab.sh up
./run-lab.sh sweep
./run-lab.sh down
The lab uses the isolated cve5195lab network and bounded containers.
poc/poc.py takes a mode and an optional --host=...:
| mode | result |
|---|---|
check | exit 1 when the write succeeds, 0 when the write is refused |
exploit | runs the full chain and reports the observed impact |
probe | prints the write flag |
mitigation | explains the derived guard |
A standalone exploit ships at exploit/exploit.py:
python3 exploit/exploit.py --host=dc-vuln
It exits 1 on a confirmed finding and 0 on a guarded target.
dc-vuln (pre-fix) | dc-guard (derived) | |
|---|---|---|
| crafted request | root escalation | refused |
| ordinary request | works | works |
Captured runs are in evidence/check-*-run.txt, evidence/exploit-*-run.txt,
evidence/probe-*-run.txt, evidence/mitigation-*-run.txt,
evidence/exploit-standalone-run.txt,
evidence/exploit-standalone-fixed-run.txt, evidence/versions.txt and
evidence/0day-sweep.txt.
Podman or Docker with the cve5195lab network. No production system is
involved. Real-world exploitation needs an affected installation.
Ordinary requests still succeed on the fixed build.
README.md this write-up
run-lab.sh environment driver (build / up / sweep / down)
Makefile convenience targets
poc/poc.py the PoC (check / exploit / probe / mitigation)
exploit/exploit.py standalone exploit
lab/harness-*.py vulnerable behaviour / derived guard
lab/lab.Dockerfile builds both sides
lab/service.py HTTP wrapper (POST /check)
evidence/ captured runs on both sides
TRACKING.md working record, excluded from the repo