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

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