| 1 |
From d7c15613590bfe9f9a40e82542c2873766a2e558 Mon Sep 17 00:00:00 2001 |
| 2 |
From: Arthur Sonzogni <[email protected]> |
| 3 |
Date: Thu, 27 Aug 2026 09:47:10 +0000 |
| 4 |
Subject: [PATCH] Fix UAF in SkCachedData::internalUnref |
| 5 |
|
| 6 |
Destroy AutoMutexWritable before calling delete this in |
| 7 |
SkCachedData::internalUnref to avoid unlocking the mutex after the |
| 8 |
object has been deleted. |
| 9 |
|
| 10 |
This was found while trying to enable the MiraclePtr rewrite |
| 11 |
that would protect "this" and cause deterministic termination. |
| 12 |
Bug: https://issues.chromium.org/issues/553345874 |
| 13 |
Doc: https://bit.ly/miracleptr-skia |
| 14 |
Change-Id: I0a1d3aed3b3d41e4ed06505295a14028ff634788 |
| 15 |
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/1340596 |
| 16 |
Reviewed-by: Michael Ludwig <[email protected]> |
| 17 |
Commit-Queue: Arthur Sonzogni <[email protected]> |
| 18 |
--- |
| 19 |
src/core/SkCachedData.cpp | 7 ++++++- |
| 20 |
1 file changed, 6 insertions(+), 1 deletion(-) |
| 21 |
|
| 22 |
diff --git a/src/core/SkCachedData.cpp b/src/core/SkCachedData.cpp |
| 23 |
index b48bee8506..6df6d1d922 100644 |
| 24 |
--- a/src/core/SkCachedData.cpp |
| 25 |
+++ b/src/core/SkCachedData.cpp |
| 26 |
@@ -65,7 +65,12 @@ void SkCachedData::internalRef(bool fromCache) const { |
| 27 |
} |
| 28 |
|
| 29 |
void SkCachedData::internalUnref(bool fromCache) const { |
| 30 |
- if (AutoMutexWritable(this)->inMutexUnref(fromCache)) { |
| 31 |
+ bool shouldDelete = false; |
| 32 |
+ { |
| 33 |
+ AutoMutexWritable amw(this); |
| 34 |
+ shouldDelete = amw->inMutexUnref(fromCache); |
| 35 |
+ } |
| 36 |
+ if (shouldDelete) { |
| 37 |
// can't delete inside doInternalUnref, since it is locking a mutex (which we own) |
| 38 |
delete this; |
| 39 |
} |
| 40 |
-- |
| 41 |
2.53.0 |
| 42 |
|