Blame SOURCES/0001-xwayland-Hold-a-pixmap-reference-in-struct-xwl_prese.patch

d23b1d
From 23c55ec32973e0a75d723e3f37769dd711c9c59c Mon Sep 17 00:00:00 2001
d23b1d
From: =?UTF-8?q?Michel=20D=C3=A4nzer?= <mdaenzer@redhat.com>
d23b1d
Date: Wed, 22 Jul 2020 18:20:14 +0200
d23b1d
Subject: [PATCH xserver] xwayland: Hold a pixmap reference in struct
d23b1d
 xwl_present_event
d23b1d
MIME-Version: 1.0
d23b1d
Content-Type: text/plain; charset=UTF-8
d23b1d
Content-Transfer-Encoding: 8bit
d23b1d
d23b1d
In the log of the commit below, I claimed this wasn't necessary on the
d23b1d
1.20 branch, but this turned out to be wrong: It meant that
d23b1d
event->buffer could already be destroyed in xwl_present_free_event,
d23b1d
resulting in use-after-free and likely a crash.
d23b1d
d23b1d
Fixes: 22c0808ac88f "xwayland: Free all remaining events in
d23b1d
                     xwl_present_cleanup"
d23b1d
Signed-off-by: Michel Dänzer <mdaenzer@redhat.com>
d23b1d
---
d23b1d
 hw/xwayland/xwayland-present.c | 17 +++++++++++++----
d23b1d
 hw/xwayland/xwayland.h         |  2 +-
d23b1d
 2 files changed, 14 insertions(+), 5 deletions(-)
d23b1d
d23b1d
diff --git a/hw/xwayland/xwayland-present.c b/hw/xwayland/xwayland-present.c
d23b1d
index 2cec63f59..f003170a9 100644
d23b1d
--- a/hw/xwayland/xwayland-present.c
d23b1d
+++ b/hw/xwayland/xwayland-present.c
d23b1d
@@ -117,8 +117,16 @@ xwl_present_free_event(struct xwl_present_event *event)
d23b1d
     if (!event)
d23b1d
         return;
d23b1d
 
d23b1d
-    if (event->buffer)
d23b1d
-        wl_buffer_set_user_data(event->buffer, NULL);
d23b1d
+    if (event->pixmap) {
d23b1d
+        if (!event->buffer_released) {
d23b1d
+            struct wl_buffer *buffer =
d23b1d
+                xwl_glamor_pixmap_get_wl_buffer(event->pixmap, NULL);
d23b1d
+
d23b1d
+            wl_buffer_set_user_data(buffer, NULL);
d23b1d
+        }
d23b1d
+
d23b1d
+        dixDestroyPixmap(event->pixmap, event->pixmap->drawable.id);
d23b1d
+    }
d23b1d
 
d23b1d
     xorg_list_del(&event->list);
d23b1d
     free(event);
d23b1d
@@ -348,7 +356,7 @@ xwl_present_queue_vblank(WindowPtr present_window,
d23b1d
         return BadAlloc;
d23b1d
 
d23b1d
     event->event_id = event_id;
d23b1d
-    event->buffer = NULL;
d23b1d
+    event->pixmap = NULL;
d23b1d
     event->xwl_present_window = xwl_present_window;
d23b1d
     event->target_msc = msc;
d23b1d
 
d23b1d
@@ -453,11 +461,12 @@ xwl_present_flip(WindowPtr present_window,
d23b1d
     if (!event)
d23b1d
         return FALSE;
d23b1d
 
d23b1d
+    pixmap->refcnt++;
d23b1d
     buffer = xwl_glamor_pixmap_get_wl_buffer(pixmap, &buffer_created);
d23b1d
 
d23b1d
     event->event_id = event_id;
d23b1d
     event->xwl_present_window = xwl_present_window;
d23b1d
-    event->buffer = buffer;
d23b1d
+    event->pixmap = pixmap;
d23b1d
     event->target_msc = target_msc;
d23b1d
     event->pending = TRUE;
d23b1d
     event->abort = FALSE;
d23b1d
diff --git a/hw/xwayland/xwayland.h b/hw/xwayland/xwayland.h
d23b1d
index bc5836ec4..b9495b313 100644
d23b1d
--- a/hw/xwayland/xwayland.h
d23b1d
+++ b/hw/xwayland/xwayland.h
d23b1d
@@ -215,7 +215,7 @@ struct xwl_present_event {
d23b1d
     Bool buffer_released;
d23b1d
 
d23b1d
     struct xwl_present_window *xwl_present_window;
d23b1d
-    struct wl_buffer *buffer;
d23b1d
+    PixmapPtr pixmap;
d23b1d
 
d23b1d
     struct xorg_list list;
d23b1d
 };
d23b1d
-- 
d23b1d
2.26.2
d23b1d