xserver/dix
Peter Hutterer c494debaa7 dix: Allocate sufficient xEvents for our DeviceStateNotify
If a device has both a button class and a key class and numButtons is
zero, we can get an OOB write due to event under-allocation.

This function seems to assume a device has either keys or buttons, not
both. It has two virtually identical code paths, both of which assume
they're applying to the first event in the sequence.

A device with both a key and button class triggered a logic bug - only
one xEvent was allocated but the deviceStateNotify pointer was pushed on
once per type. So effectively this logic code:

   int count = 1;
   if (button && nbuttons > 32) count++;
   if (key && nbuttons > 0) count++;
   if (key && nkeys > 32) count++; // this is basically always true
   // count is at 2 for our keys + zero button device

   ev = alloc(count * sizeof(xEvent));
   FixDeviceStateNotify(ev);
   if (button)
     FixDeviceStateNotify(ev++);
   if (key)
     FixDeviceStateNotify(ev++);   // santa drops into the wrong chimney here

If the device has more than 3 valuators, the OOB is pushed back - we're
off by one so it will happen when the last deviceValuator event is
written instead.

Fix this by allocating the maximum number of events we may allocate.
Note that the current behavior is not protocol-correct anyway, this
patch fixes only the allocation issue.

Note that this issue does not trigger if the device has at least one
button. While the server does not prevent a button class with zero
buttons, it is very unlikely.

CVE-2024-0229, ZDI-CAN-22678

This vulnerability was discovered by:
Jan-Niklas Sohn working with Trend Micro Zero Day Initiative

(cherry picked from commit ece23be888)
2024-01-16 09:57:49 +01:00
..
.gitignore Fix spelling/wording issues 2020-07-05 13:07:33 -07:00
BuiltInAtoms
Makefile.am dix: Implement internal gesture state handling 2021-05-30 13:26:39 +03:00
atom.c atom: make FreeAtom static 2015-07-08 16:41:29 -04:00
buildatoms
colormap.c Fix spelling/wording issues 2020-07-05 13:07:33 -07:00
cursor.c dix: Remove -fn and -fc options to set default text/cursor fonts 2019-10-30 16:17:04 +00:00
devices.c Xi: allocate enough XkbActions for our buttons 2023-12-13 11:00:15 +10:00
dispatch.c dix: Add optional terminate delay 2021-06-07 17:28:05 +02:00
dispatch.h Drop trailing whitespaces 2014-11-12 10:25:00 +10:00
dixfonts.c Fix spelling/wording issues 2020-07-05 13:07:33 -07:00
dixutils.c os: Don't crash in AttendClient if the client is gone 2019-11-19 10:15:05 -08:00
enterleave.c dix: Allocate sufficient xEvents for our DeviceStateNotify 2024-01-16 09:57:49 +01:00
enterleave.h mi: reset the PointerWindows reference on screen switch 2023-10-25 10:51:18 +10:00
eventconvert.c xi: Implement conversions from internal to Xi2 gesture event structs 2021-05-30 13:26:37 +03:00
events.c dix: Use CopyPartialInternalEvent in EnqueueEvent 2023-02-07 10:21:52 +10:00
extension.c dix: Allow an extension to disable itself 2018-04-24 14:36:04 -04:00
gc.c Use ARRAY_SIZE all over the tree 2017-10-30 13:45:20 -04:00
gestures.c Implement gesture processing logic 2021-05-30 13:26:42 +03:00
getevents.c touchevents: set the screen pointer after checking the device is enabled 2021-09-07 16:58:10 +02:00
globals.c include: Remove now-empty site.h 2019-10-30 16:17:04 +00:00
glyphcurs.c Let calloc handle multiplication 2015-04-21 16:57:07 -07:00
grabs.c xi: Implement grab support for new gesture event types 2021-05-30 13:26:32 +03:00
initatoms.c Introduce a consistent coding style 2012-03-21 13:54:42 -07:00
inpututils.c Implement gesture processing logic 2021-05-30 13:26:42 +03:00
main.c include: Remove now-empty site.h 2019-10-30 16:17:04 +00:00
meson.build dix: Implement internal gesture state handling 2021-05-30 13:26:39 +03:00
pixmap.c fix for ZDI-11426 2020-07-31 14:51:23 +00:00
privates.c dix/privates.c: Avoid undefined behaviour after realloc() 2021-10-08 21:38:01 +03:00
property.c Xi: avoid integer truncation in length check of ProcXIChangeProperty 2022-12-14 11:24:46 +10:00
protocol.txt protocol.txt: add GLX req. 35 - SetClientInfo2ARB 2018-02-27 13:08:35 -05:00
ptrveloc.c Fix spelling/wording issues 2020-07-05 13:07:33 -07:00
region.c Fix spelling/wording issues 2020-07-05 13:07:33 -07:00
registry.c Build required portions of registry.c automatically [v2] 2014-09-18 15:29:29 -07:00
resource.c dix: Fix overzealous caching of ResourceClientBits() 2023-01-11 09:01:14 +00:00
selection.c dix: Push UpdateCurrentTimeIf down out of the main loop 2016-05-04 10:58:01 -04:00
stubmain.c Allow DDX to provide a main() 2013-07-23 23:56:58 +01:00
swaprep.c Fix spelling/wording issues 2020-07-05 13:07:33 -07:00
swapreq.c dix: Disallow GenericEvent in SendEvent request. 2017-06-19 11:58:50 +10:00
tables.c Drop trailing whitespaces 2014-11-12 10:25:00 +10:00
touch.c xwayland: add -noTouchPointerEmulation 2021-09-06 21:19:46 +00:00
window.c Fix spelling/wording issues 2020-07-05 13:07:33 -07:00