21269fd
From 26ef545b3502f61ca722a7a3373507e88ef64110 Mon Sep 17 00:00:00 2001
21269fd
From: Olivier Fourdan <ofourdan@redhat.com>
21269fd
Date: Mon, 13 Mar 2023 11:08:47 +0100
21269fd
Subject: [PATCH xserver] composite: Fix use-after-free of the COW
21269fd
21269fd
ZDI-CAN-19866/CVE-2023-1393
21269fd
21269fd
If a client explicitly destroys the compositor overlay window (aka COW),
21269fd
we would leave a dangling pointer to that window in the CompScreen
21269fd
structure, which will trigger a use-after-free later.
21269fd
21269fd
Make sure to clear the CompScreen pointer to the COW when the latter gets
21269fd
destroyed explicitly by the client.
21269fd
21269fd
This vulnerability was discovered by:
21269fd
Jan-Niklas Sohn working with Trend Micro Zero Day Initiative
21269fd
21269fd
Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
21269fd
Reviewed-by: Adam Jackson <ajax@redhat.com>
21269fd
---
21269fd
 composite/compwindow.c | 5 +++++
21269fd
 1 file changed, 5 insertions(+)
21269fd
21269fd
diff --git a/composite/compwindow.c b/composite/compwindow.c
21269fd
index 4e2494b86..b30da589e 100644
21269fd
--- a/composite/compwindow.c
21269fd
+++ b/composite/compwindow.c
21269fd
@@ -620,6 +620,11 @@ compDestroyWindow(WindowPtr pWin)
21269fd
     ret = (*pScreen->DestroyWindow) (pWin);
21269fd
     cs->DestroyWindow = pScreen->DestroyWindow;
21269fd
     pScreen->DestroyWindow = compDestroyWindow;
21269fd
+
21269fd
+    /* Did we just destroy the overlay window? */
21269fd
+    if (pWin == cs->pOverlayWin)
21269fd
+        cs->pOverlayWin = NULL;
21269fd
+
21269fd
 /*    compCheckTree (pWin->drawable.pScreen); can't check -- tree isn't good*/
21269fd
     return ret;
21269fd
 }
21269fd
-- 
21269fd
2.40.0
21269fd