Skip to content
Memory corruption Write-up Advanced

Exploiting Recursion in the Linux Kernel

A local user could trigger unbounded recursion in the Linux kernel by stacking ecryptfs on procfs, causing a kernel stack overflow that could be exploited to gain root privileges.

googleprojectzero.blogspot.com

Published on googleprojectzero.blogspot.com

On June 1st, I reported an arbitrary recursion bug in the Linux kernel that can be triggered by a local user on Ubuntu if the system was installed with home directory encryption support. If you want to see the crasher, the exploit code and the shorter bug report, go to…

The author, on googleprojectzero.blogspot.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 the lack of guard pages on kernel stacks and the ability to stack ecryptfs on procfs, which allows recursive page faults when accessing /proc/$pid/environ or cmdline through ecryptfs.

Impact

A local attacker could crash the kernel or potentially execute arbitrary code with kernel privileges, leading to a root shell.

What the attacker needed

Local user access; ecryptfs-utils installed; CONFIG_CHECKPOINT_RESTORE enabled

How it was found

  1. Create a process A with a known PID.
  2. Mount an ecryptfs filesystem on /tmp/$A with /proc/$A as the lower filesystem.
  3. Use prctl(PR_SET_MM, PR_SET_MM_MAP, ...) to set the environment area of process A to point to a memory region containing a valid ecryptfs header.
  4. Map /tmp/$A/environ into process B, and set up a chain of processes mapping each other's decrypted environment areas.
  5. Trigger a page fault in process C that causes ecryptfs to read from /proc/$B/environ, leading to recursive page faults and stack overflow.
  6. Exploit the stack overflow by overwriting the saved return address with a ROP chain to gain kernel code execution.

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 uses a small stack for handling system calls, and if a function calls itself too many times, the stack can overflow into other memory. This report shows how a user could set up filesystems in a way that causes such recursion, and then use the overflow to take control of the kernel.

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.