Use-after-free in FontFace.loaded promise resolution via thenable check
FontFace.loaded was resolved with the FontFace object itself while layout was still running, so the JavaScript engine's thenable check invoked an attacker-defined getter mid-layout. Removing an iframe inside that getter freed ComputedStyle objects that layout then kept using, producing a heap-use-after-free and a crash.
- Fixed in 12 days
- Paid in 17 days
- Disclosed after 12 days
Created attachment 9548882 asan_log.txt
Summary
FontFace::MaybeResolve() resolves FontFace.loaded with the FontFace object itself. The JS engine's thenable check reads .then on the resolution value, allowing attacker-defined getters to run arbitrary JS mid-layout. Destroying an iframe in this getter frees ComputedStyle objects while layout still references them, causing a heap-use-after-free. No user interaction required.
Affected Version
- Firefox stable 148.0 (Windows), Firefox Nightly 150.0a1 (Linux)
- Cross-platform (Linux, Windows, macOS)
Steps to Reproduce
- Open
poc_fontface_uaf.htmlin Firefox. - Content process crashes on page load.
Root Cause
In FontFace::MaybeResolve() (layout/style/FontFace.cpp:269-282), when gfxFontUtils::CurrentServoStyleSet() returns null (local() font sources load synchronously during layout), the promise resolves immediately instead of being deferred to a PostTraversalTask. This triggers the thenable check mid-layout:
offsetHeight -> FlushPendingNotifications -> FlushUserFontSet
-> SetLoadState(STATUS_LOADED) -> FontFace::MaybeResolve()
-> mLoaded->MaybeResolve(this) // FontFace.cpp:282
-> JS thenable check: get .then // attacker getter runs here
-> iframe.remove() // frees all ComputedStyles
-> layout continues with freed pointers -> UAF
Security Impact
- 100% reproducible crash, zero interaction
- Freed 264-byte
ComputedValuesin default mozjemalloc arena (272-byte bin), reclaimable by attacker
ASan Log (key frames)
==510650==ERROR: AddressSanitizer: heap-use-after-free on address 0x7c666de0d848
READ of size 8 at 0x7c666de0d848 thread T0 (file:// Content)
ACCESS:
#0 StyleFont ServoComputedData.h:73
#7 nsTextFrame::EnsureTextRun nsTextFrame.cpp:3212
#49 PresShell::DoFlushPendingNotifications PresShell.cpp:4497
#56 HTMLElement_Binding::get_offsetHeight HTMLElementBinding.cpp:2987
FREE:
#1 Arc<T>::drop servo_arc/lib.rs:562
#15 nsIFrame::Destroy nsIFrame.cpp:986
#31 nsCSSFrameConstructor::WillDestroyFrameTree nsCSSFrameConstructor.cpp:7291
#38 nsGenericHTMLFrameElement::UnbindFromTree nsGenericHTMLFrameElement.cpp:210
ALLOC:
#8 Servo_ComputedValues_Inherit glue.rs:4790
#10 ServoStyleSet::ResolveStyleForText ServoStyleSet.cpp:407
0x7c666de0d848: 8 bytes inside 264-byte region [0x7c666de0d840,0x7c666de0d948)
Full log attached as asan_log.txt.
Suggested Fix
Defer resolution when no ServoStyleSet is available. Apply the same to MaybeReject() (line 285):
// In FontFace::MaybeResolve(), replace the immediate resolution with:
RefPtr<FontFace> self = this;
nsContentUtils::AddScriptRunner(NS_NewRunnableFunction(
"FontFace::MaybeResolve", [self]() {
if (self->mLoaded) {
self->mLoaded->MaybeResolve(self.get());
}
}));
Attachments
poc_fontface_uaf.html- Minimal PoC (crashes on page load)asan_log.txt- Full ASan output
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the promise was resolved synchronously during layout instead of being deferred to a post-traversal task, so the thenable check ran attacker JavaScript while layout still held references to style objects.
Impact
A page could crash the content process with no user interaction, and the freed 264-byte ComputedValues block sits in a general-purpose allocator bin that the report says is reclaimable by an attacker, though no code execution is demonstrated.
What the attacker needed
Victim loads a malicious page; no user interaction needed
The fix
The report suggests deferring the resolution through a script runner when no ServoStyleSet is available, and applying the same change to MaybeReject(); the text does not say whether this was shipped.
How it was found
- Open the proof-of-concept HTML file in Firefox.
- The content process crashes as the page loads.
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 report has not been written yet. The Original tab links to the source.
When a web font finishes loading, the browser tells the page by resolving a promise. To do that, the browser has to check whether the value it hands back looks like another promise, and that check can run code written by the page. Here that page code ran while the browser was still working out the page layout, and it deleted part of the page, so the browser carried on using memory it had already thrown away. That kind of mistake is called a use-after-free and usually crashes 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.