Skip to content
Memory corruption Write-up Advanced

Exploration of the Dirty Pipe Vulnerability (CVE-2022-0847)

A Linux kernel flaw in the pipe buffer handling allowed a process to overwrite the page cache of any file it could open read-only, even files owned by root, without marking the page dirty. An attacker with local access could therefore modify supposedly read-only files in memory, which could lead to privilege escalation.

lolcads.github.io

Published on lolcads.github.io

This blog post reflects our exploration of the Dirty Pipe Vulnerability in the Linux kernel. The bug was discovered by Max Kellermann and described here.

The author, on lolcads.github.io

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 stale pipe buffer flags were not cleared when a pipe buffer was reused, so a buffer that should have been read-only could be written into the page cache.

Impact

A local user could overwrite the in-memory contents of files they can only read, including root-owned files, which could lead to privilege escalation.

What the attacker needed

Local access to the system; ability to open the target file read-only

How it was found

  1. Open the target file read-only.
  2. Create a pipe.
  3. Fill the pipe so its buffers are initialised.
  4. Drain the pipe while keeping the buffer flags.
  5. Splice data from the target file into the pipe.
  6. Write to the pipe to overwrite the cached page.

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 kernel keeps recently read file contents in memory (the page cache) so it does not have to go to disk again. A bug in how pipes track their buffers let a normal user change that in-memory copy of a file they were only allowed to read, such as a root-owned file. Because the change lives in memory, the system can be tricked into using altered content, which can be a step towards taking over the machine.

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.