Skip to content
Memory corruption Disclosed report Advanced CVE-2022-31737

heap-buffer-overflow in mozilla::gl::GLContext::raw_fReadPixels

A WebGL readPixels call in Firefox caused a heap buffer overflow: the graphics driver wrote more pixel data than the destination buffer could hold. An attacker could trigger a memory corruption crash, and potentially worse, by loading a crafted page that performs the read.

Atte Kettunen Follow

Originally disclosed on Mozilla

  • Fixed in 5 months
  • Paid in 6 months
  • Disclosed after 5 months

Created attachment 9253176 heap-buffer-overflow-mozilla-glGLContextraw_fReadPixels.html

Tested on: OS: Ubuntu 20.04 in VMware VM Firefox:

fuzzfetch --target firefox --os Linux --asan --fuzzing -n firefox
[2021-12-01 10:14:05] Identified task: https://firefox-ci-tc.services.mozilla.com/api/index/v1/task/gecko.v2.mozilla-central.latest.firefox.linux64-fuzzing-asan-opt
[2021-12-01 10:14:05] > Task ID: Frxzk0u7Qeu4nG7rilMWAQ
[2021-12-01 10:14:05] > Rank: 1638335107
[2021-12-01 10:14:05] > Changeset: 89800efd9e5cfcf0146767961a63d5c4e2a86e2c
[2021-12-01 10:14:05] > Build ID: 20211201050507
[2021-12-01 10:14:05] > Downloading: https://firefox-ci-tc.services.mozilla.com/api/queue/v1/task/Frxzk0u7Qeu4nG7rilMWAQ/artifacts/public/build/target.tar.bz2 (382.95MiB total)

prefs.js: fuzzing prefs.js generated with prefpicker, adding as an attachment.

I have reproduced the issue on my machine with/without the fuzzing prefs.js, and with/without Xvfb . Including prefs.js as an attachment to ensure reproducibility.

The write size can be changed by changing the canvas width. For example changing width and 300px, the write will be size 1200, 10px and it will be 40. 1px on fuzzfetch --fuzzing build will result to a

Hit MOZ_CRASH(Trying to run a non-debug fuzzing build.) at /builds/worker/checkouts/gecko/third_party/rust/neqo-crypto/src/aead_fuzzing.rs:19

I don't think it is related to the issue. Using 1px with regular asan-build downloaded without --fuzzing doesn't crash, but other tested values 10px up reproduced sameway on regular and fuzzing builds.

Reproducing:

$ ffpuppet -p ~/prefs.js -u ./heap-buffer-overflow-mozilla-glGLContextraw_fReadPixels.html ./firefox/firefox --xvfb -d
[2021-12-01 10:37:01] Launching Firefox...
[2021-12-01 10:37:13] Running Firefox (pid: 16680)...
[2021-12-01 10:37:14] Shutting down...
[2021-12-01 10:37:16] Firefox process is closed. (Reason: <Reason.ALERT: 0>)
[2021-12-01 10:37:16] Displaying logs...
===
=== Dumping 'log_ffp_asan_16655.log.16807.txt' (14.89KB)
===
=================================================================
==16807==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x7f59218c8c00 at pc 0x55ee081ba203 bp 0x7fff0cc77200 sp 0x7fff0cc769c0
WRITE of size 1600 at 0x7f59218c8c00 thread T0 (file:// Content)
    #0 0x55ee081ba202 in __interceptor_memcpy /builds/worker/fetches/llvm-project/llvm/projects/compiler-rt/lib/asan/../sanitizer_common/sanitizer_common_interceptors.inc:827:5

ASAN-trace(truncated, full trace as an attachment):

==16807==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x7f59218c8c00 at pc 0x55ee081ba203 bp 0x7fff0cc77200 sp 0x7fff0cc769c0
WRITE of size 1600 at 0x7f59218c8c00 thread T0 (file:// Content)
    #0 0x55ee081ba202 in __interceptor_memcpy /builds/worker/fetches/llvm-project/llvm/projects/compiler-rt/lib/asan/../sanitizer_common/sanitizer_common_interceptors.inc:827:5
    #1 0x7f59333e3ef8  (/usr/lib/x86_64-linux-gnu/dri/swrast_dri.so+0x320ef8)
    #2 0x7f59332997fc  (/usr/lib/x86_64-linux-gnu/dri/swrast_dri.so+0x1d67fc)
    #3 0x7f59333e42dc  (/usr/lib/x86_64-linux-gnu/dri/swrast_dri.so+0x3212dc)
    #4 0x7f59333e4b15  (/usr/lib/x86_64-linux-gnu/dri/swrast_dri.so+0x321b15)
    #5 0x7f59c93ecd70 in mozilla::gl::GLContext::raw_fReadPixels(int, int, int, int, unsigned int, unsigned int, void*) /builds/worker/workspace/obj-build/dist/include/GLContext.h:1568:5
    #6 0x7f59cc103cb1 in mozilla::WebGLContext::DoReadPixelsAndConvert(mozilla::webgl::FormatInfo const*, mozilla::webgl::ReadPixelsDesc const&, unsigned long, unsigned long, unsigned int) /builds/worker/checkouts/gecko/dom/canvas/WebGLContextGL.cpp
    #7 0x7f59cc106190 in mozilla::WebGLContext::ReadPixelsImpl(mozilla::webgl::ReadPixelsDesc const&, unsigned long, unsigned long) /builds/worker/checkouts/gecko/dom/canvas/WebGLContextGL.cpp:1238:7
    #8 0x7f59cc1041a7 in mozilla::WebGLContext::ReadPixelsInto(mozilla::webgl::ReadPixelsDesc const&, mozilla::Range<unsigned char> const&) /builds/worker/checkouts/gecko/dom/canvas/WebGLContextGL.cpp:962:10
    #9 0x7f59cbfe89b4 in mozilla::HostWebGLContext::ReadPixelsInto(mozilla::webgl::ReadPixelsDesc const&, mozilla::Range<unsigned char> const&) const /builds/worker/checkouts/gecko/dom/canvas/HostWebGLContext.h:646:22
...
    #53 0x55ee08252dfd in content_process_main(mozilla::Bootstrap*, int, char**) /builds/worker/checkouts/gecko/browser/app/../../ipc/contentproc/plugin-container.cpp:57:28
    #54 0x55ee08253228 in main /builds/worker/checkouts/gecko/browser/app/nsBrowserApp.cpp:327:18
    #55 0x7f59e54b50b2 in __libc_start_main /build/glibc-eX1tMB/glibc-2.31/csu/../csu/libc-start.c:308:16
    #56 0x55ee081a1ec9 in _start (/firefox/firefox+0x5cec9)

0x7f59218c8c00 is located 0 bytes to the right of 640000-byte region [0x7f592182c800,0x7f59218c8c00)
allocated by thread T0 (file:// Content) here:
    #0 0x55ee0821e632 in __interceptor_calloc /builds/worker/fetches/llvm-project/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cpp:138:3
    #1 0x7f59d39151cb in AllocateArrayBufferContents /builds/worker/checkouts/gecko/js/src/vm/ArrayBufferObject.cpp:459:11
    #2 0x7f59d39151cb in std::tuple<js::ArrayBufferObject*, unsigned char*> js::ArrayBufferObject::createBufferAndData<(js::ArrayBufferObject::FillContents)0>(JSContext*, unsigned long, js::AutoSetNewObjectMetadata&, JS::Handle<JSObject*>) /builds/worker/checkouts/gecko/js/src/vm/ArrayBufferObject.cpp:1351:18
    #3 0x7f59d390ceea in js::ArrayBufferObject::createZeroed(JSContext*, unsigned long, JS::Handle<JSObject*>) /builds/worker/checkouts/gecko/js/src/vm/ArrayBufferObject.cpp:1414:7
...
    #22 0x7f59ce5744aa in mozilla::dom::ScriptElement::MaybeProcessScript() /builds/worker/checkouts/gecko/dom/script/ScriptElement.cpp:118:18
    #23 0x7f59c91a2d6e in nsIScriptElement::AttemptToExecute() /builds/worker/workspace/obj-build/dist/include/nsIScriptElement.h:211:18

SUMMARY: AddressSanitizer: heap-buffer-overflow /builds/worker/fetches/llvm-project/llvm/projects/compiler-rt/lib/asan/../sanitizer_common/sanitizer_common_interceptors.inc:827:5 in __interceptor_memcpy
Shadow bytes around the buggy address:
...
==16807==ABORTING

The original report as published on Mozilla's Bugzilla, by Atte Kettunen. 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

Root cause

Likely the readPixels path passed a destination buffer sized for the requested width while the graphics driver wrote a larger amount of pixel data, so the copy overran the allocation.

Impact

The overflow writes past a heap allocation and aborts the content process; the report does not demonstrate code execution, only memory corruption.

What the attacker needed

Victim loads a crafted web page; WebGL available in the browser

How it was found

  1. Open the attached test page in an ASAN build of Firefox.
  2. The page performs a WebGL readPixels operation.
  3. The graphics driver copies pixel data into the buffer.
  4. AddressSanitizer reports a heap-buffer-overflow write.

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.

Web pages can draw with WebGL, a browser feature that uses the graphics card. When a page reads pixels back from that drawing surface, the browser asks the graphics driver to copy the data into a buffer. Here the driver copied more bytes than the buffer had room for, so it wrote past the end of the memory block, which is a memory corruption 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.

More by Atte Kettunen

View all

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