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

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