Type Confusion in ANGLE (CVE-2026-13883)
A logic error in ANGLE's RewriteStructSamplers pass mishandles comma operators, causing type-confused AST nodes and malformed SPIR-V. An attacker could serve a crafted WebGL shader that reaches native Vulkan drivers, potentially causing memory corruption and sandbox escape.
Google Chrome
Originally disclosed on Chrome VRP
- Fix shipped in 3 months
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 without the security team.
Overview: A logic error in ANGLE's RewriteStructSamplers AST pass causes incorrect traversal of EOpComma operators during struct field resolution. This results in type-confused AST nodes, which subsequently causes OutputSPIRV to generate structurally invalid SPIR-V instructions. Passing this malformed SPIR-V to native Vulkan drivers can cause memory corruption in the driver's shader compiler, leading to a potential sandbox escape from WebGL.
Affected files:
third_party/angle/src/compiler/translator/tree_ops/RewriteStructSamplers.cppthird_party/angle/src/compiler/translator/ParseContext.cppthird_party/angle/src/compiler/translator/IntermNode.cppthird_party/angle/src/compiler/translator/spirv/OutputSPIRV.cpp
Estimated timestamp from git blame: 2024-07-30
Summary
A vulnerability exists in ANGLE's RewriteStructSamplers AST transformation pass. The function RewriteModifiedStructFieldSelectionExpression incorrectly assumes it can trace the base uniform of a struct field selection by repeatedly traversing the left child of binary nodes. When a comma operator (EOpComma) is present, it mistakenly traverses into the unevaluated left operand instead of the right operand. In release builds, an unhandled node type within a switch statement causes the comma operator to be silently dropped, leading to a type-confused AST and the generation of invalid SPIR-V bytecode.
Technical Details
- Incorrect Traversal: During the
RewriteStructSamplerspass, ANGLE needs to trace field selections (e.g.,(a[i++], b).s) back to their base uniform to extract samplers into global scope.RewriteModifiedStructFieldSelectionExpressionuses awhileloop that iterates usingiter = iter->getLeft()->getAsBinaryNode(). For anEOpCommanode,getLeft()returns the left operand (a[i++]), failing to traverse the semantically correct right operand (b) which holds the actual struct being accessed. This misidentifies the base uniform. - Silently Dropping Nodes: During the rebuild phase, the code iterates over the collected nodes bottom-up. The
switch (indexNode->getOp())block lacks acase EOpComma:, falling through todefault:, which callsUNREACHABLE(). In Chromium release builds,UNREACHABLE()expands to a no-op macro (ASSERT(false)becomestrue ? static_cast<void>(0) : ...). As a result, the comma node and its correct right-hand side are silently dropped, and the incorrectly identified left-hand uniform is substituted in its place. - AST Type Confusion: The parent
TIntermAggregatenode for an associated function call (e.g.,texture()) is not updated. Its constantTFunctionpointer still expects the original arguments (e.g.,sampler2D), but its child node now evaluates to the incorrectly substituted type (e.g.,samplerCube). - Malformed SPIR-V Generation: During SPIR-V generation,
OutputSPIRVTraverser::createImageTextureBuiltInuses the original function signature to determine coordinate requirements (e.g., expectingvec2coordinates for a 2D sampler) but loads the actual sampler ID from the rewritten, type-confused child node. This emits structurally invalid SPIR-V instructions, such asOpImageSampleImplicitLodattempting to sample aCubeimage using 2-component coordinates. - Validation Bypass: At the end of
OutputSPIRV, ANGLE callsASSERT(spirv::Validate(result)). BecauseASSERTis compiled out in release builds, ANGLE fails to catch the malformed SPIR-V and passes it directly tovkCreateShaderModule.
Potential Exploitation Scenario
An attacker can construct a malicious WebGL 2.0 fragment shader to trigger this vulnerability:
#version 300 es
precision highp float;
struct S1 { samplerCube s; };
struct S2 { sampler2D s; float pad; };
uniform S1 a[2];
uniform S2 b;
out vec4 fragColor;
int i = 0;
void main() {
// The comma operator survives folding due to the side effect in a[i++].
// The rewriter incorrectly extracts the sampler from 'a' instead of 'b'.
fragColor = texture((a[i++], b).s, vec2(0.5));
}
By serving this shader via WebGL, the attacker forces the GPU process to send malformed SPIR-V to the underlying proprietary Vulkan driver (e.g., AMD, NVIDIA, Intel, Adreno, Mali). These drivers' JIT compilers are highly complex and often assume the incoming SPIR-V is strictly valid. Encountering instructions with mismatched image and coordinate dimensions can break compiler invariants, leading to out-of-bounds reads/writes during register allocation or code emission. This provides a direct vector for Remote Code Execution and Sandbox Escape within the highly privileged GPU process.
Note: These steps describe a potential exploitation path; our automated tooling does not currently run the exploit code to verify the final outcome in the Vulkan driver.
Suggested Fix
- Modify
RewriteModifiedStructFieldSelectionExpressioninRewriteStructSamplers.cppto properly handleEOpComma. When tracing the base uniform, the traversal must correctly followgetRight()forEOpCommanodes, as the right operand determines the evaluated struct. - Ensure that the rebuilding phase of
RewriteModifiedStructFieldSelectionExpressionproperly reconstructs theEOpCommanode, preserving both the left-hand side effects and the right-hand struct access. - Consider enforcing a strict
spirv::Validatecheck in release builds before passing shaders to Vulkan drivers, or emitting a safe default shader if validation fails, to harden the GPU process against driver-level compiler vulnerabilities.
Evaluated with Chrome root at commit: f200f57a19490707ff8bc7aa5de3cbc443a3afad
Results so far have been promising, but there can be wrong deductions. If this proves to be a false positive, please close as WAI; 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 RewriteStructSamplers pass follows the left operand of a comma operator instead of the right, and its rebuild switch has no case for comma nodes, so release builds silently drop them and substitute the wrong uniform.
Impact
The malformed SPIR-V could break compiler invariants in proprietary Vulkan drivers, potentially leading to memory corruption and sandbox escape, though the report notes the exploit was not run to verify the final outcome.
What the attacker needed
Victim visits a malicious web page; browser uses ANGLE with Vulkan backend; release build without assertions
The fix
The traversal should follow the right operand for comma nodes, the rebuild should preserve the comma node, and release builds should validate SPIR-V before passing it to drivers.
How it was found
- Craft a WebGL 2.0 fragment shader that uses a comma expression to select a struct field.
- Serve the shader through WebGL so ANGLE's RewriteStructSamplers pass processes it.
- The pass misidentifies the base uniform and drops the comma node in release builds.
- OutputSPIRV emits structurally invalid SPIR-V instructions.
- The malformed SPIR-V is passed to the native Vulkan driver without validation.
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 web pages draw 3D graphics, and ANGLE is the part of the browser that translates shader code into a form the graphics driver understands. A mistake in that translation can produce invalid instructions that the driver is not prepared for, and a bad driver reaction could let a web page break out of its security sandbox.
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.