Skip to content
KitploitKITPLOIT
ToolsExploitsBlog
Log in
Submit
ToolsExploitsBlog
Submit

Hacking, PenTest, and Cybersecurity Tools for Your Security Arsenal!

Kitploit is a directory of hacking, cybersecurity, and pentesting tools. Discover the latest project updates to find vulnerabilities, analyze systems, automate testing, and strengthen your security.

FeedsContactPrivacy© 2026 Kitploit

Tool Directory

Categories

View all categories
Loading categories
linux-backport-CVE-2016-5195 — Backports the CVE-2016-5195 (Dirty COW) kernel fix to Linux 4.4.20, with conflict-resolved patches, a QEMU race regression harness, and build environment notes. | Kitploit
Tools/GitHubGitHub/mlucianoeze/linux-backport-cve-2016-5195
Privilege EscalationVulnerability AnalysisExploitationPapers & ResearchLearning & EducationLabs & Practice
GitHubmlucianoeze/linux-backport-cve-2016-5195

linux-backport-CVE-2016-5195

Backports the CVE-2016-5195 (Dirty COW) kernel fix to Linux 4.4.20, with conflict-resolved patches, a QEMU race regression harness, and build environment notes.

View Repository
Nov 12, 2026Not yet reviewed
Share

Backporting CVE-2016-5195 (Dirty COW) to Linux 4.4.20

My second kernel-backport exercise, and a deliberately harder one than the first. Where the Dirty Pipe backport was a clean two-line fix, this one is about the parts that actually make backporting difficult: an upstream fix that spans more than one commit, real merge conflicts that have to be resolved by hand, and a 2016 kernel that won't build or boot with a modern toolchain until you rebuild the toolchain itself. By far more interesting and entertaining than the first.

The point of this repository is the judgement: deciding which commits a target kernel actually needs, resolving conflicts correctly rather than mechanically, and reconstructing a build/boot environment for an old kernel from scratch.

Result

Same probabilistic race test, same harness, two kernels built from the same 4.4.20 base, yet two opposite outcomes:

KernelDirty COW race (3 s budget)Verdict
4.4.20 (unpatched)RO file corruptedVULNERABLE
4.4.20 + backported fixRO file intactNOT_VULNERABLE
RESULT vulnerable: VULNERABLE      # race won in ~1s, victim 0444 "AAAA" -> "AXAA"
RESULT patched:    NOT_VULNERABLE  # full 3s budget exhausted, victim "AAAA" unchanged

1. The vulnerability

CVE-2016-5195 ("Dirty COW") is a race condition in the kernel's copy-on-write handling of private, read-only memory mappings. By racing a write through /proc/self/mem against madvise(MADV_DONTNEED), an unprivileged user can land a write on the original page-cache page of a read-only file instead of on the private COW copy, hence corrupting a file they only have read access to, which leads to local privilege escalation. It was found being actively exploited in the wild (reported by Phil Oester).

The fix introduces an internal FOLL_COW flag: instead of racily clearing FOLL_WRITE after a COW, the kernel marks that the COW already happened and validates it with the pte dirty bit, closing the window.

2. Exposure analysis: an ancient bug with no single "introducing" commit

The upstream fix (19be0eaffa3a, by Linus Torvalds) has no Fixes: tag, and the commit message explains why: this is a design-level flaw that was first (badly) patched in 2005 (4ceb5db9757a), reverted due to s390 problems (f33ea7f404e5), and only properly fixed eleven years later. There is no clean "the commit that introduced it", actually, the bug predates any 4.x kernel, so a 4.4.20 target is unambiguously exposed. Exposure analysis here isn't about a version window (as it was for Dirty Pipe), but rather about the bug's archaeology.

One dependency from the commit message matters for the backport: the fix relies on pte_dirty(), and the message notes the s390 software dirty bit only landed in v3.9. My target is 4.4 (post-3.9), so the precondition holds on all architectures, but nonetheless the kind of dependency check a backporter has to make before applying.

3. Picking the right subset of commits

Searching the history for the FOLL_COW flag (git log -S'FOLL_COW') surfaces not one but four distinct changes. The backporting skill is deciding which of them a 4.4.20 target actually needs:

ChangeNeeded for 4.4.20?Why
19be0eaffa3a - FOLL_COW core fix in mm/gup.cYesThe fix itself
8310d48b125d - respect FOLL_COW for THP in huge_memory.cYes4.4 has THP, so without it the fix is incomplete and introduces a kernel hang (see below)
mm, gup: close FOLL MAP_PRIVATE raceNoOnly ever backported to 3.2/3.4 branches; never reached any 4.x - not applicable
mm/gup: fix FOLL_FORCE COW … and remove FOLL_COWNoA later, separate CVE (2022); out of scope for Dirty COW

The THP follow-up is the interesting one. Its own commit message (8310d48b125d, Keno Fischer) states that the original fix updated the check in gup.c but a "similar check in huge_memory.c was forgotten", and that remote writes to RO transparent-huge-page regions then cause an infinite loop in the kernel. So applying only the main fix to 4.4.20 (which has THP) would leave the huge-page path exploitable and also introduce a DoS. I confirmed follow_trans_huge_pmd exists in 4.4.20 before concluding the follow-up was required, so the evidence has been taken directly from the source tree rather than assuming from the version number or something else.

I distinguished mainline commits from their stable backports with git merge-base --is-ancestor <sha> origin/master rather than guessing from git describe output, and cherry-picked the mainline versions to force real adaptation onto 4.4.

4. The backports

Both commits conflicted against 4.4.20 since the mainline fixes landed around 4.9. I resolved both conflicts manually first, then as a sanity check, cross-referenced my changes against the official 4.4 stable backport, and it was great to see my manual resolution matched upstream perfectly.

Main fix (gup.c + mm.h). Clean auto-merge in gup.c; the conflict was in include/linux/mm.h, over the value of the new FOLL_COW flag. The upstream diff also wanted to add FOLL_REMOTE 0x2000 (which didn't exist in 4.4) as context. I kept only FOLL_COW and set it to 0x4000 so it matches the upstream's value, which is what's done in the stable patch as well, leaving 0x2000 reserved, a deliberate choice of upstream-consistency, even if that leaves a gap.

THP follow-up (huge_memory.c). The conflict dumped a large block of upstream context - touch_pmd, follow_devmap_pmd, an EXPORT_SYMBOL, none of which exists in 4.4.20. Only two pieces are the actual security fix: can_follow_write_pmd() and the changed check in follow_trans_huge_pmd. I kept those and omitted the rest, including the WARN_ONCE in follow_devmap_pmd whose target function doesn't exist in 4.4.

5. Validation

Dirty COW is a race, so the test is probabilistic rather than deterministic. The regression test (initramfs/dirtycow-test.c) runs two threads: a writer through /proc/self/mem and an madvise(MADV_DONTNEED) loop, against a root-owned 0444 file mapped MAP_PRIVATE, for a wall-clock budget (3 s by default, overridable). It reports VULNERABLE if the file changes even once in that budget, NOT_VULNERABLE otherwise. The asymmetry makes the verdict robust: a vulnerable kernel wins the race in milliseconds (the run exits early), while a patched kernel exhausts the full budget and never wins. It asserts a behavior, not whether a syscall appeared to succeed.

The harness (run-matrix.sh) boots each kernel in QEMU, scrapes a single POC_RESULT: sentinel line from the serial console, and maps it to an exit code. The run log shows the asymmetry directly: the vulnerable kernel powers down at ~1.2 s (won early), the patched kernel at ~3.5 s (full budget, never won).

A note on the test as written: it runs as root (PID 1 in the initramfs), so it isolates the page-cache corruption primitive (the exact invariant the fix restores) rather than end-to-end privilege escalation. For a backport regression test, the primitive is the correct and sufficient assertion. It also exercises the normal-page path (the classic Dirty COW); the THP path backported in commit 2 is covered by analysis and could be exercised with a huge-page variant of the test.

6. Build environment (the most fun part)

Download Tool

Related Tools

  • PEASS-ng

    PEASS - Privilege Escalation Awesome Scripts SUITE (with colors)

  • PrivescCheck

    Privilege Escalation Enumeration Script for Windows

  • LinEnum

    Scripted Local Linux Enumeration & Privilege Escalation Checks

Most Popular

View all →

Discover the most used tools by our community.

  • 1

    Callisto

    jetp1ane/callisto

    Automated binary vulnerability analysis tool that decompiles executables via Ghidra, scans pseudo-C code with Semgrep, and validates findings using GPT-3.5-Turbo to reduce false positives.

    796
  • 2

    ghostlock-app

    yukonga/ghostlock-app

    One-tap Android kernel exploit app for CVE-2026-43499, providing privilege escalation via kernel module loading, with offset extraction and on-device analysis tools.

    735
  • 3

    IMSIcatcher

    28zaaky/imsicatcher

    IMSI Catcher platform that deploys a rogue GSM cell to intercept SMS, inject messages and track mobile devices

    721
  • 4

    opencti

    opencti-platform/opencti

    Open Cyber Threat Intelligence Platform

    535
  • 5

    ARTEX

    baarai/artex

    LLM multi-agent autonomous penetration testing platform with planner/worker agents, asset and exploration graphs, MITM traffic recording, and vulnerability retesting.

    424
  • 6

    DFRoot

    a2333c/dfroot

    Android root tool for Samsung Galaxy S25 Ultra (SM-S938B) that chains DirtyFrag CVE-2026-43284 and CVE-2026-43499 to gain root automatically at boot via KernelSU.

    419

Explore all tools

Browse our collection of tools

View all tools →