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

AddressSanitizer: SEGV on unknown address in mozilla::dom::Directory::GetFullRealPath(nsTSubstring<char16_t>&) -> operator-> get

A use-after-free occurs in Firefox when a directory file input is reloaded while the file picker is open, causing the tab to crash. An attacker could potentially exploit this to crash the browser, but the report only demonstrates a crash.

Irvan Kurniawan Follow

Originally disclosed on Mozilla

  • Fixed in 34 days
  • Paid in 46 days
  • Disclosed after 34 days

Created attachment 9240529 testcase.html

When using <input type="file"> then set attribute webkitdirectory to true then repeatedly reload the page with form submit or location.reload(). When page reload while holding down "Enter" key after file select dialog appears then select file, the tab crashes with AddressSanitizer: SEGV on unknown address in mozilla::dom::Directory::GetFullRealPath -> operator-> get

After holding down the "Enter" key, the file dialog still allow to choose file even set webkitdirectory to true. I think the HTMLInputElement still refer to previous pointer, one of the crash address on Windows 10 show e5e5e5e5 (probably uaf?)

When testing this on Firefox ASan 64-bit on Linux it shows AddressSanitizer: SEGV on unknown address with Hint: this fault was caused by a dereference of a high value address (see register values below) on Firefox ASan 32-bit it shows the address SEGV address on unknown address 0x270edfe3 (same address every-time I tried the testcase)

Steps to reproduce:

  1. Visit attached testcase.html
  2. Hold down "Enter" key
  3. After file open dialog appears, then select file
  4. Click "Open" or press "Enter" key
  5. The tab crashed

ASan output:

=================================================================
==1971273==ERROR: AddressSanitizer: SEGV on unknown address (pc 0x7f8aa549f80f bp 0x7fff19db80f0 sp 0x7fff19db80f0 T0)
==1971273==The signal is caused by a READ memory access.
==1971273==Hint: this fault was caused by a dereference of a high value address (see register values below).  Disassemble the provided pc to learn which register was used.
    #0 0x7f8aa549f80f in get /home/sourc7/git/gecko-dev-asan/objdir-ff-asan/dist/include/nsCOMPtr.h:851:48
    #1 0x7f8aa549f80f in operator-> /home/sourc7/git/gecko-dev-asan/objdir-ff-asan/dist/include/nsCOMPtr.h:872:12
    #2 0x7f8aa549f80f in mozilla::dom::Directory::GetFullRealPath(nsTSubstring<char16_t>&) /home/sourc7/git/gecko-dev-asan/dom/filesystem/Directory.cpp:133:17
    #3 0x7f8aa55f00be in GetDOMFileOrDirectoryPath /home/sourc7/git/gecko-dev-asan/dom/html/HTMLInputElement.cpp:433:29
    #4 0x7f8aa55f00be in mozilla::dom::HTMLInputElement::AfterSetFilesOrDirectories(bool) /home/sourc7/git/gecko-dev-asan/dom/html/HTMLInputElement.cpp:2511:5
    #5 0x7f8aa561e661 in mozilla::dom::DispatchChangeEventCallback::Callback(nsresult, FallibleTArray<RefPtr<mozilla::dom::BlobImpl> > const&) /home/sourc7/git/gecko-dev-asan/dom/html/HTMLInputElement.cpp:234:20
    #6 0x7f8aa55c9ccb in mozilla::dom::HTMLInputElement::nsFilePickerShownCallback::Done(short) /home/sourc7/git/gecko-dev-asan/dom/html/HTMLInputElement.cpp:559:13
    #7 0x7f8aa7bb8e9f in nsFilePickerProxy::Recv__delete__(mozilla::dom::MaybeInputData const&, short const&) /home/sourc7/git/gecko-dev-asan/widget/nsFilePickerProxy.cpp:191:16
    #8 0x7f8a9fe561f3 in mozilla::dom::PFilePickerChild::OnMessageReceived(IPC::Message const&) /home/sourc7/git/gecko-dev-asan/objdir-ff-asan/ipc/ipdl/PFilePickerChild.cpp:186:28
    #9 0x7f8a9fc441e5 in mozilla::dom::PContentChild::OnMessageReceived(IPC::Message const&) /home/sourc7/git/gecko-dev-asan/objdir-ff-asan/ipc/ipdl/PContentChild.cpp:8336:32
    #10 0x7f8a9f96b45c in mozilla::ipc::MessageChannel::DispatchAsyncMessage(mozilla::ipc::ActorLifecycleProxy*, IPC::Message const&) /home/sourc7/git/gecko-dev-asan/ipc/glue/MessageChannel.cpp:2051:25
    #11 0x7f8a9f967af6 in mozilla::ipc::MessageChannel::DispatchMessage(IPC::Message&&) /home/sourc7/git/gecko-dev-asan/ipc/glue/MessageChannel.cpp:1978:9
    #12 0x7f8a9f96997a in mozilla::ipc::MessageChannel::RunMessage(mozilla::ipc::MessageChannel::MessageTask&) /home/sourc7/git/gecko-dev-asan/ipc/glue/MessageChannel.cpp:1826:3
    #13 0x7f8a9f96a2c1 in mozilla::ipc::MessageChannel::MessageTask::Run() /home/sourc7/git/gecko-dev-asan/ipc/glue/MessageChannel.cpp:1857:13
    #14 0x7f8a9e39ad5a in mozilla::RunnableTask::Run() /home/sourc7/git/gecko-dev-asan/xpcom/threads/TaskController.cpp:502:16
    #15 0x7f8a9e35640f in mozilla::TaskController::DoExecuteNextTaskOnlyMainThreadInternal(mozilla::detail::BaseAutoLock<mozilla::Mutex&> const&) /home/sourc7/git/gecko-dev-asan/xpcom/threads/TaskController.cpp:805:26
    #16 0x7f8a9e352c88 in mozilla::TaskController::ExecuteNextTaskOnlyMainThreadInternal(mozilla::detail::BaseAutoLock<mozilla::Mutex&> const&) /home/sourc7/git/gecko-dev-asan/xpcom/threads/TaskController.cpp:641:15
    #17 0x7f8a9e353358 in mozilla::TaskController::ProcessPendingMTTask(bool) /home/sourc7/git/gecko-dev-asan/xpcom/threads/TaskController.cpp:425:36
    #18 0x7f8a9e38f361 in operator() /home/sourc7/git/gecko-dev-asan/xpcom/threads/TaskController.cpp:135:37
    #19 0x7f8a9e38f361 in mozilla::detail::RunnableFunction<mozilla::TaskController::InitializeInternal()::$_0>::Run() /home/sourc7/git/gecko-dev-asan/xpcom/threads/nsThreadUtils.h:532:5
    #20 0x7f8a9e37599b in nsThread::ProcessNextEvent(bool, bool*) /home/sourc7/git/gecko-dev-asan/xpcom/threads/nsThread.cpp:1148:16
    #21 0x7f8a9e381e81 in NS_ProcessNextEvent(nsIThread*, bool) /home/sourc7/git/gecko-dev-asan/xpcom/threads/nsThreadUtils.cpp:466:10
    #22 0x7f8a9f974907 in mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate*) /home/sourc7/git/gecko-dev-asan/ipc/glue/MessagePump.cpp:85:21
    #23 0x7f8a9f7d6741 in RunInternal /home/sourc7/git/gecko-dev-asan/ipc/chromium/src/base/message_loop.cc:331:10
    #24 0x7f8a9f7d6741 in RunHandler /home/sourc7/git/gecko-dev-asan/ipc/chromium/src/base/message_loop.cc:324:3
    #25 0x7f8a9f7d6741 in MessageLoop::Run() /home/sourc7/git/gecko-dev-asan/ipc/chromium/src/base/message_loop.cc:306:3
    #26 0x7f8aa7ba9c3a in nsBaseAppShell::Run() /home/sourc7/git/gecko-dev-asan/widget/nsBaseAppShell.cpp:137:27
    #27 0x7f8aac8c8a5f in XRE_RunAppShell() /home/sourc7/git/gecko-dev-asan/toolkit/xre/nsEmbedFunctions.cpp:923:20
    #28 0x7f8a9f7d6741 in RunInternal /home/sourc7/git/gecko-dev-asan/ipc/chromium/src/base/message_loop.cc:331:10
    #29 0x7f8a9f7d6741 in RunHandler /home/sourc7/git/gecko-dev-asan/ipc/chromium/src/base/message_loop.cc:324:3
    #30 0x7f8a9f7d6741 in MessageLoop::Run() /home/sourc7/git/gecko-dev-asan/ipc/chromium/src/base/message_loop.cc:306:3
    #31 0x7f8aac8c7908 in XRE_InitChildProcess(int, char**, XREChildData const*) /home/sourc7/git/gecko-dev-asan/toolkit/xre/nsEmbedFunctions.cpp:755:34
    #32 0x55e150df0b2c in content_process_main /home/sourc7/git/gecko-dev-asan/browser/app/../../ipc/contentproc/plugin-container.cpp:57:28
    #33 0x55e150df0b2c in main /home/sourc7/git/gecko-dev-asan/browser/app/nsBrowserApp.cpp:327:18
    #34 0x7f8ab7ce8b24 in __libc_start_main (/usr/lib/libc.so.6+0x27b24)
    #35 0x55e150d417d8 in _start (/home/sourc7/git/gecko-dev-asan/objdir-ff-asan/dist/bin/firefox+0xa97d8)

The original report as published on Mozilla's Bugzilla, by Irvan Kurniawan. 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 a use-after-free: the HTMLInputElement retains a stale pointer to a Directory object after the page reloads, and later dereferences it.

Impact

The tab crashes, and the report suggests it may be a use-after-free that could potentially be exploited, but no code execution is demonstrated.

What the attacker needed

Firefox browser; User interaction with file dialog

How it was found

  1. Visit the testcase page with a directory file input.
  2. Hold down the Enter key.
  3. When the file open dialog appears, select a file.
  4. Click Open or press Enter.
  5. The tab crashes.

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 bug in Firefox where a file selection dialog is left open while the page reloads. The browser then tries to use information that has already been freed, which crashes the tab. It is like reading a note that has been shredded.

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 Irvan Kurniawan

View all

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