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

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