Out of bounds write in ANGLE (CVE-2026-79131)
An out-of-bounds write exists in ANGLE's Metal backend when rewriting index buffers for primitive restart. An attacker could craft a WebGL2 index buffer with restart markers at the start to write up to 8 bytes of controlled data past the end of a GPU buffer.
Google Chrome
Originally disclosed on Chrome VRP
- Fix shipped in 38 days
Project Fortify, an experimental security project, has identified the following potential security issue. If you're a feature owner CC-ed on this bug, please do your best to review these reports. Please see https://chromium.googlesource.com/chromium/src/+/main/docs/security/ai-generated-security-bugs-faq.md for more information.
Overview: A potential out-of-bounds write vulnerability exists in the ANGLE Metal backend when rewriting index buffers for primitive restart. By crafting an index buffer with restart markers at the beginning, an attacker can cause the output buffer's bind offset to exceed the allocated space by 8 bytes, allowing arbitrary writes past the end of the MTLBuffer.
Affected files:
third_party/angle/src/libANGLE/renderer/metal/ProvokingVertexHelper.mmthird_party/angle/src/libANGLE/renderer/metal/shaders/rewrite_indices.metal
Estimated timestamp from git blame: 2021-07-06
1. Summary of the Issue (Meant for Human Triage)
A potential out-of-bounds (OOB) write vulnerability has been identified in ANGLE's Metal backend within ProvokingVertexHelper::preconditionIndexBuffer. Specifically, the output MTLBuffer allocation is sized based on the aggregate (count / perPrim) * perPrim index count. However, during the execution of primitive-restart-delimited ranges, the compute shader fixIndexBuffer is bound using an absolute offset: clippedRange.begin << indexTypeShift.
When an attacker crafts an ELEMENT_ARRAY_BUFFER with primitive-restart markers at the very beginning, the start of the rendered range is shifted past firstIndex. If the restart markers shift the beginning offset by b indices (e.g., b = 2) while the total count satisfies count ≡ b (mod perPrim), the compute shader writes up to (perPrim - 1) * indexSize bytes beyond the end of the allocated MTLBuffer. Because the writes are performed using raw Metal device uint * pointers without bounds-checking, this results in an out-of-bounds memory write in the GPU process.
This issue is reachable by untrusted WebGL2 content running on macOS/iOS (where Metal is the default ANGLE backend). Because the Metal backend is compile-time excluded on Android, this is capped as a High (S1) severity sandbox/GPU process compromise. Note: As our agent tooling does not execute live code, the following steps and exploit vectors are suggested and theoretical based on rigorous static analysis.
2. Proof-of-Concept & Detailed Execution Flow
The following sequence traces the exact execution flow from the attacker's entry point to the code sink, leading to an 8-byte out-of-bounds write.
Phase 1: Context Setup and Preconditions
- WebGL2 Initialization: An attacker creates a WebGL2 context on macOS. Chromium's passthrough command decoder unconditionally enables
GL_PRIMITIVE_RESTART_FIXED_INDEXfor WebGL2 contexts viaglEnableFn(gpu/command_buffer/service/gles2_cmd_decoder_passthrough.cc:1188-1192). - Shader Preparation: The attacker compiles and links a shader program containing a
flatvarying attribute (e.g.,flat out int v;).ProgramExecutableMtl::linkUpdateHasFlatAttributesdetects this and setsmProgramHasFlatAttributes = true(ProgramExecutableMtl.mm:704-712). - Trigger Requirement: With
gl::PrimitiveMode::Triangles,mProgramHasFlatAttributes == true, and ANGLE's defaultLastVertexConvention(State.cpp:370), the methodContextMtl::requiresIndexRewritereturnstrue(ContextMtl.mm:2159-2163).
Phase 2: The Malicious Payload & Draw Call Trigger
- Payload Crafting: The attacker crafts a
Uint32Arraycontaining exactly 24578 elements. Indices0and1are set to0xFFFFFFFF(the primitive restart marker). Indices2through24577are set to an arbitrary 32-bit payload (e.g.,0x41414141). - Triggering the Draw: The array is uploaded to the
ELEMENT_ARRAY_BUFFER. The attacker initiatesgl.drawElements(gl.TRIANGLES, 24578, gl.UNSIGNED_INT, 0);. This is explicitly orchestrated to be the first large flat-shaded indexed draw in the WebGL context.
Phase 3: Parsing the Index Ranges & Flawed Allocation
- Range Extraction:
BufferMtl::CalculateDrawIndexRanges<uint32_t>parses theELEMENT_ARRAY_BUFFER, skips the markers at indices 0 and 1, and returns a single contiguous range:drawIndexRanges = [{begin: 2, end: 24577}](BufferMtl.mm:476-501). - Allocation Sizing:
VertexArrayMtlpasses this range intoProvokingVertexHelper::preconditionIndexBufferwithcount=24578andfirstIndex=0. - Size Calculation: The code calculates the required size using the aggregate
count(ProvokingVertexHelper.mm:227-242):totalPrimCount = 24578 / 3 = 8192primitives.totalNewIndexCount = 8192 * 3 = 24576indices.checkedBufferSize = 24576 << 2 = 98304bytes.
- Buffer Allocation:
mIndexBuffers.allocate(context, 98304, &newBuffer)requests a buffer.BufferPool::allocaterounds up to 4-byte alignment (98304), and allocates a freshMTLBufferof exactly98304bytes (mtl_buffer_pool.mm:229-246). Grooming Note:98304is an exact multiple of the macOS Metal page size (16384 * 6), so the driver applies zero intra-page tail padding.
Phase 4: Absolute Offset Bind Calculation Flaw
- Offset Calculation Flaw: Inside
preconditionIndexBuffer, aforloop processes the range{begin: 2, end: 24577}(ProvokingVertexHelper.mm:263-296).indexCount = 24577 - 2 + 1 = 24576.primitiveCount = 24576 / 3 = 8192.- CRITICAL FLAW:
newBeginOffsetis computed using the absolute offsetclippedRange.begin << indexTypeShiftinstead of being relative tofirstIndex. Thus,newBeginOffset = 2 << 2 = 8bytes.
- Shader Dispatch: The compute encoder binds the output
MTLBuffer(buffer(1)) for writing at offsetnewBuffer.offset() + newBeginOffset = 0 + 8 = 8. The compute shader is dispatched with8192threads.
Phase 5: Unchecked OOB Write in Compute Shader
- Execution: The
fixIndexBuffercompute shader executes. For the final threadprim = 8191,onIndexandonOutIndexare set toprim * 3 = 24573(rewrite_indices.metal:267-269). - Reading Payload: The shader reads
READ_IDX(24573),READ_IDX(24574), andREAD_IDX(24575)relative to the input bind offset of8, successfully loading the attacker's0x41414141payload from the originalELEMENT_ARRAY_BUFFERelements at indices 24575, 24576, and 24577. - Out-of-Bounds Write: The
WRITE_IDXmacro performs a raw, bounds-uncheckeddevice uint *store (outIndexBufferUint32[_idx] = _val; _idx++;atrewrite_indices.metal:74-85).- Write 1:
outIndexBufferUint32[24573]maps to byte8 + (24573 * 4) = 98300(valid). - Write 2:
outIndexBufferUint32[24574]maps to byte8 + (24574 * 4) = 98304(OOB: 4 bytes past the 98304 byte allocation). - Write 3:
outIndexBufferUint32[24575]maps to byte8 + (24575 * 4) = 98308(OOB: 8 bytes past the 98304 byte allocation).
- Write 1:
- Result: Up to 8 bytes of fully attacker-controlled data are written past the end of the
MTLStorageModeSharedbuffer into adjacent mapped memory inside the GPU process.
Suggested Fix
In third_party/angle/src/libANGLE/renderer/metal/ProvokingVertexHelper.mm:276, the output offset calculation should be updated to be relative to firstIndex rather than an absolute bound, preventing the forward shift. For example:
newBeginOffset = (clippedRange.begin - firstIndex) << indexTypeShift;
Alternatively, checkedBufferSize (lines 239-242) must be adjusted to account for the maximum absolute end index of all provided drawIndexRanges rather than relying solely on the aggregate count.
3. Technical Verification Details (Automated Audit Logs)
Determination: verified —
ProvokingVertexHelper::preconditionIndexBuffersizes its output MTLBuffer from⌊count/3⌋·3indices but binds it at absolute offsetclippedRange.begin << indexTypeShiftfor each primitive-restart-delimited range, then dispatchesfixIndexBufferwhich writesprimitiveCount·3contiguous uint32s from that offset. When restart markers shiftclippedRange.beginpastfirstIndexbyb∈{1,2}whilecount≡b (mod 3), the compute kernel writes up to 8 bytes past the end of the MTLBuffer with attacker-chosen ELEMENT_ARRAY_BUFFER values. A-SERVER reachable via WebGL2 on macOS (ANGLE-Metal default).
Prior Critic Double-Check Verdict:
-
Severity: High (S1)
-
Brief Notes / Reasoning: The vulnerability accurately describes an 8-byte out-of-bounds (OOB) write in the ANGLE Metal backend within the GPU process. The root cause is a sizing and offset mismatch in
ProvokingVertexHelper::preconditionIndexBuffer: the outputMTLBufferallocation is sized based on the aggregate(count / 3) * 3elements (for Triangles), but thefixIndexBuffercompute shader is bound using the absolute offsetclippedRange.begin << indexTypeShift. When primitive restart markers are placed at the beginning of the buffer, the shader writes(indexCount / 3) * 3elements starting fromclippedRange.begin. Ifcount ≡ 2 (mod 3), the write ends at indexcount, which is 2 elements (8 bytes) beyond the allocated size.The attacker fully controls the payload (via the
ELEMENT_ARRAY_BUFFER) and the allocation size. By making the allocation size a multiple of the page size, the attacker avoids intra-page padding, causing the 8-byte write to reliably corrupt adjacent memory.Per the severity guidelines, a web-reachable GPU process memory corruption is typically Critical (S0) because the GPU process is unsandboxed on Android. However, because this is explicitly a
[Metal-backend]vulnerability, it is compile-time excluded on Android. Evaluated at the least-sandboxed platform on which it actually runs (macOS/iOS), the GPU process is sandboxed, so this constitutes a sandbox compromise, correctly capping the severity at High (S1). Furthermore, the Medium (S2) cap for the Metal shader compiler does not apply here; the OOB write occurs during the execution of a precompiled ANGLE compute kernel (fixIndexBuffer) writing to GPU memory, rather than during shader compilation.
Exhaustive Code Audit Ledger:
- Buffer Allocation Size Evaluation:
ProvokingVertexHelper.mm:227-244confirms sizing logic:C++ uint32_t totalPrimCount = primCountForIndexCount(indexBufferKey, count); uint32_t totalNewIndexCount = 0; ANGLE_CHECK_GL_MATH(context, indexCountForPrimCount(indexBufferKey, totalPrimCount, &totalNewIndexCount)); angle::CheckedNumeric<size_t> checkedBufferSize(totalNewIndexCount); checkedBufferSize <<= indexTypeShift; checkedBufferSize += newFirstIndexOffset; ANGLE_TRY(mIndexBuffers.allocate(context, checkedBufferSize.ValueOrDie(), &newBuffer)); - Absolute Offset Write Application:
ProvokingVertexHelper.mm:263-288shows the flaw:C++ DrawIndexRange clippedRange{std::max(range.begin, firstIndex), std::min(range.end, lastIndex)}; uint32_t indexCount = static_cast<uint32_t>(clippedRange.end - clippedRange.begin + 1); if (mode == newMode) { primitiveCount = indexCount / perPrimitiveIndexCount; newBeginOffset = clippedRange.begin << indexTypeShift; // ERROR: Absolute offset } encoder->setBufferForWrite(newBuffer.buffer(), newBuffer.offset() + newBeginOffset, 1); - Unchecked Shader Writes:
rewrite_indices.metal:74-85, 267-269confirms lack of bounds checking:METAL #define WRITE_IDX(_idx, _val) ({ if(outIndexBufferIsUint16) { outIndexBufferUint16[(_idx)] = _val; } if(outIndexBufferIsUint32) { outIndexBufferUint32[(_idx)] = _val; } _idx++; }) // ... case MtlFixIndexBufferKeyTriangles: onIndex = prim * 3; onOutIndex = prim * 3; break; - BufferPool Sizing & Alignment:
mtl_buffer_pool.mm:229-246confirms exact allocation without additional safety padding if a specific page-aligned size is requested beyondmInitialSize. - WebGL2 Default Enablement:
gpu/command_buffer/service/gles2_cmd_decoder_passthrough.cc:1188-1192confirmsGL_PRIMITIVE_RESTART_FIXED_INDEXis enabled by default for all WebGL2 contexts, guaranteeing reachability for uncompromised web content.
Evaluated with Chrome root at commit: b96d2ec58f4f5f92b540a723966b199d6e9951b4
Results so far have been promising, but there can be wrong deductions. Feel free to adjust as follows:
- If you are familiar with the severity guidelines, you may adjust the severity.
- If this is a false positive, and there's no work to be done, please close as WAI.
- If there is work to do here but not a vulnerability, please change the issue type to Task/Bug/FR.
Data from false positives will be used to improve accuracy over time. And please feel free to reach out to me directly if you have concerns or feedback on the project.
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 output buffer is sized from the total index count, but the compute shader is bound at an absolute offset based on the first index of the range, so restart markers at the start shift the write past the allocation.
Impact
An attacker could write up to 8 bytes of controlled data past a GPU buffer, potentially compromising the sandboxed GPU process on macOS/iOS; the Metal backend is not used on Android.
What the attacker needed
WebGL2 support on macOS/iOS; Victim visits a malicious web page; Shader with flat varying attribute
The fix
The output offset calculation should be made relative to firstIndex, or the buffer size should account for the maximum absolute end index of all ranges.
How it was found
- Create a WebGL2 context on macOS, which enables primitive restart by default.
- Compile a shader with a flat varying attribute to trigger index rewriting.
- Upload an index buffer with restart markers at the beginning and attacker-controlled data after them.
- Call drawElements with a count that causes the output buffer to be sized without accounting for the shifted offset.
- The compute shader writes past the end of the allocated buffer.
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.
WebGL2 lets web pages draw 3D graphics using the GPU. ANGLE is the part of the browser that translates WebGL2 commands into the GPU's native language. A bug in that translation could let a malicious web page write a small amount of data outside a GPU memory buffer, which might corrupt other GPU memory.
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.