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

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