| 1 |
From b08789681f25af07a9b8ff639b1f6bf53953e54a Mon Sep 17 00:00:00 2001 |
| 2 |
From: Thomas Smith <[email protected]> |
| 3 |
Date: Mon, 20 Jul 2026 15:42:34 -0400 |
| 4 |
Subject: [PATCH] [ganesh][gl] Imagination FBO deletion workaround |
| 5 |
|
| 6 |
* Adds workaround for driver level bug where a context retains a |
| 7 |
reference to a deleted FBO, resulting in a UAF hazard. |
| 8 |
|
| 9 |
Bug: https://issues.chromium.org/issues/532941869 |
| 10 |
Change-Id: Ie6a1fb23fa0a72fd5da98489b1daced3409d9bd4 |
| 11 |
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/1298697 |
| 12 |
Reviewed-by: Michael Ludwig <[email protected]> |
| 13 |
Commit-Queue: Thomas Smith <[email protected]> |
| 14 |
--- |
| 15 |
.../ganesh/GrDriverBugWorkaroundsAutogen.h | 2 ++ |
| 16 |
src/gpu/ganesh/gl/GrGLCaps.cpp | 6 ++++ |
| 17 |
src/gpu/ganesh/gl/GrGLGpu.cpp | 31 ++++++++++++------- |
| 18 |
src/gpu/gpu_workaround_list.txt | 1 + |
| 19 |
4 files changed, 28 insertions(+), 12 deletions(-) |
| 20 |
|
| 21 |
diff --git a/include/gpu/ganesh/GrDriverBugWorkaroundsAutogen.h b/include/gpu/ganesh/GrDriverBugWorkaroundsAutogen.h |
| 22 |
index ab6db1c226..cdc05461ab 100644 |
| 23 |
--- a/include/gpu/ganesh/GrDriverBugWorkaroundsAutogen.h |
| 24 |
+++ b/include/gpu/ganesh/GrDriverBugWorkaroundsAutogen.h |
| 25 |
@@ -21,6 +21,8 @@ |
| 26 |
disallow_large_instanced_draw) \ |
| 27 |
GPU_OP(EMULATE_ABS_INT_FUNCTION, \ |
| 28 |
emulate_abs_int_function) \ |
| 29 |
+ GPU_OP(ENSURE_PREVIOUS_FRAMEBUFFER_NOT_DELETED, \ |
| 30 |
+ ensure_previous_framebuffer_not_deleted) \ |
| 31 |
GPU_OP(FLUSH_ON_FRAMEBUFFER_CHANGE, \ |
| 32 |
flush_on_framebuffer_change) \ |
| 33 |
GPU_OP(FORCE_UPDATE_SCISSOR_STATE_WHEN_BINDING_FBO0, \ |
| 34 |
diff --git a/src/gpu/ganesh/gl/GrGLCaps.cpp b/src/gpu/ganesh/gl/GrGLCaps.cpp |
| 35 |
index 9dc3137dc1..48c288447a 100644 |
| 36 |
--- a/src/gpu/ganesh/gl/GrGLCaps.cpp |
| 37 |
+++ b/src/gpu/ganesh/gl/GrGLCaps.cpp |
| 38 |
@@ -4786,6 +4786,12 @@ void GrGLCaps::applyDriverCorrectnessWorkarounds(const GrGLContextInfo& ctxInfo, |
| 39 |
fShaderCaps->fShaderDerivativeSupport = false; |
| 40 |
} |
| 41 |
|
| 42 |
+ // b/532941869 |
| 43 |
+ if (ctxInfo.vendor() == GrGLVendor::kImagination || |
| 44 |
+ ctxInfo.driver() == GrGLDriver::kImagination) { |
| 45 |
+ fDriverBugWorkarounds.ensure_previous_framebuffer_not_deleted = true; |
| 46 |
+ } |
| 47 |
+ |
| 48 |
if (ctxInfo.driver() == GrGLDriver::kFreedreno) { |
| 49 |
formatWorkarounds->fDisallowUnorm16Transfers = true; |
| 50 |
} |
| 51 |
diff --git a/src/gpu/ganesh/gl/GrGLGpu.cpp b/src/gpu/ganesh/gl/GrGLGpu.cpp |
| 52 |
index ae7ba388bf..ff31c6e848 100644 |
| 53 |
--- a/src/gpu/ganesh/gl/GrGLGpu.cpp |
| 54 |
+++ b/src/gpu/ganesh/gl/GrGLGpu.cpp |
| 55 |
@@ -3228,18 +3228,25 @@ void GrGLGpu::deleteFramebuffer(GrGLuint fboid) { |
| 56 |
// We're relying on the GL state shadowing being correct in the workaround code below so we |
| 57 |
// need to handle a dirty context. |
| 58 |
this->handleDirtyContext(); |
| 59 |
- if (fboid == fBoundDrawFramebuffer && |
| 60 |
- this->caps()->workarounds().unbind_attachments_on_bound_render_fbo_delete) { |
| 61 |
- // This workaround only applies to deleting currently bound framebuffers |
| 62 |
- // on Adreno 420. Because this is a somewhat rare case, instead of |
| 63 |
- // tracking all the attachments of every framebuffer instead just always |
| 64 |
- // unbind all attachments. |
| 65 |
- GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, GR_GL_COLOR_ATTACHMENT0, |
| 66 |
- GR_GL_RENDERBUFFER, 0)); |
| 67 |
- GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, GR_GL_STENCIL_ATTACHMENT, |
| 68 |
- GR_GL_RENDERBUFFER, 0)); |
| 69 |
- GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, GR_GL_DEPTH_ATTACHMENT, |
| 70 |
- GR_GL_RENDERBUFFER, 0)); |
| 71 |
+ if (fboid == fBoundDrawFramebuffer) { |
| 72 |
+ if (this->caps()->workarounds().unbind_attachments_on_bound_render_fbo_delete) { |
| 73 |
+ // This workaround only applies to deleting currently bound framebuffers |
| 74 |
+ // on Adreno 420. Because this is a somewhat rare case, instead of |
| 75 |
+ // tracking all the attachments of every framebuffer instead just always |
| 76 |
+ // unbind all attachments. |
| 77 |
+ GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, GR_GL_COLOR_ATTACHMENT0, |
| 78 |
+ GR_GL_RENDERBUFFER, 0)); |
| 79 |
+ GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, GR_GL_STENCIL_ATTACHMENT, |
| 80 |
+ GR_GL_RENDERBUFFER, 0)); |
| 81 |
+ GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, GR_GL_DEPTH_ATTACHMENT, |
| 82 |
+ GR_GL_RENDERBUFFER, 0)); |
| 83 |
+ } |
| 84 |
+ |
| 85 |
+ if (this->caps()->workarounds().ensure_previous_framebuffer_not_deleted) { |
| 86 |
+ // Some drivers keep an internal reference to the previously bound |
| 87 |
+ // framebuffer, so make sure it isn't the one being deleted. |
| 88 |
+ this->bindFramebuffer(GR_GL_FRAMEBUFFER, 0); |
| 89 |
+ } |
| 90 |
} |
| 91 |
|
| 92 |
GL_CALL(DeleteFramebuffers(1, &fboid)); |
| 93 |
diff --git a/src/gpu/gpu_workaround_list.txt b/src/gpu/gpu_workaround_list.txt |
| 94 |
index b0b38cf977..a4c83b1c68 100644 |
| 95 |
--- a/src/gpu/gpu_workaround_list.txt |
| 96 |
+++ b/src/gpu/gpu_workaround_list.txt |
| 97 |
@@ -4,6 +4,7 @@ disable_discard_framebuffer |
| 98 |
disable_texture_storage |
| 99 |
disallow_large_instanced_draw |
| 100 |
emulate_abs_int_function |
| 101 |
+ensure_previous_framebuffer_not_deleted |
| 102 |
flush_on_framebuffer_change |
| 103 |
force_update_scissor_state_when_binding_fbo0 |
| 104 |
gl_clear_broken |
| 105 |
-- |
| 106 |
2.53.0 |
| 107 |
|