Heap-use-after-free in Mesa with incomplete OcclusionQuery
A WebGPU test page begins an occlusion query in a render pass but never ends it, leaving the query incomplete. In Mesa's software Vulkan driver this leads to a heap-use-after-free, detected only under an AddressSanitizer build.
Originally disclosed on Mozilla
- Fixed in 41 days
- Paid in 49 days
- Disclosed after 41 days
Created attachment 9529205
test_232736_min_repro.html
Tested on:
- OS: Ubuntu 24.04
- wgpuDriverInfo: Mesa 25.0.7 (git-742a20f48c) (LLVM 15.0.7) ( Full WebGPU info as an attachment. )
- Firefox: 147.0a1, fetched with fuzzfetch -a --fuzzing
'''
Identified task: https://firefox-ci-tc.services.mozilla.com/api/index/v1/task/gecko.v2.mozilla-central.latest.firefox.linux64-fuzzing-asan-opt
> Task ID: GXvJD3xkQNatBqLrP0r8Wg
> Rank: 1764103614
> Changeset: 25d9b1462c784597c0fd024eac6cc48548867398
> Build ID: 20251125204654
> Downloading: https://firefox-ci-tc.services.mozilla.com/api/queue/v1/task/GXvJD3xkQNatBqLrP0r8Wg/artifacts/public/build/target.tar.xz (422.33MiB total)
'''
Reproducing file as an attachment.
Reproducing file creates an occlusion query pass and adds `pass.beginOcclusionQuery(0);` without `pass.endOcclusionQuery();`, leaving the query incomplete.
Chrome throws an error from incomplete occlusion query:
Render pass [RenderPassEncoder (unlabeled)] ended with incomplete occlusion query index 0 of [QuerySet (unlabeled)].
- While encoding [RenderPassEncoder (unlabeled)].End().
- While finishing [CommandEncoder (unlabeled)].
This issue doesn't cause a crash without ASAN build of Mesa. Didn't try with Valgrind or such. I can provide build instructions if needed.
ASAN-trace:(Full trace as an attachment)
'''
==367097==ERROR: AddressSanitizer: heap-use-after-free on address 0x7d6ff6eed888 at pc 0x7bff3279a84b bp 0x7bff2e2e0b30 sp 0x7bff2e2e0b28
READ of size 4 at 0x7d6ff6eed888 thread T112
#0 0x7bff3279a84a in lp_rast_end_query /tmp/vulkan-build/mesa/build/../src/gallium/drivers/llvmpipe/lp_rast.c:661:16
#1 0x7bff3279a84a in lp_rast_tile_end /tmp/vulkan-build/mesa/build/../src/gallium/drivers/llvmpipe/lp_rast.c:701:7
#2 0x7bff3279a84a in rasterize_bin /tmp/vulkan-build/mesa/build/../src/gallium/drivers/llvmpipe/lp_rast.c:1008:4
#3 0x7bff3279a84a in rasterize_scene /tmp/vulkan-build/mesa/build/../src/gallium/drivers/llvmpipe/lp_rast.c:1069:13
...
0x7d6ff6eed888 is located 520 bytes inside of 664-byte region [0x7d6ff6eed680,0x7d6ff6eed918)
freed by thread T110 here:
#0 0x5555556c3526 in __interceptor_free _asan_rtl_:3
#1 0x7bff32033484 in handle_reset_query_pool /tmp/vulkan-build/mesa/build/../src/gallium/frontends/lavapipe/lvp_execute.c:3044:10
#2 0x7bff32033484 in lvp_execute_cmd_buffer /tmp/vulkan-build/mesa/build/../src/gallium/frontends/lavapipe/lvp_execute.c:5100:10
#3 0x7bff32028430 in lvp_execute_cmds /tmp/vulkan-build/mesa/build/../src/gallium/frontends/lavapipe/lvp_execute.c:5395:4
#4 0x7bff3201780d in lvp_queue_submit /tmp/vulkan-build/mesa/build/../src/gallium/frontends/lavapipe/lvp_device.c:1649:7
#5 0x7bff31ecf75a in vk_queue_submit_final /tmp/vulkan-build/mesa/build/../src/vulkan/runtime/vk_queue.c:717:13
...
previously allocated by thread T110 here:
#0 0x5555556c38e9 in ___interceptor_calloc _asan_rtl_:3
#1 0x7bff32794be3 in llvmpipe_create_query /tmp/vulkan-build/mesa/build/../src/gallium/drivers/llvmpipe/lp_query.c:60:32
#2 0x7bff320372c8 in handle_begin_query /tmp/vulkan-build/mesa/build/../src/gallium/frontends/lavapipe/lvp_execute.c:2976:45
#3 0x7bff320372c8 in lvp_execute_cmd_buffer /tmp/vulkan-build/mesa/build/../src/gallium/frontends/lavapipe/lvp_execute.c:5094:10
#4 0x7bff32028430 in lvp_execute_cmds /tmp/vulkan-build/mesa/build/../src/gallium/frontends/lavapipe/lvp_execute.c:5395:4
...
'''
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 driver frees the query object when the query pool is reset while a rasteriser thread still holds a reference to it, so the incomplete query is read after being freed.
Impact
The issue does not cause a crash without an ASAN build of Mesa, so the practical impact is limited to memory-safety detection in instrumented builds.
What the attacker needed
Firefox fuzzing build; Mesa with ASAN; WebGPU enabled
How it was found
- Open the attached minimal reproduction HTML page in the fuzzing build of Firefox.
- The page creates a render pass and begins an occlusion query without ending it.
- The incomplete query is submitted, and the ASAN build of Mesa reports a heap-use-after-free.
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 graphics card to count how many pixels of a shape actually get drawn; this is called an occlusion query. The test page starts such a count but never finishes it, which is an invalid sequence. In a special debugging build of the graphics driver, this bad sequence makes the driver read memory it has already released, which is a memory safety bug.
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.