Blame SOURCES/0004-Xi-disallow-passive-grabs-with-a-detail-255.patch

731cc8
From 0dab0b527ac5c4fe0272ea679522bd87238a733b Mon Sep 17 00:00:00 2001
731cc8
From: Peter Hutterer <peter.hutterer@who-t.net>
731cc8
Date: Tue, 29 Nov 2022 13:55:32 +1000
731cc8
Subject: [PATCH xserver 4/7] Xi: disallow passive grabs with a detail > 255
731cc8
731cc8
The XKB protocol effectively prevents us from ever using keycodes above
731cc8
255. For buttons it's theoretically possible but realistically too niche
731cc8
to worry about. For all other passive grabs, the detail must be zero
731cc8
anyway.
731cc8
731cc8
This fixes an OOB write:
731cc8
731cc8
ProcXIPassiveUngrabDevice() calls DeletePassiveGrabFromList with a
731cc8
temporary grab struct which contains tempGrab->detail.exact = stuff->detail.
731cc8
For matching existing grabs, DeleteDetailFromMask is called with the
731cc8
stuff->detail value. This function creates a new mask with the one bit
731cc8
representing stuff->detail cleared.
731cc8
731cc8
However, the array size for the new mask is 8 * sizeof(CARD32) bits,
731cc8
thus any detail above 255 results in an OOB array write.
731cc8
731cc8
CVE-2022-46341, ZDI-CAN 19381
731cc8
731cc8
This vulnerability was discovered by:
731cc8
Jan-Niklas Sohn working with Trend Micro Zero Day Initiative
731cc8
731cc8
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
731cc8
Acked-by: Olivier Fourdan <ofourdan@redhat.com>
731cc8
---
731cc8
 Xi/xipassivegrab.c | 12 ++++++++++++
731cc8
 1 file changed, 12 insertions(+)
731cc8
731cc8
diff --git a/Xi/xipassivegrab.c b/Xi/xipassivegrab.c
731cc8
index 65d5870f6f..89a591098a 100644
731cc8
--- a/Xi/xipassivegrab.c
731cc8
+++ b/Xi/xipassivegrab.c
731cc8
@@ -133,6 +133,12 @@ ProcXIPassiveGrabDevice(ClientPtr client)
731cc8
         return BadValue;
731cc8
     }
731cc8
 
731cc8
+    /* XI2 allows 32-bit keycodes but thanks to XKB we can never
731cc8
+     * implement this. Just return an error for all keycodes that
731cc8
+     * cannot work anyway, same for buttons > 255. */
731cc8
+    if (stuff->detail > 255)
731cc8
+        return XIAlreadyGrabbed;
731cc8
+
731cc8
     if (XICheckInvalidMaskBits(client, (unsigned char *) &stuff[1],
731cc8
                                stuff->mask_len * 4) != Success)
731cc8
         return BadValue;
731cc8
@@ -313,6 +319,12 @@ ProcXIPassiveUngrabDevice(ClientPtr client)
731cc8
         return BadValue;
731cc8
     }
731cc8
 
731cc8
+    /* We don't allow passive grabs for details > 255 anyway */
731cc8
+    if (stuff->detail > 255) {
731cc8
+        client->errorValue = stuff->detail;
731cc8
+        return BadValue;
731cc8
+    }
731cc8
+
731cc8
     rc = dixLookupWindow(&win, stuff->grab_window, client, DixSetAttrAccess);
731cc8
     if (rc != Success)
731cc8
         return rc;
731cc8
-- 
731cc8
2.38.1
731cc8