Commit 642f8dc
[Backport] Security bug 421629753
Manual cherry-pick of patch originally reviewed on
https://skia-review.googlesource.com/c/skia/+/1002497:
Remove destructor calls on shutdown for static local variables
After thinking about it more and chatting some experienced folks,
I think I identified the wrong root cause in the linked bug and
thus had the wrong fix in https://skia-review.googlesource.com/c/skia/+/1001824
Skia was violating the style guide [1] and running into the reasons
that these non-trivial destructors are banned. sk_sp *has* a non-trivial
destructor - it does reference counting and possible destructing of
the held object. So even though SkImageFilterCache has a trivial
destructor, sk_sp's freeing was causing the problem.
"when a program starts threads that are not joined at exit,
those threads may attempt to access objects after their
lifetime has ended if their destructor has already run."
Here's roughly what was going on, pieced together from the linked
crash log
1) Thread 0 creates children threads
2) Thread 5 called SkImageFilterCache::Get() to create static
local sk_sp<SkImageFilterCache>. Let's call it Alice. The
function returns a copy of sk_sp called Bob. Bob and Alice
point to an object with refcount 2. Bob goes out of scope.
and there's just Alice with refcount of 1.
3) Thread 0 begins to shutdown. Via __run_exit_handlers it calls
the destructor for Alice, which upon hitting a refcount of 0
free's the memory for the underlying cache.
4) Thread 5 is still plugging away and calls ::Get() which returns
a new sk_sp (called Carol) with refcount 1 but pointing to
a freed pointer.
5) Crash caught by sanitizer.
In a non-sanitizer build, step 5 is likely "nothing happens anyway"
or "segfault during shutdown".
To fix this, we don't want the static local to be an sk_sp, but
instead it should be a bare pointer. This ensures the object lives
all the way until the OS reclaims the memory.
[1] https://google.github.io/styleguide/cppguide.html#Static_and_Global_Variables
Change-Id: I134156898f840924f0ec7001d0eb7a11a45d6c53
Bug: b/421629753
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/1002497
Reviewed-by: Michael Ludwig <[email protected]>
Commit-Queue: Michael Ludwig <[email protected]>
Commit-Queue: Kaylee Lubick <[email protected]>
Auto-Submit: Kaylee Lubick <[email protected]>
Reviewed-on: https://codereview.qt-project.org/c/qt/qtwebengine-chromium/+/659334
Reviewed-by: Moss Heim <[email protected]>1 parent 16f89e0 commit 642f8dc
File tree
3 files changed
+23
-22
lines changed- chromium/third_party/skia/src
- core
- gpu/ganesh
3 files changed
+23
-22
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
155 | | - | |
156 | | - | |
| 155 | + | |
| 156 | + | |
157 | 157 | | |
158 | 158 | | |
159 | 159 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
158 | 158 | | |
159 | 159 | | |
160 | 160 | | |
161 | | - | |
| 161 | + | |
162 | 162 | | |
163 | 163 | | |
164 | | - | |
| 164 | + | |
165 | 165 | | |
166 | | - | |
167 | | - | |
168 | | - | |
| 166 | + | |
| 167 | + | |
169 | 168 | | |
Lines changed: 17 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
325 | 326 | | |
326 | 327 | | |
327 | 328 | | |
328 | | - | |
329 | | - | |
330 | | - | |
| 329 | + | |
| 330 | + | |
331 | 331 | | |
332 | 332 | | |
333 | 333 | | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
338 | 339 | | |
339 | 340 | | |
340 | 341 | | |
341 | 342 | | |
342 | 343 | | |
343 | | - | |
344 | | - | |
345 | | - | |
| 344 | + | |
| 345 | + | |
346 | 346 | | |
347 | 347 | | |
348 | 348 | | |
349 | 349 | | |
350 | | - | |
351 | | - | |
352 | | - | |
353 | | - | |
354 | | - | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
355 | 357 | | |
356 | 358 | | |
357 | 359 | | |
| |||
0 commit comments