Skip to content
Memory corruption Disclosed report Advanced CVE-2021-38498

SUMMARY: AddressSanitizer: heap-use-after-free PLDHashTable.cpp:619 in PLDHashTable::MakeEntryHandle

A heap-use-after-free occurs in Firefox's PLDHashTable when a document is created via DOMImplementation.createDocument, because the language atom service's hash table was freed during shutdown but is still accessed. An attacker could trigger a crash in the tab process by loading a crafted page.

m.cooolie Follow

Originally disclosed on Mozilla

  • Fixed in 7 days
  • Paid in 20 days
  • Disclosed after 7 days
Text
Created attachment 9240010
0908.zip

#Summary
SUMMARY: AddressSanitizer: heap-use-after-free PLDHashTable.cpp:619 in PLDHashTable::MakeEntryHandle

#Reproduce
OS:Win10 X64
Firefox: Nightly 94.0a1 (2021-09-07) (64-bit)

step:

1. python -m http.server 80
2. install node&puppeteer-core (ffpuppet not work on windows)
3. node ff.test.js D:\firefox_asan\target\firefox\firefox.exe http://localhost/poc.htm
4. wait for 30s if not crashes try again

#Type of crash
Tab process

#Analysis
Not yet

#Patch
Not Yet

#ASAN
=================================================================
==3780==ERROR: AddressSanitizer: heap-use-after-free on address 0x1275b70c0d70 at pc 0x7ffe09934350 bp 0x00d37d5f9880 sp 0x00d37d5f98c8
READ of size 4 at 0x1275b70c0d70 thread T0
    #0 0x7ffe0993434f in PLDHashTable::MakeEntryHandle /builds/worker/checkouts/gecko/xpcom/ds/PLDHashTable.cpp:619
    #1 0x7ffe09934c5b in PLDHashTable::MakeEntryHandle /builds/worker/checkouts/gecko/xpcom/ds/PLDHashTable.cpp:673
    #2 0x7ffe09cf2113 in nsLanguageAtomService::GetLanguageGroup /builds/worker/checkouts/gecko/intl/locale/nsLanguageAtomService.cpp:146
    #3 0x7ffe1344b863 in mozilla::StaticPresData::GetFontPrefsForLang /builds/worker/checkouts/gecko/layout/base/StaticPresData.cpp:219
    #4 0x7ffe132c18af in nsStyleFont::nsStyleFont /builds/worker/checkouts/gecko/layout/style/nsStyleStruct.cpp:240
    #5 0x7ffe187c3330 in style::gecko_properties::ComputedValues::default_values /builds/worker/workspace/obj-build/x86_64-pc-windows-msvc/release/build/style-4ff881e47c64df5b/out/gecko_properties.rs:315
    #6 0x7ffe181cf3fa in geckoservo::glue::Servo_StyleSet_Init /builds/worker/checkouts/gecko/servo/ports/geckolib/glue.rs:4095
    #7 0x7ffe1325536a in mozilla::ServoStyleSet::ServoStyleSet /builds/worker/checkouts/gecko/layout/style/ServoStyleSet.cpp:117
    #8 0x7ffe0cfde456 in mozilla::dom::Document::Init /builds/worker/checkouts/gecko/dom/base/Document.cpp:2639
    #9 0x7ffe123d40d9 in NS_NewDOMDocument /builds/worker/checkouts/gecko/dom/xml/XMLDocument.cpp:75
    #10 0x7ffe0cec6f50 in mozilla::dom::DOMImplementation::CreateDocument /builds/worker/checkouts/gecko/dom/base/DOMImplementation.cpp:100
    #11 0x7ffe0cec77ed in mozilla::dom::DOMImplementation::CreateDocument /builds/worker/checkouts/gecko/dom/base/DOMImplementation.cpp:128
    #12 0x7ffe0efefef1 in mozilla::dom::DOMImplementation_Binding::createDocument /builds/worker/workspace/obj-build/dom/bindings/DOMImplementationBinding.cpp:166
    #13 0x7ffe0f858269 in mozilla::dom::binding_detail::GenericMethod<mozilla::dom::binding_detail::NormalThisPolicy,mozilla::dom::binding_detail::ThrowExceptions> /builds/worker/checkouts/gecko/dom/bindings/BindingUtils.cpp:3300
    #14 0x24bd57e396e  (<unknown module>)

0x1275b70c0d70 is located 32 bytes inside of 48-byte region [0x1275b70c0d50,0x1275b70c0d80)
freed by thread T0 here:
    #0 0x7ffe33555afb in free Z:\task_163036031364766\fetches\llvm-project\llvm\projects\compiler-rt\lib\asan\asan_malloc_win.cpp:82
    #1 0x7ffe09834114 in mozilla::KillClearOnShutdown /builds/worker/checkouts/gecko/xpcom/base/ClearOnShutdown.cpp:55
    #2 0x7ffe09b9473d in mozilla::ShutdownXPCOM /builds/worker/checkouts/gecko/xpcom/build/XPCOMInit.cpp:650
    #3 0x7ffe16f70200 in XRE_TermEmbedding /builds/worker/checkouts/gecko/toolkit/xre/nsEmbedFunctions.cpp:218
    #4 0x7ffe0aef9368 in mozilla::ipc::ScopedXREEmbed::Stop /builds/worker/checkouts/gecko/ipc/glue/ScopedXREEmbed.cpp:90
    #5 0x7ffe16f71064 in XRE_InitChildProcess /builds/worker/checkouts/gecko/toolkit/xre/nsEmbedFunctions.cpp:753
    #6 0x7ff7897e1f49 in NS_internal_main /builds/worker/checkouts/gecko/browser/app/nsBrowserApp.cpp:327
    #7 0x7ff7897e14d4 in wmain /builds/worker/checkouts/gecko/toolkit/xre/nsWindowsWMain.cpp:131
    #8 0x7ff7898de217 in __scrt_common_main_seh d:\agent\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
    #9 0x7ffe61627033 in BaseThreadInitThunk+0x13 (C:\Windows\System32\KERNEL32.DLL+0x180017033)
    #10 0x7ffe63602650 in RtlUserThreadStart+0x20 (C:\Windows\SYSTEM32\ntdll.dll+0x180052650)

previously allocated by thread T0 here:
    #0 0x7ffe33555c0b in malloc Z:\task_163036031364766\fetches\llvm-project\llvm\projects\compiler-rt\lib\asan\asan_malloc_win.cpp:98
    #1 0x7ffe33ec139d in moz_xmalloc /builds/worker/checkouts/gecko/memory/mozalloc/mozalloc.cpp:52
    #2 0x7ffe09cf1bf7 in nsLanguageAtomService::GetService /builds/worker/checkouts/gecko/intl/locale/nsLanguageAtomService.cpp:87
    #3 0x7ffe1344a428 in mozilla::StaticPresData::Init /builds/worker/checkouts/gecko/layout/base/StaticPresData.cpp:20
    #4 0x7ffe13f33dd5 in nsLayoutStatics::Initialize /builds/worker/checkouts/gecko/layout/build/nsLayoutStatics.cpp:178
    #5 0x7ffe13f33cbd in nsLayoutModuleInitialize /builds/worker/checkouts/gecko/layout/build/nsLayoutModule.cpp:104
    #6 0x7ffe09a8abf9 in nsComponentManagerImpl::Init /builds/worker/checkouts/gecko/xpcom/components/nsComponentManager.cpp:408
    #7 0x7ffe09b936e1 in NS_InitXPCOM /builds/worker/checkouts/gecko/xpcom/build/XPCOMInit.cpp:446
    #8 0x7ffe16f7013e in XRE_InitEmbedding2 /builds/worker/checkouts/gecko/toolkit/xre/nsEmbedFunctions.cpp:192
    #9 0x7ffe0aef98ac in mozilla::ipc::ScopedXREEmbed::Start /builds/worker/checkouts/gecko/ipc/glue/ScopedXREEmbed.cpp:83
    #10 0x7ffe120ffe0f in mozilla::dom::ContentProcess::Init /builds/worker/checkouts/gecko/dom/ipc/ContentProcess.cpp:202
    #11 0x7ffe16f70f01 in XRE_InitChildProcess /builds/worker/checkouts/gecko/toolkit/xre/nsEmbedFunctions.cpp:715
    #12 0x7ff7897e1f49 in NS_internal_main /builds/worker/checkouts/gecko/browser/app/nsBrowserApp.cpp:327
    #13 0x7ff7897e14d4 in wmain /builds/worker/checkouts/gecko/toolkit/xre/nsWindowsWMain.cpp:131
    #14 0x7ff7898de217 in __scrt_common_main_seh d:\agent\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
    #15 0x7ffe61627033 in BaseThreadInitThunk+0x13 (C:\Windows\System32\KERNEL32.DLL+0x180017033)
    #16 0x7ffe63602650 in RtlUserThreadStart+0x20 (C:\Windows\SYSTEM32\ntdll.dll+0x180052650)

SUMMARY: AddressSanitizer: heap-use-after-free /builds/worker/checkouts/gecko/xpcom/ds/PLDHashTable.cpp:619 in PLDHashTable::MakeEntryHandle
Shadow bytes around the buggy address:
  0x04bc6de98150: fa fa fd fd fd fd fd fd fa fa fd fd fd fd fd fa
  0x04bc6de98160: fa fa 00 00 00 00 00 00 fa fa 00 00 00 00 00 00
  0x04bc6de98170: fa fa 00 00 00 00 00 04 fa fa 00 00 00 00 00 00
  0x04bc6de98180: fa fa 00 00 00 00 00 00 fa fa 00 00 00 00 00 00
  0x04bc6de98190: fa fa 00 00 00 00 00 00 fa fa 00 00 00 00 00 00
=>0x04bc6de981a0: fa fa 00 00 00 00 00 00 fa fa fd fd fd fd[fd]fd
  0x04bc6de981b0: fa fa fd fd fd fd fd fa fa fa 00 00 00 00 00 fa
  0x04bc6de981c0: fa fa fd fd fd fd fd fa fa fa fd fd fd fd fd fa
  0x04bc6de981d0: fa fa fd fd fd fd fd fa fa fa fd fd fd fd fd fa
  0x04bc6de981e0: fa fa fd fd fd fd fd fa fa fa fd fd fd fd fd fa
  0x04bc6de981f0: fa fa 00 00 00 00 00 fa fa fa 00 00 00 00 00 fa
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
  Shadow gap:              cc
==3780==ABORTING

The original report as published on Mozilla's Bugzilla, by m.cooolie. 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

Impact

The vulnerability causes a heap-use-after-free that crashes the tab process; the report does not claim any further impact such as code execution.

What the attacker needed

Firefox Nightly 94.0a1 (2021-09-07) on Windows 10 x64; Victim visits a crafted page; Node.js and puppeteer-core for reproduction

How it was found

  1. Start a local HTTP server on port 80.
  2. Install Node.js and puppeteer-core.
  3. Run the provided Node script with the Firefox executable and the URL of the proof-of-concept page.
  4. Wait up to 30 seconds for a crash; retry if it does not crash.

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.

This is a memory safety bug in Firefox where a data structure (a hash table) is used after it has been freed. When a web page creates a new document in a certain way, Firefox tries to read from that freed memory, which can crash the browser tab. The report shows the crash but does not explain how to exploit it beyond causing a crash.

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 m.cooolie

View all

10 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.