Commit Graph

518 Commits

Author SHA1 Message Date
Enrico Weigelt, metux IT consult 7c51bcb093 os: unexport internal logging functions
Lots of logging functions, especially init and teardown aren't called
by any drivers/modules, so no need to keep them exported.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 17:21:46 +02:00
Enrico Weigelt, metux IT consult e025b8c805 dix: protect from allocation failure
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 17:21:43 +02:00
Enrico Weigelt, metux IT consult ba4fb2588e dix: replace xallocarray() by calloc()
Only key difference that calloc(), in contrast to rellocarray(),
is zero-initializing. The overhead is hard to measure on today's
machines, and it's safer programming practise to always allocate
zero-initialized, so one can't forget to do it explicitly.

Cocci rule:

    @@
    expression COUNT;
    expression LEN;
    @@
    - xallocarray(COUNT,LEN)
    + calloc(COUNT,LEN)

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 17:21:43 +02:00
Enrico Weigelt, metux IT consult 7ea43bd5e9 dix: let change_modmap() return BadValue instead of -1
The function returns X result codes, but -1 isn't a valid value here.
Therefore all callers explicitly translate -1 to BadValue, so we can return
that directly instead of -1.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 17:21:42 +02:00
Enrico Weigelt, metux IT consult 71139c015e dix: write out X_QueryKeymap reply directly
No need for using a complex callback machinery, if we just move the
little pieces of byte-swapping directly into the request handler.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 16:55:26 +02:00
Enrico Weigelt, metux IT consult 13bec61739 dix: write out X_GetPointerControl reply directly
No need for using a complex callback machinery, if we just move the
little pieces of byte-swapping directly into the request handler.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 16:55:23 +02:00
Enrico Weigelt, metux IT consult 39dcf3e233 dix: write out X_GetPointerControl reply directly
No need for using a complex callback machinery, if we just move the
little pieces of byte-swapping directly into the request handler.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 16:55:19 +02:00
Enrico Weigelt, metux IT consult 46abb82984 dix: write out X_GetKeyboardControl reply directly
No need for using a complex callback machinery, if we just move the
little pieces of byte-swapping directly into the request handler.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 16:55:16 +02:00
Enrico Weigelt, metux IT consult 5829703de2 dix: write out X_GetKeyboardMapping reply directly
No need for using a complex callback machinery, if we just move the
little pieces of byte-swapping directly into the request handler.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 16:55:12 +02:00
Enrico Weigelt, metux IT consult c8ea12d436 dix: write out X_GetPointerMapping reply directly
No need for using a complex callback machinery, if we just move the
little pieces of byte-swapping directly into the request handler.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 16:55:09 +02:00
Enrico Weigelt, metux IT consult 1ef0e46cbc dix: write out X_SetPointerMapping reply directly
No need for using a complex callback machinery, if we just move the
little pieces of byte-swapping directly into the request handler.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 16:55:05 +02:00
Enrico Weigelt, metux IT consult 6091ce6d57 dix: write out X_GetModifierMapping reply directly
No need for using a complex callback machinery, if we just move the
little pieces of byte-swapping directly into the request handler.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 16:55:02 +02:00
Enrico Weigelt, metux IT consult 80d748e1cd dix: write out X_SetModifierMapping reply directly
No need for using a complex callback machinery, if we just move the
little pieces of byte-swapping directly into the request handler.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 16:54:59 +02:00
Enrico Weigelt, metux IT consult 1ae30998d5 dix: make SameClient() macro private
Not used in any external modules, so need to keep it public.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 16:53:43 +02:00
Enrico Weigelt, metux IT consult 0127d6ef13 dix: use calloc() instead of malloc()
Using calloc() instead of malloc() as preventive measure, so there
never can be any hidden bugs or leaks due uninitialized memory.

The extra cost of using this compiler intrinsic should be practically
impossible to measure - in many cases a good compiler can even deduce
if certain areas really don't need to be zero'd (because they're written
to right after allocation) and create more efficient machine code.

The code pathes in question are pretty cold anyways, so it's probably
not worth even thinking about potential extra runtime costs.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 16:49:43 +02:00
Enrico Weigelt, metux IT consult af71108cd3 dix: devices: refine NULL checks in GetMaster()
The checking / branchin isn't entirely trivial to understand, and the
analyzer also gets confused. So rewrite it in an simpler way that's
easier to understand both the human reader as well as the analyzer.
(and so get rid of yet another false alarm)

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 16:34:34 +02:00
Enrico Weigelt, metux IT consult 6dc7eab871 dix: rename IsFloating() to InputDevIsFloating()
Give it a better fitting name.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 16:19:40 +02:00
Enrico Weigelt, metux IT consult 4f2bd438cd dix: rename IsMaster to InputDevIsMaster()
Give it a better fitting name.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 16:19:33 +02:00
Enrico Weigelt, metux IT consult 32a0109615 dix: unexport, document and rename GetCurrentRootWindow()
Not used by any drivers, so no need to keep it exported.
Also spending it for a better fitter name.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 16:18:23 +02:00
Enrico Weigelt, metux IT consult e9351ba7e0 include: drop obsolete dixevents.h
The include has become empty now. Not used by any external drivers,
so it can be dropped now.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 16:17:35 +02:00
Olivier Fourdan 6e0f332ba4 dix: Dequeue pending events on frozen device on removal
When a device is removed while still frozen, the events queued for that
device remain while the device itself is freed.

As a result, replaying the events will cause a use after free.

To avoid the issue, make sure to dequeue and free any pending events on
a frozen device when removed.

CVE-2025-26600, ZDI-CAN-25871

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

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1828>
2025-02-25 11:43:01 +01:00
Enrico Weigelt, metux IT consult 346d5f5c35 os: move BUG_*() macros to own private header
These macros aren't used by any external modules, so no need
to keep them public. Moving them into private header.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1804>
2025-02-17 19:32:48 +00:00
Enrico Weigelt, metux IT consult 0f7770bce3 mi: unexport mieqProcessDeviceEvent()
Not used by any drivers/modules, so no need to keep it exported.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1727>
2025-02-06 16:45:20 +02:00
Alan Coopersmith 45c485bfdf dix: Use __builtin_popcountl if available to replace Ones()
If the compiler knows of a better algorithm for counting the number of
bits set in a word for the target CPU, let it use that, instead of the
classic algorithm optimized for PDP-6.

Based on xorg/lib/libxext@490a25e6f8a4d2482af4364c700b68ad11a4d10b

v2: make old version static inline, stop exporting after !1695

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1674>
2024-10-26 10:04:13 -07:00
Enrico Weigelt, metux IT consult 1642adec3b dix: unexport Ones()
It's not used by any module/driver, so no need to keep it exported.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1695>
2024-10-26 16:35:57 +00:00
Enrico Weigelt, metux IT consult 84be5b4e9c dix: unexport non-public functions from dixgrabs.h and document prototypes
* unexport functions from dixgrab.h, that aren't used by any driver/module.
* add paremeter names to prototypes
* add doxygen-style documentation for all the prototypes

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2024-10-10 13:50:57 +00:00
Enrico Weigelt, metux IT consult 48cee2fd22 dix: make FreeGrab() NULL tolerant
Allow NULL parameters to be passed to FreeGrab(), so callers don't all
need to check on their own anymore.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2024-10-10 13:50:57 +00:00
Enrico Weigelt, metux IT consult 4cac1ee46d dix: drop unnecessary check on HAVE_DIX_CONFIG_H
The dix-config.h include file is always present, so no need for
an extra check and conditional include.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2024-10-10 13:38:31 +00:00
Alan Coopersmith e6fc0861d8 dix: GetPairedDevice: check if GetMaster returned NULL
Clears warning from gcc 14.1:

../dix/devices.c: In function ‘GetPairedDevice’:
../dix/devices.c:2734:15: warning: dereference of NULL ‘dev’
 [CWE-476] [-Wanalyzer-null-dereference]
 2734 |     return dev->spriteInfo? dev->spriteInfo->paired: NULL;
      |            ~~~^~~~~~~~~~~~

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1673>
2024-09-08 13:21:14 -07:00
Peter Hutterer 9b983fecf9 dix: don't push the XKB state to a non-existing master keyboard
If our master keyboard is disabled, GetMaster() returns NULL and
we segfault in XkbPushLockedStateToSlaves().

Fixes 45fb3a934d
Fixes #1611

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1256>
2024-09-01 23:12:28 +00:00
Enrico Weigelt, metux IT consult 2cec3cfbf1 include: move private definitions out of input.h
It's not good having the public server api headers clobbered with private
definitions, so cleaning them up.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1354>
2024-09-01 17:59:23 +00:00
Enrico Weigelt, metux IT consult 61233adbca treewide: replace xnfreallocarray macro call by XNFreallocarray()
The xnfreallocarray was added along (and just as an alias to) XNFreallocarray
back a decade ago. It's just used in a few places and it's only saves us from
passing the first parameter (NULL), so the actual benefit isn't really huge.

No (known) driver is using it, so the macro can be dropped entirely.

Fixes: ae75d50395
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1529>
2024-07-26 23:41:33 +00:00
Enrico Weigelt, metux IT consult 9524ffee89 xace: typesafe hook function for XACE_DEVICE_ACCESS
The generic XaceHook() call isn't typesafe (und unnecessarily slow).
Better add an explicit function, just like we already have for others.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1556>
2024-06-23 21:07:48 +00:00
Enrico Weigelt, metux IT consult eff7ccc11c include: move private definitions out of exevents.h
Public server module API shouldn't be clobbered with private definitions,
thus move them out to private header.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1289>
2024-04-30 00:47:38 +00:00
Enrico Weigelt, metux IT consult bae6cbc8ca include: move private defs to dixstruct_priv.h
Public server module API shouldn't be clobbered with private definitions,
thus move them out to dixstruct_priv.h

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1289>
2024-04-30 00:47:38 +00:00
Enrico Weigelt, metux IT consult d444cd4237 dix: unexport some lookup functions
These aren't used by any drivers, so no need to export them.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1380>
2024-04-15 18:11:57 -07:00
Enrico Weigelt, metux IT consult a3ebe4fa41 dix: move non-exported ptrveloc functions to separate header
unclutter ptrveloc.h by moving non-exported declarations into their own
private header file.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1347>
2024-03-09 18:01:52 +00:00
Peter Hutterer eaa92ea422 Revert "include: move BUG_*() macros to separate header"
This breaks the xf86-input-synaptics driver:

  synaptics.c: In function 'clickpad_guess_clickfingers':
  synaptics.c:2638:5: error: implicit declaration of function 'BUG_RETURN_VAL' [-Werror=implicit-function-declaration]
   2638 |     BUG_RETURN_VAL(hw->num_mt_mask > sizeof(close_point) * 8, 0);

This reverts commit 442aec2219.

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1316>
2024-02-23 23:11:01 +00:00
Enrico Weigelt 442aec2219 include: move BUG_*() macros to separate header
Yet another step of uncluttering includes: move out the BUG_* macros
into a separate header, which then is included as-needed.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2024-02-15 23:33:46 +00:00
Peter Hutterer 26769aa71f dix: when disabling a master, float disabled slaved devices too
Disabling a master device floats all slave devices but we didn't do this
to already-disabled slave devices. As a result those devices kept their
reference to the master device resulting in access to already freed
memory if the master device was removed before the corresponding slave
device.

And to match this behavior, also forcibly reset that pointer during
CloseDownDevices().

Related to CVE-2024-21886, ZDI-CAN-22840
2024-01-16 09:24:31 +01:00
José Expósito bc1fdbe465 Xi: do not keep linked list pointer during recursion
The `DisableDevice()` function is called whenever an enabled device
is disabled and it moves the device from the `inputInfo.devices` linked
list to the `inputInfo.off_devices` linked list.

However, its link/unlink operation has an issue during the recursive
call to `DisableDevice()` due to the `prev` pointer pointing to a
removed device.

This issue leads to a length mismatch between the total number of
devices and the number of device in the list, leading to a heap
overflow and, possibly, to local privilege escalation.

Simplify the code that checked whether the device passed to
`DisableDevice()` was in `inputInfo.devices` or not and find the
previous device after the recursion.

CVE-2024-21886, ZDI-CAN-22840

This vulnerability was discovered by:
Jan-Niklas Sohn working with Trend Micro Zero Day Initiative
2024-01-16 09:24:31 +01:00
Peter Hutterer de0031eefd dix: initialize the XTest sendEventsProc for all devices
XTest requests lets the client specify a device ID, only if none
is specified do we fall back to the XTEST special device.
As of commit
  aa4074251 input: Add new hook DeviceSendEventsProc for XTEST
regular devices are no longer able to send XTest events because they
have no sendEventsProc set.

This caused issue #1574 and the crash was fixed with commit
  e820030de xtest: Check whether there is a sendEventsProc to call
but we still cannot send XTest events through a specific device.

Fix this by defaulting every device to the XTest send function and
punting it to the DDX (i.e. Xwayland) to override the devices as
necessary.

Fixes e820030de2
Fixes aa4074251f
2024-01-09 00:45:31 +00:00
Peter Hutterer d0b0137a95 Two whitespace fixes 2024-01-09 09:49:54 +10:00
Peter Hutterer 0a9f223eec dix: factor out the duplicate the RemoveDevice code paths
This is the same loop twice, once over inputInfo.devices and once over
inputInfo.off_devices, let's make both the same.
2024-01-09 09:49:54 +10:00
Peter Hutterer 2cee5fb36c test: fix various leaks in the tests 2024-01-09 09:49:54 +10:00
Peter Hutterer 373cd80081 dix: use valuator_mask_free() to free the last touches vmask
No functional effect since that one is just a free() call anyway.
2024-01-09 09:49:54 +10:00
Peter Hutterer 7aba2514b2 dix: don't allow for devices with 0 axes
This just makes the existing behavior explicit, previously we relied on
a malloc(numAxes * ...) to return NULL to error out.
2024-01-09 09:49:54 +10:00
Peter Hutterer 0c1a93d319 Xi: allocate enough XkbActions for our buttons
button->xkb_acts is supposed to be an array sufficiently large for all
our buttons, not just a single XkbActions struct. Allocating
insufficient memory here means when we memcpy() later in
XkbSetDeviceInfo we write into memory that wasn't ours to begin with,
leading to the usual security ooopsiedaisies.

CVE-2023-6377, ZDI-CAN-22412, ZDI-CAN-22413

This vulnerability was discovered by:
Jan-Niklas Sohn working with Trend Micro Zero Day Initiative
2023-12-13 10:44:49 +10:00
Peter Hutterer 45009fb7f5 dix: clean up the GestureInfoRec on device close
Direct leak of 1080 byte(s) in 3 object(s) allocated from:
    #0 0x7f00a4ed8cc7 in calloc (/lib64/libasan.so.8+0xd8cc7) (BuildId: 6f17f87dc4c1aa9f9dde7c4856604c3a25ba4872)
    #1 0x59f740 in InitGestureClassDeviceStruct ../dix/devices.c:1692
    #2 0x418a0b in xwl_pointer_proc_pointer_gestures ../hw/xwayland/xwayland-input.c:325
    #3 0x598e5c in ActivateDevice ../dix/devices.c:578
    #4 0x420207 in init_pointer_gestures_device ../hw/xwayland/xwayland-input.c:1677
    #5 0x420bf1 in seat_handle_capabilities ../hw/xwayland/xwayland-input.c:1801
    #6 0x7f00a4145055 in ffi_call_unix64 (/lib64/libffi.so.8+0x9055) (BuildId: 308041eea4a8d89d9265d3c24b7261dfbe44a61e)

Acked-by: Olivier Fourdan <ofourdan@redhat.com>
2023-12-05 14:21:28 +10:00
Yao Wei 7ce57e179b dix: Force update LEDs after device state update in EnableDevice
This is to make sure the hardware gets the device states regardless
whether the internal state has changed or not, to overcome situations
that device LEDs are out of sync e.g. switching between VTs.

Signed-off-by: Yao Wei (魏銘廷) <yao.wei@canonical.com>
2023-02-21 03:43:05 +00:00