Dirty Pipe (CVE-2022-0847): overwriting read-only files on Linux 5.8+
On 2022-03-07 Max Kellermann published Dirty Pipe, a Linux kernel bug that let any local user write into files they could only read: /etc/passwd, setuid binaries, files on read-only mounts. It affected every kernel from 5.8 until the fixes in February 2022, including Android phones. It was found while debugging corrupted log archives on a web hosting platform. 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 did not initialise the flags field. Since Linux 4.9 (2016) 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, in plain terms
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. No permission check happens, because writing to a pipe never checks file permissions. It works on read-only files, immutable files, read-only bind mounts and read-only btrfs snapshots.
There are limits: 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 easily in 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. That 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. This is the most common reason a scanner still reports a kernel CVE 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
- Reboot after kernel updates. Plan a regular reboot window, or use live patching for urgent fixes. The guide on security updates without downtime covers both.
- Local kernel bugs break isolation. Containers, chroots and read-only mounts do not stop a kernel bug. On hosts that run untrusted code (CI runners, shared hosting, customer containers), kernel updates are as urgent as remote bugs.
- Debug the strange cases. The bug was found because one person followed up on a few corrupted files a month instead of blaming the disk.
- An attack may not show on disk. File integrity checks of the disk do not show page cache changes. When in doubt after a local compromise, reboot from a known kernel and compare.
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 agent of Patchbrief reports the packages and settings of a server once a day; the digest names what to fix first.