Improper input validation in ANGLE (CVE-2026-91738)
ANGLE's Metal backend did not cap the visibility-result offset used for occlusion queries within a single render pass, so a WebGL2 page could repeatedly issue scissored clears to push the offset past the Metal device's maximum. When the command buffer was flushed, the invalid offset reached the driver call, which the report says could cause undefined GPU driver behaviour.
Google Chrome
Originally disclosed on Chrome VRP
- Fix shipped in 59 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: ANGLE's Metal backend fails to enforce a cap on visibility-result offsets during a single render pass. A WebGL2 page can repeatedly issue scissored clears inside an active occlusion query to drive the offset beyond the Metal device's limit. This causes a spec-invalid offset to reach [MTLRenderCommandEncoder setVisibilityResultMode:offset:] unchecked, potentially leading to undefined GPU driver behavior.
Affected files:
third_party/angle/src/libANGLE/renderer/metal/QueryMtl.hthird_party/angle/src/libANGLE/renderer/metal/mtl_occlusion_query_pool.mmthird_party/angle/src/libANGLE/renderer/metal/mtl_command_buffer.mmthird_party/angle/src/libANGLE/renderer/metal/ContextMtl.mmthird_party/angle/src/libANGLE/renderer/metal/FrameBufferMtl.mm
Estimated timestamp from git blame: 2020-08-04
1. Summary of the Issue (Meant for Human Triage)
A validating-layer gap exists in ANGLE's Metal backend where occlusion query visibility offsets can grow without bound within a single render pass. Under specific WebGL2 interaction scenarios involving scissored rendering clears inside an active occlusion query, ANGLE reuses the active render pass encoder without flushing the command buffer. This allows a malicious page to repeatedly allocate visibility-result offsets until the counter value exceeds the Metal device's maximum visibility query offset.
When the command buffer is eventually flushed, this spec-invalid offset is replayed directly to the underlying driver via -[MTLRenderCommandEncoder setVisibilityResultMode:offset:]. Apple's Metal specification explicitly mandates that the offset must be less than or equal to the device's maximum visibility query offset (e.g., 262,136 bytes on modern Apple architectures). Violating this constraint passes an invalid state to the driver, resulting in undefined GPU driver behavior. Because ANGLE correctly dynamically resizes the underlying MTLBuffer containing the pool, the primary risk is isolated to the GPU hardware/driver (e.g., driver table overflows) rather than a host-side out-of-bounds write.
2. Proof-of-Concept & Detailed Execution Flow
The following outlines the potential steps an attacker could use to trigger this vulnerability from a WebGL2 context (A-SERVER) on macOS:
- Query Initiation: The attacker initiates an occlusion query by calling
gl.beginQuery(gl.ANY_SAMPLES_PASSED, q). This translates toContextMtl::onOcclusionQueryBegin(third_party/angle/src/libANGLE/renderer/metal/ContextMtl.mm:2231), settingmOcclusionQuery. - Render Pass Setup: The attacker issues a draw call to start a render pass, such as
gl.drawArrays(gl.POINTS, 0, 1).ContextMtl::setupDraw(ContextMtl.mm:2513) notices the active query and callsstartOcclusionQueryInRenderPass(mOcclusionQuery, false)to allocate the first visibility offset. - Scissor Configuration: The attacker constrains the clear area by calling
gl.enable(gl.SCISSOR_TEST); gl.scissor(0, 0, 1, 1);. - The Malicious Loop: The attacker executes a tight loop calling
gl.clear(gl.COLOR_BUFFER_BIT)approximately 40,000 times. - Clear Routing and Draw Fallback: Due to the scissor constraint (
clearArea != renderArea),FramebufferMtl::clearImpl(FrameBufferMtl.mm:1374) falls back toclearWithDraw(:1431). - Encoder Reuse (Flush Bypass):
FramebufferMtl::clearWithDrawinvokesensureRenderPassStarted(FrameBufferMtl.mm:914), which early-returns the existing encoder becauseencoder->getSerial() == mStartedRenderEncoderSerial. This safely skips requesting a new encoder, thereby completely bypassingContextMtl::flushCommandBufferIfNeeded()on this execution path. The command stream accumulates indefinitely. - Query Suspension:
ClearUtils::clearWithDraw(mtl_render_utils.mm:1138) uses a stack-allocatedScopedDisableOcclusionQuery(:1169) to temporarily disable the query viacontextMtl->disableActiveOcclusionQueryInRenderPass(), pushing a disable command to the stream. - Query Resumption: The clear is performed via a triangle draw. The
ScopedDisableOcclusionQuerydestructor (mtl_render_utils.mm:245) then invokesContextMtl::restartActiveOcclusionQueryInRenderPass(), which callsstartOcclusionQueryInRenderPass(mOcclusionQuery, false). - Pool Allocation: This forwards to
OcclusionQueryPool::allocateQueryOffset(mtl_occlusion_query_pool.mm:39). This function correctly identifies if the pool size is insufficient and dynamically doubles theMTLBuffercapacity (:62), averting host OOB writes. It then hits theelsebranch (:79), adding a placeholder and callingquery->addAllocatedVisibilityOffset(). - Uncapped Growth:
VisibilityBufferOffsetsMtl::addOffset()(QueryMtl.h:55) executesmNumOffsets++without any cap or validation against the Metal device's visibility offset limits. - Intermediate Stream Accumulation: The loop continuously pushes newly incremented offsets to the intermediate command stream via
mRenderEncoder.setVisibilityResultMode(MTLVisibilityResultModeBoolean, query->getAllocatedVisibilityOffsets().back())(ContextMtl.mm:2291). The state cache misses each time because the mode toggles between Disabled (from the scoped disable) and Boolean. - Limit Exceeded: After roughly 32,768 iterations,
mNumOffsetstranslates to a calculated offset (mStartOffset + (mNumOffsets - 1) * 8) exceeding 262,136 bytes, the hardware limit formaxVisibilityQueryOffseton Apple7+ GPUs. - Flushing & Replaying: The attacker calls
gl.endQuery(gl.ANY_SAMPLES_PASSED); gl.flush();. This eventually triggersRenderCommandEncoder::endEncodingImpl(mtl_command_buffer.mm:1500), which binds the safely oversized pool buffer (:1533) and evaluates the deferred commands. - Specification Violation: The stream replays the commands through
SetVisibilityResultModeCmd(mtl_command_buffer.mm:374), which directly invokes[encoder setVisibilityResultMode:mode offset:offset]with the spec-invalid offset. This violates the Metal specification and invokes undefined driver behavior on the GPU.
Suggested Fix
ANGLE should enforce the Metal device's limit when allocating occlusion query offsets. In OcclusionQueryPool::allocateQueryOffset() or VisibilityBufferOffsetsMtl::addOffset(), ANGLE should compare the resulting offset against [MTLDevice maxVisibilityQueryOffset]. If the limit is reached, ANGLE should force an endEncoding() and flush the current render pass, or handle the query overflow gracefully according to WebGL spec requirements, thereby preventing spec-invalid calls to the driver.
3. Technical Verification Details (Automated Audit Logs)
Prior Critic Verdict:
Severity: Medium (S2)
Brief Notes / Reasoning: The report accurately identifies a validating-layer gap in ANGLE's Metal backend. A WebGL2 page can repeatedly call
gl.clear()inside an active occlusion query, causingmNumOffsetsto grow without bound, as the render encoder is reused (bypassingflushCommandBufferIfNeeded()) and the command buffer is not flushed. This allows an attacker to generate a visibility query offset that exceeds the Metal device's maximum visibility query offset. When flushed, this unbounded offset is passed to-[MTLRenderCommandEncoder setVisibilityResultMode:offset:], which explicitly violates Apple's Metal specification ('must be less than or equal to the maximum visibility query offset for the device').Because ANGLE correctly resizes
mRenderPassResultsPool(MTLBuffer) to accommodate the offset (currentOffset + kOcclusionQueryResultSize > mRenderPassResultsPool->size()), the hardware visibility write itself lands safely in-bounds of the GPU memory allocated for it. The only hazard is undefined behavior within the Metal driver (e.g., an internal driver table overflow), which is unconfirmed. Per the GPU validating-layer gap guidelines, a spec-invalid value reaching the driver from web content (A-SERVER) starts at High (S1) if it targets a sandboxed GPU process (the Metal backend is macOS/iOS only, where the GPU process is sandboxed). Since the consequence is unconfirmed and strictly driver-dependent (no host-memory or driver state corruption is demonstrated), it is discounted one level to Medium (S2). Escalate to High (S1) if driver state corruption on a shipping macOS driver is proven.
Raw Execution Logs & Code Reachability Proofs:
- The validator confirmed
VisibilityBufferOffsetsMtl::addOffset()atthird_party/angle/src/libANGLE/renderer/metal/QueryMtl.h:55-59unconditionally incrementsmNumOffsetswithout device-limit checks. - The validator confirmed
OcclusionQueryPool::allocateQueryOffset()atthird_party/angle/src/libANGLE/renderer/metal/mtl_occlusion_query_pool.mm:39-100dynamically doubles the buffer size usingBuffer::MakeBufferWithStorageModewhencurrentOffset + kOcclusionQueryResultSize > mRenderPassResultsPool->size(). This prevents out-of-bounds writes on the host side, localizing the issue to the GPU driver. - The validator confirmed that
ContextMtl::flushCommandBufferIfNeeded()(defined atContextMtl.mm:1801-1811) is exclusively called bygetRenderPassCommandEncoder,getBlitCommandEncoder, andgetComputeCommandEncoder. BecauseFramebufferMtl::ensureRenderPassStarted(FrameBufferMtl.mm:914-920) matchesmStartedRenderEncoderSerialand early-returns the existing encoder during the tightgl.clear()loop, the flush watchdog (needsFlushForDrawCallLimits()) is completely bypassed. - The validator confirmed
SetVisibilityResultModeCmdatmtl_command_buffer.mm:374-377blindly passes the fetchedoffsetto[encoder setVisibilityResultMode:mode offset:offset].
Critical Environmental Assumptions:
- The Metal backend is utilized by default on macOS (
[no-Android]). - The GPU process is sandboxed on macOS.
- Driver consequence of a spec-invalid
visibilityResultBufferoffset is undefined and dependent on the Apple Metal runtime implementation. A host-side OOB write is ruled out by the buffer resizing logic.
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
Likely the offset counter in the occlusion query pool was incremented without comparing the resulting offset against the Metal device's maximum visibility query offset, and the render encoder was reused so the command buffer was never flushed mid-loop.
Impact
The report says the invalid offset could cause undefined GPU driver behaviour, but the buffer is resized so no host-side out-of-bounds write occurs, and any driver consequence is unconfirmed and driver-dependent.
What the attacker needed
MacOS with Metal backend; WebGL2 support in the browser; victim loads attacker-controlled page
The fix
ANGLE should compare the resulting offset against the device's maximum visibility query offset and, when the limit is reached, end encoding and flush the render pass or handle the overflow per the WebGL spec.
How it was found
- Begin an occlusion query from the WebGL2 context.
- Issue a draw call so a render pass starts and the first visibility offset is allocated.
- Enable the scissor test and set a small scissor rectangle.
- Call clear on the colour buffer in a tight loop many thousands of times, which routes through the draw-based clear path and reuses the existing encoder.
- End the query and flush, causing the accumulated commands to be replayed to the driver with the oversized offset.
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 system to count whether any pixels pass a visibility test, and each such test needs a small slot in a results buffer. The browser code kept handing out new slots without checking the graphics card's stated maximum, so a page could ask for far more slots than allowed. The bad value was then passed to the graphics driver, which the report says may behave unpredictably, though no actual crash or memory corruption was shown.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.