[Qemu-devel] [PATCH v3] ui/console: Precautionary glBindTexture and surface->texture validation in surface_gl_update_texture

Marcel Apfelbaum posted 1 patch 4 years, 12 months ago
Test asan passed
Test docker-mingw@fedora passed
Test docker-clang@ubuntu passed
Test checkpatch passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20190507080501.26712-1-marcel.apfelbaum@gmail.com
Maintainers: Gerd Hoffmann <kraxel@redhat.com>
ui/console-gl.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
[Qemu-devel] [PATCH v3] ui/console: Precautionary glBindTexture and surface->texture validation in surface_gl_update_texture
Posted by Marcel Apfelbaum 4 years, 12 months ago
From: HOU Qiming <hqm03ster@gmail.com>

In a GVT-g setup with dmabuf and GTK GUI, the current 2D texture at
surface_gl_update_texture is not necessarily
surface->texture. Adding a glBindTexture fixes related crashes and
artifacts, and is generally more secure.

Signed-off-by: HOU Qiming <hqm03ster@gmail.com>
Tested-by: Marcel Apfelbaum<marcel.apfelbaum@gmail.com>
[fixed malformed patch, rebase to master]
Signed-off-by: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
---

v3:
 - Fixed contributor name (Philippe)

v2:
 - fixed malformed patch
 - rebased to master

 ui/console-gl.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/ui/console-gl.c b/ui/console-gl.c
index a56e1cd8eb..c1cb3bd673 100644
--- a/ui/console-gl.c
+++ b/ui/console-gl.c
@@ -92,13 +92,17 @@ void surface_gl_update_texture(QemuGLShader *gls,
 
     assert(gls);
 
-    glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT,
-                  surface_stride(surface) / surface_bytes_per_pixel(surface));
-    glTexSubImage2D(GL_TEXTURE_2D, 0,
-                    x, y, w, h,
-                    surface->glformat, surface->gltype,
-                    data + surface_stride(surface) * y
-                    + surface_bytes_per_pixel(surface) * x);
+    if (surface->texture) {
+        glBindTexture(GL_TEXTURE_2D, surface->texture);
+        glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT,
+                      surface_stride(surface)
+                      / surface_bytes_per_pixel(surface));
+        glTexSubImage2D(GL_TEXTURE_2D, 0,
+                        x, y, w, h,
+                        surface->glformat, surface->gltype,
+                        data + surface_stride(surface) * y
+                        + surface_bytes_per_pixel(surface) * x);
+    }
 }
 
 void surface_gl_render_texture(QemuGLShader *gls,
-- 
2.17.1


Re: [Qemu-devel] [PATCH v3] ui/console: Precautionary glBindTexture and surface->texture validation in surface_gl_update_texture
Posted by Gerd Hoffmann 4 years, 11 months ago
On Tue, May 07, 2019 at 11:05:01AM +0300, Marcel Apfelbaum wrote:
> From: HOU Qiming <hqm03ster@gmail.com>
> 
> In a GVT-g setup with dmabuf and GTK GUI, the current 2D texture at
> surface_gl_update_texture is not necessarily
> surface->texture. Adding a glBindTexture fixes related crashes and
> artifacts, and is generally more secure.

Added to UI patch queue.

thanks,
  Gerd