Skip to content
Race condition Write-up Advanced

PS4 5.05 BPF Double Free Kernel Exploit Writeup

A race condition in the BPF driver's filter-setting code let two threads copy the same filter pointer and free it twice, corrupting the kernel heap. An attacker could then hijack a kernel function pointer through a corrupted knote object to run code in kernel mode.

github.com

Published on github.com

History

The author, on github.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

The pointer to the old write filter was copied to a stack variable outside the BPF descriptor lock, so concurrent ioctl calls could both capture and later free the same filter.

Impact

A local attacker with access to the BPF device could achieve kernel code execution, though the bug is no longer reachable past 5.05 because the driver was blocked from unprivileged processes and a stack-pointer mitigation forced a more complex kernel ROP approach.

What the attacker needed

Access to /dev/bpf from a sandboxed process; ability to run concurrent threads; PS4 firmware 5.05 or earlier

The fix

The text does not describe a code fix; it notes that Sony blocked unprivileged access to the BPF driver, and the underlying locking flaw should be fixed by taking the lock before reading the filter pointer.

How it was found

  1. Open BPF descriptors and set up a NOP filter and a heap-spray filter
  2. Prepare a fake knote object and fake filterops table in the WebKit heap
  3. Set up the kernel ROP chain
  4. Start one thread that creates a kqueue, sets a filter, triggers a kevent, sprays the heap and closes the kqueue
  5. Start a second thread that continuously sets a write filter to race the first

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.

A driver is a piece of kernel code that lets programs talk to devices, and the BPF driver handles packet filters. Two threads could run the same filter-setting code at once, and because a pointer was read without a lock, both ended up freeing the same memory, which corrupts the kernel's memory bookkeeping. The author then abuses that corruption to redirect a kernel function pointer and run their own code with the highest privileges.

What is Race condition?

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.

Similar reports

View all

Same bug class and techniques, clearest first.

Race conditions

The lesson behind this report.

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.