Skip to content
Memory corruption Advisory Advanced CVE-2024-7966

Out of bounds memory access in Skia (CVE-2024-7966)

A compromised renderer could bypass Skia's restrictions on SkSL shaders by nesting them inside a SkPicture, because the 'procs' object that disallows SkSL is not forwarded to nested objects. This allows arbitrary SkSL to be deserialised, and a flaw in the SkSL compiler's slot allocation leads to an out-of-bounds write in the GPU process, potentially enabling sandbox escape.

Renan Rios Follow

Originally disclosed on Chrome VRP

Bounty$10,000 High View original
  • Fix shipped in 47 days

Report description

OOB write in SkSLRasterPipelineBuilder


Bug location

Where do you want to report your vulnerability?

Chrome VRP – Report security issues affecting the Chrome browser. See program rules


The problem

Please describe the technical details of the vulnerability

Steps to reproduce

(Chromium)

  1. Apply the chromium.diff patch (there's a small binary array to register the glyph in the GPU process and draw it with a DrawSlugOp).
  2. Generate drawable_picture.skp.hh using the python script and add it to src/gpu/command_buffer/client.
  3. Build and run the browser (an access violation should happen after a few seconds, but maybe you will need to interact with something to trigger the PoC).

(Skia standalone)

  1. Apply the 'skia_DO_NOT_USE_IN_CHROMIUM.diff' to FuzzMain.cpp
  2. Generate the .skp file using the python script then run ./out/<..>/fuzz.

Vulnerability Details

In Chromium when registering a typeface in the GPU process via the font manager service we are currently allowed to write glyphs with SkPictures where deserialization is handled by Skia with restrictions to certain objects like SKSL shaders.

However a SkPicture also allows nested objects, and procs (the structure that disallows SKSL) is not being properly forwarded to them. So it's still quite trivial to create a situation where arbitrary SKSL is reachable again from a compromised renderer:

https://source.chromium.org/chromium/chromium/src/+/main:third_party/skia/src/core/SkPicture.cpp;l=186;drc=4268052f5025da8b928c9e59a04493b396acaad3;bpv=0;bpt=1 https://source.chromium.org/chromium/chromium/src/+/main:third_party/skia/src/core/SkPictureData.cpp;l=528;drc=4268052f5025da8b928c9e59a04493b396acaad3;bpv=1;bpt=1 https://source.chromium.org/chromium/chromium/src/+/main:third_party/skia/src/core/SkPictureData.cpp;l=545;drc=4268052f5025da8b928c9e59a04493b396acaad3 https://source.chromium.org/chromium/chromium/src/+/main:third_party/skia/src/core/SkPictureData.cpp;l=354;drc=2017cd8a8925f180257662f78eaf9eb93e8e394d https://source.chromium.org/chromium/chromium/src/+/main:third_party/skia/src/core/SkTypeface.cpp;l=250;drc=4268052f5025da8b928c9e59a04493b396acaad3 https://source.chromium.org/chromium/chromium/src/+/main:third_party/skia/src/utils/SkCustomTypeface.cpp;l=510;drc=4268052f5025da8b928c9e59a04493b396acaad3 https://source.chromium.org/chromium/chromium/src/+/main:third_party/skia/src/utils/SkCustomTypeface.cpp;l=485;drc=4268052f5025da8b928c9e59a04493b396acaad3 https://source.chromium.org/chromium/chromium/src/+/main:third_party/skia/include/core/SkDrawable.h;l=140;drc=4268052f5025da8b928c9e59a04493b396acaad3

(The procs object is already lost at this point).

For example, currently if we serialize a typeface inside a SkPicture, procs will not be forwarded during deserialization, therefore the new nested glyphs will be allowed to deserialize whatever skia flattenables they want.

In the SKSL compiler, looks like function return values do not count against the maximum slot size limit. But they do when building the raster pipeline (the CPU one, which is used by default with SkRuntimeColorFilter, even on Ganesh): (https://source.chromium.org/chromium/chromium/src/+/main:third_party/skia/src/sksl/codegen/SkSLRasterPipelineCodeGenerator.cpp;l=1190)

C++
SlotRange SlotManager::createSlots(std::string name,
                                   const Type& type,
                                   Position pos,
                                   bool isFunctionReturnValue) {
    size_t nslots = type.slotCount();
    ....

    SlotRange result = {fSlotCount, (int)nslots};
    fSlotCount += nslots; // <----- [1]
    return result;
}

So we can use some function in an expression that returns a big structure to make fSlotCount become large enough to overflow the total slot allocation size [2] which doesn't use safe integers. Now we have three unsafe spans [3] [4] [5] to work it. (https://source.chromium.org/chromium/chromium/src/+/main:third_party/skia/src/sksl/codegen/SkSLRasterPipelineBuilder.cpp;l=1672?q=allocateSlotData&ss=chromium)

C++
Program::SlotData Program::allocateSlotData(SkArenaAlloc* alloc) const {
    // Allocate a contiguous slab of slot data for immutables, values, and stack entries.
    const int N = SkOpts::raster_pipeline_highp_stride;
    const int scalarWidth = 1 * sizeof(float);
    const int vectorWidth = N * sizeof(float);
    const int allocSize = vectorWidth * (fNumValueSlots + fNumTempStackSlots) +
                          scalarWidth * fNumImmutableSlots; <---- [2]
    float* slotPtr = static_cast<float*>(alloc->makeBytesAlignedTo(allocSize, vectorWidth));
    sk_bzero(slotPtr, allocSize);

    // Store the temp stack immediately after the values, and immutable data after the stack.
    SlotData s;
    s.values    = SkSpan{slotPtr,        N * fNumValueSlots}; <--- [3]
    s.stack     = SkSpan{s.values.end(), N * fNumTempStackSlots}; <--- [4]
    s.immutable = SkSpan{s.stack.end(),  1 * fNumImmutableSlots}; <--- [5]
    return s;
}

The OOB write will happen later [6] with 's.immutable' while trying to copy shader constants to slots:

C++
    ...
    // Copy all immutable values into the immutable slots.
    for (const Instruction& inst : fInstructions) {
        if (inst.fOp == BuilderOp::store_immutable_value) {
            slots.immutable[inst.fSlotA] = sk_bit_cast<float>(inst.fImmA); <--- [6]
        }
    }
    ....

The SKSL compiler is currently a premium attack surface to research from an attacker's perspective, because looks like it's not ready yet to process untrusted input.

Thanks!

Please briefly explain who can exploit the vulnerability, and what they gain when doing so

A compromised renderer could use the GPU process to gain a wider attack surface and escape the sandbox.


The cause

What version of Chrome have you found the security issue in?

I'm testing in the "main" branch, so "dev" I guess

Is the security issue related to a crash?

Yes

Choose the type of vulnerability

Memory Corruption

How would you like to be publicly acknowledged for your report?

Renan Rios (@HyHy100)

The original report as published on the Chromium issue tracker, by Renan Rios (@HyHy100). Images and videos are our own copies; raw HTML is shown as text. View it on Chromium issue tracker.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 7 min read.

Context

This report concerns Skia, the 2D graphics library used by Chrome, and specifically the SkSL shader compiler and its raster pipeline code generator. Skia is reachable from the GPU process, which in Chrome's architecture is a privileged process relative to the renderer: a compromised renderer that can hand crafted data to the GPU process gains a wider attack surface and a path towards sandbox escape.

The feature at the centre of the report is the font manager service. When a typeface is registered in the GPU process through that service, glyphs can be written with SkPictures. Deserialisation of those pictures is handled by Skia, and Skia applies restrictions to certain objects, notably SkSL shaders, through a procs structure. The report shows that this restriction is not forwarded to nested objects, and that the SkSL compiler itself can be driven into an out of bounds write in SkSLRasterPipelineBuilder.

The issue was reported through the Chrome Vulnerability Reward Program, credited to Renan Rios (@HyHy100), rated high severity, and paid a bounty of 10000.00 USD. It was disclosed on 2024-09-09 as CVE-2024-7966, an out of bounds memory access in Skia.

Setup

The researcher tested against the main branch of Chromium, describing the version as "dev". Two reproduction paths are given: one inside Chromium and one against Skia standalone.

For the Chromium path the prerequisites are:

  1. A patch, chromium.diff, which contains a small binary array that registers the glyph in the GPU process and draws it with a DrawSlugOp.
  2. A generated header, drawable_picture.skp.hh, produced by a Python script and placed in src/gpu/command_buffer/client.
  3. A build of the browser, run so that the picture is exercised.

For the Skia standalone path the prerequisites are:

  1. The patch skia_DO_NOT_USE_IN_CHROMIUM.diff applied to FuzzMain.cpp.
  2. A .skp file generated by the Python script, then running ./out/<..>/fuzz.

Finding it

The starting observation is about trust boundaries. A compromised renderer can reach the GPU process through the font manager service and register a typeface whose glyphs are SkPictures. Skia deserializes those pictures with restrictions on certain object types, including SkSL shaders, enforced through the procs structure. The researcher noticed that a SkPicture can contain nested objects, and that procs is not properly forwarded to them. As a result, arbitrary SkSL becomes reachable again from a compromised renderer.

The report points at the relevant code paths in SkPicture.cpp, SkPictureData.cpp, SkTypeface.cpp, SkCustomTypeface.cpp and SkDrawable.h, and notes that the procs object is already lost at that point. Concretely, when a typeface is serialised inside a SkPicture, procs is not forwarded during deserialisation, so the new nested glyphs are allowed to deserialise whatever Skia flattenables they want.

The second observation is in the SkSL compiler. Function return values do not count against the maximum slot size limit in the compiler, but they do when building the raster pipeline, which is the CPU pipeline used by default with SkRuntimeColorFilter, even on Ganesh. In SkSLRasterPipelineCodeGenerator.cpp, SlotManager::createSlots increments the slot count for every slot range it creates:

C++
SlotRange SlotManager::createSlots(std::string name,
                                   const Type& type,
                                   Position pos,
                                   bool isFunctionReturnValue) {
    size_t nslots = type.slotCount();
    ....

    SlotRange result = {fSlotCount, (int)nslots};
    fSlotCount += nslots; // <----- [1]
    return result;
}

Because a function in an expression can return a large structure, fSlotCount can be made large enough to overflow the total slot allocation size, which is computed without safe integers.

Exploitation

Step 1: reach SkSL from a compromised renderer through a nested picture

Register a typeface in the GPU process via the font manager service, with glyphs carried in SkPictures. Because procs is not forwarded to nested objects during deserialisation, the nested glyphs can deserialise SkSL flattenables that the top level restriction was meant to block. This restores arbitrary SkSL as an input to the compiler from an untrusted renderer.

Step 2: overflow the slot allocation with a large function return value

Use a function in an expression that returns a big structure. Each call to createSlots adds type.slotCount() to fSlotCount (marked [1] above), and function return values are not counted against the maximum slot size limit in the compiler. The accumulated count overflows the allocation size computed in Program::allocateSlotData:

C++
Program::SlotData Program::allocateSlotData(SkArenaAlloc* alloc) const {
    // Allocate a contiguous slab of slot data for immutables, values, and stack entries.
    const int N = SkOpts::raster_pipeline_highp_stride;
    const int scalarWidth = 1 * sizeof(float);
    const int vectorWidth = N * sizeof(float);
    const int allocSize = vectorWidth * (fNumValueSlots + fNumTempStackSlots) +
                          scalarWidth * fNumImmutableSlots; <---- [2]
    float* slotPtr = static_cast<float*>(alloc->makeBytesAlignedTo(allocSize, vectorWidth));
    sk_bzero(slotPtr, allocSize);

    // Store the temp stack immediately after the values, and immutable data after the stack.
    SlotData s;
    s.values    = SkSpan{slotPtr,        N * fNumValueSlots}; <--- [3]
    s.stack     = SkSpan{s.values.end(), N * fNumTempStackSlots}; <--- [4]
    s.immutable = SkSpan{s.stack.end(),  1 * fNumImmutableSlots}; <--- [5]
    return s;
}

The allocation size at [2] is computed without safe integers, and the report describes [3], [4] and [5] as unsafe spans to work with. The report describes these three as unsafe spans to work with.

Step 3: trigger the out of bounds write

The write happens later, when shader constants are copied into the immutable slots:

C++
    ...
    // Copy all immutable values into the immutable slots.
    for (const Instruction& inst : fInstructions) {
        if (inst.fOp == BuilderOp::store_immutable_value) {
            slots.immutable[inst.fSlotA] = sk_bit_cast<float>(inst.fImmA); <--- [6]
        }
    }
    ....

The report states that the out of bounds write happens later at [6] with s.immutable, while copying shader constants to slots. The report classifies the result as memory corruption and confirms it is related to a crash.

Step 4: reproduce

In Chromium, apply chromium.diff, generate drawable_picture.skp.hh with the Python script and add it to src/gpu/command_buffer/client, then build and run the browser. An access violation should happen after a few seconds, though interaction with the page may be needed to trigger the PoC. In Skia standalone, apply skia_DO_NOT_USE_IN_CHROMIUM.diff to FuzzMain.cpp, generate the .skp file with the Python script, and run ./out/<..>/fuzz.

Root cause

There are two distinct mistakes. The first is a restriction that is not propagated: procs, which disallows SkSL during deserialisation, is not forwarded to nested objects inside a SkPicture, so a typeface serialised inside a picture can deserialise SkSL flattenables that the top level check was meant to reject. The second is an integer overflow in the raster pipeline slot allocation: function return values are not counted against the maximum slot size limit in the compiler, but they are counted when building the raster pipeline, and the total slot allocation size is computed without safe integers. The report describes the three spans as unsafe to work with, and the copy of immutable values writes out of bounds.

The report notes that the SkSL compiler is a premium attack surface from an attacker's perspective because it does not appear ready to process untrusted input.

Impact

A compromised renderer could use the GPU process to gain a wider attack surface and escape the sandbox. The vulnerability is an out of bounds memory access in Skia, classified as memory corruption, and the report confirms it is related to a crash. The rating is high severity.

Fix

The report does not describe a fix. Based on the root cause, the two things that need correcting are forwarding procs to nested objects during picture deserialisation so that SkSL cannot be reached through a nested typeface, and making the slot count and allocation size arithmetic safe, so that function return values cannot overflow the total slot allocation.

Variants to test

  1. Other nested flattenables inside SkPicture: serialise objects that carry their own deserialisation callbacks and check whether the top level restriction reaches them. A positive result is a nested object that deserializes a type the top level check was meant to block.
  2. Other paths into the SkSL compiler from the GPU process: look for entry points that accept shader-like data from the renderer and check whether the same slot accounting applies. A positive result is a shader that compiles but produces slot counts inconsistent with the allocation.
  3. Large function return values in expressions: construct shaders where a function returns a large structure and is used in an expression, and watch the slot count. A positive result is a slot count that wraps or exceeds the allocated slab.
  4. Other consumers of allocateSlotData: check whether the same overflow can be reached through SkRuntimeColorFilter and other runtime effect entry points on both CPU and GPU backends. A positive result is an out of bounds write in the immutable slot copy on any of those paths.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 16 min read.

What happened, in plain words

Chrome draws everything you see on a web page, text, images, buttons, with a piece of software called Skia. Skia is a 2D graphics library: it takes instructions like "draw this shape here in this colour" and turns them into pixels. Part of Skia is a small programming language for shaders, called SkSL. A shader is a short program that decides the colour of each pixel, for example to make a gradient or a glow effect.

Chrome is built from several processes. A process is a separate running program with its own memory. The renderer process turns a web page into something that can be drawn, and the GPU process talks to the graphics card and does the actual drawing. The renderer is treated as less trustworthy than the GPU process: if an attacker manages to take over the renderer (for example through a bug in how a page is parsed), the design of Chrome should still stop them from taking over the whole computer. The GPU process is more privileged, so reaching it from a compromised renderer is a step towards escaping that protection, which is called the sandbox.

This report shows two separate mistakes: a restriction that is not passed down to nested objects, and an arithmetic overflow in the SkSL compiler's memory planning. Writing outside the intended memory is called an out of bounds write, and it is a form of memory corruption: the program's own data gets damaged, and an attacker may be able to steer that damage into running their own code.

The first mistake is about a restriction that is not passed down to nested objects. The second is an arithmetic overflow in the SkSL compiler's memory planning. The report was filed through Google's Chrome Vulnerability Reward Program, credited to Renan Rios (@HyHy100), rated high severity, paid a bounty of 10000.00 USD, and disclosed on 2024-09-09 as CVE-2024-7966.

Context

Skia is the 2D graphics library used by Chrome. It is reachable from the GPU process. In Chrome's architecture the GPU process is privileged relative to the renderer: a compromised renderer that can hand crafted data to the GPU process gains a wider attack surface and a path towards sandbox escape. "Attack surface" simply means all the places where untrusted input can enter a piece of software; the more of them there are, the more chances an attacker has.

The feature at the centre of the report is the font manager service. A font is a file that describes the shapes of letters. A typeface is the specific design of a font, for example "Helvetica Bold". A glyph is one drawn character from that typeface. When a typeface is registered in the GPU process through the font manager service, glyphs can be written with SkPictures. An SkPicture is a recorded list of drawing commands that Skia can replay later, a bit like a macro recording of everything that was drawn.

Deserialisation is the act of turning stored bytes back into live objects in memory; serialisation is the reverse, turning objects into bytes. Skia handles the deserialisation of those pictures, and it applies restrictions to certain objects, notably SkSL shaders, through a procs structure. Think of procs as a guest list at the door: certain kinds of objects are not allowed in. The report shows that this restriction is not forwarded to nested objects, meaning objects stored inside other objects, and that the SkSL compiler itself can be driven into an out of bounds write in SkSLRasterPipelineBuilder.

The issue was reported through the Chrome Vulnerability Reward Program, credited to Renan Rios (@HyHy100), rated high severity, and paid a bounty of 10000.00 USD. It was disclosed on 2024-09-09 as CVE-2024-7966, an out of bounds memory access in Skia. A CVE is a public identifier given to a known security flaw so that people can refer to it unambiguously.

Setup

The researcher tested against the main branch of Chromium, describing the version as "dev". The main branch is the constantly updated development copy of the source code, so it is newer than what ordinary users run. Two reproduction paths are given: one inside Chromium and one against Skia standalone. "Standalone" means running Skia on its own, outside the browser, which makes experiments faster and easier to debug.

For the Chromium path the prerequisites are:

  1. A patch, chromium.diff, which contains a small binary array that registers the glyph in the GPU process and draws it with a DrawSlugOp. A patch is a file describing changes to source code. A binary array is a block of raw bytes embedded in the program. DrawSlugOp is the drawing operation that renders the glyph.
  2. A generated header, drawable_picture.skp.hh, produced by a Python script and placed in src/gpu/command_buffer/client. A header is a source file that other source files include, and .skp is Skia's own file format for a recorded picture.
  3. A build of the browser, run so that the picture is exercised. Building means compiling the source code into a runnable program.

For the Skia standalone path the prerequisites are:

  1. The patch skia_DO_NOT_USE_IN_CHROMIUM.diff applied to FuzzMain.cpp. A fuzzer is a program that feeds semi random input to code to find crashes; FuzzMain.cpp is the entry point of Skia's fuzzing harness.
  2. A .skp file generated by the Python script, then running ./out/<..>/fuzz. The ./out/<..>/fuzz path is the compiled fuzzer binary inside the build output folder.

Finding it

The starting observation is about trust boundaries. A trust boundary is a line in a system where data passes from a less trusted part to a more trusted part, and where checks must happen. A compromised renderer can reach the GPU process through the font manager service and register a typeface whose glyphs are SkPictures. Skia deserializes those pictures with restrictions on certain object types, including SkSL shaders, enforced through the procs structure. The researcher noticed that a SkPicture can contain nested objects, and that procs is not properly forwarded to them. As a result, arbitrary SkSL becomes reachable again from a compromised renderer. In other words, the guest list at the front door is not shown to the staff at the inner door, so a guest who was turned away at the front can still walk in through a side entrance.

The report points at the relevant code paths in SkPicture.cpp, SkPictureData.cpp, SkTypeface.cpp, SkCustomTypeface.cpp and SkDrawable.h, and notes that the procs object is already lost at that point. Concretely, when a typeface is serialised inside a SkPicture, procs is not forwarded during deserialisation, so the new nested glyphs are allowed to deserialise whatever Skia flattenables they want. A flattenable is an object that knows how to write itself to bytes and read itself back.

The second observation is in the SkSL compiler. Function return values do not count against the maximum slot size limit in the compiler, but they do when building the raster pipeline, which is the CPU pipeline used by default with SkRuntimeColorFilter, even on Ganesh. A slot is a small reserved piece of memory for one value. A raster pipeline is the sequence of small steps that compute each pixel on the CPU. SkRuntimeColorFilter is the Skia object that applies a user written shader as a colour filter. Ganesh is Skia's GPU accelerated drawing backend.

In SkSLRasterPipelineCodeGenerator.cpp, SlotManager::createSlots increments the slot count for every slot range it creates:

C++
SlotRange SlotManager::createSlots(std::string name,
                                   const Type& type,
                                   Position pos,
                                   bool isFunctionReturnValue) {
    size_t nslots = type.slotCount();
    ....

    SlotRange result = {fSlotCount, (int)nslots};
    fSlotCount += nslots; // <----- [1]
    return result;
}

Line by line:

  • SlotRange SlotManager::createSlots(...) declares a function that reserves a range of slots and returns it. SlotManager is the bookkeeper that hands out slots.
  • std::string name, const Type& type, Position pos, bool isFunctionReturnValue are the inputs: a name, the type of the value (for example a single number or a structure of many numbers), a source position for error messages, and a flag saying whether this value is a function's return value.
  • size_t nslots = type.slotCount(); asks the type how many slots it needs. A structure with many fields needs many slots.
  • SlotRange result = {fSlotCount, (int)nslots}; records where the new range starts (the current total, fSlotCount) and how long it is.
  • fSlotCount += nslots; // <----- [1] adds the new slots to the running total. The report marks this line [1] because it is where the count grows without a limit.
  • return result; hands the range back to the caller.

Because a function in an expression can return a large structure, fSlotCount can be made large enough to overflow the total slot allocation size, which is computed without safe integers. An integer overflow happens when a number grows past the largest value its storage can hold and wraps around to a small or negative value, like a car odometer rolling over from 999999 to 000000. "Safe integers" means arithmetic that detects this and refuses to continue.

Exploitation

Step 1: reach SkSL from a compromised renderer through a nested picture

Register a typeface in the GPU process via the font manager service, with glyphs carried in SkPictures. Because procs is not forwarded to nested objects during deserialisation, the nested glyphs can deserialise SkSL flattenables that the top level restriction was meant to block. This restores arbitrary SkSL as an input to the compiler from an untrusted renderer.

Step 2: overflow the slot allocation with a large function return value

Use a function in an expression that returns a big structure. Each call to createSlots adds type.slotCount() to fSlotCount (marked [1] above), and function return values are not counted against the maximum slot size limit in the compiler. The accumulated count overflows the allocation size computed in Program::allocateSlotData:

C++
Program::SlotData Program::allocateSlotData(SkArenaAlloc* alloc) const {
    // Allocate a contiguous slab of slot data for immutables, values, and stack entries.
    const int N = SkOpts::raster_pipeline_highp_stride;
    const int scalarWidth = 1 * sizeof(float);
    const int vectorWidth = N * sizeof(float);
    const int allocSize = vectorWidth * (fNumValueSlots + fNumTempStackSlots) +
                          scalarWidth * fNumImmutableSlots; <---- [2]
    float* slotPtr = static_cast<float*>(alloc->makeBytesAlignedTo(allocSize, vectorWidth));
    sk_bzero(slotPtr, allocSize);

    // Store the temp stack immediately after the values, and immutable data after the stack.
    SlotData s;
    s.values    = SkSpan{slotPtr,        N * fNumValueSlots}; <--- [3]
    s.stack     = SkSpan{s.values.end(), N * fNumTempStackSlots}; <--- [4]
    s.immutable = SkSpan{s.stack.end(),  1 * fNumImmutableSlots}; <--- [5]
    return s;
}

Line by line:

  • Program::SlotData Program::allocateSlotData(SkArenaAlloc* alloc) const is the function that reserves one block of memory for all the slots of a compiled shader. SkArenaAlloc is a simple memory pool that hands out chunks and frees them all at once.
  • const int N = SkOpts::raster_pipeline_highp_stride; reads how many floats fit in one vector step of the pipeline. A float is a number with a decimal point, the usual way to store colour and position values.
  • const int scalarWidth = 1 * sizeof(float); is the size in bytes of one float.
  • const int vectorWidth = N * sizeof(float); is the size in bytes of one vector of floats.
  • const int allocSize = vectorWidth * (fNumValueSlots + fNumTempStackSlots) + scalarWidth * fNumImmutableSlots; <---- [2] computes the total number of bytes to reserve: room for the value slots, the temporary stack slots and the immutable slots. The report marks this [2] because this multiplication is ordinary integer arithmetic with no overflow check.
  • float* slotPtr = static_cast<float*>(alloc->makeBytesAlignedTo(allocSize, vectorWidth)); asks the pool for that many bytes, aligned to a vector boundary, and treats the result as an array of floats.
  • sk_bzero(slotPtr, allocSize); fills the new block with zeros so no old data leaks through.
  • SlotData s; creates the small record that will describe the three regions.
  • s.values = SkSpan{slotPtr, N * fNumValueSlots}; <--- [3] says the values region starts at the beginning of the block and is this long. An SkSpan is a simple pair of a pointer and a length, a view onto existing memory, not a copy of it.
  • s.stack = SkSpan{s.values.end(), N * fNumTempStackSlots}; <--- [4] says the stack region starts right after the values and is this long.
  • s.immutable = SkSpan{s.stack.end(), 1 * fNumImmutableSlots}; <--- [5] says the immutable region starts right after the stack and is this long. Immutable means these values never change once set, which is why they are copied in once.
  • return s; hands the three views back.

The allocation size at [2] is computed without safe integers, and the report describes [3], [4] and [5] as unsafe spans to work with. The report describes these three as unsafe spans to work with. Picture a shelf that was ordered at the wrong length: the labels on the boxes still say where each section begins and ends, but the shelf itself is too short, so the last section sticks out past the end.

Step 3: trigger the out of bounds write

The write happens later, when shader constants are copied into the immutable slots:

C++
    ...
    // Copy all immutable values into the immutable slots.
    for (const Instruction& inst : fInstructions) {
        if (inst.fOp == BuilderOp::store_immutable_value) {
            slots.immutable[inst.fSlotA] = sk_bit_cast<float>(inst.fImmA); <--- [6]
        }
    }
    ....

Line by line:

  • for (const Instruction& inst : fInstructions) { walks over every instruction of the compiled shader, one at a time.
  • if (inst.fOp == BuilderOp::store_immutable_value) { picks out only the instructions whose job is to store a constant into an immutable slot.
  • slots.immutable[inst.fSlotA] = sk_bit_cast<float>(inst.fImmA); <--- [6] writes the constant into the slot numbered fSlotA. sk_bit_cast reinterprets the stored bits as a float without changing them. The report marks this [6] because this is the actual write.
  • The closing braces end the loop and the condition.

The report states that the out of bounds write happens later at [6] with s.immutable, while copying shader constants to slots. The report classifies the result as memory corruption and confirms it is related to a crash. A crash in this context is useful to the researcher as proof: the program tried to touch memory it did not own and the operating system stopped it.

Step 4: reproduce

In Chromium, apply chromium.diff, generate drawable_picture.skp.hh with the Python script and add it to src/gpu/command_buffer/client, then build and run the browser. An access violation should happen after a few seconds, though interaction with the page may be needed to trigger the PoC. An access violation is the operating system's name for a program touching memory it is not allowed to touch. PoC stands for proof of concept, a minimal demonstration that the bug is real. In Skia standalone, apply skia_DO_NOT_USE_IN_CHROMIUM.diff to FuzzMain.cpp, generate the .skp file with the Python script, and run ./out/<..>/fuzz.

Root cause

There are two distinct mistakes. The first is a restriction that is not propagated: procs, which disallows SkSL during deserialisation, is not forwarded to nested objects inside a SkPicture, so a typeface serialised inside a picture can deserialise SkSL flattenables that the top level check was meant to reject. The second is an integer overflow in the raster pipeline slot allocation: function return values are not counted against the maximum slot size limit in the compiler, but they are counted when building the raster pipeline, and the total slot allocation size is computed without safe integers. The report describes the three spans as unsafe to work with, and the copy of immutable values writes out of bounds.

The report notes that the SkSL compiler is a premium attack surface from an attacker's perspective because it does not appear ready to process untrusted input. "Premium attack surface" means a particularly attractive target: code that accepts complex input from outside and has not been hardened against hostile input.

Impact

A compromised renderer could use the GPU process to gain a wider attack surface and escape the sandbox. The vulnerability is an out of bounds memory access in Skia, classified as memory corruption, and the report confirms it is related to a crash. The rating is high severity.

Fix

The report does not describe a fix. Based on the root cause, the two things that need correcting are forwarding procs to nested objects during picture deserialisation so that SkSL cannot be reached through a nested typeface, and making the slot count and allocation size arithmetic safe, so that function return values cannot overflow the total slot allocation.

Variants to test

  1. Other nested flattenables inside SkPicture: serialise objects that carry their own deserialisation callbacks and check whether the top level restriction reaches them. A positive result is a nested object that deserializes a type the top level check was meant to block.
  2. Other paths into the SkSL compiler from the GPU process: look for entry points that accept shader-like data from the renderer and check whether the same slot accounting applies. A positive result is a shader that compiles but produces slot counts inconsistent with the allocation.
  3. Large function return values in expressions: construct shaders where a function returns a large structure and is used in an expression, and watch the slot count. A positive result is a slot count that wraps or exceeds the allocated slab.
  4. Other consumers of allocateSlotData: check whether the same overflow can be reached through SkRuntimeColorFilter and other runtime effect entry points on both CPU and GPU backends. A positive result is an out of bounds write in the immutable slot copy on any of those paths.

Glossary

  • Access violation: the operating system's error when a program reads or writes memory it does not own.
  • Allocation: reserving a block of memory for a program to use.
  • Attack surface: all the places where untrusted input can enter a piece of software.
  • Binary array: a block of raw bytes embedded in a program.
  • Build: compiling source code into a runnable program.
  • Chrome Vulnerability Reward Program (Chrome VRP): Google's programme that pays researchers for reporting security bugs in Chrome.
  • CVE: a public identifier for a known security vulnerability.
  • Deserialisation: turning stored bytes back into live objects in memory.
  • DrawSlugOp: the drawing operation that renders a glyph.
  • Flattenable: an object that knows how to write itself to bytes and read itself back.
  • Float: a number with a decimal point, used to store colour and position values.
  • Font manager service: the Chrome service through which fonts and typefaces are registered in the GPU process.
  • Fuzzer: a program that feeds semi random input to code to find crashes.
  • Ganesh: Skia's GPU accelerated drawing backend.
  • Glyph: one drawn character from a typeface.
  • GPU process: the Chrome process that talks to the graphics card and performs drawing; more privileged than the renderer.
  • Header: a source file that other source files include.
  • Immutable: a value that never changes once it has been set.
  • Integer overflow: arithmetic that grows past the largest value a storage type can hold and wraps around.
  • Memory corruption: damage to a program's own memory, often caused by writing outside the intended area.
  • Out of bounds write: writing to memory outside the area a program was supposed to use.
  • Patch: a file describing changes to source code.
  • PoC (proof of concept): a minimal demonstration that a bug is real.
  • Process: a separate running program with its own memory.
  • procs: the structure in Skia that disallows certain object types, such as SkSL shaders, during deserialisation.
  • Raster pipeline: the sequence of small steps that compute each pixel on the CPU.
  • Renderer process: the Chrome process that turns a web page into something that can be drawn; treated as less trustworthy.
  • Safe integers: arithmetic that detects overflow and refuses to continue.
  • Sandbox: the protection that keeps a compromised process from taking over the whole computer.
  • Serialisation: turning live objects into bytes for storage or transfer.
  • Shader: a short program that decides the colour of each pixel.
  • Skia: the 2D graphics library used by Chrome.
  • SkSL: Skia's shader programming language.
  • SkArenaAlloc: a simple memory pool that hands out chunks and frees them all at once.
  • SkPicture: a recorded list of drawing commands that Skia can replay later.
  • SkRuntimeColorFilter: the Skia object that applies a user written shader as a colour filter.
  • SkSpan: a pointer plus a length, a view onto existing memory rather than a copy.
  • Slot: a small reserved piece of memory for one value.
  • Standalone: running a library on its own, outside the browser.
  • Trust boundary: a line where data passes from a less trusted part of a system to a more trusted one, and where checks must happen.
  • Typeface: the specific design of a font, for example "Helvetica Bold".
  • Vector: a small fixed group of numbers processed together, here a group of floats.

More from Google Chrome

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.