Blame SOURCES/0001-Xtest-disallow-GenericEvents-in-XTestSwapFakeInput.patch

8713f6
From 8dba686dc277d6d262ad0c77b4632a5b276697ba Mon Sep 17 00:00:00 2001
8713f6
From: Peter Hutterer <peter.hutterer@who-t.net>
8713f6
Date: Tue, 29 Nov 2022 12:55:45 +1000
8713f6
Subject: [PATCH xserver 1/7] Xtest: disallow GenericEvents in
8713f6
 XTestSwapFakeInput
8713f6
8713f6
XTestSwapFakeInput assumes all events in this request are
8713f6
sizeof(xEvent) and iterates through these in 32-byte increments.
8713f6
However, a GenericEvent may be of arbitrary length longer than 32 bytes,
8713f6
so any GenericEvent in this list would result in subsequent events to be
8713f6
misparsed.
8713f6
8713f6
Additional, the swapped event is written into a stack-allocated struct
8713f6
xEvent (size 32 bytes). For any GenericEvent longer than 32 bytes,
8713f6
swapping the event may thus smash the stack like an avocado on toast.
8713f6
8713f6
Catch this case early and return BadValue for any GenericEvent.
8713f6
Which is what would happen in unswapped setups anyway since XTest
8713f6
doesn't support GenericEvent.
8713f6
8713f6
CVE-2022-46340, ZDI-CAN 19265
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/xtest.c | 5 +++--
8713f6
 1 file changed, 3 insertions(+), 2 deletions(-)
8713f6
8713f6
diff --git a/Xext/xtest.c b/Xext/xtest.c
8713f6
index bf27eb590b..2985a4ce6e 100644
8713f6
--- a/Xext/xtest.c
8713f6
+++ b/Xext/xtest.c
8713f6
@@ -502,10 +502,11 @@ XTestSwapFakeInput(ClientPtr client, xReq * req)
8713f6
 
8713f6
     nev = ((req->length << 2) - sizeof(xReq)) / sizeof(xEvent);
8713f6
     for (ev = (xEvent *) &req[1]; --nev >= 0; ev++) {
8713f6
+        int evtype = ev->u.u.type & 0x177;
8713f6
         /* Swap event */
8713f6
-        proc = EventSwapVector[ev->u.u.type & 0177];
8713f6
+        proc = EventSwapVector[evtype];
8713f6
         /* no swapping proc; invalid event type? */
8713f6
-        if (!proc || proc == NotImplemented) {
8713f6
+        if (!proc || proc == NotImplemented || evtype == GenericEvent) {
8713f6
             client->errorValue = ev->u.u.type;
8713f6
             return BadValue;
8713f6
         }
8713f6
-- 
8713f6
2.38.1
8713f6