Heap buffer overflow in Skia (CVE-2024-8636)
An integer overflow in Skia's PatternHelper::init allows a heap buffer overflow when drawing many quads, leading to an out-of-bounds write. An attacker could trigger this via a crafted web page, causing a GPU process crash.
Originally disclosed on Chrome VRP
- Fix shipped in 20 days
Steps to reproduce the problem
(Chromium)
- Apply the chromium.diff renderer patch to chromium.
- Run genskpic.py to generate drawable_picture.skp.hh, then move the generated file to src/gpu/command_buffer/client.
- Build and start the browser.
- Open index.html to trigger PoC.
- GPU process will crash.
(Skia standalone)
- Run genskpic.py to generate a .skp file.
- You can now run it in skpbench using: ./out/asan/skpbench --src pic.skp --config gles.
- UBSAN crash will happen.
Problem Description
Creating a separate issue as per: https://issues.chromium.org/issues/360758697#comment13
Hi, while researching Skia for more bugs, I noticed that there's another hidden integer overflow there, PatternHelper (called from RegionOpImpl::onPrepareDraws) is also not checking against overflows when multiplying the amount of vertices per repetition with the number of quads to draw, so we can still overflow the vertex space even if numRects is a valid integer, see [1] [2] [3] below:
void onPrepareDraws(GrMeshDrawTarget* target) override {
...
SkSafeMath safeMath;
for (int i = 0; i < numRegions; i++) {
numRects = safeMath.addInt(numRects, fRegions[i].fRegion.computeRegionComplexity());
}
if (!safeMath) {
// This is a nonsensical draw, so we can just drop it.
return;
}
if (!numRects) {
return;
}
QuadHelper helper(target, fProgramInfo->geomProc().vertexStride(), numRects); // <-- [1]
...
}
GrMeshDrawOp::QuadHelper::QuadHelper(GrMeshDrawTarget* target,
size_t vertexStride,
int quadsToDraw) {
...
this->init(target, GrPrimitiveType::kTriangles, vertexStride, std::move(indexBuffer),
GrResourceProvider::NumVertsPerNonAAQuad(),
GrResourceProvider::NumIndicesPerNonAAQuad(), quadsToDraw,
GrResourceProvider::MaxNumNonAAQuads()); // <-- [2]
}
void GrMeshDrawOp::PatternHelper::init(GrMeshDrawTarget* target, GrPrimitiveType primitiveType,
size_t vertexStride, sk_sp<const GrBuffer> indexBuffer,
int verticesPerRepetition, int indicesPerRepetition,
int repeatCount, int maxRepetitions) {
...
int vertexCount = verticesPerRepetition * repeatCount; // <-- [3] No checks are being made here against overflow.
fVertices = target->makeVertexSpace(vertexStride, vertexCount, &vertexBuffer, &firstVertex);
if (!fVertices) {
SkDebugf("Vertices could not be allocated for patterned rendering.");
return;
}
...
}
(indicesPerRepetition should be validated as well).
PatternHelper is used in many operations other than RegionOpImpl, so checking for overflows here would be a cool thing to also mitigate attacks using other operations.
Summary
Integer overflow in Skia GrMeshDrawOp::PatternHelper::init leads to OOB write
Custom Questions
Type of crash:
gpu
Crash state:
=================================================================
==9095==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x7d0890d2c820 at pc 0x7d090fe55493 bp 0x7ffde9e34b90 sp 0x7ffde9e34b88
WRITE of size 4 at 0x7d0890d2c820 thread T0 (chrome)
==9095==WARNING: invalid path to external symbolizer!
==9095==WARNING: Failed to use and restart external symbolizer!
#0 0x7d090fe55492 in operator<<<float> ./../../third_party/skia/src/gpu/BufferWriter.h:280:5
#1 0x7d090fe55492 in writeVertex ./../../third_party/skia/src/gpu/BufferWriter.h:0:0
#2 0x7d090fe55492 in writeQuadVertex<1, skgpu::VertexWriter::TriStrip<float>, skgpu::VertexColor> ./../../third_party/skia/src/gpu/BufferWriter.h:262:14
#3 0x7d090fe55492 in writeQuad<skgpu::VertexWriter::TriStrip<float>, skgpu::VertexColor> ./../../third_party/skia/src/gpu/BufferWriter.h:246:15
#4 0x7d090fe55492 in skgpu::ganesh::RegionOp::(anonymous namespace)::RegionOpImpl::onPrepareDraws(GrMeshDrawTarget*) ./../../third_party/skia/src/gpu/ganesh/ops/RegionOp.cpp:170:26
#5 0x7d090fe30ac0 in GrOp::prepare(GrOpFlushState*) ./../../third_party/skia/src/gpu/ganesh/ops/GrOp.h:197:15
#6 0x7d090fe3033c in skgpu::ganesh::OpsTask::onPrepare(GrOpFlushState*) ./../../third_party/skia/src/gpu/ganesh/ops/OpsTask.cpp:548:27
#7 0x7d090fc378d9 in GrRenderTask::prepare(GrOpFlushState*) ./../../third_party/skia/src/gpu/ganesh/GrRenderTask.cpp:111:11
#8 0x7d090fbdbe50 in GrDrawingManager::executeRenderTasks(GrOpFlushState*) ./../../third_party/skia/src/gpu/ganesh/GrDrawingManager.cpp:260:21
#9 0x7d090fbda829 in GrDrawingManager::flush(SkSpan<GrSurfaceProxy*>, SkSurfaces::BackendSurfaceAccess, GrFlushInfo const&, skgpu::MutableTextureState const*) ./../../third_party/skia/src/gpu/ganesh/GrDrawingManager.cpp:203:34
#10 0x7d090fbdcf7c in GrDrawingManager::flushSurfaces(SkSpan<GrSurfaceProxy*>, SkSurfaces::BackendSurfaceAccess, GrFlushInfo const&, skgpu::MutableTextureState const*) ./../../third_party/skia/src/gpu/ganesh/GrDrawingManager.cpp:530:27
#11 0x7d090fbca9c9 in GrDirectContextPriv::flushSurfaces(SkSpan<GrSurfaceProxy*>, SkSurfaces::BackendSurfaceAccess, GrFlushInfo const&, skgpu::MutableTextureState const*) ./../../third_party/skia/src/gpu/ganesh/GrDirectContextPriv.cpp:92:47
#12 0x7d090fbbf607 in flushSurface ./../../third_party/skia/src/gpu/ganesh/GrDirectContextPriv.h:106:22
#13 0x7d090fbbf607 in GrDirectContext::flush(SkSurface*, GrFlushInfo const&, skgpu::MutableTextureState const*) ./../../third_party/skia/src/gpu/ganesh/GrDirectContext.cpp:516:25
#14 0x7d090fe96e1b in skgpu::ganesh::Flush(SkSurface*) ./../../third_party/skia/src/gpu/ganesh/surface/SkSurface_Ganesh.cpp:782:45
#15 0x7d08d9f90829 in gpu::SharedContextState::FlushWriteAccess(gpu::SkiaImageRepresentation::ScopedWriteAccess*) ./../../gpu/command_buffer/service/shared_context_state.cc:789:9
#16 0x7d08d9f4927b in gpu::raster::RasterDecoderImpl::DoEndRasterCHROMIUM() ./../../gpu/command_buffer/service/raster_decoder.cc:3197:30
#17 0x7d08d9f43ac8 in gpu::raster::RasterDecoderImpl::HandleEndRasterCHROMIUM(unsigned int, void const volatile*) ./../../gpu/command_buffer/service/raster_decoder_autogen.h:151:3
#18 0x7d08d9f4e321 in gpu::error::Error gpu::raster::RasterDecoderImpl::DoCommandsImpl<false>(unsigned int, void const volatile*, int, int*) ./../../gpu/command_buffer/service/raster_decoder.cc:1539:18
#19 0x7d09046d3826 in gpu::CommandBufferService::Flush(int, gpu::AsyncAPIInterface*) ./../../gpu/command_buffer/service/command_buffer_service.cc:231:35
#20 0x7d08dc128e5c in gpu::CommandBufferStub::OnAsyncFlush(int, unsigned int, std::__Cr::vector<gpu::SyncToken, std::__Cr::allocator<gpu::SyncToken>> const&) ./../../gpu/ipc/service/command_buffer_stub.cc:502:22
#21 0x7d08dc128101 in gpu::CommandBufferStub::ExecuteDeferredRequest(gpu::mojom::DeferredCommandBufferRequestParams&) ./../../gpu/ipc/service/command_buffer_stub.cc:153:7
#22 0x7d08dc148655 in gpu::GpuChannel::ExecuteDeferredRequest(mojo::StructPtr<gpu::mojom::DeferredRequestParams>, unsigned long) ./../../gpu/ipc/service/gpu_channel.cc:932:13
#23 0x7d08dc156e8e in void base::internal::DecayedFunctorTraits<void (gpu::GpuChannel::*)(mojo::StructPtr<gpu::mojom::DeferredRequestParams>, unsigned long), base::WeakPtr<gpu::GpuChannel>&&, mojo::StructPtr<gpu::mojom::DeferredRequestParams>&&, unsigned long&&>::Invoke<void (gpu::GpuChannel::*)(mojo::StructPtr<gpu::mojom::DeferredRequestParams>, unsigned long), base::WeakPtr<gpu::GpuChannel> const&, mojo::StructPtr<gpu::mojom::DeferredRequestParams>, unsigned long>(void (gpu::GpuChannel::*)(mojo::StructPtr<gpu::mojom::DeferredRequestParams>, unsigned long), base::WeakPtr<gpu::GpuChannel> const&, mojo::StructPtr<gpu::mojom::DeferredRequestParams>&&, unsigned long&&) ./../../base/functional/bind_internal.h:738:12
#24 0x7d08dc156c74 in MakeItSo<void (gpu::GpuChannel::*)(mojo::StructPtr<gpu::mojom::DeferredRequestParams>, unsigned long), std::__Cr::tuple<base::WeakPtr<gpu::GpuChannel>, mojo::StructPtr<gpu::mojom::DeferredRequestParams>, unsigned long> > ./../../base/functional/bind_internal.h:954:5
#25 0x7d08dc156c74 in RunImpl<void (gpu::GpuChannel::*)(mojo::StructPtr<gpu::mojom::DeferredRequestParams>, unsigned long), std::__Cr::tuple<base::WeakPtr<gpu::GpuChannel>, mojo::StructPtr<gpu::mojom::DeferredRequestParams>, unsigned long>, 0UL, 1UL, 2UL> ./../../base/functional/bind_internal.h:1067:14
#26 0x7d08dc156c74 in base::internal::Invoker<base::internal::FunctorTraits<void (gpu::GpuChannel::*&&)(mojo::StructPtr<gpu::mojom::DeferredRequestParams>, unsigned long), base::WeakPtr<gpu::GpuChannel>&&, mojo::StructPtr<gpu::mojom::DeferredRequestParams>&&, unsigned long&&>, base::internal::BindState<true, true, false, void (gpu::GpuChannel::*)(mojo::StructPtr<gpu::mojom::DeferredRequestParams>, unsigned long), base::WeakPtr<gpu::GpuChannel>, mojo::StructPtr<gpu::mojom::DeferredRequestParams>, unsigned long>, void ()>::RunOnce(base::internal::BindStateBase*) ./../../base/functional/bind_internal.h:980:12
#27 0x7d090471076e in Run ./../../base/functional/callback.h:156:12
#28 0x7d090471076e in gpu::SchedulerDfs::ExecuteSequence(base::IdType<gpu::SyncPointOrderData, unsigned int, 0u, 1u>) ./../../gpu/command_buffer/service/scheduler_dfs.cc:598:24
#29 0x7d090470e155 in gpu::SchedulerDfs::RunNextTask() ./../../gpu/command_buffer/service/scheduler_dfs.cc:522:3
#30 0x7d0904711f40 in Invoke<void (gpu::SchedulerDfs::*)(), gpu::SchedulerDfs *> ./../../base/functional/bind_internal.h:738:12
#31 0x7d0904711f40 in MakeItSo<void (gpu::SchedulerDfs::*)(), std::__Cr::tuple<base::internal::UnretainedWrapper<gpu::SchedulerDfs, base::unretained_traits::MayNotDangle, (partition_alloc::internal::RawPtrTraits)0> > > ./../../base/functional/bind_internal.h:930:12
#32 0x7d0904711f40 in RunImpl<void (gpu::SchedulerDfs::*)(), std::__Cr::tuple<base::internal::UnretainedWrapper<gpu::SchedulerDfs, base::unretained_traits::MayNotDangle, (partition_alloc::internal::RawPtrTraits)0> >, 0UL> ./../../base/functional/bind_internal.h:1067:14
#33 0x7d0904711f40 in base::internal::Invoker<base::internal::FunctorTraits<void (gpu::SchedulerDfs::*&&)(), gpu::SchedulerDfs*>, base::internal::BindState<true, true, false, void (gpu::SchedulerDfs::*)(), base::internal::UnretainedWrapper<gpu::SchedulerDfs, base::unretained_traits::MayNotDangle, (partition_alloc::internal::RawPtrTraits)0>>, void ()>::RunOnce(base::internal::BindStateBase*) ./../../base/functional/bind_internal.h:980:12
#34 0x7d09139bee6a in Run ./../../base/functional/callback.h:156:12
#35 0x7d09139bee6a in base::TaskAnnotator::RunTaskImpl(base::PendingTask&) ./../../base/task/common/task_annotator.cc:203:34
#36 0x7d0913a30793 in RunTask<(lambda at ../../base/task/sequence_manager/thread_controller_with_message_pump_impl.cc:486:11)> ./../../base/task/common/task_annotator.h:90:5
#37 0x7d0913a30793 in base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWorkImpl(base::LazyNow*) ./../../base/task/sequence_manager/thread_controller_with_message_pump_impl.cc:484:23
#38 0x7d0913a2f69e in base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWork() ./../../base/task/sequence_manager/thread_controller_with_message_pump_impl.cc:346:40
#39 0x7d0913a314b4 in non-virtual thunk to base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWork() ./../../base/task/sequence_manager/thread_controller_with_message_pump_impl.cc:0:0
#40 0x7d0913bc2cb3 in base::MessagePumpGlib::Run(base::MessagePump::Delegate*) ./../../base/message_loop/message_pump_glib.cc:694:48
#41 0x7d0913a32084 in base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::Run(bool, base::TimeDelta) ./../../base/task/sequence_manager/thread_controller_with_message_pump_impl.cc:654:12
#42 0x7d0913943a12 in base::RunLoop::Run(base::Location const&) ./../../base/run_loop.cc:134:14
#43 0x7d0907b71fdb in content::GpuMain(content::MainFunctionParams) ./../../content/gpu/gpu_main.cc:431:14
#44 0x7d090b77ad5a in content::RunZygote(content::ContentMainDelegate*) ./../../content/app/content_main_runner_impl.cc:703:14
#45 0x7d090b77bb29 in content::RunOtherNamedProcessTypeMain(std::__Cr::basic_string<char, std::__Cr::char_traits<char>, std::__Cr::allocator<char>> const&, content::MainFunctionParams, content::ContentMainDelegate*) ./../../content/app/content_main_runner_impl.cc:807:12
#46 0x7d090b77dfd2 in content::ContentMainRunnerImpl::Run() ./../../content/app/content_main_runner_impl.cc:1175:10
#47 0x7d090b77902c in content::RunContentProcess(content::ContentMainParams, content::ContentMainRunner*) ./../../content/app/content_main.cc:333:36
#48 0x7d090b77985a in content::ContentMain(content::ContentMainParams) ./../../content/app/content_main.cc:346:10
#49 0x58d4249a28b5 in ChromeMain ./../../chrome/app/chrome_main.cc:230:12
#50 0x7d08b3e29d8f in __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
0x7d0890d2c820 is located 0 bytes after 1048608-byte region [0x7d0890c2c800,0x7d0890d2c820)
allocated by thread T0 (chrome) here:
#0 0x58d4249a00bd in operator new(unsigned long) _asan_rtl_:3
#1 0x7d090fb9bc9d in Make ./../../third_party/skia/src/gpu/ganesh/GrCpuBuffer.h:29:20
#2 0x7d090fb9bc9d in GrBufferAllocPool::CpuBufferCache::makeBuffer(unsigned long, bool) ./../../third_party/skia/src/gpu/ganesh/GrBufferAllocPool.cpp:56:30
#3 0x7d090fb9cb9c in GrBufferAllocPool::resetCpuData(unsigned long) ./../../third_party/skia/src/gpu/ganesh/GrBufferAllocPool.cpp:389:60
#4 0x7d090fb9e51a in GrBufferAllocPool::createBlock(unsigned long) ./../../third_party/skia/src/gpu/ganesh/GrBufferAllocPool.cpp:362:15
#5 0x7d090fb9da01 in GrBufferAllocPool::makeSpace(unsigned long, unsigned long, sk_sp<GrBuffer const>*, unsigned long*) ./../../third_party/skia/src/gpu/ganesh/GrBufferAllocPool.cpp:229:16
#6 0x7d090fb9fc02 in GrVertexBufferAllocPool::makeSpace(unsigned long, int, sk_sp<GrBuffer const>*, int*) ./../../third_party/skia/src/gpu/ganesh/GrBufferAllocPool.cpp:445:28
#7 0x7d090fdf3eef in GrMeshDrawOp::PatternHelper::init(GrMeshDrawTarget*, GrPrimitiveType, unsigned long, sk_sp<GrBuffer const>, int, int, int, int) ./../../third_party/skia/src/gpu/ganesh/ops/GrMeshDrawOp.cpp:96:25
#8 0x7d090fdf4500 in GrMeshDrawOp::QuadHelper::QuadHelper(GrMeshDrawTarget*, unsigned long, int) ./../../third_party/skia/src/gpu/ganesh/ops/GrMeshDrawOp.cpp:134:11
#9 0x7d090fe542bf in skgpu::ganesh::RegionOp::(anonymous namespace)::RegionOpImpl::onPrepareDraws(GrMeshDrawTarget*) ./../../third_party/skia/src/gpu/ganesh/ops/RegionOp.cpp:157:20
#10 0x7d090fe30ac0 in GrOp::prepare(GrOpFlushState*) ./../../third_party/skia/src/gpu/ganesh/ops/GrOp.h:197:15
#11 0x7d090fe3033c in skgpu::ganesh::OpsTask::onPrepare(GrOpFlushState*) ./../../third_party/skia/src/gpu/ganesh/ops/OpsTask.cpp:548:27
#12 0x7d090fc378d9 in GrRenderTask::prepare(GrOpFlushState*) ./../../third_party/skia/src/gpu/ganesh/GrRenderTask.cpp:111:11
#13 0x7d090fbdbe50 in GrDrawingManager::executeRenderTasks(GrOpFlushState*) ./../../third_party/skia/src/gpu/ganesh/GrDrawingManager.cpp:260:21
#14 0x7d090fbda829 in GrDrawingManager::flush(SkSpan<GrSurfaceProxy*>, SkSurfaces::BackendSurfaceAccess, GrFlushInfo const&, skgpu::MutableTextureState const*) ./../../third_party/skia/src/gpu/ganesh/GrDrawingManager.cpp:203:34
#15 0x7d090fbdcf7c in GrDrawingManager::flushSurfaces(SkSpan<GrSurfaceProxy*>, SkSurfaces::BackendSurfaceAccess, GrFlushInfo const&, skgpu::MutableTextureState const*) ./../../third_party/skia/src/gpu/ganesh/GrDrawingManager.cpp:530:27
#16 0x7d090fbca9c9 in GrDirectContextPriv::flushSurfaces(SkSpan<GrSurfaceProxy*>, SkSurfaces::BackendSurfaceAccess, GrFlushInfo const&, skgpu::MutableTextureState const*) ./../../third_party/skia/src/gpu/ganesh/GrDirectContextPriv.cpp:92:47
#17 0x7d090fbbf607 in flushSurface ./../../third_party/skia/src/gpu/ganesh/GrDirectContextPriv.h:106:22
#18 0x7d090fbbf607 in GrDirectContext::flush(SkSurface*, GrFlushInfo const&, skgpu::MutableTextureState const*) ./../../third_party/skia/src/gpu/ganesh/GrDirectContext.cpp:516:25
#19 0x7d090fe96e1b in skgpu::ganesh::Flush(SkSurface*) ./../../third_party/skia/src/gpu/ganesh/surface/SkSurface_Ganesh.cpp:782:45
#20 0x7d08d9f90829 in gpu::SharedContextState::FlushWriteAccess(gpu::SkiaImageRepresentation::ScopedWriteAccess*) ./../../gpu/command_buffer/service/shared_context_state.cc:789:9
#21 0x7d08d9f4927b in gpu::raster::RasterDecoderImpl::DoEndRasterCHROMIUM() ./../../gpu/command_buffer/service/raster_decoder.cc:3197:30
#22 0x7d08d9f43ac8 in gpu::raster::RasterDecoderImpl::HandleEndRasterCHROMIUM(unsigned int, void const volatile*) ./../../gpu/command_buffer/service/raster_decoder_autogen.h:151:3
#23 0x7d08d9f4e321 in gpu::error::Error gpu::raster::RasterDecoderImpl::DoCommandsImpl<false>(unsigned int, void const volatile*, int, int*) ./../../gpu/command_buffer/service/raster_decoder.cc:1539:18
#24 0x7d09046d3826 in gpu::CommandBufferService::Flush(int, gpu::AsyncAPIInterface*) ./../../gpu/command_buffer/service/command_buffer_service.cc:231:35
#25 0x7d08dc128e5c in gpu::CommandBufferStub::OnAsyncFlush(int, unsigned int, std::__Cr::vector<gpu::SyncToken, std::__Cr::allocator<gpu::SyncToken>> const&) ./../../gpu/ipc/service/command_buffer_stub.cc:502:22
#26 0x7d08dc128101 in gpu::CommandBufferStub::ExecuteDeferredRequest(gpu::mojom::DeferredCommandBufferRequestParams&) ./../../gpu/ipc/service/command_buffer_stub.cc:153:7
#27 0x7d08dc148655 in gpu::GpuChannel::ExecuteDeferredRequest(mojo::StructPtr<gpu::mojom::DeferredRequestParams>, unsigned long) ./../../gpu/ipc/service/gpu_channel.cc:932:13
#28 0x7d08dc156e8e in void base::internal::DecayedFunctorTraits<void (gpu::GpuChannel::*)(mojo::StructPtr<gpu::mojom::DeferredRequestParams>, unsigned long), base::WeakPtr<gpu::GpuChannel>&&, mojo::StructPtr<gpu::mojom::DeferredRequestParams>&&, unsigned long&&>::Invoke<void (gpu::GpuChannel::*)(mojo::StructPtr<gpu::mojom::DeferredRequestParams>, unsigned long), base::WeakPtr<gpu::GpuChannel> const&, mojo::StructPtr<gpu::mojom::DeferredRequestParams>, unsigned long>(void (gpu::GpuChannel::*)(mojo::StructPtr<gpu::mojom::DeferredRequestParams>, unsigned long), base::WeakPtr<gpu::GpuChannel> const&, mojo::StructPtr<gpu::mojom::DeferredRequestParams>&&, unsigned long&&) ./../../base/functional/bind_internal.h:738:12
#29 0x7d08dc156c74 in MakeItSo<void (gpu::GpuChannel::*)(mojo::StructPtr<gpu::mojom::DeferredRequestParams>, unsigned long), std::__Cr::tuple<base::WeakPtr<gpu::GpuChannel>, mojo::StructPtr<gpu::mojom::DeferredRequestParams>, unsigned long> > ./../../base/functional/bind_internal.h:954:5
#30 0x7d08dc156c74 in RunImpl<void (gpu::GpuChannel::*)(mojo::StructPtr<gpu::mojom::DeferredRequestParams>, unsigned long), std::__Cr::tuple<base::WeakPtr<gpu::GpuChannel>, mojo::StructPtr<gpu::mojom::DeferredRequestParams>, unsigned long>, 0UL, 1UL, 2UL> ./../../base/functional/bind_internal.h:1067:14
#31 0x7d08dc156c74 in base::internal::Invoker<base::internal::FunctorTraits<void (gpu::GpuChannel::*&&)(mojo::StructPtr<gpu::mojom::DeferredRequestParams>, unsigned long), base::WeakPtr<gpu::GpuChannel>&&, mojo::StructPtr<gpu::mojom::DeferredRequestParams>&&, unsigned long&&>, base::internal::BindState<true, true, false, void (gpu::GpuChannel::*)(mojo::StructPtr<gpu::mojom::DeferredRequestParams>, unsigned long), base::WeakPtr<gpu::GpuChannel>, mojo::StructPtr<gpu::mojom::DeferredRequestParams>, unsigned long>, void ()>::RunOnce(base::internal::BindStateBase*) ./../../base/functional/bind_internal.h:980:12
#32 0x7d090471076e in Run ./../../base/functional/callback.h:156:12
#33 0x7d090471076e in gpu::SchedulerDfs::ExecuteSequence(base::IdType<gpu::SyncPointOrderData, unsigned int, 0u, 1u>) ./../../gpu/command_buffer/service/scheduler_dfs.cc:598:24
#34 0x7d090470e155 in gpu::SchedulerDfs::RunNextTask() ./../../gpu/command_buffer/service/scheduler_dfs.cc:522:3
SUMMARY: AddressSanitizer: heap-buffer-overflow (/home/hyhy100/chromium2/src/out/asan/libskia.so+0xc55492) (BuildId: 739a908ae5387373)
Shadow bytes around the buggy address:
0x7d0890d2c580: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x7d0890d2c600: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x7d0890d2c680: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x7d0890d2c700: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x7d0890d2c780: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x7d0890d2c800: 00 00 00 00[fa]fa fa fa fa fa fa fa fa fa fa fa
0x7d0890d2c880: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x7d0890d2c900: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x7d0890d2c980: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x7d0890d2ca00: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x7d0890d2ca80: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==9095==ADDITIONAL INFO
==9095==Note: Please include this section with the ASan report.
Task trace:
#0 0x7d090470e73a in gpu::SchedulerDfs::RunNextTask() ./../../gpu/command_buffer/service/scheduler_dfs.cc:538:27
#1 0x7d090470e73a in gpu::SchedulerDfs::RunNextTask() ./../../gpu/command_buffer/service/scheduler_dfs.cc:538:27
#2 0x7d090470e73a in gpu::SchedulerDfs::RunNextTask() ./../../gpu/command_buffer/service/scheduler_dfs.cc:538:27
#3 0x7d090470e73a in gpu::SchedulerDfs::RunNextTask() ./../../gpu/command_buffer/service/scheduler_dfs.cc:538:27
Command line: `/proc/self/exe --type=gpu-process --string-annotations --crashpad-handler-pid=9058 --enable-crash-reporter=, --no-subproc-heap-profiling --change-stack-guard-on-fork=enable --gpu-preferences=UAAAAAAAAAAgAAAEAAAAAAAAAAAAAAAAAABgAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAABAAAAAAAAAAEAAAAAAAAAAIAAAAAAAAAAgAAAAAAAAA --shared-files --metrics-shmem-handle=4,i,7711159281679077118,5503874274070490124,262144 --field-trial-handle=3,i,8533360048761144999,15654948628870376523,262144 --variations-seed-version`
==9095==END OF ADDITIONAL INFO
==9095==ABORTING
[9053:9053:0822/110423.428241:ERROR:gpu_process_host.cc(980)] GPU process exited unexpectedly: exit_code=256
Reporter credit:
Renan Rios (@hyhy_100)
Additional Data
Category: Security
Chrome Channel: Not sure
Regression: No
Context
This report describes a heap buffer overflow in Skia, the 2D graphics library used by Chrome and other products, tracked as CVE-2024-8636. The affected component is the Ganesh GPU backend, specifically the code path that prepares a RegionOp draw for execution. The researcher, Renan Rios (@hyhy_100), filed it through the Chrome VRP and it was disclosed on 2024-09-10 with a bounty of 15,000 USD and a severity of high.
RegionOp draws a region, that is, a set of rectangles, as a mesh of quads on the GPU. To do this it uses QuadHelper, which derives from PatternHelper. PatternHelper::init computes how many vertices are needed for a patterned draw and asks the mesh draw target to reserve that much vertex space. The reservation is a multiplication of the number of vertices per repetition by the number of repetitions, and that multiplication is where the bug lives.
The report was opened as a separate issue following an earlier discussion, referenced as https://issues.chromium.org/issues/360758697#comment13. The researcher states that while researching Skia for more bugs he noticed another hidden integer overflow.
Setup
The report gives two reproduction environments.
For Chromium:
- Apply the
chromium.diffrenderer patch to Chromium. - Run
genskpic.pyto generatedrawable_picture.skp.hh, then move the generated file tosrc/gpu/command_buffer/client. - Build and start the browser.
- Open
index.htmlto trigger the PoC. - The GPU process crashes.
For Skia standalone:
- Run
genskpic.pyto generate a.skpfile. - Run it in
skpbenchwith the command below. - A UBSAN crash occurs.
./out/asan/skpbench --src pic.skp --config gles
The crash state shown in the report is an AddressSanitizer build. The stack trace references a build path under /home/hyhy100/chromium2/src/out/asan/libskia.so, and the command line shows a GPU process launched with --type=gpu-process. The report does not state the Chrome version or the Skia revision beyond the source links it quotes.
Finding it
The researcher explains that PatternHelper, called from RegionOpImpl::onPrepareDraws, does not check for overflow when multiplying the number of vertices per repetition by the number of quads to draw. As a result the vertex space can still be overflowed even when numRects is a valid integer.
He points at three places in the source, labelled [1], [2] and [3].
[1] is RegionOpImpl::onPrepareDraws in third_party/skia/src/gpu/ganesh/ops/RegionOp.cpp around line 150. The code sums the region complexity of each region using SkSafeMath, and drops the draw if the sum overflowed or is zero. It then constructs a QuadHelper with numRects:
void onPrepareDraws(GrMeshDrawTarget* target) override {
...
SkSafeMath safeMath;
for (int i = 0; i < numRegions; i++) {
numRects = safeMath.addInt(numRects, fRegions[i].fRegion.computeRegionComplexity());
}
if (!safeMath) {
// This is a nonsensical draw, so we can just drop it.
return;
}
if (!numRects) {
return;
}
QuadHelper helper(target, fProgramInfo->geomProc().vertexStride(), numRects); // <-- [1]
...
}
The important observation is that the addition is guarded, so numRects itself is a valid integer. The guard does not extend to what happens next.
[2] is the QuadHelper constructor in third_party/skia/src/gpu/ganesh/ops/GrMeshDrawOp.cpp around line 134. It forwards quadsToDraw into init together with the per-quad vertex and index counts and the maximum number of non-AA quads:
GrMeshDrawOp::QuadHelper::QuadHelper(GrMeshDrawTarget* target,
size_t vertexStride,
int quadsToDraw) {
...
this->init(target, GrPrimitiveType::kTriangles, vertexStride, std::move(indexBuffer),
GrResourceProvider::NumVertsPerNonAAQuad(),
GrResourceProvider::NumIndicesPerNonAAQuad(), quadsToDraw,
GrResourceProvider::MaxNumNonAAQuads()); // <-- [2]
}
[3] is PatternHelper::init in the same file around line 95. Here the vertex count is computed by a plain multiplication with no overflow check, and the result is passed to makeVertexSpace:
void GrMeshDrawOp::PatternHelper::init(GrMeshDrawTarget* target, GrPrimitiveType primitiveType,
size_t vertexStride, sk_sp<const GrBuffer> indexBuffer,
int verticesPerRepetition, int indicesPerRepetition,
int repeatCount, int maxRepetitions) {
...
int vertexCount = verticesPerRepetition * repeatCount; // <-- [3] No checks are being made here against overflow.
fVertices = target->makeVertexSpace(vertexStride, vertexCount, &vertexBuffer, &firstVertex);
if (!fVertices) {
SkDebugf("Vertices could not be allocated for patterned rendering.");
return;
}
...
}
The researcher also notes that indicesPerRepetition should be validated as well. He adds that PatternHelper is used in many operations other than RegionOpImpl, so checking for overflows here would also mitigate attacks using other operations.
The summary he gives is: integer overflow in Skia GrMeshDrawOp::PatternHelper::init leads to OOB write.
Exploitation
Step 1: build the instrumented browser
The report does not include the contents of that patch, so what it changes is not stated here.
Step 2: generate the picture
Run genskpic.py to produce drawable_picture.skp.hh, then move the generated file into src/gpu/command_buffer/client. The script itself is not reproduced in the report; The script itself is not reproduced in the report, and the report does not describe the contents of the generated picture.
Step 3: build and start
Build the browser and start it. The crash occurs in the GPU process, and the trace shown comes from a build with AddressSanitizer enabled.
Step 4: open the trigger page
Open index.html to trigger the PoC. The page is not reproduced in the report. The effect is that the GPU process crashes.
Step 5: read the crash
The crash state is an AddressSanitizer heap-buffer-overflow report. The write is of size 4, in thread T0 (chrome), at an address 0 bytes after a 1048608-byte region. The top frames are in BufferWriter.h, writing a quad vertex, called from RegionOpImpl::onPrepareDraws at RegionOp.cpp:170:
==9095==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x7d0890d2c820 at pc 0x7d090fe55493 bp 0x7ffde9e34b90 sp 0x7ffde9e34b88
WRITE of size 4 at 0x7d0890d2c820 thread T0 (chrome)
#0 0x7d090fe55492 in operator<<<float> ./../../third_party/skia/src/gpu/BufferWriter.h:280:5
#1 0x7d090fe55492 in writeVertex ./../../third_party/skia/src/gpu/BufferWriter.h:0:0
#2 0x7d090fe55492 in writeQuadVertex<1, skgpu::VertexWriter::TriStrip<float>, skgpu::VertexColor> ./../../third_party/skia/src/gpu/BufferWriter.h:262:14
#3 0x7d090fe55492 in writeQuad<skgpu::VertexWriter::TriStrip<float>, skgpu::VertexColor> ./../../third_party/skia/src/gpu/BufferWriter.h:246:15
#4 0x7d090fe55492 in skgpu::ganesh::RegionOp::(anonymous namespace)::RegionOpImpl::onPrepareDraws(GrMeshDrawTarget*) ./../../third_party/skia/src/gpu/ganesh/ops/RegionOp.cpp:170:26
The allocation side of the report shows where the undersized buffer came from. PatternHelper::init at GrMeshDrawOp.cpp:96 calls into GrVertexBufferAllocPool::makeSpace, which creates a block through GrBufferAllocPool::createBlock and resetCpuData, ending in GrCpuBuffer.h allocating the buffer with operator new:
0x7d0890d2c820 is located 0 bytes after 1048608-byte region [0x7d0890c2c800,0x7d0890d2c820)
allocated by thread T0 (chrome) here:
#0 0x58d4249a00bd in operator new(unsigned long) _asan_rtl_:3
#1 0x7d090fb9bc9d in Make ./../../third_party/skia/src/gpu/ganesh/GrCpuBuffer.h:29:20
#2 0x7d090fb9bc9d in GrBufferAllocPool::CpuBufferCache::makeBuffer(unsigned long, bool) ./../../third_party/skia/src/gpu/ganesh/GrBufferAllocPool.cpp:56:30
#3 0x7d090fb9cb9c in GrBufferAllocPool::resetCpuData(unsigned long) ./../../third_party/skia/src/gpu/ganesh/GrBufferAllocPool.cpp:389:60
#4 0x7d090fb9e51a in GrBufferAllocPool::createBlock(unsigned long) ./../../third_party/skia/src/gpu/ganesh/GrBufferAllocPool.cpp:362:15
#5 0x7d090fb9da01 in GrBufferAllocPool::makeSpace(unsigned long, unsigned long, sk_sp<GrBuffer const>*, unsigned long*) ./../../third_party/skia/src/gpu/ganesh/GrBufferAllocPool.cpp:229:16
#6 0x7d090fb9fc02 in GrVertexBufferAllocPool::makeSpace(unsigned long, int, sk_sp<GrBuffer const>*, int*) ./../../third_party/skia/src/gpu/ganesh/GrBufferAllocPool.cpp:445:28
#7 0x7d090fdf3eef in GrMeshDrawOp::PatternHelper::init(GrMeshDrawTarget*, GrPrimitiveType, unsigned long, sk_sp<GrBuffer const>, int, int, int, int) ./../../third_party/skia/src/gpu/ganesh/ops/GrMeshDrawOp.cpp:96:25
#8 0x7d090fdf4500 in GrMeshDrawOp::QuadHelper::QuadHelper(GrMeshDrawTarget*, unsigned long, int) ./../../third_party/skia/src/gpu/ganesh/ops/GrMeshDrawOp.cpp:134:11
#9 0x7d090fe542bf in skgpu::ganesh::RegionOp::(anonymous namespace)::RegionOpImpl::onPrepareDraws(GrMeshDrawTarget*) ./../../third_party/skia/src/gpu/ganesh/ops/RegionOp.cpp:157:20
The rest of the stack shows the path from the browser side into the GPU process: RasterDecoderImpl::DoEndRasterCHROMIUM, CommandBufferService::Flush, CommandBufferStub::OnAsyncFlush, GpuChannel::ExecuteDeferredRequest, SchedulerDfs::RunNextTask, and finally content::GpuMain. The summary line is:
SUMMARY: AddressSanitizer: heap-buffer-overflow (/home/hyhy100/chromium2/src/out/asan/libskia.so+0xc55492) (BuildId: 739a908ae5387373)
The report also includes the shadow byte map around the faulting address, showing the redzone (fa) immediately after the addressable region, and the GPU process exit line:
[9053:9053:0822/110423.428241:ERROR:gpu_process_host.cc(980)] GPU process exited unexpectedly: exit_code=256
The command line recorded for the GPU process is:
/proc/self/exe --type=gpu-process --string-annotations --crashpad-handler-pid=9058 --enable-crash-reporter=, --no-subproc-heap-profiling --change-stack-guard-on-fork=enable --gpu-preferences=UAAAAAAAAAAgAAAEAAAAAAAAAAAAAAAAAABgAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAABAAAAAAAAAAEAAAAAAAAAAIAAAAAAAAAAgAAAAAAAAA --shared-files --metrics-shmem-handle=4,i,7711159281679077118,5503874274070490124,262144 --field-trial-handle=3,i,8533360048761144999,15654948628870376523,262144 --variations-seed-version
Step 6: reproduce in Skia standalone
Run genskpic.py to generate a .skp file, then run it in skpbench with the command shown in Setup. A UBSAN crash occurs. The report also lists a standalone Skia reproduction that produces a UBSAN crash.
Root cause
RegionOpImpl::onPrepareDraws carefully sums the region complexity with SkSafeMath and bails out if the sum overflowed or is zero. That guard makes numRects a valid int. The value is then handed to QuadHelper, which passes it as repeatCount to PatternHelper::init. There, the vertex count is computed as:
int vertexCount = verticesPerRepetition * repeatCount;
This is a signed integer multiplication with no overflow check. When the product exceeds the range of int, it wraps, and makeVertexSpace reserves a buffer for the wrapped count. The ASan report shows a write of size 4 immediately after the allocation made by PatternHelper::init. The ASan report shows exactly this: a write of size 4 immediately after a 1048608-byte allocation made by PatternHelper::init.
The researcher also flags indicesPerRepetition as needing validation.
The existing defence, SkSafeMath in RegionOpImpl, only covers the addition that produces numRects. It does not cover the multiplication inside the shared helper, The researcher notes that PatternHelper is used in many operations other than RegionOpImpl, so checking for overflows here would also mitigate attacks using other operations. The researcher states that PatternHelper is used in many operations other than RegionOpImpl, which is why he suggests fixing it in the helper rather than only in RegionOp.
Impact
The report classifies the crash as a GPU process crash and describes the bug as an integer overflow leading to an out-of-bounds write. The write happens in the GPU process, in memory allocated for vertex data. The severity assigned by the platform is high, with a bounty of 15,000 USD.
Because the same helper is shared by other draw operations, the report suggests the same class of overflow may be reachable through operations other than RegionOp. The report does not enumerate which ones or show PoCs for them.
Fix
What it does say is what should be checked: the multiplication in PatternHelper::init that computes vertexCount from verticesPerRepetition and repeatCount, and indicesPerRepetition as well. The researcher's recommendation is to add overflow checks in PatternHelper itself, since it is shared by many operations, rather than only in RegionOpImpl.
Variants to test
- Other users of
PatternHelper. The report says the helper is used by many operations besidesRegionOpImpl. Look for draw operations that let an attacker influence the repetition count, and check whether the vertex count multiplication can wrap. A positive result is an ASan heap-buffer-overflow inBufferWriter.hreached from that operation'sonPrepareDraws. - The index path. The researcher notes that
indicesPerRepetitionshould be validated too. Try to drive the index count multiplication past the integer range. A positive result is an out-of-bounds write or read in the index buffer rather than the vertex buffer. - Other guarded sums followed by unguarded products. The pattern here is a
SkSafeMathaddition that is checked, followed by a multiplication that is not. Search Skia for similar pairs. A positive result is a wrapped allocation size followed by a write past the allocation. - The standalone Skia path. Reproduce with
skpbenchunder UBSAN or ASAN on other picture inputs. A positive result is a UBSAN signed integer overflow or an ASAN heap-buffer-overflow in the same helper.
What happened, in plain words
A security researcher found a bug in a piece of software called Skia. Skia is a graphics library: a collection of code that knows how to draw shapes, text and images. It is used inside Google Chrome, the browser, and in other products too. When you look at a web page, a lot of what you see on screen is drawn by Skia.
The bug is a type of problem called a heap buffer overflow. To understand that, imagine a row of numbered lockers. Someone is told "you may use lockers 1 to 10". If they keep putting things into locker 11, 12 and beyond, they are writing outside the space they were given. In a computer, memory is handed out in blocks like that, and writing past the end of your block can corrupt whatever sits next to it. The "heap" is the general pool of memory a program uses for things it creates while running.
The specific mistake is an integer overflow. Computers store whole numbers in fixed-size boxes. A common size is 32 bits, which can hold values up to about 2.1 billion. If you multiply two large numbers and the true answer is bigger than that, the result wraps around and becomes a small or negative number. The program then reserves memory based on the wrapped number, and later writes past what it reserved.
In this case, Skia was asked to draw a shape made of many small four-sided pieces (quads). It calculated how much memory it needed by multiplying "vertices per piece" by "number of pieces". That multiplication had no safety check. The researcher, Renan Rios (@hyhy_100), reported it through the Chrome VRP, which is Google's programme that pays people for finding security bugs. The bug was given the identifier CVE-2024-8636, disclosed on 2024-09-10, rated high severity, with a bounty of 15,000 USD.
The report was filed as a separate issue following an earlier discussion, referenced as https://issues.chromium.org/issues/360758697#comment13. The researcher says that while researching Skia for more bugs, he noticed another hidden integer overflow.
Context
The affected part is called the Ganesh GPU backend. A GPU is the graphics processing unit, the chip that draws things quickly. A "backend" is the part of a library that talks to a particular piece of hardware or system. Ganesh is Skia's way of sending drawing work to the GPU.
The code path involved prepares a RegionOp draw for execution. A RegionOp draws a region, which here means a set of rectangles, as a mesh of quads on the GPU. A mesh is a grid of small shapes that together form a picture, like tiles in a mosaic.
To do this, RegionOp uses a helper called QuadHelper, which is built on top of another helper called PatternHelper. A helper is just a piece of code that does a common job so other code does not have to repeat it. PatternHelper::init works out how many vertices are needed for a patterned draw and asks the mesh draw target to reserve that much vertex space. A vertex is a corner point of a shape; a quad has four of them, and the GPU needs to know where each one goes.
The reservation is a multiplication of the number of vertices per repetition by the number of repetitions. "Repetition" here means one copy of the pattern. If you draw the same little shape many times, each copy is a repetition. That multiplication is where the bug lives.
Setup
The report gives two reproduction environments. "Reproduction" means the steps someone else can follow to make the bug happen on their own machine.
For Chromium (the open-source project that Chrome is built from):
- Apply the
chromium.diffrenderer patch to Chromium. - Run
genskpic.pyto generatedrawable_picture.skp.hh, then move the generated file tosrc/gpu/command_buffer/client. - Build and start the browser.
- Open
index.htmlto trigger the PoC. - The GPU process crashes.
A patch is a small file describing changes to source code, like a set of edit instructions. A renderer is the part of the browser that turns a web page into pixels. A PoC, or proof of concept, is a small test that demonstrates a bug really happens. A process is a running program with its own memory; Chrome splits itself into several processes, and the GPU process is the one that does graphics work.
For Skia standalone (without Chrome around it):
- Run
genskpic.pyto generate a.skpfile. - Run it in
skpbenchwith the command below. - A UBSAN crash occurs.
./out/asan/skpbench --src pic.skp --config gles
Line by line:
./out/asan/skpbenchruns a program calledskpbench. The./means "in the current folder".out/asanis a build folder;asanhints that this build includes AddressSanitizer, a tool that watches memory accesses and shouts when one goes out of bounds.--src pic.skptells the program to use the filepic.skpas its input. A.skpfile is a saved Skia picture, a recording of drawing commands.--config glesasks it to use the GLES configuration, a common way of talking to graphics hardware.
A UBSAN crash is one reported by UndefinedBehaviorSanitizer, a tool that flags operations whose result the programming language does not define, such as a signed integer multiplication that overflows.
The crash state shown in the report is from an AddressSanitizer build. The stack trace references a build path under /home/hyhy100/chromium2/src/out/asan/libskia.so, and the command line shows a GPU process launched with --type=gpu-process. A stack trace is the list of function calls that led to the crash, like a receipt showing every step. The report does not state the Chrome version or the Skia revision beyond the source links it quotes.
Finding it
The researcher explains that PatternHelper, called from RegionOpImpl::onPrepareDraws, does not check for overflow when multiplying the number of vertices per repetition by the number of quads to draw. As a result the vertex space can still be overflowed even when numRects is a valid integer. numRects is simply the count of rectangles the draw involves.
He points at three places in the source, labelled [1], [2] and [3]. "Source" means the human-written code of the program.
[1] is RegionOpImpl::onPrepareDraws in third_party/skia/src/gpu/ganesh/ops/RegionOp.cpp around line 150. The code sums the region complexity of each region using SkSafeMath, and drops the draw if the sum overflowed or is zero. It then constructs a QuadHelper with numRects:
void onPrepareDraws(GrMeshDrawTarget* target) override {
...
SkSafeMath safeMath;
for (int i = 0; i < numRegions; i++) {
numRects = safeMath.addInt(numRects, fRegions[i].fRegion.computeRegionComplexity());
}
if (!safeMath) {
// This is a nonsensical draw, so we can just drop it.
return;
}
if (!numRects) {
return;
}
QuadHelper helper(target, fProgramInfo->geomProc().vertexStride(), numRects); // <-- [1]
...
}
Line by line:
void onPrepareDraws(GrMeshDrawTarget* target) override {starts a function that prepares a draw.GrMeshDrawTarget*is a pointer to the thing that will hold the mesh data; a pointer is a reference to a location in memory.SkSafeMath safeMath;creates a small helper object whose job is to do arithmetic and remember whether anything went wrong.for (int i = 0; i < numRegions; i++) {loops over each region.numRects = safeMath.addInt(numRects, fRegions[i].fRegion.computeRegionComplexity());adds the complexity of each region to a running total, using the safe adder.computeRegionComplexity()returns how many rectangles that region needs.if (!safeMath) {checks whether the safe adder recorded an overflow.// This is a nonsensical draw, so we can just drop it.is a comment explaining that an impossible draw is simply skipped.return;leaves the function without drawing.if (!numRects) { return; }skips the draw if there is nothing to draw.QuadHelper helper(target, fProgramInfo->geomProc().vertexStride(), numRects);creates the helper, passing the target, the size of one vertex (vertexStride), and the rectangle count.
The important observation is that the addition is guarded, so numRects itself is a valid integer. The guard does not extend to what happens next.
[2] is the QuadHelper constructor in third_party/skia/src/gpu/ganesh/ops/GrMeshDrawOp.cpp around line 134. It forwards quadsToDraw into init together with the per-quad vertex and index counts and the maximum number of non-AA quads:
GrMeshDrawOp::QuadHelper::QuadHelper(GrMeshDrawTarget* target,
size_t vertexStride,
int quadsToDraw) {
...
this->init(target, GrPrimitiveType::kTriangles, vertexStride, std::move(indexBuffer),
GrResourceProvider::NumVertsPerNonAAQuad(),
GrResourceProvider::NumIndicesPerNonAAQuad(), quadsToDraw,
GrResourceProvider::MaxNumNonAAQuads()); // <-- [2]
}
Line by line:
GrMeshDrawOp::QuadHelper::QuadHelper(...)is the constructor, the code that runs when aQuadHelperis created.GrMeshDrawTarget* targetis the place the mesh will be built.size_t vertexStrideis the size in bytes of one vertex.size_tis an unsigned whole-number type used for sizes.int quadsToDrawis how many quads to draw.this->init(...)calls the shared initialisation routine.GrPrimitiveType::kTrianglessays the GPU should draw triangles. A quad is drawn as two triangles.std::move(indexBuffer)hands over a buffer of indices. An index buffer lists which vertices form each triangle, so vertices can be reused.GrResourceProvider::NumVertsPerNonAAQuad()is the number of vertices per quad when anti-aliasing is off. Anti-aliasing is the smoothing of jagged edges.GrResourceProvider::NumIndicesPerNonAAQuad()is the number of indices per such quad.quadsToDrawis passed through as the repetition count.GrResourceProvider::MaxNumNonAAQuads()is the maximum number of quads the system expects.
[3] is PatternHelper::init in the same file around line 95. Here the vertex count is computed by a plain multiplication with no overflow check, and the result is passed to makeVertexSpace:
void GrMeshDrawOp::PatternHelper::init(GrMeshDrawTarget* target, GrPrimitiveType primitiveType,
size_t vertexStride, sk_sp<const GrBuffer> indexBuffer,
int verticesPerRepetition, int indicesPerRepetition,
int repeatCount, int maxRepetitions) {
...
int vertexCount = verticesPerRepetition * repeatCount; // <-- [3] No checks are being made here against overflow.
fVertices = target->makeVertexSpace(vertexStride, vertexCount, &vertexBuffer, &firstVertex);
if (!fVertices) {
SkDebugf("Vertices could not be allocated for patterned rendering.");
return;
}
...
}
Line by line:
- The function signature lists everything it needs: the target, the primitive type (triangles, lines and so on), the vertex size, the index buffer, how many vertices and indices each repetition uses, how many repetitions there are, and the maximum allowed.
int vertexCount = verticesPerRepetition * repeatCount;multiplies the two counts. Both areint, a signed 32-bit whole number. If the product is too large, it wraps around silently.fVertices = target->makeVertexSpace(vertexStride, vertexCount, &vertexBuffer, &firstVertex);asks for space forvertexCountvertices. BecausevertexCountmay have wrapped to a small number, too little space is reserved.if (!fVertices) {checks whether the reservation failed.SkDebugf("Vertices could not be allocated for patterned rendering.");prints a debug message if it did.return;leaves the function.
The researcher also notes that indicesPerRepetition should be validated as well. He adds that PatternHelper is used in many operations other than RegionOpImpl, so checking for overflows here would also mitigate attacks using other operations. "Mitigate" means reduce the risk.
The summary he gives is: integer overflow in Skia GrMeshDrawOp::PatternHelper::init leads to OOB write. OOB stands for out of bounds, meaning outside the memory that was reserved.
Exploitation
"Exploitation" here means actually making the bug happen, not necessarily taking over a machine.
Step 1: build the instrumented browser
The report does not include the contents of that patch, so what it changes is not stated here. "Instrumented" means built with extra checking tools such as AddressSanitizer.
Step 2: generate the picture
Run genskpic.py to produce drawable_picture.skp.hh, then move the generated file into src/gpu/command_buffer/client. The script itself is not reproduced in the report; The script itself is not reproduced in the report, and the report does not describe the contents of the generated picture. A .hh file is a C++ header file, a file of declarations included by other code.
Step 3: build and start
Build the browser and start it. The crash occurs in the GPU process, and the trace shown comes from a build with AddressSanitizer enabled.
Step 4: open the trigger page
Open index.html to trigger the PoC. The page is not reproduced in the report. The effect is that the GPU process crashes.
Step 5: read the crash
The crash state is an AddressSanitizer heap-buffer-overflow report. The write is of size 4, in thread T0 (chrome), at an address 0 bytes after a 1048608-byte region. A thread is a sequence of instructions running inside a process; T0 is the first one. The top frames are in BufferWriter.h, writing a quad vertex, called from RegionOpImpl::onPrepareDraws at RegionOp.cpp:170:
==9095==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x7d0890d2c820 at pc 0x7d090fe55493 bp 0x7ffde9e34b90 sp 0x7ffde9e34b88
WRITE of size 4 at 0x7d0890d2c820 thread T0 (chrome)
#0 0x7d090fe55492 in operator<<<float> ./../../third_party/skia/src/gpu/BufferWriter.h:280:5
#1 0x7d090fe55492 in writeVertex ./../../third_party/skia/src/gpu/BufferWriter.h:0:0
#2 0x7d090fe55492 in writeQuadVertex<1, skgpu::VertexWriter::TriStrip<float>, skgpu::VertexColor> ./../../third_party/skia/src/gpu/BufferWriter.h:262:14
#3 0x7d090fe55492 in writeQuad<skgpu::VertexWriter::TriStrip<float>, skgpu::VertexColor> ./../../third_party/skia/src/gpu/BufferWriter.h:246:15
#4 0x7d090fe55492 in skgpu::ganesh::RegionOp::(anonymous namespace)::RegionOpImpl::onPrepareDraws(GrMeshDrawTarget*) ./../../third_party/skia/src/gpu/ganesh/ops/RegionOp.cpp:170:26
Line by line:
==9095==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x7d0890d2c820 ...says the tool caught a write outside a memory block. The long numbers are memory addresses and register values; they are not needed to understand the bug.WRITE of size 4 at 0x7d0890d2c820 thread T0 (chrome)says four bytes were written at that address by the main thread of the process named chrome.#0 ... operator<<<float> ... BufferWriter.h:280is the innermost call: a small helper that writes a floating-point number into a buffer.#1 ... writeVertex ...writes one vertex.#2 ... writeQuadVertex<...>writes the vertices of one quad.#3 ... writeQuad<...>writes a whole quad.#4 ... RegionOpImpl::onPrepareDraws ... RegionOp.cpp:170is the region drawing code that started it all.
The allocation side of the report shows where the undersized buffer came from. PatternHelper::init at GrMeshDrawOp.cpp:96 calls into GrVertexBufferAllocPool::makeSpace, which creates a block through GrBufferAllocPool::createBlock and resetCpuData, ending in GrCpuBuffer.h allocating the buffer with operator new:
0x7d0890d2c820 is located 0 bytes after 1048608-byte region [0x7d0890c2c800,0x7d0890d2c820)
allocated by thread T0 (chrome) here:
#0 0x58d4249a00bd in operator new(unsigned long) _asan_rtl_:3
#1 0x7d090fb9bc9d in Make ./../../third_party/skia/src/gpu/ganesh/GrCpuBuffer.h:29:20
#2 0x7d090fb9bc9d in GrBufferAllocPool::CpuBufferCache::makeBuffer(unsigned long, bool) ./../../third_party/skia/src/gpu/ganesh/GrBufferAllocPool.cpp:56:30
#3 0x7d090fb9cb9c in GrBufferAllocPool::resetCpuData(unsigned long) ./../../third_party/skia/src/gpu/ganesh/GrBufferAllocPool.cpp:389:60
#4 0x7d090fb9e51a in GrBufferAllocPool::createBlock(unsigned long) ./../../third_party/skia/src/gpu/ganesh/GrBufferAllocPool.cpp:362:15
#5 0x7d090fb9da01 in GrBufferAllocPool::makeSpace(unsigned long, unsigned long, sk_sp<GrBuffer const>*, unsigned long*) ./../../third_party/skia/src/gpu/ganesh/GrBufferAllocPool.cpp:229:16
#6 0x7d090fb9fc02 in GrVertexBufferAllocPool::makeSpace(unsigned long, int, sk_sp<GrBuffer const>*, int*) ./../../third_party/skia/src/gpu/ganesh/GrBufferAllocPool.cpp:445:28
#7 0x7d090fdf3eef in GrMeshDrawOp::PatternHelper::init(GrMeshDrawTarget*, GrPrimitiveType, unsigned long, sk_sp<GrBuffer const>, int, int, int, int) ./../../third_party/skia/src/gpu/ganesh/ops/GrMeshDrawOp.cpp:96:25
#8 0x7d090fdf4500 in GrMeshDrawOp::QuadHelper::QuadHelper(GrMeshDrawTarget*, unsigned long, int) ./../../third_party/skia/src/gpu/ganesh/ops/GrMeshDrawOp.cpp:134:11
#9 0x7d090fe542bf in skgpu::ganesh::RegionOp::(anonymous namespace)::RegionOpImpl::onPrepareDraws(GrMeshDrawTarget*) ./../../third_party/skia/src/gpu/ganesh/ops/RegionOp.cpp:157:20
Line by line:
- The first line says the bad address sits exactly 0 bytes after a region of 1048608 bytes. In other words, the write landed right at the edge and one step past it.
allocated by thread T0 (chrome) here:introduces the list of calls that created that region.#0 ... operator new(unsigned long)is the low-level memory allocator.operator newis the C++ way of asking the system for memory.#1 ... Make ... GrCpuBuffer.h:29wraps that memory in a buffer object.#2 ... CpuBufferCache::makeBuffer ...creates a buffer for CPU-side data.#3 ... resetCpuData ...and#4 ... createBlock ...set up a block of pooled memory. A pool reuses memory in chunks to avoid asking the system constantly.#5 ... makeSpace ...and#6 ... GrVertexBufferAllocPool::makeSpace ...reserve space inside that block for vertices.#7 ... PatternHelper::init ... GrMeshDrawOp.cpp:96is the call that asked for the space, using the wrapped count.#8 ... QuadHelper::QuadHelper ...and#9 ... RegionOpImpl::onPrepareDraws ...show the chain that led there.
The rest of the stack shows the path from the browser side into the GPU process: RasterDecoderImpl::DoEndRasterCHROMIUM, CommandBufferService::Flush, CommandBufferStub::OnAsyncFlush, GpuChannel::ExecuteDeferredRequest, SchedulerDfs::RunNextTask, and finally content::GpuMain. A decoder here is the code that reads commands sent from the browser to the GPU process. Flush means "now carry out the queued work". The summary line is:
SUMMARY: AddressSanitizer: heap-buffer-overflow (/home/hyhy100/chromium2/src/out/asan/libskia.so+0xc55492) (BuildId: 739a908ae5387373)
This line restates the finding and names the library file, libskia.so, and the offset inside it. A BuildId is a fingerprint of the build.
The report also includes the shadow byte map around the faulting address, showing the redzone (fa) immediately after the addressable region, and the GPU process exit line:
[9053:9053:0822/110423.428241:ERROR:gpu_process_host.cc(980)] GPU process exited unexpectedly: exit_code=256
A shadow byte map is AddressSanitizer's own bookkeeping: for every chunk of real memory it keeps a byte saying whether that chunk is safe to use. fa marks a redzone, a deliberately poisoned area around allocations so that stray writes are caught. The exit line says the GPU process died with code 256, which is how the browser noticed.
The command line recorded for the GPU process is:
/proc/self/exe --type=gpu-process --string-annotations --crashpad-handler-pid=9058 --enable-crash-reporter=, --no-subproc-heap-profiling --change-stack-guard-on-fork=enable --gpu-preferences=UAAAAAAAAAAgAAAEAAAAAAAAAAAAAAAAAABgAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAABAAAAAAAAAAEAAAAAAAAAAIAAAAAAAAAAgAAAAAAAAA --shared-files --metrics-shmem-handle=4,i,7711159281679077118,5503874274070490124,262144 --field-trial-handle=3,i,8533360048761144999,15654948628870376523,262144 --variations-seed-version
Line by line:
/proc/self/exeis a special path on Linux that means "the program currently running".--type=gpu-processtells Chrome to start as the GPU process.--crashpad-handler-pid=9058names the process that collects crash reports. A PID is a process identifier.--enable-crash-reporter=,turns on crash reporting.--gpu-preferences=...is a long encoded blob of GPU settings.--shared-files,--metrics-shmem-handle=...,--field-trial-handle=...and--variations-seed-versionrelate to shared memory and experiment configuration.
Step 6: reproduce in Skia standalone
Run genskpic.py to generate a .skp file, then run it in skpbench with the command shown in Setup. A UBSAN crash occurs. The report also lists a standalone Skia reproduction that produces a UBSAN crash. "Integration" means the way Chrome uses Skia.
Root cause
RegionOpImpl::onPrepareDraws carefully sums the region complexity with SkSafeMath and bails out if the sum overflowed or is zero. That guard makes numRects a valid int. The value is then handed to QuadHelper, which passes it as repeatCount to PatternHelper::init. There, the vertex count is computed as:
int vertexCount = verticesPerRepetition * repeatCount;
This is a signed integer multiplication with no overflow check. When the product exceeds the range of int, it wraps, and makeVertexSpace reserves a buffer for the wrapped count. The ASan report shows a write of size 4 immediately after the allocation made by PatternHelper::init. The ASan report shows exactly this: a write of size 4 immediately after a 1048608-byte allocation made by PatternHelper::init.
The researcher also flags indicesPerRepetition as needing validation.
The existing defence, SkSafeMath in RegionOpImpl, only covers the addition that produces numRects. It does not cover the multiplication inside the shared helper, The researcher notes that PatternHelper is used in many operations other than RegionOpImpl, so checking for overflows here would also mitigate attacks using other operations. The researcher states that PatternHelper is used in many operations other than RegionOpImpl, which is why he suggests fixing it in the helper rather than only in RegionOp.
Impact
The report classifies the crash as a GPU process crash and describes the bug as an integer overflow leading to an out-of-bounds write. The write happens in the GPU process, in memory allocated for vertex data. A sandbox is the isolation around a process that limits what it can touch if compromised. The severity assigned by the platform is high, with a bounty of 15,000 USD.
Because the same helper is shared by other draw operations, the report suggests the same class of overflow may be reachable through operations other than RegionOp. The report does not enumerate which ones or show PoCs for them.
Fix
A commit is a recorded change in a source code repository. What it does say is what should be checked: the multiplication in PatternHelper::init that computes vertexCount from verticesPerRepetition and repeatCount, and indicesPerRepetition as well. The researcher's recommendation is to add overflow checks in PatternHelper itself, since it is shared by many operations, rather than only in RegionOpImpl.
Variants to test
A variant is a related version of the same bug that might exist elsewhere.
- Other users of
PatternHelper. The report says the helper is used by many operations besidesRegionOpImpl. Look for draw operations that let an attacker influence the repetition count, and check whether the vertex count multiplication can wrap. A positive result is an ASan heap-buffer-overflow inBufferWriter.hreached from that operation'sonPrepareDraws. - The index path. The researcher notes that
indicesPerRepetitionshould be validated too. Try to drive the index count multiplication past the integer range. A positive result is an out-of-bounds write or read in the index buffer rather than the vertex buffer. - Other guarded sums followed by unguarded products. The pattern here is a
SkSafeMathaddition that is checked, followed by a multiplication that is not. Search Skia for similar pairs. A positive result is a wrapped allocation size followed by a write past the allocation. - The standalone Skia path. Reproduce with
skpbenchunder UBSAN or ASAN on other picture inputs. A positive result is a UBSAN signed integer overflow or an ASAN heap-buffer-overflow in the same helper.
Glossary
- AddressSanitizer (ASan): a tool built into a program that watches memory accesses and reports any read or write outside the memory that was reserved.
- Anti-aliasing: smoothing of jagged edges in drawn shapes.
- API: an agreed way for one piece of software to ask another to do something, like a menu of allowed requests.
- Backend: the part of a library that talks to a particular system or piece of hardware.
- Bounty: money paid by a programme for a valid security report.
- Buffer: a block of memory set aside to hold data.
- BuildId: a fingerprint identifying a particular build of a program.
- Chromium: the open-source browser project that Google Chrome is built from.
- Commit: a recorded change in a source code repository.
- CVE: a public identifier for a known security vulnerability.
- Decoder: code that reads and interprets commands, here the commands sent from the browser to the GPU process.
- Flush: to carry out queued work now.
- Ganesh: Skia's backend for drawing with a GPU.
- GPU: graphics processing unit, the chip that draws images quickly.
- Heap: the general pool of memory a program uses for things it creates while running.
- Heap buffer overflow: writing past the end of a block of memory taken from the heap.
- Helper: a piece of code that does a common job so other code does not repeat it.
- Index buffer: a list saying which vertices form each triangle, so vertices can be reused.
- Instrumented build: a build with extra checking tools such as ASan or UBSAN.
- Integer overflow: when a whole number grows past the largest value its storage can hold and wraps around to a small or negative value.
- Mesh: a grid of small shapes that together form a picture.
- Mitigate: reduce the risk of something happening.
- OOB (out of bounds): outside the memory that was reserved.
- Patch: a file describing changes to source code.
- PID: process identifier, a number the operating system gives a running program.
- Pointer: a reference to a location in memory.
- PoC (proof of concept): a small test that demonstrates a bug really happens.
- Pool: a store of memory reused in chunks to avoid asking the system constantly.
- Process: a running program with its own memory.
- Quad: a four-sided shape, drawn on the GPU as two triangles.
- Redzone: a deliberately poisoned area around an allocation so stray writes are caught.
- Region: here, a set of rectangles to be drawn.
- Renderer: the part of a browser that turns a web page into pixels.
- Repetition: one copy of a pattern in a repeated draw.
- Sandbox: isolation around a process that limits what it can touch if compromised.
- Shadow byte map: AddressSanitizer's bookkeeping that records whether each chunk of memory is safe to use.
- Skia: a 2D graphics library used by Chrome and other products.
- Skp: a saved Skia picture, a recording of drawing commands.
- Stack trace: the list of function calls that led to a crash.
- Thread: a sequence of instructions running inside a process.
- UBSAN (UndefinedBehaviorSanitizer): a tool that flags operations whose result the programming language does not define, such as a signed integer multiplication that overflows.
- Vertex: a corner point of a shape.
- VRP (Vulnerability Reward Program): a programme that pays people for finding security bugs.