Skip to content
Memory corruption Write-up Advanced

Linux 3.4+: arbitrary write with CONFIG_X86_X32 (CVE-2014-0038)

The x32 compat implementation of recvmmsg passed a user-supplied timeout pointer straight to the kernel without copying it, so an unprivileged user could make the kernel read and write at an address they chose. This gave a limited arbitrary kernel write primitive, and could also be used to probe kernel addresses and defeat KASLR.

seclists.org

Published on seclists.org

This issue was brought to linux-distros and [email protected] 2 days ago via the message quoted below, and it was just made public at 22:00 UTC today (two hours ago) via grsecurity and PaX (who were the ones to find the issue). Normally, the person who brought this to linux-distros would be the one responsible to bring the…

The author, on seclists.org

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

The x32 branch of compat_sys_recvmmsg cast the user timeout pointer to a kernel pointer and passed it to __sys_recvmmsg, which dereferences it directly instead of copying the timespec from user space first.

Impact

An unprivileged local user could write to kernel memory at a chosen address, subject to the target area already holding valid timespec data, and could also scan the kernel address space to reveal KASLR; the bug only affects kernels built with the x32 ABI.

What the attacker needed

Local unprivileged access; kernel built with CONFIG_X86_X32; target memory holds valid timespec data

The fix

The fix copies the timespec from user space into a kernel buffer before the call and copies the result back afterwards, using the compat helpers, instead of passing the user pointer through.

How it was found

  1. Build a kernel with CONFIG_X86_X32 enabled so the x32 ABI is available.
  2. Create a UDP socket bound to a local port and prepare an array of message headers.
  3. Call the x32 recvmmsg syscall with a timeout pointer chosen by the caller.
  4. Observe a kernel null-pointer dereference on the read side when the pointer is invalid.
  5. Choose a suitable timeout pointer to reach the write side and write to kernel memory.

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 has a system call that receives several network messages at once and takes a pointer to a timeout value. Normally the kernel copies that value from the user's memory into its own memory before using it. In the x32 variant it skipped the copy and used the user's pointer directly, so a normal program could point it at kernel memory and have the kernel read or overwrite it.

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.