dix: allocate enough space for logical button maps

Both DeviceFocusEvent and the XIQueryPointer reply contain a bit for
each logical button currently down. Since buttons can be arbitrarily mapped
to anything up to 255 make sure we have enough bits for the maximum mapping.

CVE-2023-6816, ZDI-CAN-22664, ZDI-CAN-22665

This vulnerability was discovered by:
Jan-Niklas Sohn working with Trend Micro Zero Day Initiative
This commit is contained in:
Peter Hutterer 2023-12-14 11:29:49 +10:00 committed by José Expósito
parent cad42fcb08
commit 9e2ecb2af8
2 changed files with 4 additions and 4 deletions

View File

@ -149,8 +149,7 @@ ProcXIQueryPointer(ClientPtr client)
if (pDev->button) { if (pDev->button) {
int i; int i;
rep.buttons_len = rep.buttons_len = bytes_to_int32(bits_to_bytes(256)); /* button map up to 255 */
bytes_to_int32(bits_to_bytes(pDev->button->numButtons));
rep.length += rep.buttons_len; rep.length += rep.buttons_len;
buttons = calloc(rep.buttons_len, 4); buttons = calloc(rep.buttons_len, 4);
if (!buttons) if (!buttons)

View File

@ -784,8 +784,9 @@ DeviceFocusEvent(DeviceIntPtr dev, int type, int mode, int detail,
mouse = IsFloating(dev) ? dev : GetMaster(dev, MASTER_POINTER); mouse = IsFloating(dev) ? dev : GetMaster(dev, MASTER_POINTER);
/* XI 2 event */ /* XI 2 event contains the logical button map - maps are CARD8
btlen = (mouse->button) ? bits_to_bytes(mouse->button->numButtons) : 0; * so we need 256 bits for the possibly maximum mapping */
btlen = (mouse->button) ? bits_to_bytes(256) : 0;
btlen = bytes_to_int32(btlen); btlen = bytes_to_int32(btlen);
len = sizeof(xXIFocusInEvent) + btlen * 4; len = sizeof(xXIFocusInEvent) + btlen * 4;