Heap Overflow in webGL PixelbyPixel
A heap overflow occurs in the WebGL blitFramebuffer implementation when user-controlled source and destination coordinates are used to calculate memory addresses without proper bounds checking. An attacker could potentially execute arbitrary code by crafting a malicious WebGL call.
- Fixed in 3 months
- Paid in 3 months
- Disclosed after 3 months
Created attachment 9174247
poc-vcrunitme.html
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:80.0) Gecko/20100101 Firefox/80.0
Steps to reproduce:
The crash happens at VCRUNTIME140!memcpy+0xa2 which is called by libGLESv2!rx::`anonymous namespace'::StretchedBlitNearest_PixelByPixel.
In function StretchedBlitNearest_PixelByPixel the destination address for memory write is calculated by:
uint8_t *destPixel = destData + writeRow * destRowPitch + writeColumn * destPixelStride + writeOffset;
From the above instruction writeRow and writeColumn can be controlled by the user input:
gl1.blitFramebuffer( 453, 17, 457, 21, 8400, 160, 8404, 164, gl1.STENCIL_BUFFER_BIT, gl1.NEAREST );
In the same function the source address for memory read is calculated by:
const uint8_t *sourcePixel = sourceData + readRow * sourceRowPitch + readColumn * srcPixelStride + readOffset;
The sourcePixel value can also be controlled by the user inputs readRow and readColumn.
Actual syntax for blitFramebuffer is:
void gl.blitFramebuffer(srcX0, srcY0, srcX1, srcY1,dstX0, dstY0, dstX1, dstY1, mask, filter);
User controlled values affecting source and destination addresses,
• writeRow = destY0
• writeColumn = destX0
• readRow = srcY0
• readColumn = srcX0
Additionally, the value for destRowPitch can also be modified from the below webgl function:
gl1.renderbufferStorage( gl1.RENDERBUFFER, gl1.DEPTH_STENCIL, 4, 4 );
Here the 3rd and the 4th parameter are width and height which are used for the calculation of destRowPitch.
From the values provided in the above mentioned blitFramebuffer function the source and the destination address can be modified as follows:
Register values at crash:
rax=00000150f9a04343 rbx=00000150f9a04343 rcx=0000000000000000
rdx=00000150fb671717 rsi=0000004d6d7fcfe8 rdi=0000004d6d7fd060
rip=00007ffe72bb1392 rsp=0000004d6d7fcb18 rbp=00000000000020d0
r8=0000000000000001 r9=00007ffe72bb0000 r10=00000150fb671717
r11=00000150f9a04343 r12=00000150fb671003 r13=00000000000000a0
r14=00000000000020d4 r15=0000004d6d7fd050
iopl=0 nv up ei pl nz na pe nc
cs=0033 ss=002b ds=002b es=002b fs=0053 gs=002b efl=00010202
VCRUNTIME140!memcpy+0xa2:
00007ffe`72bb1392 8808 mov byte ptr [rax],cl ds:00000150`f9a04343=??
From the above register values, rax and rbx contain the destination address (destPixel) modifiable by the user. rdx and r10 contain the source address (sourcePixel) modifiable by the user. Registers rbp, r13 and r14 contain the values of dstX0, dstY0 and dstX1 from blitFramebuffer function.
Actual results:
00 0000004d`6d7fcb18 00007ffe`58a31b93 VCRUNTIME140!memcpy+0xa2 [d:\agent\_work\2\s\src\vctools\crt\vcruntime\src\string\amd64\memcpy.asm @ 255]
01 (Inline Function) --------`-------- libGLESv2!rx::`anonymous namespace'::StretchedBlitNearest_PixelByPixel+0x145 [/builds/worker/checkouts/gecko/gfx/angle/checkout/src/libANGLE/renderer/d3d/d3d11/Blit11.cpp @ 124]
02 0000004d`6d7fcb20 00007ffe`58a31eaa libGLESv2!rx::`anonymous namespace'::StretchedBlitNearest+0x2f3 [/builds/worker/checkouts/gecko/gfx/angle/checkout/src/libANGLE/renderer/d3d/d3d11/Blit11.cpp @ 158]
03 0000004d`6d7fcc10 00007ffe`58a315c9 libGLESv2!rx::Blit11::copyAndConvertImpl+0x25a [/builds/worker/checkouts/gecko/gfx/angle/checkout/src/libANGLE/renderer/d3d/d3d11/Blit11.cpp @ 1271]
04 0000004d`6d7fcd30 00007ffe`58a31063 libGLESv2!rx::Blit11::copyAndConvert+0x199 [/builds/worker/checkouts/gecko/gfx/angle/checkout/src/libANGLE/renderer/d3d/d3d11/Blit11.cpp @ 1308]
05 0000004d`6d7fce40 00007ffe`58a55a41 libGLESv2!rx::Blit11::copyDepthStencilImpl+0x193 [/builds/worker/checkouts/gecko/gfx/angle/checkout/src/libANGLE/renderer/d3d/d3d11/Blit11.cpp @ 1211]
06 0000004d`6d7fcf20 00007ffe`58a40069 libGLESv2!rx::Renderer11::blitRenderbufferRect+0xb51 [/builds/worker/checkouts/gecko/gfx/angle/checkout/src/libANGLE/renderer/d3d/d3d11/Renderer11.cpp @ 0]
07 0000004d`6d7fd160 00007ffe`58a0207f libGLESv2!rx::Framebuffer11::blitImpl+0x3e9 [/builds/worker/checkouts/gecko/gfx/angle/checkout/src/libANGLE/renderer/d3d/d3d11/Framebuffer11.cpp @ 366]
08 0000004d`6d7fd250 00007ffe`589621c3 libGLESv2!rx::FramebufferD3D::blit+0x6f [/builds/worker/checkouts/gecko/gfx/angle/checkout/src/libANGLE/renderer/d3d/FramebufferD3D.cpp @ 286]
09 0000004d`6d7fd2d0 00007ffe`5893ea22 libGLESv2!gl::Framebuffer::blit+0x53 [/builds/worker/checkouts/gecko/gfx/angle/checkout/src/libANGLE/Framebuffer.cpp @ 1551]
0a 0000004d`6d7fd320 00007ffe`58afe9d9 libGLESv2!gl::Context::blitFramebuffer+0x162 [/builds/worker/checkouts/gecko/gfx/angle/checkout/src/libANGLE/Context.cpp @ 3640]
0b 0000004d`6d7fd3d0 00007ffe`1fe471d7 libGLESv2!gl::BlitFramebuffer+0xb9 [/builds/worker/checkouts/gecko/gfx/angle/checkout/src/libGLESv2/entry_points_gles_3_0_autogen.cpp @ 169]
0c 0000004d`6d7fd480 00007ffe`20ca1828 xul!mozilla::gl::GLContext::raw_fBlitFramebuffer+0x97 [/builds/worker/workspace/obj-build/dist/include/GLContext.h @ 2491]
0d (Inline Function) --------`-------- xul!mozilla::gl::GLContext::fBlitFramebuffer+0x46 [/builds/worker/checkouts/gecko/gfx/gl/GLContext.h @ 2477]
0e 0000004d`6d7fd530 00007ffe`20c753dc xul!mozilla::WebGLFramebuffer::BlitFramebuffer+0x978 [/builds/worker/checkouts/gecko/dom/canvas/WebGLFramebuffer.cpp @ 1516]
0f 0000004d`6d7fd6a0 00007ffe`20c432fe xul!mozilla::WebGL2Context::BlitFramebuffer+0x22c [/builds/worker/checkouts/gecko/dom/canvas/WebGL2ContextFramebuffers.cpp @ 65]
10 0000004d`6d7fd760 00007ffe`20c43024 xul!mozilla::ClientWebGLContext::Run<void (mozilla::HostWebGLContext::*)(int, int, int, int, int, int, int, int, unsigned int, unsigned int) const,&mozilla::HostWebGLContext::BlitFramebuffer,int &,int &,int &,int &,int &,int &,int &,int &,unsigned int &,unsigned int &>+0x28e [/builds/worker/checkouts/gecko/dom/canvas/ClientWebGLContext.cpp @ 313]
11 0000004d`6d7fd860 00007ffe`20866833 xul!mozilla::ClientWebGLContext::BlitFramebuffer+0x94 [/builds/worker/checkouts/gecko/dom/canvas/ClientWebGLContext.cpp @ 3433]
12 0000004d`6d7fd8e0 00007ffe`1ec91711 xul!mozilla::dom::WebGL2RenderingContext_Binding::blitFramebuffer+0x213 [/builds/worker/workspace/obj-build/dom/bindings/WebGL2RenderingContextBinding.cpp @ 1489]
13 0000004d`6d7fd9d0 00007ffe`1eb68917 xul!mozilla::dom::binding_detail::GenericMethod<mozilla::dom::binding_detail::NormalThisPolicy,mozilla::dom::binding_detail::ThrowExceptions>+0x101 [/builds/worker/checkouts/gecko/dom/bindings/BindingUtils.cpp @ 3225]
14 (Inline Function) --------`-------- xul!CallJSNative+0x9e [/builds/worker/checkouts/gecko/js/src/vm/Interpreter.cpp @ 485]
15 0000004d`6d7fda90 00007ffe`2264fffd xul!js::InternalCallOrConstruct+0x177 [/builds/worker/checkouts/gecko/js/src/vm/Interpreter.cpp @ 577]
16 (Inline Function) --------`-------- xul!InternalCall+0x95 [/builds/worker/checkouts/gecko/js/src/vm/Interpreter.cpp @ 640]
17 (Inline Function) --------`-------- xul!js::CallFromStack+0x95 [/builds/worker/checkouts/gecko/js/src/vm/Interpreter.cpp @ 644]
18 0000004d`6d7fdba0 00007ffe`226684d0 xul!Interpret+0x1add [/builds/worker/checkouts/gecko/js/src/vm/Interpreter.cpp @ 0]
19 (Inline Function) --------`-------- xul!js::RunScript+0x1e3 [/builds/worker/checkouts/gecko/js/src/vm/Interpreter.cpp @ 457]
1a 0000004d`6d7fe0f0 00007ffe`22668665 xul!js::ExecuteKernel+0x2b0 [/builds/worker/checkouts/gecko/js/src/vm/Interpreter.cpp @ 832]
1b 0000004d`6d7fe1b0 00007ffe`227102e7 xul!js::Execute+0x85 [/builds/worker/checkouts/gecko/js/src/vm/Interpreter.cpp @ 864]
1c 0000004d`6d7fe210 00007ffe`1ee035f8 xul!ExecuteScript+0x107 [/builds/worker/checkouts/gecko/js/src/vm/CompilationAndEvaluation.cpp @ 403]
1d 0000004d`6d7fe2b0 00007ffe`1ee03575 xul!JS_ExecuteScript+0x48 [/builds/worker/checkouts/gecko/js/src/vm/CompilationAndEvaluation.cpp @ 429]
1e 0000004d`6d7fe300 00007ffe`215240ec xul!nsJSUtils::ExecutionContext::ExecScript+0x25 [/builds/worker/checkouts/gecko/dom/base/nsJSUtils.cpp @ 337]
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 blitFramebuffer implementation failed to validate that the source and destination coordinates were within the bounds of the renderbuffers, leading to out-of-bounds memory access.
Impact
A malicious webpage could cause a heap overflow, potentially leading to arbitrary code execution or a browser crash.
What the attacker needed
Victim visits a malicious webpage; Browser supports WebGL2
How it was found
- Create a WebGL2 context and a renderbuffer with a small size (e.g., 4x4).
- Call blitFramebuffer with large source and destination coordinates that exceed the renderbuffer dimensions.
- The browser crashes due to a heap overflow in the memcpy operation.
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.
WebGL lets websites draw 3D graphics using the graphics card. A function called blitFramebuffer copies pixels from one buffer to another, but the code that calculates where to write the pixels did not check if the coordinates were within the buffer. This allowed a malicious webpage to write data outside the intended memory area, which could crash the browser or potentially let an attacker run their own code.
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.