Skip to content
Memory corruption Write-up Advanced

We won $92,337 bug bounty using a single kernel 0-day

A Linux kernel bug in the rtmutex code leaves a dangling pointer to a stack-allocated waiter object after a failed proxy lock requeue. An unprivileged local attacker can exploit this to gain root privileges and escape containers.

nebusec.ai

Published on nebusec.ai

GhostLock was introduced in Linux 2.6.39 and fixed in Linux 7.1. It has existed in the Linux kernel for more than 15 years.

The author, on nebusec.ai

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 remove_waiter() function assumes current is the waiter, but on the proxy path it is the requeuer, so it clears pi_blocked_on on the wrong task, leaving a dangling pointer.

Impact

An unprivileged local attacker could escalate to root and escape containers, as demonstrated by a 97% stable exploit that earned $92,337 in kernelCTF.

What the attacker needed

Local unprivileged access; CONFIG_FUTEX_PI=y; no special kernel config or privilege

The fix

The bug was fixed by changing remove_waiter() to clear pi_blocked_on on the correct task (waiter->task) instead of current, and a follow-up fix addressed a NULL pointer dereference introduced by the first patch.

How it was found

  1. The waiter thread locks a PI futex and then blocks in FUTEX_WAIT_REQUEUE_PI on another futex, placing its rt_mutex_waiter on its stack.
  2. The owner thread locks the target PI futex and then blocks on the futex held by the waiter, creating a dependency cycle.
  3. The main thread calls FUTEX_CMP_REQUEUE_PI to proxy the waiter onto the target futex, which detects the deadlock and rolls back, leaving the waiter with a dangling pi_blocked_on pointer.
  4. The waiter thread returns to userspace and calls prctl(PR_SET_MM, PR_SET_MM_MAP, ...) to spray controlled data over its own kernel stack, forging a fake rt_mutex_waiter.
  5. A consumer thread triggers sched_setattr() on the waiter to walk the PI chain, causing an rb-tree erase that writes a controlled pointer to a chosen address.
  6. The attacker overwrites a function table entry (e.g., inet6_protos[IPPROTO_UDP]) to point to a fake structure in the CPU entry area, then triggers a loopback IPv6 UDP packet to hijack control flow and execute a ROP chain that flips…

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.

This is a bug in the Linux kernel's locking system. When one thread tries to help another thread acquire a lock, a cleanup function mistakenly clears a pointer on the wrong thread, leaving a dangling reference to memory on the stack. An attacker can then reuse that stack memory with controlled data to trick the kernel into writing to an address of their choosing, eventually taking full control of the system.

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.