Use-after-free in mozilla::gl::GLContext::raw_fDrawElementsInstanced
A WebGL 2.0 conformance test triggered a heap-use-after-free in Firefox's GL context code, where a memcpy inside the graphics driver read memory that had already been freed. The crash was only seen in an ASAN fuzzing build and the reporter suspected a race condition, so the practical attacker impact is not established in the text.
Originally disclosed on Mozilla
- Fixed in 10 months
- Paid in 10 months
- Disclosed after 10 months
Created attachment 9258310 heap-use-after-free-interceptormemcpy-GLContextrawfDrawElementsInstanced.zip
Tested on:
OS: Ubuntu 20.04 running in VMware Workstation 16 VM.
Firefox: Downloaded with fuzzfetch
fuzzfetch --target firefox --os Linux --asan --fuzzing -n firefox
[2022-01-10 04:29:30] Identified task: https://firefox-ci-tc.services.mozilla.com/api/index/v1/task/gecko.v2.mozilla-central.latest.firefox.linux64-fuzzing-asan-opt [2022-01-10 04:29:30] > Task ID: Mm64vHQPRmii0o0Mq2DOHQ [2022-01-10 04:29:30] > Rank: 1641807422 [2022-01-10 04:29:30] > Changeset: b81970e39db444fa9a70eaf2e656f3e48c18a7c1 [2022-01-10 04:29:30] > Build ID: 20220110093702 [2022-01-10 04:29:32] > Downloading: https://firefox-ci-tc.services.mozilla.com/api/queue/v1/task/Mm64vHQPRmii0o0Mq2DOHQ/artifacts/public/build/target.tar.bz2
I couldn't reproduce the issue with debug build. I think there is some race condition that is not reachable with my laptop and debug build.
Sorry for the complex test case, but reducing it any further caused the test case to go unrealiable.
The test case is based on WebGL 2.0.0 conformance-suite gles3 frameblitter test(https://github.com/KhronosGroup/WebGL/blob/main/conformance-suites/2.0.0/deqp/functional/gles3/framebufferblit/default_framebuffer_02.html ) and requires group of files from the test suite. I have added all the required files to the attached .zip. Same files are included in the Firefox source checkout in /dom/canvas/test/webgl-conf/checkout/deqp/. As reproducing additionally requires a custom http-server, I thought that it would be easier to include all the files in a single .zip.
.zip includes: 20220110-044334_ffp_logs_cu0dh2z3: ffpuppet logs deqp: required test files goog: Google Closure library used by the conformance test suite js : Additional js files from the test suite firefox-ffpuppet-run.log: ffpuppet stdout/stderr heap-use-after-free-interceptormemcpy0.html: The repro-file prefs.js: Firefox prefs.js file, not required, but included to ensure reproducability report.txt: This file repro-server.py: python server that serves included files via http and 'no-cache'
On my machine the issue has reproduced reliably, but requires firefox to be run with xvfb. You can find ffpuppet run log from the attached .zip file.
Reproducing:
# 0. cd to the folder extracted from the zip
# 1. Start python server
python repro-server.py 8000 &
# 2. Run firefox with ffpuppet and included prefs.js
ffpuppet ~/Downloads/firefox/firefox -u http://localhost:8000/heap-use-after-free-interceptormemcpy0.html -p ./prefs.js --xvfb -d
# 3. Wait. On my laptop the issue reproduced typically in ~23s, or multiple of 23s, but under 2min.
ASAN-trace:
==1162948==ERROR: AddressSanitizer: heap-use-after-free on address 0x61200026ee40 at pc 0x55e691fc1354 bp 0x7fff2e8fff00 sp 0x7fff2e8ff6c0
READ of size 64 at 0x61200026ee40 thread T0 (Isolated Web Co)
#0 0x55e691fc1353 in __interceptor_memcpy /builds/worker/fetches/llvm-project/llvm/projects/compiler-rt/lib/asan/../sanitizer_common/sanitizer_common_interceptors.inc:827:5
#1 0x7fc24cf54554 (/usr/lib/x86_64-linux-gnu/dri/swrast_dri.so+0x811554)
#2 0x7fc24cf54aa9 (/usr/lib/x86_64-linux-gnu/dri/swrast_dri.so+0x811aa9)
#3 0x7fc24cf54ec9 (/usr/lib/x86_64-linux-gnu/dri/swrast_dri.so+0x811ec9)
#4 0x7fc24cf55746 (/usr/lib/x86_64-linux-gnu/dri/swrast_dri.so+0x812746)
#5 0x7fc24cf6dc3a (/usr/lib/x86_64-linux-gnu/dri/swrast_dri.so+0x82ac3a)
#6 0x7fc24c90e768 (/usr/lib/x86_64-linux-gnu/dri/swrast_dri.so+0x1cb768)
#7 0x7fc24c90d225 (/usr/lib/x86_64-linux-gnu/dri/swrast_dri.so+0x1ca225)
#8 0x7fc24c8f84a9 (/usr/lib/x86_64-linux-gnu/dri/swrast_dri.so+0x1b54a9)
#9 0x7fc24c9d7c58 (/usr/lib/x86_64-linux-gnu/dri/swrast_dri.so+0x294c58)
#10 0x7fc24c9d8f46 (/usr/lib/x86_64-linux-gnu/dri/swrast_dri.so+0x295f46)
#11 0x7fc26a28289f in mozilla::gl::GLContext::raw_fDrawElementsInstanced(unsigned int, int, unsigned int, void const*, int) /builds/worker/checkouts/gecko/gfx/gl/GLContext.h:2521:5
#12 0x7fc26a271b98 in mozilla::gl::GLContext::fDrawElementsInstanced(unsigned int, int, unsigned int, void const*, int) /builds/worker/checkouts/gecko/gfx/gl/GLContext.h:2504:5
#13 0x7fc26a271478 in mozilla::WebGLContext::DrawElementsInstanced(unsigned int, int, unsigned int, long, int)
...
0x61200026ee40 is located 0 bytes inside of 268-byte region [0x61200026ee40,0x61200026ef4c)
freed by thread T0 (Isolated Web Co) here:
#0 0x55e6920254c2 in __interceptor_free /builds/worker/fetches/llvm-project/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cpp:111:3
#1 0x7fc24c94f55f (/usr/lib/x86_64-linux-gnu/dri/swrast_dri.so+0x20c55f)
previously allocated by thread T0 (Isolated Web Co) here:
#0 0x55e692026197 in __interceptor_posix_memalign /builds/worker/fetches/llvm-project/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cpp:210:3
#1 0x7fc24c94f63d (/usr/lib/x86_64-linux-gnu/dri/swrast_dri.so+0x20c63d)
SUMMARY: AddressSanitizer: heap-use-after-free /builds/worker/fetches/llvm-project/llvm/projects/compiler-rt/lib/asan/../sanitizer_common/sanitizer_common_interceptors.inc:827:5 in __interceptor_memcpy
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 race in the WebGL draw path where a buffer backing a draw call is freed before the driver finishes copying from it.
Impact
The text only shows a crash in an ASAN fuzzing build under a virtual display; it does not claim that a normal user or attacker could reach it, and the reporter could not reproduce it in a debug build.
What the attacker needed
ASAN fuzzing build of Firefox; Linux with software GL driver; Firefox run under a virtual display; Local HTTP server serving test files
How it was found
- Extract the attached archive and change into that folder.
- Start the included Python HTTP server on a local port.
- Launch the instrumented Firefox under ffpuppet with the supplied preferences, the repro page URL and a virtual display.
- Wait; the crash typically appeared within about 23 seconds and under two minutes.
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.
When a program frees a block of memory and then keeps using it, that is a use-after-free. Here the graphics layer asked the driver to copy data from a buffer that had already been released, and a memory checker caught it. The report does not show that a normal user or attacker could trigger it outside a special instrumented build.
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.