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

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