WebKit exploit write-up
A use-after-free in WebKit's setAttributeNodeNS allowed an attribute node to be attached to two elements, so freeing one left a stale reference to an iframe object. An attacker could then corrupt the freed object's backing memory to build read/write primitives and run a ROP chain for code execution in the browser.
github.com
Published on github.com
History
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 setAttributeNodeNS calls setAttributeInternal before attaching the new attribute, and that call can re-enter setAttributeNodeNS, leaving two attribute nodes sharing one owner element and a stale reference after one is freed.
Impact
An attacker could achieve userland code execution in WebKit on unpatched platforms, though the write-up notes the exploit was patched in firmware 5.03.
What the attacker needed
Victim loads a malicious web page; unpatched WebKit build
How it was found
- Create an attribute whose value runs a callback, and attach it to an iframe.
- Remove the iframe and drop references, then force garbage collection.
- In the callback, attach the same attribute to a div and a fresh attribute to the iframe, leaving a stale reference.
- Leak a JSValue from uninitialised ImageData backing memory via postMessage and history state.
- Spray ImageData objects to reclaim the freed iframe and corrupt its butterfly pointer.
- Misalign a fake array view to build read/write primitives and 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.
When a web page changes an element's attributes, the browser keeps track of which element owns each attribute. A bug meant one attribute could end up owned by two elements at once, so when one element was cleaned up the other still pointed at freed memory. By carefully filling that freed memory with their own data, an attacker could make the browser read and write arbitrary memory and eventually 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.