Out of bounds write in Skia (CVE-2026-7923)
A logic flaw in Skia's SkSL Raster Pipeline builder allows a peephole optimisation to incorrectly process multi-slot instructions during a partial stack discard, leading to a negative temporary stack depth. An attacker could then write attacker-controlled uniform data out-of-bounds, potentially achieving RCE in the GPU or Utility process.
Google Chrome
Originally disclosed on Chrome VRP
- Fix shipped in 30 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 without the security team.
Overview: A logic flaw in the SkSL Raster Pipeline builder allows a peephole optimization to incorrectly process multi-slot instructions during a partial stack discard. This results in a negative temporary stack depth, causing the stack pointer to walk backwards out-of-bounds. Subsequent instructions can then write attacker-controlled uniform data into adjacent memory, potentially leading to RCE in the GPU or Utility process.
Affected files:
third_party/skia/src/sksl/codegen/SkSLRasterPipelineBuilder.cpp
Estimated timestamp from git blame: 2023-06-28
The Vulnerability
In third_party/skia/src/sksl/codegen/SkSLRasterPipelineBuilder.cpp, the Builder::discard_stack(int32_t count) method attempts to optimize away unnecessary stack operations. When count == 1, it checks for a specific sequence (push, immediate-op, unmasked copy) by calling simplifyImmediateUnmaskedOp().
However, simplifyImmediateUnmaskedOp() contains a logic bug: it fails to verify that the count of slots being discarded matches the size of the multi-slot immediate operation it is optimizing. It only checks if immInstruction->fImmA == popInstruction->fImmA.
The Trigger
This can be triggered by an identity swizzle on a vectorized intrinsic that uses an immediate operation, such as float4 v; (v = abs(v)).xyz;.
v = abs(v)evaluates to a sequence ending withpush_slots(4 slots),bitwise_and_imm_int(4 slots), andcopy_stack_to_slots_unmasked(4 slots).- The
.xyzswizzle requires discarding 1 tail element, callingdiscard_stack(1). simplifyImmediateUnmaskedOp()matches the 4-slot sequence. Because it ignores thecount == 1parameter, it erroneously proceeds: it subtracts 4 from thepush_slotscount (making it 0) and pops thecopy_stack_to_slots_unmaskedinstruction off the list. It returnstrue, anddiscard_stack(1)returns early without emitting any instruction.- The CodeGenerator must then discard the remaining 3 slots of the expression statement via
discardExpression(3), callingdiscard_stack(3). - Because the previous instructions were modified, the optimization no longer matches, and a raw
discard_stackinstruction withfImmA = 3is appended to the stream.
This results in a net stack usage of -3 slots (0 slots pushed, 3 slots discarded).
Out-of-Bounds Write
By repeating this statement, an attacker can accumulate an arbitrarily large negative stack depth. During pipeline compilation (Program::makeStages):
- Assertions protecting stack depth (
SkASSERTF(current[stackID] >= 0)) and pointer boundaries (SkASSERT(tempStackPtr >= slots.stack.data())) are compiled out in production Release builds. stack_usage()returns negative values for the mismatcheddiscard_stackoperations, causingtempStackPtrto linearly walk backwards, out of its designated memory slab and into adjacent memory allocated within the sameSkArenaAlloc.- The attacker can follow the underflow with an operation that writes to the stack using raw pointers, such as reading an attacker-controlled uniform variable (
v = my_uniform;). - The
push_uniforminstruction initializes aUniformCtxstage. Crucially, it populatesctx->dstby casting the out-of-boundstempStackPtrdirectly to a rawfloat*. - During pipeline execution,
copy_uniformswrites the attacker's uniform data to this raw pointer, bypassing the 32-bitSkRPOffsetsafety mechanism used by other pipeline instructions.
Impact
The SkArenaAlloc slab often houses critical objects prior to the SkSL stack allocation, including MatrixRec data, uniform arrays, and instances of SkRasterPipelineBlitter (which contain vtables). By carefully crafting the stack underflow depth and the uniform payload, an attacker could overwrite these objects, hijack execution flow, and achieve arbitrary Remote Code Execution (RCE) and a Sandbox Escape from a compromised Renderer to the GPU Process or Utility Process.
Proposed Fix
In third_party/skia/src/sksl/codegen/SkSLRasterPipelineBuilder.cpp, simplifyImmediateUnmaskedOp must be updated to verify that the count passed to discard_stack exactly matches the slot count of the immediate operation. Alternatively, discard_stack should simply pass count as an argument to simplifyImmediateUnmaskedOp() to ensure validation.
bool Builder::simplifyImmediateUnmaskedOp(int count) {
// ...
if (immInstruction->fImmA == popInstruction->fImmA && immInstruction->fImmA == count) {
// ...
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 peephole optimisation function simplifyImmediateUnmaskedOp does not check that the number of slots being discarded matches the size of the multi-slot immediate operation it is optimising.
Impact
An attacker could overwrite critical objects in the SkArenaAlloc slab, hijack execution flow, and achieve arbitrary Remote Code Execution and a Sandbox Escape from a compromised Renderer to the GPU Process or Utility Process.
What the attacker needed
Ability to supply a crafted shader; Chrome Release build (assertions disabled)
The fix
The simplifyImmediateUnmaskedOp function should be updated to verify that the count passed to discard_stack exactly matches the slot count of the immediate operation, or discard_stack should pass count as an argument to simplifyImmediateUnmaskedOp.
How it was found
- Write a shader statement that applies an identity swizzle to a vectorised intrinsic using an immediate operation, such as float4 v; (v = abs(v)).xyz;.
- The swizzle triggers discard_stack(1), which incorrectly matches a 4-slot sequence and modifies the instruction stream.
- The code generator then discards the remaining 3 slots, appending a raw discard_stack instruction with fImmA = 3.
- Repeat the statement to accumulate an arbitrarily large negative stack depth.
- Follow the underflow with an operation that writes to the stack using raw pointers, such as reading an attacker-controlled uniform variable.
- During pipeline execution, copy_uniforms writes the attacker's uniform data to the out-of-bounds pointer.
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.
Skia is a graphics library used by Chrome. A bug in how it builds shader programs lets a crafted shader make the program's internal stack pointer go below zero. Later instructions then write data outside the intended memory area, which could let an attacker run their own code.
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.