Debian Codegraph @

debian/patches/CVE-2026-17757

raw
1 From e6496d127941b51f348f4c880032547d4c440c37 Mon Sep 17 00:00:00 2001
2 From: Robert Phillips <[email protected]>
3 Date: Thu, 25 Jun 2026 13:21:59 +0000
4 Subject: [PATCH] Fix Ganesh stencil UMR
5
6 When, for a given OpsTask, the stencil ops are discard/store there was a possibility of uninitialized values to creep into the stencil buffer.
7
8 This CL reduces the cases in which discard will be used, mapping the problematic cases to clear/store.
9
10 Bug: https://issues.chromium.org/issues/502351526
11 Change-Id: Ic5d7e352d4c59426f103f2cfc39d5cf3fd879213
12 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/1269136
13 Reviewed-by: Greg Daniel <[email protected]>
14 Commit-Queue: Robert Phillips <[email protected]>
15 ---
16 gn/tests.gni | 1 +
17 src/gpu/ganesh/ops/OpsTask.cpp | 27 ++++++-
18 tests/StencilClearTest.cpp | 131 +++++++++++++++++++++++++++++++++
19 3 files changed, 156 insertions(+), 3 deletions(-)
20 create mode 100644 tests/StencilClearTest.cpp
21
22 --- a/gn/tests.gni
23 +++ b/gn/tests.gni
24 @@ -493,6 +493,7 @@
25 "$_tests/Skbug6653.cpp",
26 "$_tests/SlugTest.cpp",
27 "$_tests/SrcSrcOverBatchTest.cpp",
28 + "$_tests/StencilClearTest.cpp",
29 "$_tests/SurfaceDrawContextTest.cpp",
30 "$_tests/SurfaceSemaphoreTest.cpp",
31 "$_tests/TextBlobCacheTest.cpp",
32 --- a/src/gpu/ganesh/ops/OpsTask.cpp
33 +++ b/src/gpu/ganesh/ops/OpsTask.cpp
34 @@ -588,7 +588,17 @@
35 GrLoadOp stencilLoadOp;
36 switch (fInitialStencilContent) {
37 case StencilContent::kDontCare:
38 - stencilLoadOp = GrLoadOp::kDiscard;
39 + if (stencil && !caps.performStencilClearsAsDraws()) {
40 + // This OpTask has a stencil, doesn't care about its contents,
41 + // isn't clearing it with draws, and is going to store the result.
42 + // In that case, we proactively clear it so that uninitialized data won't
43 + // creep into the stencil buffer.
44 + stencilLoadOp = GrLoadOp::kClear;
45 + } else {
46 + // This should only intentionally happen for the AtlasRenderTask which
47 + // immediately inserts a clear.
48 + stencilLoadOp = GrLoadOp::kDiscard;
49 + }
50 break;
51 case StencilContent::kUserBitsCleared:
52 SkASSERT(!caps.performStencilClearsAsDraws());
53 @@ -623,6 +633,7 @@
54 // their store op might be "discard", and we currently make the assumption that a discard will
55 // not invalidate what's already in main memory. This is probably ok for now, but certainly
56 // something we want to address soon.
57 + // b/160958008 forces discardStencilValuesAfterRenderPass to always return false.
58 GrStoreOp stencilStoreOp = (caps.discardStencilValuesAfterRenderPass() && !fMustPreserveStencil)
59 ? GrStoreOp::kDiscard
60 : GrStoreOp::kStore;
61 @@ -643,6 +654,16 @@
62 if (!renderPass) {
63 return false;
64 }
65 +
66 +#if defined(SK_DEBUG)
67 + if (stencilLoadOp == GrLoadOp::kDiscard) {
68 + // The only time we should have a stencil discard load-op is when either:
69 + // there is no stencil buffer
70 + // or stencil clears are being performed by draws
71 + SkASSERT(!stencil || caps.performStencilClearsAsDraws());
72 + }
73 +#endif
74 +
75 flushState->setOpsRenderPass(renderPass);
76 renderPass->begin();
77
78 @@ -732,10 +753,10 @@
79 fTotalBounds.join(toMerge->fTotalBounds);
80 fRenderPassXferBarriers |= toMerge->fRenderPassXferBarriers;
81 if (fInitialStencilContent == StencilContent::kDontCare) {
82 - // Propogate the first stencil content that isn't kDontCare.
83 + // Propagate the first stencil content that isn't kDontCare.
84 //
85 // Once the stencil has any kind of initial content that isn't kDontCare, then the
86 - // inital contents of subsequent opsTasks that get merged in don't matter.
87 + // initial contents of subsequent opsTasks that get merged in don't matter.
88 //
89 // (This works because the opsTask all target the same render target and are in
90 // painter's order. kPreserved obviously happens automatically with a merge, and kClear