Skip to content
Memory corruption Write-up Advanced

Making Sense of the Dirty Pipe Vulnerability (CVE-2022-0847)

A flaw in the Linux kernel's pipe buffer handling allowed an attacker with read access to overwrite data in the page cache of arbitrary files, even read-only ones. This could lead to privilege escalation by modifying sensitive files such as SUID binaries or /etc/passwd.

redhuntlabs.com

Published on redhuntlabs.com

On Monday 7th March, a vulnerability in the Linux Kernel was disclosed publicly which could allow an attacker to escalate privileges. The vulnerability discovered by Max Kellermann dubbed “Dirty Pipe” affects the Linux Kernel 5.8 and later versions (including Android).

Pinaki Mondal, on redhuntlabs.com

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

Likely a missing initialization of the flags variable in pipe buffer allocation, combined with the later introduction of the PIPE_BUF_FLAG_CAN_MERGE flag, allowed page cache pages to be merged with pipe data without proper permission checks.

Impact

An attacker with read access could write to any file, even read-only or immutable files, potentially leading to privilege escalation; the exploit is local, which lessens the severity.

What the attacker needed

Read access to the target file; local access to the system

The fix

The vulnerability was fixed in kernel versions 5.16.11, 5.15.25, and 5.10.102, and Google merged a fix for Android.

How it was found

  1. Initialize a pipe.
  2. Populate the pipe with arbitrary content and then clear it to set the PIPE_BUF_FLAG_CAN_MERGE flag.
  3. Use splice() to move data from the target file into the pipe just before the desired offset.
  4. Overwrite the cached file page with write().

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 a copy of recently read files in memory (the page cache) to speed up access. A bug in how pipes (a way for programs to send data to each other) handle memory meant that a program could accidentally write into that cached copy of a file, even if the file was supposed to be read-only. An attacker could use this to change important system files and gain higher privileges.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.