Dirty Pipe (CVE-2022-0847): overwriting read-only files on Linux 5.8+
On 2022-03-07 Max Kellermann published Dirty Pipe, a bug in Linux 5.8 and later that let any local user write into files they could only read, such as /etc/passwd or setuid binaries, even on read-only mounts. He found it while debugging corrupted log archives on a web hosting platform. The fixed kernels came out on 2022-02-23, and a fixed kernel protects a server only after a reboot into it.
What broke
Linux keeps recently used file contents in memory, the page cache. The splice() system call can move data from a file into a pipe without copying it: the pipe buffer then points at the page in the page cache.
Pipe buffers have flags. One of them, PIPE_BUF_FLAG_CAN_MERGE, says "later writes to the pipe may be appended into this page". It makes sense for normal pipe pages and must never be set on a page that belongs to a file.
Two kernel functions that create pipe buffers, copy_page_to_iter_pipe() and push_pipe(), did not initialise the flags field. From Linux 4.9 (2016) on, that was harmless. Linux 5.8 (2020) turned the merge behaviour into this flag, and from then on a stale CAN_MERGE flag could stay on a buffer that pointed into the page cache of a file.
How the attack worked
The attacker:
- fills a pipe and drains it, so that every slot in the pipe ring has the merge flag set;
- splices one byte of the target file into the pipe, which puts a reference to the cached file page into a slot that still has the stale flag;
- writes new data into the pipe.
The kernel merges the new data into the cached page of the file. Writing to a pipe never checks file permissions, so nothing stops it. It works on read-only files, immutable files, read-only bind mounts and read-only btrfs snapshots.
The attacker needs read access to the file, cannot write at a page boundary or across one, and cannot make the file longer. Overwriting a password hash in /etc/passwd or code in a setuid-root binary fits within those limits.
The change sits in the page cache only. It is not written to disk unless something else marks the page dirty, and it disappears after a reboot or when the kernel drops the page, which makes an attack hard to see afterwards.
The CVSS v3.1 score is 7.8 (AV:L/AC:L/PR:L). CISA added it to the KEV catalog on 2022-04-25.
Who was affected
Linux 5.8 and later, up to the fixed releases 5.16.11, 5.15.25 and 5.10.102 (released on 2022-02-23). Kellermann also reproduced it on a Google Pixel 6.
Long-term kernels before 5.8 were not affected. On Debian, 10 (kernel 4.19) was not affected and Debian 11 (kernel 5.10) got the fix in linux 5.10.92-2 (DSA-5092-1). Distribution kernels carry their own version numbers, so check the tracker of your distribution as well as the upstream number.
Containers share the kernel of the host, so a process in a container on a vulnerable host could use Dirty Pipe as well.
How to check a server today
The running kernel is what counts:
uname -r
Compare it with the fixed version for your distribution. Then check whether a newer kernel is installed but not running:
# Debian, Ubuntu (package needrestart): KSTA 1 means current, 2 or 3 means a newer kernel waits, 0 unknown
sudo needrestart -b -k
# RHEL family (package dnf-plugins-core)
sudo dnf needs-restarting -r
An installed fix does nothing until the server boots into the new kernel. Until then, a scanner that reads the running kernel reports the CVE even after apt upgrade.
How it was fixed
The fix (kernel commit 9d2231c5d74e) initialises the flags field in the two functions. Kellermann reported the bug with an exploit and a patch on 2022-02-20; the stable releases with the fix came out three days later, the linux-distros list was notified on 2022-02-28, and the details were published on 2022-03-07.
What to take from it
Plan a regular reboot window for kernel updates, or use live patching for urgent fixes. Security updates without downtime covers both.
Containers, chroots and read-only mounts do not stop a kernel bug. On hosts that run untrusted code (CI runners, shared hosting, customer containers), local kernel bugs are as urgent as remote ones.
File integrity checks read the disk and miss changes in the page cache. After a local compromise, reboot into a known kernel before you compare files.
Sources
- Max Kellermann: The Dirty Pipe Vulnerability (history of the bug, commits, limits, page cache behaviour, Pixel 6, timeline, fixed versions)
- CVE-2022-0847 record (description, CVSS from CISA ADP)
- Debian security tracker: CVE-2022-0847 (Debian 10 not affected, Debian 11 fixed in 5.10.92-2, DSA-5092-1)
- Kernel fix 9d2231c5d74e
- CISA KEV catalog, version 2026.11.25 (added 2022-04-25)
Check your servers every day
The Vulnpocalypse agent reports the packages and settings of a server once a day, and the digest lists what to fix, most urgent first.