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

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