Blame SOURCES/0006-Xext-free-the-XvRTVideoNotify-when-turning-off-from-.patch

b25474
From a42635ee3c01f71a49052d83a372933504c9db04 Mon Sep 17 00:00:00 2001
b25474
From: Peter Hutterer <peter.hutterer@who-t.net>
b25474
Date: Wed, 30 Nov 2022 11:20:40 +1000
b25474
Subject: [PATCH xserver 6/7] Xext: free the XvRTVideoNotify when turning off
b25474
 from the same client
b25474
b25474
This fixes a use-after-free bug:
b25474
b25474
When a client first calls XvdiSelectVideoNotify() on a drawable with a
b25474
TRUE onoff argument, a struct XvVideoNotifyRec is allocated. This struct
b25474
is added twice to the resources:
b25474
  - as the drawable's XvRTVideoNotifyList. This happens only once per
b25474
    drawable, subsequent calls append to this list.
b25474
  - as the client's XvRTVideoNotify. This happens for every client.
b25474
b25474
The struct keeps the ClientPtr around once it has been added for a
b25474
client. The idea, presumably, is that if the client disconnects we can remove
b25474
all structs from the drawable's list that match the client (by resetting
b25474
the ClientPtr to NULL), but if the drawable is destroyed we can remove
b25474
and free the whole list.
b25474
b25474
However, if the same client then calls XvdiSelectVideoNotify() on the
b25474
same drawable with a FALSE onoff argument, only the ClientPtr on the
b25474
existing struct was set to NULL. The struct itself remained in the
b25474
client's resources.
b25474
b25474
If the drawable is now destroyed, the resource system invokes
b25474
XvdiDestroyVideoNotifyList which frees the whole list for this drawable
b25474
- including our struct. This function however does not free the resource
b25474
for the client since our ClientPtr is NULL.
b25474
b25474
Later, when the client is destroyed and the resource system invokes
b25474
XvdiDestroyVideoNotify, we unconditionally set the ClientPtr to NULL. On
b25474
a struct that has been freed previously. This is generally frowned upon.
b25474
b25474
Fix this by calling FreeResource() on the second call instead of merely
b25474
setting the ClientPtr to NULL. This removes the struct from the client
b25474
resources (but not from the list), ensuring that it won't be accessed
b25474
again when the client quits.
b25474
b25474
Note that the assignment tpn->client = NULL; is superfluous since the
b25474
XvdiDestroyVideoNotify function will do this anyway. But it's left for
b25474
clarity and to match a similar invocation in XvdiSelectPortNotify.
b25474
b25474
CVE-2022-46342, ZDI-CAN 19400
b25474
b25474
This vulnerability was discovered by:
b25474
Jan-Niklas Sohn working with Trend Micro Zero Day Initiative
b25474
b25474
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
b25474
Acked-by: Olivier Fourdan <ofourdan@redhat.com>
b25474
---
b25474
 Xext/xvmain.c | 4 +++-
b25474
 1 file changed, 3 insertions(+), 1 deletion(-)
b25474
b25474
diff --git a/Xext/xvmain.c b/Xext/xvmain.c
b25474
index f627471938..2a08f8744a 100644
b25474
--- a/Xext/xvmain.c
b25474
+++ b/Xext/xvmain.c
b25474
@@ -811,8 +811,10 @@ XvdiSelectVideoNotify(ClientPtr client, DrawablePtr pDraw, BOOL onoff)
b25474
         tpn = pn;
b25474
         while (tpn) {
b25474
             if (tpn->client == client) {
b25474
-                if (!onoff)
b25474
+                if (!onoff) {
b25474
                     tpn->client = NULL;
b25474
+                    FreeResource(tpn->id, XvRTVideoNotify);
b25474
+                }
b25474
                 return Success;
b25474
             }
b25474
             if (!tpn->client)
b25474
-- 
b25474
2.38.1
b25474