Double free in Release() / nsHostResolver.cpp
An AddressSanitizer build of Firefox reported a double free in the DNS host resolver's reference-counted record during shutdown. The reporter could not reproduce it and only has a stack trace, so the text does not establish what an attacker could do.
Originally disclosed on Mozilla
- Fixed in 2.6 years
- Paid in 2.7 years
- Disclosed after 2.6 years
With an ASAN build I observed a double free in the function Release().
Unfortunately not reproducible, so I only have a stack trace.
==27730==ERROR: AddressSanitizer: attempting double-free on 0x61300042b300 in thread T0:
#0 0x561d003835d2 in __interceptor_free /builds/worker/workspace/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:124:3
#1 0x7f45115e55fc in Release /builds/worker/workspace/build/src/netwerk/dns/nsHostResolver.cpp:193:1
#2 0x7f45115e55fc in AddrHostRecord::Release() /builds/worker/workspace/build/src/netwerk/dns/nsHostResolver.cpp:273
#3 0x7f45115fe52d in Release /builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/RefPtr.h:45:40
#4 0x7f45115fe52d in Release /builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/RefPtr.h:362
#5 0x7f45115fe52d in ~RefPtr /builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/RefPtr.h:76
#6 0x7f45115fe52d in ~nsBaseHashtableET /builds/worker/workspace/build/src/obj-firefox/dist/include/nsBaseHashtable.h:433
#7 0x7f45115fe52d in nsTHashtable<nsBaseHashtableET<nsGenericHashKey<nsHostKey>, RefPtr<nsHostRecord> > >::s_ClearEntry(PLDHashTable*, PLDHashEntryHdr*) /builds/worker/workspace/build/src/obj-firefox/dist/include/nsTHashtable.h:429
#8 0x7f451113547b in operator() /builds/worker/workspace/build/src/xpcom/ds/PLDHashTable.cpp:295:7
#9 0x7f451113547b in ForEachSlot<(lambda at /builds/worker/workspace/build/src/xpcom/ds/PLDHashTable.cpp:293:51)> /builds/worker/workspace/build/src/obj-firefox/dist/include/PLDHashTable.h:359
#10 0x7f451113547b in ForEachSlot<(lambda at /builds/worker/workspace/build/src/xpcom/ds/PLDHashTable.cpp:293:51)> /builds/worker/workspace/build/src/obj-firefox/dist/include/PLDHashTable.h:349
#11 0x7f451113547b in ~PLDHashTable /builds/worker/workspace/build/src/xpcom/ds/PLDHashTable.cpp:293
#12 0x7f451113547b in ClearAndPrepareForLength /builds/worker/workspace/build/src/xpcom/ds/PLDHashTable.cpp:309
#13 0x7f451113547b in PLDHashTable::Clear() /builds/worker/workspace/build/src/xpcom/ds/PLDHashTable.cpp:313
#14 0x7f45115eb69f in Clear /builds/worker/workspace/build/src/obj-firefox/dist/include/nsTHashtable.h:261:25
#15 0x7f45115eb69f in Clear /builds/worker/workspace/build/src/obj-firefox/dist/include/nsBaseHashtable.h:387
#16 0x7f45115eb69f in nsHostResolver::Shutdown() /builds/worker/workspace/build/src/netwerk/dns/nsHostResolver.cpp:785
#17 0x7f4511629fbd in nsDNSService::Shutdown() /builds/worker/workspace/build/src/netwerk/dns/nsDNSService2.cpp:713:10
#18 0x7f451162e5cb in nsDNSService::Observe(nsISupports*, char const*, char16_t const*) /builds/worker/workspace/build/src/netwerk/dns/nsDNSService2.cpp:1130:5
#19 0x7f4511159201 in nsObserverList::NotifyObservers(nsISupports*, char const*, char16_t const*) /builds/worker/workspace/build/src/xpcom/ds/nsObserverList.cpp:66:19
#20 0x7f451115d061 in nsObserverService::NotifyObservers(nsISupports*, char const*, char16_t const*) /builds/worker/workspace/build/src/xpcom/ds/nsObserverService.cpp:288:19
#21 0x7f45112f5dc1 in mozilla::ShutdownXPCOM(nsIServiceManager*) /builds/worker/workspace/build/src/xpcom/build/XPCOMInit.cpp:639:26
#22 0x7f451d787c6b in ScopedXPCOMStartup::~ScopedXPCOMStartup() /builds/worker/workspace/build/src/toolkit/xre/nsAppRunner.cpp:1313:5
#23 0x7f451d7a528b in operator() /builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/UniquePtr.h:486:5
#24 0x7f451d7a528b in reset /builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/UniquePtr.h:323
#25 0x7f451d7a528b in operator= /builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/UniquePtr.h:296
#26 0x7f451d7a528b in XREMain::XRE_main(int, char**, mozilla::BootstrapConfig const&) /builds/worker/workspace/build/src/toolkit/xre/nsAppRunner.cpp:4884
#27 0x7f451d7a6a70 in XRE_main(int, char**, mozilla::BootstrapConfig const&) /builds/worker/workspace/build/src/toolkit/xre/nsAppRunner.cpp:4940:21
#28 0x561d003b61ec in do_main /builds/worker/workspace/build/src/browser/app/nsBrowserApp.cpp:214:22
#29 0x561d003b61ec in main /builds/worker/workspace/build/src/browser/app/nsBrowserApp.cpp:293
#30 0x7f4530956b96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310
#31 0x561d002dbaa8 in _start (/root/firefox/firefox+0x2aaa8)
0x61300042b300 is located 0 bytes inside of 336-byte region [0x61300042b300,0x61300042b450)
freed by thread T0 here:
#0 0x561d003835d2 in __interceptor_free /builds/worker/workspace/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:124:3
#1 0x7f45115e52cc in nsHostRecord::Release() /builds/worker/workspace/build/src/netwerk/dns/nsHostResolver.cpp:193:1
#2 0x7f45115e5c9d in AddrHostRecord::~AddrHostRecord() /builds/worker/workspace/build/src/netwerk/dns/nsHostResolver.cpp:297:35
#3 0x7f45115e55fc in Release /builds/worker/workspace/build/src/netwerk/dns/nsHostResolver.cpp:193:1
#4 0x7f45115e55fc in AddrHostRecord::Release() /builds/worker/workspace/build/src/netwerk/dns/nsHostResolver.cpp:273
#5 0x7f45115fe52d in Release /builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/RefPtr.h:45:40
#6 0x7f45115fe52d in Release /builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/RefPtr.h:362
#7 0x7f45115fe52d in ~RefPtr /builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/RefPtr.h:76
#8 0x7f45115fe52d in ~nsBaseHashtableET /builds/worker/workspace/build/src/obj-firefox/dist/include/nsBaseHashtable.h:433
#9 0x7f45115fe52d in nsTHashtable<nsBaseHashtableET<nsGenericHashKey<nsHostKey>, RefPtr<nsHostRecord> > >::s_ClearEntry(PLDHashTable*, PLDHashEntryHdr*) /builds/worker/workspace/build/src/obj-firefox/dist/include/nsTHashtable.h:429
#10 0x7f451113547b in operator() /builds/worker/workspace/build/src/xpcom/ds/PLDHashTable.cpp:295:7
#11 0x7f451113547b in ForEachSlot<(lambda at /builds/worker/workspace/build/src/xpcom/ds/PLDHashTable.cpp:293:51)> /builds/worker/workspace/build/src/obj-firefox/dist/include/PLDHashTable.h:359
#12 0x7f451113547b in ForEachSlot<(lambda at /builds/worker/workspace/build/src/xpcom/ds/PLDHashTable.cpp:293:51)> /builds/worker/workspace/build/src/obj-firefox/dist/include/PLDHashTable.h:349
#13 0x7f451113547b in ~PLDHashTable /builds/worker/workspace/build/src/xpcom/ds/PLDHashTable.cpp:293
#14 0x7f451113547b in ClearAndPrepareForLength /builds/worker/workspace/build/src/xpcom/ds/PLDHashTable.cpp:309
#15 0x7f451113547b in PLDHashTable::Clear() /builds/worker/workspace/build/src/xpcom/ds/PLDHashTable.cpp:313
#16 0x7f45115eb69f in Clear /builds/worker/workspace/build/src/obj-firefox/dist/include/nsTHashtable.h:261:25
#17 0x7f45115eb69f in Clear /builds/worker/workspace/build/src/obj-firefox/dist/include/nsBaseHashtable.h:387
#18 0x7f45115eb69f in nsHostResolver::Shutdown() /builds/worker/workspace/build/src/netwerk/dns/nsHostResolver.cpp:785
#19 0x7f4511629fbd in nsDNSService::Shutdown() /builds/worker/workspace/build/src/netwerk/dns/nsDNSService2.cpp:713:10
#20 0x7f451162e5cb in nsDNSService::Observe(nsISupports*, char const*, char16_t const*) /builds/worker/workspace/build/src/netwerk/dns/nsDNSService2.cpp:1130:5
#21 0x7f4511159201 in nsObserverList::NotifyObservers(nsISupports*, char const*, char16_t const*) /builds/worker/workspace/build/src/xpcom/ds/nsObserverList.cpp:66:19
#22 0x7f451115d061 in nsObserverService::NotifyObservers(nsISupports*, char const*, char16_t const*) /builds/worker/workspace/build/src/xpcom/ds/nsObserverService.cpp:288:19
#23 0x7f45112f5dc1 in mozilla::ShutdownXPCOM(nsIServiceManager*) /builds/worker/workspace/build/src/xpcom/build/XPCOMInit.cpp:639:26
#24 0x7f451d787c6b in ScopedXPCOMStartup::~ScopedXPCOMStartup() /builds/worker/workspace/build/src/toolkit/xre/nsAppRunner.cpp:1313:5
#25 0x7f451d7a528b in operator() /builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/UniquePtr.h:486:5
#26 0x7f451d7a528b in reset /builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/UniquePtr.h:323
#27 0x7f451d7a528b in operator= /builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/UniquePtr.h:296
#28 0x7f451d7a528b in XREMain::XRE_main(int, char**, mozilla::BootstrapConfig const&) /builds/worker/workspace/build/src/toolkit/xre/nsAppRunner.cpp:4884
#29 0x7f451d7a6a70 in XRE_main(int, char**, mozilla::BootstrapConfig const&) /builds/worker/workspace/build/src/toolkit/xre/nsAppRunner.cpp:4940:21
#30 0x561d003b61ec in do_main /builds/worker/workspace/build/src/browser/app/nsBrowserApp.cpp:214:22
#31 0x561d003b61ec in main /builds/worker/workspace/build/src/browser/app/nsBrowserApp.cpp:293
#32 0x7f4530956b96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310
previously allocated by thread T0 here:
#0 0x561d00383953 in malloc /builds/worker/workspace/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:146:3
#1 0x561d003b817d in moz_xmalloc /builds/worker/workspace/build/src/memory/mozalloc/mozalloc.cpp:68:15
#2 0x7f45115edff1 in operator new /builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/mozalloc.h:131:10
#3 0x7f45115edff1 in nsHostResolver::ResolveHost(nsTSubstring<char> const&, unsigned short, mozilla::OriginAttributes const&, unsigned short, unsigned short, nsResolveHostCallback*) /builds/worker/workspace/build/src/netwerk/dns/nsHostResolver.cpp:903
#4 0x7f451162bbc9 in nsDNSService::AsyncResolveInternal(nsTSubstring<char> const&, unsigned short, unsigned int, nsIDNSListener*, nsIEventTarget*, mozilla::OriginAttributes const&, nsICancelable**) /builds/worker/workspace/build/src/netwerk/dns/nsDNSService2.cpp:849:13
#5 0x7f451162cc2d in nsDNSService::AsyncResolveNative(nsTSubstring<char> const&, unsigned int, nsIDNSListener*, nsIEventTarget*, mozilla::OriginAttributes const&, nsICancelable**) /builds/worker/workspace/build/src/netwerk/dns/nsDNSService2.cpp:913:10
#6 0x7f45179d76bc in nsHTMLDNSPrefetch::nsDeferrals::SubmitQueue() /builds/worker/workspace/build/src/dom/html/nsHTMLDNSPrefetch.cpp:376:31
#7 0x7f45179d85c0 in nsHTMLDNSPrefetch::nsDeferrals::OnStateChange(nsIWebProgress*, nsIRequest*, unsigned int, nsresult) /builds/worker/workspace/build/src/dom/html/nsHTMLDNSPrefetch.cpp:471:32
#8 0x7f4513309dcd in nsDocLoader::DoFireOnStateChange(nsIWebProgress*, nsIRequest*, int&, nsresult) /builds/worker/workspace/build/src/uriloader/base/nsDocLoader.cpp:1236:3
#9 0x7f4513308e47 in nsDocLoader::doStopDocumentLoad(nsIRequest*, nsresult) /builds/worker/workspace/build/src/uriloader/base/nsDocLoader.cpp:795:14
#10 0x7f451330598e in nsDocLoader::DocLoaderIsEmpty(bool) /builds/worker/workspace/build/src/uriloader/base/nsDocLoader.cpp:694:9
#11 0x7f45133059a7 in ChildDoneWithOnload /builds/worker/workspace/build/src/uriloader/base/nsDocLoader.h:201:5
#12 0x7f45133059a7 in nsDocLoader::DocLoaderIsEmpty(bool) /builds/worker/workspace/build/src/uriloader/base/nsDocLoader.cpp:697
#13 0x7f4513307bd3 in nsDocLoader::OnStopRequest(nsIRequest*, nsISupports*, nsresult) /builds/worker/workspace/build/src/uriloader/base/nsDocLoader.cpp:589:5
#14 0x7f4513308a1c in non-virtual thunk to nsDocLoader::OnStopRequest(nsIRequest*, nsISupports*, nsresult) /builds/worker/workspace/build/src/uriloader/base/nsDocLoader.cpp
#15 0x7f45114a38dc in mozilla::net::nsLoadGroup::RemoveRequest(nsIRequest*, nsISupports*, nsresult) /builds/worker/workspace/build/src/netwerk/base/nsLoadGroup.cpp:575:22
#16 0x7f4511e7a706 in mozilla::net::nsHttpChannel::ContinueOnStopRequest(nsresult, bool, bool) /builds/worker/workspace/build/src/netwerk/protocol/http/nsHttpChannel.cpp:7966:17
#17 0x7f4511e7901b in mozilla::net::nsHttpChannel::ContinueOnStopRequestAfterAuthRetry(nsresult, bool, bool, bool, mozilla::net::nsHttpTransaction*) /builds/worker/workspace/build/src/netwerk/protocol/http/nsHttpChannel.cpp:7775:10
#18 0x7f4511e7701e in mozilla::net::nsHttpChannel::OnStopRequest(nsIRequest*, nsISupports*, nsresult) /builds/worker/workspace/build/src/netwerk/protocol/http/nsHttpChannel.cpp:7708:12
#19 0x7f451149dbb2 in nsInputStreamPump::OnStateStop() /builds/worker/workspace/build/src/netwerk/base/nsInputStreamPump.cpp:655:16
#20 0x7f451149bdd5 in nsInputStreamPump::OnInputStreamReady(nsIAsyncInputStream*) /builds/worker/workspace/build/src/netwerk/base/nsInputStreamPump.cpp:403:21
#21 0x7f4511211676 in nsInputStreamReadyEvent::Run() /builds/worker/workspace/build/src/xpcom/io/nsStreamUtils.cpp:91:20
#22 0x7f451129ea26 in nsThread::ProcessNextEvent(bool, bool*) /builds/worker/workspace/build/src/xpcom/threads/nsThread.cpp:1162:14
#23 0x7f45112a4d18 in NS_ProcessNextEvent(nsIThread*, bool) /builds/worker/workspace/build/src/xpcom/threads/nsThreadUtils.cpp:474:10
#24 0x7f451222efea in mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate*) /builds/worker/workspace/build/src/ipc/glue/MessagePump.cpp:88:21
#25 0x7f451217488f in RunInternal /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:315:10
#26 0x7f451217488f in RunHandler /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:308
#27 0x7f451217488f in MessageLoop::Run() /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:290
#28 0x7f45194ad779 in nsBaseAppShell::Run() /builds/worker/workspace/build/src/widget/nsBaseAppShell.cpp:137:27
#29 0x7f451d5453d0 in nsAppStartup::Run() /builds/worker/workspace/build/src/toolkit/components/startup/nsAppStartup.cpp:271:30
#30 0x7f451d7a2ed7 in XREMain::XRE_mainRun() /builds/worker/workspace/build/src/toolkit/xre/nsAppRunner.cpp:4718:22
#31 0x7f451d7a4f44 in XREMain::XRE_main(int, char**, mozilla::BootstrapConfig const&) /builds/worker/workspace/build/src/toolkit/xre/nsAppRunner.cpp:4856:8
#32 0x7f451d7a6a70 in XRE_main(int, char**, mozilla::BootstrapConfig const&) /builds/worker/workspace/build/src/toolkit/xre/nsAppRunner.cpp:4940:21
#33 0x561d003b61ec in do_main /builds/worker/workspace/build/src/browser/app/nsBrowserApp.cpp:214:22
#34 0x561d003b61ec in main /builds/worker/workspace/build/src/browser/app/nsBrowserApp.cpp:293
SUMMARY: AddressSanitizer: double-free /builds/worker/workspace/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:124:3 in __interceptor_free
==27730==ABORTING
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 reference-counting mistake in the DNS host record, where the record is released once through its destructor and then released again when the resolver's table is cleared during shutdown.
Impact
The text only shows a crash under AddressSanitizer at shutdown; it does not claim any attacker-controlled path or memory-corruption exploit.
What the attacker needed
AddressSanitizer build; browser shutdown; not reproducible
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.
Firefox keeps a list of hostnames it is looking up, and each entry is shared between parts of the program using a counter called a reference count. When the counter reaches zero the entry is freed; a double free means the program frees the same memory twice, which can crash it or, in principle, let an attacker corrupt memory. Here it happened while the browser was shutting down, and the reporter could not make it happen again.
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.