Cross-origin GPU memory disclosure via WebGL2 TEXTURE_2D_ARRAY lazy-clear bypass on COLOR_ATTACHMENT1+
Firefox's lazy-clear for WebGL2 layered textures fails when the texture is attached to COLOR_ATTACHMENT1 or higher, because the clear targets a draw buffer that is disabled on the temporary framebuffer. A page could then read back uninitialised GPU memory that may contain pixel data written by other origins.
- Fixed in 35 days
- Paid in 2 months
- Disclosed after 35 days
Created attachment 9601524 webgl2_lazyclear_poc.zip
Description I found that Firefox's lazy-clear mechanism for WebGL2 layered textures silently fails when the texture is attached to COLOR_ATTACHMENT1 or higher. This allows a page to read uninitialized GPU memory, which on discrete GPUs (tested on NVIDIA RTX 4070 Super) contains pixel data from other origins that previously used WebGL.
Root cause
WebGLFramebuffer::ResolveAttachmentData() in dom/canvas/WebGLFramebuffer.cpp, line 907. When processing a layered texture (TEXTURE_2D_ARRAY with depth > 1) in the WebGL 2 path, it creates a temporary FBO via ScopedFramebuffer and iterates over uninitialized slices, attaching each layer to cur->mAttachmentPoint and calling glClearBufferfv(GL_COLOR, drawBuffer, zeros).
The problem is that a newly created FBO has default draw buffer configuration: index 0 = COLOR_ATTACHMENT0, index 1 = GL_NONE, index 2 = GL_NONE, etc. So when the texture's attachment point is COLOR_ATTACHMENT1, drawBuffer is 1, and the clear targets draw buffer index 1 which is GL_NONE on the temp FBO. The clear is silently discarded by the GL driver. But the code unconditionally calls mUninitializedSlices.reset() afterwards (line 922), marking the texture as initialized even though nothing was actually written.
After that, any readPixels from this texture returns raw GPU memory.
Note that the WebGL 1 path in the same function (lines 960-961) correctly calls gl->fDrawBuffers() before clearing, so this draw-buffer setup was known to be necessary but was missed in the WebGL 2 layered-texture branch.
Cross-origin impact
I built a PoC with two separate origins (http://127.0.0.1:8080 and http://127.0.0.2:8081) to confirm this crosses security boundaries. The setup:
-
Origin A (writer, 127.0.0.1:8080): allocates several large TEXTURE_2D_ARRAY textures filled with a known marker pattern (0xDEADBEEF as RGBA bytes), forces GPU upload, then deletes all textures and loses the WebGL context. The VRAM goes back to the GPU driver's free pool.
-
Origin B (reader, 127.0.0.2:8081): creates a completely separate WebGL2 context on a different origin, allocates a TEXTURE_2D_ARRAY with null data (should be zero), attaches it to COLOR_ATTACHMENT1, triggers the lazy-clear via checkFramebufferStatus, then reads pixels from each layer.
-
A harness page (127.0.0.1:8082) loads the writer in one iframe, waits for completion, then loads the reader in a second iframe from the other origin.
Reproduction on RTX 4070 Super (Windows, Firefox 152.0.3)
On first page load, all pixels come back as zero — the GPU has enough fresh VRAM to hand out. After refreshing the page once or twice, the reader starts picking up the writer's 0xDEADBEEF pattern in its pixels. This is because NVIDIA does not zero VRAM when recycling freed allocations. After a couple of allocation/free cycles, the driver starts handing back pages that still contain data from previous WebGL contexts, including contexts from other origins.
This is the realistic attack scenario: a user visits a site that uses WebGL (banking dashboards, medical imaging, maps, games), then navigates to an attacker's page. The attacker allocates textures via this bug and reads back pixel data the victim's site wrote to the GPU.
Tested with webgl.force-enabled both true and false — reproduces either way on default Firefox config. Tested the same PoC on Chromium on the same machine (same RTX 4070 Super, same OS) — does not reproduce. All pixels come back as zero every time. This is a Firefox-specific bug in its lazy-clear implementation, not a driver issue.
PoC files (see attached zip)
writer.html— sprays GPU memory from origin A (127.0.0.1:8080)reader.html— reads leaked memory from origin B (127.0.0.2:8081)harness.html— orchestrates the two iframes and shows verdictserver.py— Python server that serves each file on its own portserver.js— Node.js alternative (if Python is unavailable)run.bat— Windows launcher (double-click to start)
To reproduce:
- Unzip, run
python server.py(or double-clickrun.baton Windows) - Open
http://127.0.0.1:8082/in Firefox - Refresh the page 1-2 times
- The harness will show "CROSS-ORIGIN DATA LEAK CONFIRMED" when the reader detects the writer's secret pattern
The refresh is needed because NVIDIA recycles VRAM lazily — the first load allocates fresh zeroed memory, but after freeing and reallocating, the driver hands back previously-used pages without zeroing them.
Suggested fix
Before clearing on the temp FBO, set up draw buffers to enable the correct index. The WebGL 1 path already does this correctly at line 960-961. For the WebGL 2 layered path, something like:
const uint32_t drawBuffer = cur->mAttachmentPoint - LOCAL_GL_COLOR_ATTACHMENT0;
std::vector<GLenum> bufs(drawBuffer + 1, LOCAL_GL_NONE);
bufs[drawBuffer] = cur->mAttachmentPoint;
gl->fDrawBuffers(bufs.size(), bufs.data());
Or alternatively, always attach to COLOR_ATTACHMENT0 on the temp FBO and hardcode drawBuffer=0 in the clear call, since the temp FBO is thrown away immediately after clearing.
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 temporary framebuffer used for the clear has its draw buffer for the target attachment index set to GL_NONE, so the clear is discarded, yet the code still marks the slices as initialised.
Impact
A page could read pixel data left in GPU memory by other origins, though the leak only appeared after one or two refreshes and did not reproduce on Chromium.
What the attacker needed
Victim visits a WebGL-using site first; attacker page opened afterwards; discrete NVIDIA GPU; page refreshed once or twice
The fix
The temporary framebuffer's draw buffers should be set to enable the correct attachment index before clearing, as the WebGL 1 path already does, or the layer should always be attached to COLOR_ATTACHMENT0.
How it was found
- Serve the writer, reader and harness pages on separate local origins and open the harness page in Firefox.
- The harness loads the writer page in one iframe, which fills large layered textures with a marker pattern and then frees them.
- The harness then loads the reader page from a different origin in a second iframe.
- The reader allocates a layered texture with no data, attaches it to COLOR_ATTACHMENT1 and triggers the lazy-clear.
- Refresh the page once or twice so the driver recycles previously used video memory.
- The reader reads back its pixels and the harness reports a cross-origin leak when the marker pattern appears.
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 graphics card's memory is shared between everything that draws on screen. Normally the browser wipes a texture before handing it to a web page, so a page cannot see leftovers from another site. Here the wiping step silently did nothing in one specific setup, so a malicious page could read whatever was left in that memory.
What is Info disclosure?
Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.