Linux Kernel Dirty Pipe Exploitation (Logic Bug — CVE-2022�
A logic bug in the Linux kernel's pipe buffer handling allowed an unprivileged user to overwrite read-only files in the page cache. An attacker could exploit this to gain root privileges by modifying files such as /etc/passwd or /etc/bash.bashrc.
Published on medium.com
Dirty Pipe (CVE-2022–0847) is one of the most significant security vulnerabilities in Linux Kernel 5.8–5.15.24, discovered by Max Kellermann in 2022. This vulnerability allows ordinary users (without special privileges) to overwrite data in files that should be read-only.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
The kernel failed to reset the PIPE_BUF_FLAG_CAN_MERGE flag in the pipe_buffer structure when using splice(), allowing subsequent writes to merge into page cache pages of read-only files.
What the attacker needed
Local access to a vulnerable Linux system; Kernel version 5.8 to 5.15.24 (or 5.16.11)
The fix
The kernel was fixed by resetting the flags field to zero in the pipe_buffer structure during splice operations.
How it was found
- Fill the pipe completely to set the CAN_MERGE flag on all buffers.
- Drain the pipe, leaving the flag set in the buffer structures.
- Use splice() to map a read-only file into the pipe without resetting the flag.
- Write payload data to the pipe, which modifies the page cache of the file.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
The Linux kernel keeps copies of files in memory (the page cache) to speed up access. A flaw in how the kernel manages a flag for pipe buffers meant that a normal user could trick the kernel into writing to those in-memory copies, even for files marked read-only. By changing important system files like the password file, the user could become the administrator (root).
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.