Skip to content
Info disclosure Disclosed report Advanced CVE-2026-12308

bufferData(COPY_WRITE_BUFFER, ...) on a Kind::ElementArray buffer drops mIndexCache without rebuilding it, allowing index-validation bypass and uncramped gl_VertexID delivery to vertex shaders

A WebGL buffer of element-array kind could be re-filled through the COPY_WRITE_BUFFER target, which skipped rebuilding the index-validation cache and left it null. The validator then treated the draw as valid, so an out-of-range index reached the vertex shader as an unclamped gl_VertexID.

Mihalis Haatainen Follow

Originally disclosed on Mozilla

  • Fixed in 18 days
  • Paid in 2 months
  • Disclosed after 18 days

Created attachment 9584658 sibling.html

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:150.0) Gecko/20100101 Firefox/150.0

Steps to reproduce:

Actual results:

bufferData(COPY_WRITE_BUFFER, ...) on a Kind::ElementArray buffer drops mIndexCache without rebuilding it, allowing index-validation bypass and uncramped gl_VertexID delivery to vertex shaders

Filing fields

Field Value
Product Core
Component Graphics: CanvasWebGL
Type defect
Group Core Security (mark as security bug)
Version Firefox 150.0
Platform / OS All; tested on macOS
See Also bug 2037323, bug 1836705 (CVE-2023-5724), bug 1028891 (CVE-2014-1556)

Attach: sibling.html (the PoC).

Summary

This is a sibling to bug 2037323 (copyBufferSubData on EAB). Different code path, different fix surface, same impact class (validator bypass, uncramped gl_VertexID, OOB attribute fetches on non-robust drivers).

WebGLBuffer::BufferData allocates the index-validation cache only when its target argument is ELEMENT_ARRAY_BUFFER (WebGLBuffer.cpp line 120). However, a buffer with Kind::ElementArray is bindable to COPY_WRITE_BUFFER per WebGL2 spec section 5.1, and bufferData(COPY_WRITE_BUFFER, ...) is a valid call. When invoked with the COPY_WRITE_BUFFER target, the function:

  1. Skips the newIndexCache allocation (line 120 condition is false).
  2. Updates the GL VBO contents via gl->fBufferData(target, ...) at line 142 / 156.
  3. At line 164, executes mIndexCache = std::move(newIndexCache). Since newIndexCache was never assigned, mIndexCache becomes null.
  4. Skips the mIndexRanges.clear() at line 170 because the guard at line 166 (if (mIndexCache)) is false after the move; stale memoized ranges remain (not directly exploitable since the consumer short-circuits earlier, but worth noting).

The downstream consumer at WebGLContextDraw.cpp line 1006-1008:

C++
const auto globalMaxVertId =
    indexBuffer->GetIndexedFetchMaxVert(type, 0, indexCapacity);
if (!globalMaxVertId) return true;

When mIndexCache is null, GetIndexedFetchMaxVert returns Nothing() at line 333. The lambda short-circuits to "fetch valid". drawElements proceeds to the driver with no clamping, and the post-bufferData GPU index value reaches the vertex shader.

Reproduction

Attached PoC firefox-eab-cache-drop-via-copy-write.html. Self-contained, R32UI integer FBO for clean readback (no extension required).

Steps:

  1. Create vertex attribute buffer with 3 vec2 slots (maxVerts = 3).
  2. Create EAB X. bindBuffer(ELEMENT_ARRAY_BUFFER, X). mContent = Kind::ElementArray.
  3. bufferData(ELEMENT_ARRAY_BUFFER, [0, 1, 2]). mIndexCache(X) = [0, 1, 2]. GL VBO(X) = [0, 1, 2].
  4. WARM draw: drawElements(POINTS, 1, UNSIGNED_BYTE, 0). Validation populates mIndexRanges(X)[(UBYTE, 0, 1)] = Some(0). PoC reads back gl_VertexID = 0 from the integer FBO. No GL error.
  5. TRIGGER: bindBuffer(COPY_WRITE_BUFFER, X). Allowed because COPY_* doesn't restrict kind (ValidateCanBindToTarget lines 408-410).
  6. bufferData(COPY_WRITE_BUFFER, [42, 99, 99]). Inside WebGLBuffer::BufferData, target != ELEMENT_ARRAY_BUFFER, so the cache is dropped to null. GL VBO(X) becomes [42, 99, 99]. No GL error.
  7. BAD draw: bindBuffer(ELEMENT_ARRAY_BUFFER, X) then identical drawElements(POINTS, 1, UNSIGNED_BYTE, 0). PoC reads back gl_VertexID = 42. No GL error. The validator did not reject the draw despite the index 42 being out of bounds for the vertex attribute capacity of 3.

Test environment confirmed

  • macOS, Apple Silicon (Mac15,12, M3 MacBook Air)
  • Firefox 150.0
  • gl.getSupportedExtensions() does not advertise any robust_* extension
  • mNeedsIndexValidation engaged (default on macOS native GL path)

PoC output:

robust extensions advertised: (none)
warm draw: gl_VertexID echo = 0 (expect 0), gl error = 0x0
trigger bufferData(COPY_WRITE_BUFFER, [42,99,99]) gl error = 0x0
bad  draw: gl_VertexID echo = 42 (42 == bypass, 0 == clamp), gl error = 0x0
CONFIRMED: validator bypass via bufferData(COPY_WRITE_BUFFER, ...).

Impact

Confirmed:

  • Index validation bypass: drawElements with index 42 against a 3-vertex attribute completes without INVALID_OPERATION. The cache state corruption invariant mIndexCache mirrors VBO contents for EABs with mNeedsIndexValidation=true is violated.
  • Unclamped gl_VertexID = 42 reaches the vertex shader.

Plausible but not yet demonstrated on tested hardware:

  • Information disclosure: on drivers without KHR_robust_buffer_access_behavior, OOB vertex attribute fetches may return adjacent GPU memory rather than zero. Apple's path on M3 returned 0 for OOB attribute fetches in adjacent variants tested for bug 2037323. Linux/Mesa testing for bug 2037323 (Comment 1 and Comment 5 of that bug) did demonstrate non-zero leaked values run-to-run including recognizable float bit patterns. The same disclosure path should apply here since the post-bypass driver behavior is determined by the driver, not the trigger.

This is the same architectural pattern as bug 2037323 and the same impact ceiling. The CVE precedents (CVE-2023-5724, CVE-2014-1556) for index/draw validation gaps in the same area were rated sec-high.

Why this is not a duplicate of bug 2037323

Aspect bug 2037323 this filing
Trigger copyBufferSubData(COPY_READ, EAB) bufferData(COPY_WRITE_BUFFER, ...) on EAB-kind buffer
Cache failure mode mIndexCache retains pre-copy bytes (stale) mIndexCache is dropped to null entirely
Cache mirror after trigger stale (still readable, contents diverge from VBO) absent (!mIndexCache)
Validator path cache-hit returns memoized stale Some(maxVert) GetIndexedFetchMaxVert returns Nothing()
Consumer behavior validation passes against stale value consumer short-circuits to "fetch valid"
Fix location WebGL2Context::CopyBufferSubData (post-fCopyBufferSubData) WebGLBuffer::BufferData (target-check at line 120)
Suggested fix shape (in 2037323) OnBytesReplacedExternally() after the copy does NOT cover this path; see below

The fix suggested in bug 2037323 (if (writeBuffer->Content() == Kind::ElementArray) writeBuffer->OnBytesReplacedExternally() inside CopyBufferSubData) does not address this filing. The trigger here is bufferData, not copyBufferSubData, and the bug is the missing allocation of newIndexCache rather than a missing invalidation of an existing one. Both bugs need to be fixed for the cache invariant to hold.

Suggested fix

The check at WebGLBuffer.cpp line 120 conditions cache allocation on the call's target argument:

C++
if (target == LOCAL_GL_ELEMENT_ARRAY_BUFFER && needsIndexCache) {
  newIndexCache = UniqueBuffer::Take(malloc(...));
  ...
}

The intent is "only build the index cache for EABs". The bug is that the buffer's kind (which determines whether the buffer will be used as an EAB later) is decoupled from the target of the current bufferData call. The buffer can be Kind::ElementArray and the call's target can be COPY_WRITE_BUFFER simultaneously.

The fix is to gate on the buffer's kind, not on the call's target:

C++
const bool needsIndexCache = mContext->mNeedsIndexValidation ||
                             mContext->mMaybeNeedsLegacyVertexAttrib0Handling;
if (mContent == WebGLBuffer::Kind::ElementArray && needsIndexCache) {
  newIndexCache = UniqueBuffer::Take(malloc(AssertedCast<size_t>(size)));
  if (!newIndexCache) {
    mContext->ErrorOutOfMemory("Failed to alloc index cache.");
    return;
  }
  memcpy(newIndexCache.get(), uploadData, size);
  uploadData = newIndexCache.get();
}

Note mContent is the buffer's WebGL kind. By the time BufferData is called, the buffer has been bound through some target via ValidateBufferSelection, and the path that reaches here for a Kind::Undefined buffer first goes through BindBuffer → SetContentAfterBind, so mContent is set when the call reaches BufferData. (Caveat: see the secondary spec note below.)

Alternative minimal patch: keep the target check but add the kind check disjunctively:

C++
if ((target == LOCAL_GL_ELEMENT_ARRAY_BUFFER ||
     mContent == WebGLBuffer::Kind::ElementArray) && needsIndexCache) {

This preserves existing behavior for newly-created Undefined buffers while closing the COPY_WRITE_BUFFER path on already-Kind::ElementArray buffers.

Secondary note (separate, low-priority spec compliance)

While auditing, I also noticed WebGLBuffer::SetContentAfterBind (line 27-48) sets mContent = Kind::OtherData for COPY_READ_BUFFER and COPY_WRITE_BUFFER targets. Per WebGL 2.0 spec section 5.1, calling bindBuffer "with the target argument set to any buffer binding point except COPY_READ_BUFFER or COPY_WRITE_BUFFER" sets the WebGL buffer type. The current implementation deviates from spec by setting Kind for COPY_* targets. This is over-restrictive (closes a path the spec leaves open) rather than permissive, so it's not a security issue, but it's a real spec deviation. Filing separately if desired; mentioning here only because it touches the same kind-classification code path.

Notes for the security team

  • The PoC HTML is self-contained, reads back integer pixel data only, and does not attempt any privilege boundary crossing. It demonstrates the desync and the leaked gl_VertexID value.
  • I did not test on Linux/Mesa or other non-Apple drivers for this filing. The same driver-side OOB-fetch behavior documented in bug 2037323 Comment 1 and Comment 5 (run-to-run variance, recognizable float bit patterns) should apply here on those drivers; the bypass mechanism differs but the post-bypass shader execution is identical.
  • The existing bug 2037323 fix surface (OnBytesReplacedExternally after fCopyBufferSubData) does not cover this path. Both bugs need a fix.

Reporter info

Mihalis Haatainen (Bountyy Oy)

Expected results:

The original report as published on Mozilla's Bugzilla, by Mihalis Haatainen. 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 cache allocation in WebGLBuffer::BufferData is gated on the call's target argument rather than the buffer's kind, so a Kind::ElementArray buffer refilled via COPY_WRITE_BUFFER ends up with a null index cache.

Impact

The index-validation bypass and unclamped gl_VertexID delivery were confirmed, while out-of-bounds attribute fetches returning adjacent GPU memory are only plausible and were not demonstrated on the tested Apple hardware, which returned zero.

What the attacker needed

Victim visits a malicious web page; browser without robust buffer access extensions

The fix

The cache allocation should be gated on the buffer's kind rather than the call's target, or the kind check added disjunctively to the existing target check.

How it was found

  1. Create a vertex attribute buffer with three vec2 slots and an element-array buffer holding three small indices.
  2. Perform a warm drawElements call so validation records the valid index range and read back gl_VertexID.
  3. Bind the same buffer to COPY_WRITE_BUFFER and call bufferData with larger index values, which drops the index cache.
  4. Rebind the buffer to ELEMENT_ARRAY_BUFFER and repeat the identical drawElements call.
  5. Read back gl_VertexID and observe the out-of-range value instead of a clamped one, with no GL error.

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 a web page draw shapes on the GPU. Before drawing, Firefox checks that the list of vertex numbers (indices) stays inside the buffer, so the GPU never reads past the end. Here a particular way of refilling the buffer made Firefox forget its record of the valid range, and instead of rebuilding it, the check simply passed, so an out-of-range number was used.

What is Info disclosure?

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.

More by Mihalis Haatainen

View all

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

Information disclosure

The lesson behind this report.

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.