Skip to content
Memory corruption Write-up Advanced

PEGASUS iOS Kernel Vulnerability Explained – Part 2

The OSUnserializeBinary() function in the iOS kernel contained multiple use-after-free (UAF) vulnerabilities due to improper reference counting. An attacker could exploit these to corrupt kernel memory and potentially take over the device.

sektioneins.de

Published on sektioneins.de

After our analysis of the PEGASUS iOS kernel vulnerability CVE-2016-4656 from last week that you can read in part one of this blog post there have been new discoveries about the kernel vulnerability in question:

Stefan Esser, on sektioneins.de

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 code called release() on objects during deserialization without ensuring they were still referenced elsewhere, leading to premature freeing and later use.

Impact

An attacker could exploit the UAF to execute arbitrary code in the kernel, potentially fully compromising the device.

What the attacker needed

Ability to supply serialized data to the kernel

The fix

The function was restructured to remove mid-function release() calls and instead release all objects at the end, preventing reference counts from dropping to zero during deserialization.

How it was found

  1. Line 398 sets a dictionary key to an object, increasing reference counts.
  2. Line 399 releases the object, decreasing its reference count.
  3. Line 400 releases the key symbol, decreasing its reference count.
  4. When a new object with the same key is inserted, the old object's reference count drops to zero and it is freed.
  5. If the deserializer later tries to reference the freed object, a use-after-free occurs.

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 use-after-free (UAF) is a type of bug where a program frees memory but then keeps using it, which can let an attacker control what happens next. In this case, the iOS kernel had several such bugs in a function that processes serialized data, and an attacker could exploit them to run malicious code with high privileges.

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.