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

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