Dirty Pipe (CVE-2022-0847) – Linux Kernel Privilege Escalation
Dirty Pipe is a logic bug in the Linux kernel's pipe buffer handling. Page cache pages can be marked as writable even for read-only file-backed mappings, allowing any unprivileged user to overwrite the contents of read-only files — including SUID binaries and /etc/passwd. It is one of the most reliable kernel exploits available: no memory corruption, no ASLR bypass needed, and it does not crash the system.
Affected Versions
Linux kernel 5.8.0 through 5.16.10
Linux kernel 5.15.0 through 5.15.24
Linux kernel 5.10.0 through 5.10.101
Not affected: kernels below 5.8 (pipe buffer splicing introduced in 5.8), kernels 5.16.11+, 5.15.25+, 5.10.102+.
Prerequisites Check
Check kernel version:
Confirm you are in the vulnerable range. Also confirm the build date — if the kernel was built recently it may be backport-patched:
On Debian/Ubuntu, check the exact package version:
Confirm there is at least one readable file on the system (any non-empty file works — the exploit needs an existing page cache entry):
No special privileges, group memberships, or capabilities required. Any local user account works.
Exploit 1 — Overwrite /etc/passwd (Recommended)
This variant modifies /etc/passwd to create a passwordless root account. Extremely stable — pure file write, no shellcode.
Step 1 — Get the exploit:
Step 2 — Run the exploit:
The exploit:
Reads the first line of
/etc/passwdinto a pipeOverwrites the
xpassword placeholder with a blank entryExecutes
su root— root now has no password
Step 3 — Authenticate as root:
Step 4 — Restore /etc/passwd:
The exploit attempts automatic restoration, but verify the file is intact:
If the password hash was corrupted, restore from backup:
Exploit 2 — Overwrite SUID Binary
This variant overwrites a SUID binary with a shellcode payload. Useful when /etc/passwd modification is not sufficient or when you need a persistent binary.
The exploit patches /usr/bin/sudo with shellcode that spawns a root shell. Execute the patched binary:
You get a root shell. The exploit attempts to restore the original binary after execution — verify it was restored:
Compile from Source (No git Required)
When git is unavailable on your attack box or you want to compile a single file:
When the Exploit Fails
"Segmentation fault" immediately: The kernel version is not in the vulnerable range or is backport-patched. Check uname -v for build date.
su root fails after exploit: The exploit ran but the system uses shadow-only authentication. Try writing to /etc/shadow instead using the same technique — compile a variant that targets shadow.
"Permission denied" when running the binary: Confirm the file is executable — chmod +x exploit-1.
Compile error on target (no gcc): Compile on your attack box targeting the same architecture, then transfer the binary.
Why This Works
Pipes in Linux use splice operations to move data between file descriptors without copying. A bug in the pipe buffer's flags handling allowed the PIPE_BUF_FLAG_CAN_MERGE flag to persist across splice operations, causing subsequent pipe writes to overwrite the cached page of a read-only file. The kernel patches this by clearing the flag in copy_page_to_iter_pipe() and push_pipe().
References
-
Dirty Pipedirtypipe.cm4all.com (opens in new tab)
Original Disclosure (Max Kellermann) Full technical write-up by the discoverer including proof-of-concept and root cause analysis.
-
CVE-2022-0847 Exploitsgithub.com/AlexisAhmed/CVE-2022-0847-DirtyPipe-Exploits (opens in new tab)
AlexisAhmed Two exploit variants: /etc/passwd overwrite and SUID binary patching.
-
Red Hat Advisory Affected package versions and patch information per distribution.
Was this helpful?
Your feedback helps improve this page.