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

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