Skip to content
Memory corruption Write-up Advanced

The First PS4 Kernel Exploit: Adieu

A type confusion in the PS4 kernel's named object system allowed a userland process to free an arbitrary kernel pointer and then reallocate it with controlled data, leading to kernel code execution. The exploit used a use-after-free on a kqueue object to hijack a function pointer and run a ROP chain.

fail0verflow.com

Published on fail0verflow.com

Now we will step back a bit and explain how we managed to jump from the browser process into the kernel such that ps4-kexec et al. are usable.

The author, on fail0verflow.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 kernel allowed userland to set the 'kind' field of an id_entry to a value that was not a unique power of two, and later code used that kind to cast the entry to a different structure type without proper validation.

Impact

An attacker could execute arbitrary code in the kernel, allowing full control of the PS4 system.

What the attacker needed

Ability to run code in the browser process; PS4 firmware version 1.01 (or up to 4.05)

The fix

The vulnerability was fixed in firmware version 4.06 by adding a check that rejects kind values with the 0x4000 bit set in namedobj_create.

How it was found

  1. Call namedobj_create with a name and a kind value that includes 0x4000, causing a namedobj_usr_t pointer to be stored in the id table.
  2. Call mdbg_service with command 1 and the same name, causing the kernel to treat the stored pointer as a namedobj_dbg_t and overwrite fields including the lower 32 bits of the name pointer.
  3. Call namedobj_delete with the handle to free the object, which frees the corrupted name pointer (an arbitrary kernel address).
  4. Spray a fake kqueue object into the freed memory using ioctl.
  5. Trigger the use of the corrupted kqueue by calling kevent on the associated file descriptor, causing a function pointer to be called and starting a ROP chain.

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 PS4 kernel had a bug where a program could create an object with one type but then trick the kernel into treating it as a different type. This let the attacker free a kernel memory pointer of their choice and then fill that memory with fake data, eventually taking 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.