Heap-use-after-free with WebGPU copyTextureToTexture and Mesa drivers
A WebGPU texture was destroyed while commands that still referenced it were queued, causing a heap-use-after-free in Mesa's Vulkan driver. An attacker could trigger a browser crash by running a crafted WebGPU page.
Originally disclosed on Mozilla
- Fixed in 51 days
- Paid in 57 days
- Disclosed after 51 days
Created attachment 9527385
minimal-repro.html
Tested on:
-OS: Ubuntu 24.04
-Mesa: ASAN build Mesa 25.0.7 (git-742a20f48c). Also tested to reproduce on current newest for Ubuntu 24.04, Mesa 25.0.7.
-Firefox: fuzzfetch -a --fuzzing
'''
Version: 147.0a1
BuildID=20251114094637
SourceStamp=4e885473cb08ec97b42aa99ea83cc2485a463d31
'''
Reproducing file as an attachment.
I suspect this issue to be a race condition where texture.destroy frees the texture before commands from queue.submit have finished. If you put `sourceTexture.destroy()` in a setTimeout, it will crash with timeout 0, but anything >0 and it doesn't crash anymore.
ASAN-trace with ASAN-built Mesa:
'''
=================================================================
==541676==ERROR: AddressSanitizer: heap-use-after-free on address 0x7d1ff73685c8 at pc 0x7bfeade4fdc6 bp 0x7bfe80bcc0d0 sp 0x7bfe80bcc0c8
READ of size 4 at 0x7d1ff73685c8 thread T141
#0 0x7bfeade4fdc5 in vk_object_base_assert_valid /tmp/vulkan-build/mesa/build/../src/vulkan/runtime/vk_object.h:120:4
#1 0x7bfeade4fdc5 in lvp_image_from_handle /tmp/vulkan-build/mesa/build/../src/gallium/frontends/lavapipe/lvp_private.h:704:1
#2 0x7bfeade4fdc5 in handle_copy_buffer_to_image /tmp/vulkan-build/mesa/build/../src/gallium/frontends/lavapipe/lvp_execute.c:2363:4
#3 0x7bfeade4fdc5 in lvp_execute_cmd_buffer /tmp/vulkan-build/mesa/build/../src/gallium/frontends/lavapipe/lvp_execute.c:5057:10
#4 0x7bfeade28430 in lvp_execute_cmds /tmp/vulkan-build/mesa/build/../src/gallium/frontends/lavapipe/lvp_execute.c:5395:4
...
0x7d1ff73685c8 is located 8 bytes inside of 288-byte region [0x7d1ff73685c0,0x7d1ff73686e0)
freed by thread T73 here:
#0 0x5555556c37c6 in __interceptor_free _asan_rtl_:3
#1 0x7bffe3f9a6b0 in ash::device::Device::destroy_image::h4fe97e07efd3f066 /builds/worker/checkouts/gecko/third_party/rust/ash/src/device.rs:1153:9
#2 0x7bffe3f9a6b0 in wgpu_hal::vulkan::device::_$LT$impl$u20$wgpu_hal..Device$u20$for$u20$wgpu_hal..vulkan..Device$GT$::destroy_texture::h0c7c441f067e1be5 /builds/worker/checkouts/gecko/third_party/rust/wgpu-hal/src/vulkan/device.rs:1208:38
...
previously allocated by thread T73 here:
#0 0x5555556c3a64 in __interceptor_malloc _asan_rtl_:3
#1 0x7bfeadcc5735 in vk_alloc /tmp/vulkan-build/mesa/build/../src/vulkan/util/vk_alloc.h:48:11
#2 0x7bfeadcc5735 in vk_alloc2 /tmp/vulkan-build/mesa/build/../src/vulkan/util/vk_alloc.h:0:0
#3 0x7bfeadcc5735 in vk_zalloc2 /tmp/vulkan-build/mesa/build/../src/vulkan/util/vk_alloc.h:143:16
#4 0x7bfeadcc5735 in vk_image_create /tmp/vulkan-build/mesa/build/../src/vulkan/runtime/vk_image.c:141:7
#5 0x7bfeade5eb6a in lvp_image_create /tmp/vulkan-build/mesa/build/../src/gallium/frontends/lavapipe/lvp_image.c:69:12
#6 0x7bfeade5e74f in lvp_CreateImage /tmp/vulkan-build/mesa/build/../src/gallium/frontends/lavapipe/lvp_image.c:259:11
#7 0x7bffe3f98780 in ash::device::Device::create_image::hcef909c6d63cbbe9 /builds/worker/checkouts/gecko/third_party/rust/ash/src/device.rs:2596:9
...
'''
With system Mesa:
'''
==55338==ERROR: AddressSanitizer: SEGV on unknown address (pc 0x7bff32eb7cf4 bp 0x7bff2fa64910 sp 0x7bff2fa648b8 T122)
==55338==The signal is caused by a READ memory access.
==55338==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 0x7bff32eb7cf4 in util_run_tests ??:?
#1 0x7bff32eb9a8d in util_run_tests ??:?
#2 0x7bff32eb7982 in util_run_tests ??:?
#3 0x7bff32eb7ce8 in util_run_tests ??:?
#4 0x7bff32ccfffa in vk_icdGetInstanceProcAddr ??:?
#5 0x7bff32cd81f8 in vk_icdGetInstanceProcAddr ??:?
...
==55338==Register values:
rax = 0x00007f0ff7accce8 rbx = 0x0000000000000000 rcx = 0x0000000000000000 rdx = 0x0000000000000000
rdi = 0x00007f0ff7acc800 rsi = 0xe5e5e5e5e5e5e5e5 rbp = 0x00007bff2fa64910 rsp = 0x00007bff2fa648b8
r8 = 0x0000000000000001 r9 = 0x0000000000000000 r10 = 0xe5e5e5e5e5e5e5e5 r11 = 0x00007c6ff8238e50
r12 = 0x00007daff6f4e008 r13 = 0xe5e5e5e5e5e5e5e5 r14 = 0x0000000000000000 r15 = 0x00007f0ff7acc800
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/usr/lib/x86_64-linux-gnu/libvulkan_lvp.so+0x2b7cf4) (BuildId: 303ca66f5bb9d4347b8481428adecbb49e9ce623)
Thread T122 created by T74 here:
#0 0x5555556a7f01 in ___interceptor_pthread_create _asan_rtl_:3
#1 0x7bff32d763b4 in std::vector<unsigned char, std::allocator<unsigned char> >::_M_default_append(unsigned long) ??:?
#2 0x7bff32c8184a in ?? ??:0
#3 0x7bff32c83bcc in ?? ??:0
#4 0x7bff32cc8364 in vk_icdGetInstanceProcAddr ??:?
#5 0x7bff5ce306fd in ?? ??:0
#6 0x7bff5ce2d600 in ?? ??:0
#7 0x7bff5ce28af4 in ?? ??:0
#8 0x7bff5ce390f2 in vkCreateDevice ??:0:0
#9 0x7bffe3f78d40 in ash::instance::Instance::create_device::h459f9d1f4e71d6ca /builds/worker/checkouts/gecko/third_party/rust/ash/src/instance.rs:369:22
...
'''
WebGPU Info with ASAN-built Mesa:
'''
{
"navigator.gpu.requestAdapter({\"forceFallbackAdapter\":true})": {
"info": {
"architecture": "",
"description": "",
"device": "",
"isFallbackAdapter": true,
"subgroupMaxSize": 128,
"subgroupMinSize": 4,
"vendor": "",
"wgpuBackend": "Vulkan",
"wgpuDevice": 0,
"wgpuDeviceType": "Cpu",
"wgpuDriver": "llvmpipe",
"wgpuDriverInfo": "Mesa 25.0.7 (git-742a20f48c) (LLVM 15.0.7)",
"wgpuName": "llvmpipe (LLVM 15.0.7, 256 bits)",
"wgpuVendor": 65541
},
"features": [
"bgra8unorm-storage",
"core-features-and-limits",
"depth-clip-control",
"depth32float-stencil8",
"float32-filterable",
"indirect-first-instance",
"rg11b10ufloat-renderable",
"shader-f16",
"texture-compression-bc",
"texture-compression-bc-sliced-3d",
"timestamp-query"
],
"limits": {
"maxBindGroups": 8,
"maxBindGroupsPlusVertexBuffers": 24,
"maxBindingsPerBindGroup": 1000,
"maxBufferSize": 1073741824,
"maxColorAttachmentBytesPerSample": 32,
"maxColorAttachments": 8,
"maxComputeInvocationsPerWorkgroup": 1024,
"maxComputeWorkgroupSizeX": 1024,
"maxComputeWorkgroupSizeY": 1024,
"maxComputeWorkgroupSizeZ": 1024,
"maxComputeWorkgroupStorageSize": 32768,
"maxComputeWorkgroupsPerDimension": 65535,
"maxDynamicStorageBuffersPerPipelineLayout": 1000000,
"maxDynamicUniformBuffersPerPipelineLayout": 1000000,
"maxInterStageShaderVariables": 16,
"maxSampledTexturesPerShaderStage": 64,
"maxSamplersPerShaderStage": 64,
"maxStorageBufferBindingSize": 134217728,
"maxStorageBuffersPerShaderStage": 64,
"maxStorageTexturesPerShaderStage": 64,
"maxTextureArrayLayers": 2048,
"maxTextureDimension1D": 16384,
"maxTextureDimension2D": 16384,
"maxTextureDimension3D": 4096,
"maxUniformBufferBindingSize": 65536,
"maxUniformBuffersPerShaderStage": 64,
"maxVertexAttributes": 32,
"maxVertexBufferArrayStride": 2048,
"maxVertexBuffers": 16,
"minStorageBufferOffsetAlignment": 32,
"minUniformBufferOffsetAlignment": 32
}
}
}
'''
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 the texture was destroyed before the queued GPU commands that referenced it had finished executing, so the driver accessed freed memory.
Impact
A crafted WebGPU page could crash the browser process; the report does not claim code execution.
What the attacker needed
WebGPU support enabled; victim visits a crafted page
How it was found
- Open the attached minimal reproduction page in a fuzzing build of Firefox.
- Run the WebGPU copyTextureToTexture operation and then destroy the source texture.
- Observe the crash under AddressSanitizer.
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.
WebGPU lets a web page draw with the graphics card. The page can tell the browser to throw away a texture, but the graphics driver may still be using it in the background. If the texture is freed too early, the driver reads memory that no longer belongs to it, which crashes the browser.
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.