Out-of-bound memory access in WebGL2 blitFramebuffer
A WebGL2 blitFramebuffer operation on a depth-stencil renderbuffer computes a source pixel offset using canvas dimensions instead of the renderbuffer's own width and height, so the offset can exceed the buffer. An attacker could read out-of-bounds memory and have those values written into the destination, leaking information.
- Fixed in 4 months
- Paid in 4 months
- Disclosed after 4 months
Created attachment 9341705
blit.html
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36
Steps to reproduce:
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/116.0
When accessing the POC file from the browser, an out-of-bounds error occurs, leading to the termination of the GPU process.
In a typical environment, it works well, but in a VM, it may need the "webgl.force-enabled" option set to true to be triggered.
Actual results:
An out-of-bound bug occurs when calculating the sourcePixel in the BlitD24S8ToD32F function.
This function is as follows.
'''javascript
for (int row = 0; row < destArea.height; ++row)
{
for (int column = 0; column < destArea.width; ++column)
{
ptrdiff_t offset = row * sourceRowPitch + column * srcPixelStride;
const float *sourcePixel = reinterpret_cast<const float *>(sourceData + offset);
float *destPixel =
reinterpret_cast<float *>(destData + row * destRowPitch + column * destPixelStride);
Depth32FStencil8ToDepth32F(sourcePixel, destPixel);
}
}
'''
When calculating the sourcePixel, the offset can be larger than the size of the sourceData, resulting in an out-of-bound bug.
'''javascript
sourceData = width*height*srcPixelStride
'''
- width and height are values that can be set in the renderbufferStorage API.
- srcPixelStride is set to 8 when using DEPTH32F_STENCIL8 foramt in the renderbufferStorage API.
'''javascript
offset = row*sourceRowPitch+column+srcPixelStride
'''
- row = dstY0-dstY1
- dstY0 and dstY1 are values that can be set in the blitFramebuffer API.
- sourceRowPitch = width*srcPixelStride
- width is value that can be set in the renderbufferStorage API.
- srcPixelStride is set to 8 when using DEPTH32F_STENCIL8 foramt in the renderbufferStorage API.
- column = dstX0-dstX1
- dstX0 and dstX1 are values that can be set in the blitFramebuffer API.
The size of the sourceData is affected by the width and height values set by the renderbufferStorage API.
If there is no validation for row or column values when calculating offset, an out-of-bound bug will occur.
In fact, there is a check of values for row and column. But this check is wrong.
Row must be verified to be less than width and column less than height. At this time, width and height must be values set by the renderbufferStorage API.
However, row is compared to the width of the canvas object and column is compared to the height of the canvas object.
Therefore, if you set the width and height of the canvas object large, the offset increases a lot.
Expected results:
This bug allows for inserting values obtained through an out-of-bound read into the destPixel. Therefore, this results in information leak.
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
The bounds check for the source row and column compares them against the canvas width and height instead of the renderbuffer's width and height, so a large canvas allows an out-of-range source offset.
Impact
The out-of-bounds read could leak information into the destination buffer, and in the reported case it crashed the GPU process.
What the attacker needed
Victim opens a malicious web page; WebGL2 enabled (may need forcing in a VM)
How it was found
- Open the proof-of-concept page in the browser.
- In a virtual machine, enable the webgl.force-enabled option so WebGL runs.
- The out-of-bounds access occurs and the GPU process terminates.
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 copy part of one image buffer into another. The code that works out where to read from used the size of the visible canvas rather than the size of the buffer it was reading, so it could read past the end of that buffer. That lets a malicious page pull in memory it should not see and copy it into a place it can read back.
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.