Possible UAF in nsGlobalWindowInner::TryToObserveRefresh
A use-after-free was found in a lambda inside nsGlobalWindowInner::TryToObserveRefresh, triggered by a custom patch that caused nested event loop processing. An attacker could potentially cause a crash if a similar condition were reachable in unpatched Firefox, but the report notes no way for users to reproduce it without the patch.
Originally disclosed on Mozilla
- Fixed in 29 hours
- Paid in 2 months
- Disclosed after 29 hours
Created attachment 9367029
The patch that can be used to trigger the crash
In Tor Browser we found a possible use-after-free in the lambda defined in `nsGlobalWindowInner::TryToObserveRefresh`.
The UAF was caused by a patch we added, so we haven't found a way for users to reproduce the problem in Firefox, but we still wanted to open this Bug because maybe a similar condition could be triggered in another way.
In our case, `MaybeCallDocumentFlushedResolvers` made the code of our patch that interacts with the clipboard run.
The Wayland implementation called `gtk_main_iteration`, which in turn at a certain point called the the lambda again.
After the nested run, the observer was deleted, and `mRawPtr` of `win` was set to `0xe5e5e5e5e5e5e5e5`. Therefore, the `win->mObservingRefresh = false;` in the first run resulted in a segmentation fault.
I've attached a reduced version of the patch that enables the crash.
To reproduce it, apply the patch, run Firefox on Linux with Wayland, pin an extension such as NoScript or uBlockOrigin, and click on its icon.
The browser should crash immediately. Otherwise, try to click again.
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 lambda captured a raw pointer to an object that could be deleted during a nested event loop iteration, leading to a use-after-free when the lambda ran again.
Impact
The crash is only demonstrated with a custom patch; the report states no way for users to reproduce it in unpatched Firefox, though a similar condition could potentially cause a crash if reachable.
What the attacker needed
Custom patch applied; Linux with Wayland; extension pinned; user clicks extension icon
How it was found
- Apply the provided patch to Firefox.
- Run Firefox on Linux with Wayland.
- Pin an extension such as NoScript or uBlockOrigin.
- Click on the extension's icon.
- The browser should crash immediately; if not, try clicking again.
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.
A use-after-free is a bug where a program keeps using memory after it has been freed, which can lead to crashes or worse. Here, a custom patch caused the browser to run some code twice in a nested way, so the second run used a pointer that had already been deleted. The report says this specific crash only happens with their patch, but a similar situation might be possible in normal Firefox.
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.