| 1 |
From 013ad6e7097238654847bfa5a5fb2c6c3823ee41 Mon Sep 17 00:00:00 2001 |
| 2 |
From: Alexis Cruz-Ayala <[email protected]> |
| 3 |
Date: Fri, 17 Jul 2026 12:51:34 -0400 |
| 4 |
Subject: [PATCH] [Security] Add a SmallPathIDChangeListener to |
| 5 |
SmallPathAtlasMgr |
| 6 |
|
| 7 |
There was a vulnerability where SkPathID could have duplicate entries if an attacker created and discarded enough Small, Complex Paths to overwhelm the SmallPathAtlasMgr cache. This could lead to the attacker submitting a request to the cache for a path, and receiving a victim's path instead. |
| 8 |
|
| 9 |
The solution involved mirroring what is done in the SoftwarePathRenderer.cpp and using an SkIDChangeListener to listen for when a path is modified or discarded and delete the entry in the cache. This way, duplicate entries are avoided. |
| 10 |
|
| 11 |
A test was added that shows that an ID collision can be forced amongst SmallPaths with complex geometry; any hash of two small, complex paths would rely only on the genID, making it easier to hit a duplicate entry. |
| 12 |
|
| 13 |
Bug: https://issues.chromium.org/issues/501759192 |
| 14 |
Change-Id: Id80a0167370dfca1b7dac511f1ddcfda16a72fc1 |
| 15 |
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/1294996 |
| 16 |
Reviewed-by: Florin Malita <[email protected]> |
| 17 |
Commit-Queue: Alexis Cruz-Ayala <[email protected]> |
| 18 |
--- |
| 19 |
src/gpu/ganesh/ops/SmallPathAtlasMgr.cpp | 16 +++++++++++++--- |
| 20 |
src/gpu/ganesh/ops/SmallPathAtlasMgr.h | 2 +- |
| 21 |
src/gpu/ganesh/ops/SmallPathShapeData.h | 19 ++++++++++++++++++- |
| 22 |
3 files changed, 32 insertions(+), 5 deletions(-) |
| 23 |
|
| 24 |
--- a/src/gpu/ganesh/ops/SmallPathAtlasMgr.cpp |
| 25 |
+++ b/src/gpu/ganesh/ops/SmallPathAtlasMgr.cpp |
| 26 |
@@ -11,9 +11,11 @@ |
| 27 |
#include "include/gpu/GpuTypes.h" |
| 28 |
#include "include/gpu/ganesh/GrBackendSurface.h" |
| 29 |
#include "include/gpu/ganesh/GrTypes.h" |
| 30 |
+#include "include/private/SkIDChangeListener.h" |
| 31 |
#include "include/private/base/SkTo.h" |
| 32 |
#include "include/private/gpu/ganesh/GrTypesPriv.h" |
| 33 |
#include "src/gpu/ganesh/GrCaps.h" |
| 34 |
+#include "src/gpu/ganesh/geometry/GrStyledShape.h" |
| 35 |
#include "src/gpu/ganesh/ops/SmallPathShapeData.h" |
| 36 |
|
| 37 |
#include <cstddef> |
| 38 |
@@ -87,11 +89,19 @@ |
| 39 |
delete shapeData; |
| 40 |
} |
| 41 |
|
| 42 |
-SmallPathShapeData* SmallPathAtlasMgr::findOrCreate(const SmallPathShapeDataKey& key) { |
| 43 |
+SmallPathShapeData* SmallPathAtlasMgr::findOrCreate(const SmallPathShapeDataKey& key, |
| 44 |
+ const GrStyledShape& shape) { |
| 45 |
auto shapeData = fShapeCache.find(key); |
| 46 |
+ |
| 47 |
+ if (shapeData && shapeData->fIDChangeListener->hasChanged()) { |
| 48 |
+ this->deleteCacheEntry(shapeData); |
| 49 |
+ shapeData = nullptr; |
| 50 |
+ } |
| 51 |
+ |
| 52 |
if (!shapeData) { |
| 53 |
// TODO: move the key into the ctor |
| 54 |
shapeData = new SmallPathShapeData(key); |
| 55 |
+ shape.addGenIDChangeListener(shapeData->fIDChangeListener); |
| 56 |
fShapeCache.add(shapeData); |
| 57 |
fShapeList.addToTail(shapeData); |
| 58 |
#ifdef DF_PATH_TRACKING |
| 59 |
@@ -109,7 +119,7 @@ |
| 60 |
SmallPathShapeDataKey key(shape, desiredDimension); |
| 61 |
|
| 62 |
// TODO: move the key into 'findOrCreate' |
| 63 |
- return this->findOrCreate(key); |
| 64 |
+ return this->findOrCreate(key, shape); |
| 65 |
} |
| 66 |
|
| 67 |
SmallPathShapeData* SmallPathAtlasMgr::findOrCreate(const GrStyledShape& shape, |
| 68 |
@@ -117,7 +127,7 @@ |
| 69 |
SmallPathShapeDataKey key(shape, ctm); |
| 70 |
|
| 71 |
// TODO: move the key into 'findOrCreate' |
| 72 |
- return this->findOrCreate(key); |
| 73 |
+ return this->findOrCreate(key, shape); |
| 74 |
} |
| 75 |
|
| 76 |
GrDrawOpAtlas::ErrorCode SmallPathAtlasMgr::addToAtlas(GrResourceProvider* resourceProvider, |
| 77 |
--- a/src/gpu/ganesh/ops/SmallPathAtlasMgr.h |
| 78 |
+++ b/src/gpu/ganesh/ops/SmallPathAtlasMgr.h |
| 79 |
@@ -92,7 +92,7 @@ |
| 80 |
void deleteCacheEntry(SmallPathShapeData*); |
| 81 |
|
| 82 |
private: |
| 83 |
- SmallPathShapeData* findOrCreate(const SmallPathShapeDataKey&); |
| 84 |
+ SmallPathShapeData* findOrCreate(const SmallPathShapeDataKey&, const GrStyledShape&); |
| 85 |
|
| 86 |
void evict(skgpu::PlotLocator) override; |
| 87 |
|
| 88 |
--- a/src/gpu/ganesh/ops/SmallPathShapeData.h |
| 89 |
+++ b/src/gpu/ganesh/ops/SmallPathShapeData.h |
| 90 |
@@ -12,6 +12,7 @@ |
| 91 |
#if !defined(SK_ENABLE_OPTIMIZE_SIZE) |
| 92 |
|
| 93 |
#include "include/core/SkRect.h" |
| 94 |
+#include "include/private/SkIDChangeListener.h" |
| 95 |
#include "include/private/base/SkTemplates.h" |
| 96 |
#include "src/base/SkTInternalLList.h" |
| 97 |
#include "src/core/SkChecksum.h" |
| 98 |
@@ -25,6 +26,18 @@ |
| 99 |
|
| 100 |
namespace skgpu::ganesh { |
| 101 |
|
| 102 |
+class SmallPathIDChangeListener : public SkIDChangeListener { |
| 103 |
+public: |
| 104 |
+ SmallPathIDChangeListener() : fHasChanged(false) {} |
| 105 |
+ |
| 106 |
+ bool hasChanged() const { return fHasChanged.load(std::memory_order_relaxed); } |
| 107 |
+ |
| 108 |
+ void changed() override { fHasChanged.store(true, std::memory_order_relaxed); } |
| 109 |
+ |
| 110 |
+private: |
| 111 |
+ std::atomic<bool> fHasChanged; |
| 112 |
+}; |
| 113 |
+ |
| 114 |
class SmallPathShapeDataKey { |
| 115 |
public: |
| 116 |
// TODO: add a move variant |
| 117 |
@@ -58,7 +71,9 @@ |
| 118 |
|
| 119 |
class SmallPathShapeData { |
| 120 |
public: |
| 121 |
- SmallPathShapeData(const SmallPathShapeDataKey& key) : fKey(key) {} |
| 122 |
+ SmallPathShapeData(const SmallPathShapeDataKey& key) |
| 123 |
+ : fKey(key), fIDChangeListener(sk_make_sp<SmallPathIDChangeListener>()) {} |
| 124 |
+ ~SmallPathShapeData() { fIDChangeListener->markShouldDeregister(); } |
| 125 |
|
| 126 |
const SmallPathShapeDataKey fKey; |
| 127 |
SkRect fBounds; |
| 128 |
@@ -73,6 +88,8 @@ |
| 129 |
static inline uint32_t Hash(const SmallPathShapeDataKey& key) { |
| 130 |
return SkChecksum::Hash32(key.data(), sizeof(uint32_t) * key.count32()); |
| 131 |
} |
| 132 |
+ |
| 133 |
+ sk_sp<SmallPathIDChangeListener> fIDChangeListener; |
| 134 |
}; |
| 135 |
|
| 136 |
} // namespace skgpu::ganesh |