Skip to content
Memory corruption Write-up Advanced

Shifting boundaries: Exploiting an Integer Overflow in Apple Safari

An integer overflow in WebKit's FTL JIT range analysis for left-shift operations caused the compiler to compute an incorrect value range, so it removed overflow checks it should have kept. An attacker could turn this into an out-of-bounds read/write on the JavaScriptCore heap and build addrof and fakeobj primitives.

Vignesh Rao Follow

Published on blog.exodusintel.com

JULY 20, 2023 Vulnerability Analysis, Exploit Techniques, General Research

Exodus Intel VRT, on blog.exodusintel.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 shl() range calculation only widened the upper bound when the shifted maximum overflowed, leaving the lower bound at zero even though the real result could become negative and fall below it.

Impact

The incorrect range could be turned into a controlled out-of-bounds read/write on the JavaScriptCore heap, which the authors then used to build addrof and fakeobj primitives; the text does not show a full code-execution chain.

What the attacker needed

Victim loads a crafted web page; Safari/WebKit with the FTL JIT enabled

How it was found

  1. Train the JIT by calling the function many times with small values so it compiles the code.
  2. Mask the input with a bitwise and so the compiler believes the value lies between zero and the maximum 32-bit integer.
  3. Left-shift the value by a constant amount so the range analysis overflows.
  4. Use the shifted result in a subtraction so the range analysis runs on it.
  5. Dump the B3 IR and confirm the checked add was replaced by a plain add without overflow checks.

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.

Browsers speed up heavily used JavaScript with a just-in-time compiler, which guesses the possible values of numbers to skip safety checks. Here the guess about a left-shift result was wrong, so a safety check against overflow was dropped. That let a crafted page read and write memory outside a normal array, which is the first step towards taking over the browser.

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.

More from Apple

View all

The newest disclosed reports for this program.

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.