Skip to content
Memory corruption Write-up Advanced

PEGASUS iOS Kernel Vulnerability Explained

The iOS kernel's binary deserializer could create references to objects that had already been freed, leading to a use-after-free. An attacker could trigger this from within any sandbox by calling IOKit or mach APIs that accept serialized arguments.

sektioneins.de

Published on sektioneins.de

SektionEins has analysed Apple's iOS security patches to find out more about the kernel vulnerability CVE-2016-4656 abused by the PEGASUS iOS malware.

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 deserializer stored objects in a table without increasing their reference count, and a code path freed an OSString object that was already in that table, allowing a later reference to point to freed memory.

Impact

The vulnerability could be triggered from within any sandbox on iOS or OS X, and although no exploit was developed, it is a use-after-free that could lead to code execution.

What the attacker needed

Ability to call IOKit or mach APIs with serialized data; no special privileges required

The fix

Apple fixed the vulnerability in iOS 9.3.5 by changing the OSUnserializeXML function, though the exact patch is not described.

How it was found

  1. Create a binary serialized dictionary with two elements.
  2. Use an OSString as the key, which gets converted to an OSSymbol and the OSString is freed.
  3. Add a reference to the freed OSString object using the object data type.
  4. Call an IOKit matching function with the crafted binary data to trigger the bug.

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.

When data is unpacked, the program keeps a list of objects it has created. A mistake meant that one object was destroyed but still left in that list, so later data could point to the destroyed object. Using a destroyed object can crash the device or let an attacker run their own code.

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.