Commit Graph

913 Commits

Author SHA1 Message Date
Enrico Weigelt, metux IT consult
3780ef3ef1 xkb: use REQUEST_HEAD_STRUCT and REQUEST_FIELD_* macros
Use the new macros to make request struct parsing / field swapping
much easier.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2026-02-05 15:26:33 +01:00
Enrico Weigelt, metux IT consult
b8ca69d8b7 xkb: declare variables when needed
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2026-02-05 15:25:48 +01:00
Alexander Melnyk
547d13575d xkb: Fix locked/latched indicator desync across multiple keyboards
When a group indicator (or a latched indicator of any kind) is defined,
e.g.:
  indicator "Scroll Lock" { groups = Group2; }
the logical and physical indicator state may desync across multiple
connected keyboards.

This is caused by XkbPushLockedStateToSlaves only pushing locked_mods to
the slave devices. Pushing locked_group (as well as latched groups/mods)
along with locked_mods resolves the issue.

The issue is not observed with API calls because a different code path
is taken (avoiding XkbPushLockedStateToSlaves altogether).

Signed-off-by: Alexander Melnyk <inboxnumberzero@zoho.com>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/2120>
2026-01-29 14:34:16 +01:00
Enrico Weigelt, metux IT consult
5a7fb205a1 xkb: rename xkbgeom.h to xkbgeom_priv.h
Our naming convention for headers is that private ones (not exported,
ie. not part of xf86 sdk) shall be suffixed by "_priv.h".

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2026-01-20 12:45:01 +01:00
b-aaz
d2dcac6eca Revert "xkb: unexport XkbGetCoreMap() and XkbSetRepeatKeys()"
This reverts commit 25d99353ee.
These symbols are required by the xorgxrdp driver.

Signed-off-by: b-aaz <b-aazbsd@proton.me>
2026-01-07 10:56:33 +01:00
b-aaz
7f7efe8195 Revert 9a82f5c, bring back Cygwin support.
Brought back the code removed in that commit so that we can bring back
Cygwin support.
Small changes are done in the process of resolving conflicts against the
current head.

Some checks have not been reverted, because they were not necessary
anymore.

Signed-off-by: b-aaz <b-aazbsd@proton.me>
2025-12-21 12:59:03 +01:00
Enrico Weigelt, metux IT consult
25fff39056 xkb: fix printf() format warnings
> 6008 |             LogMessage(X_WARNING, "ProcXkbGetKbdByName() childbuf size (%ld) mismatch mrep size (%ld // %ld units)\n",
>       |                                                                                                         ~~^
>       |                                                                                                           |
>       |                                                                                                           long int
>       |                                                                                                         %d
>  6009 |                        (unsigned long)childbuf.wpos, (unsigned long)mrep.length * 4, mrep.length);
>       |                                                                                      ~~~~~~~~~~~
>       |                                                                                          |
>       |                                                                                          CARD32 {aka unsigned int}

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-12-09 20:29:47 +01:00
Enrico Weigelt, metux IT consult
6b189b7a22 xkb: fix printf argument size mismatch warning
> ../xkb/xkb.c:6008:106: warning: format ‘%d’ expects argument of type ‘int’, but argument 5 has type ‘CARD32’ {aka ‘long unsigned int’} [-Wformat=]
>  6008 |             LogMessage(X_WARNING, "ProcXkbGetKbdByName() childbuf size (%ld) mismatch mrep size (%ld // %d units)\n",
>       |                                                                                                         ~^
>       |                                                                                                          |
>       |                                                                                                          int
>       |                                                                                                         %ld
>  6009 |                        (unsigned long)childbuf.wpos, (unsigned long)mrep.length * 4, mrep.length);
>       |                                                                                      ~~~~~~~~~~~
>       |                                                                                          |
>       |                                                                                          CARD32 {aka long unsigned int}
[...]

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-12-04 16:03:28 +01:00
Enrico Weigelt, metux IT consult
de60ac5bbe xkb: consistenly name reply structs "reply" instead of "rep"
Preparation for future use of generic reply assembly macros.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-12-03 15:03:11 +01:00
Enrico Weigelt, metux IT consult
1487c7c03f xkb: drop some junk comments
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-12-03 14:37:58 +01:00
Mike Gelfand
0aea4cf3a7 xkb: move include guards up to wrap the whole file
See: https://gcc.gnu.org/onlinedocs/cppinternals/Guard-Macros.html
Signed-off-by: Mike Gelfand <mikedld@mikedld.com>
2025-11-21 15:20:11 +01:00
Enrico Weigelt, metux IT consult
40acb2d83e dix: unexport PrintPassiveGrabs() and PrintWindowTree()
These are only for internal debug output, not needed for drivers.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-11-20 19:22:18 +01:00
Enrico Weigelt, metux IT consult
bde7f54a40 xkb: drop special generation magic on atom initialization
dixAddAtom() is safe to call multiple times with same name,
always return the corresponding XID, no matter whether the
atom just been newly created or already existed.

Thus, there's no need for special server generation treatment here.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-11-20 16:36:29 +01:00
Enrico Weigelt, metux IT consult
25d99353ee xkb: unexport XkbGetCoreMap() and XkbSetRepeatKeys()
Not needed by external drivers, so no need to keep them public.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-11-19 13:32:12 +01:00
Chase
594d05757d xkb.c: const correctness 2025-11-17 18:45:29 +01:00
Enrico Weigelt, metux IT consult
f1c6f79819 xkb: inline remaining byte-swapping
The final one, SProcXkbSelectEvents(), is a bit more complex. Just moving
this into ProcXkbSelectEvents() for now, so we can drop also the swapped
dispatcher. There's still a lot of room for simplications, but leaving
this for follow-up work.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-10-29 10:58:37 +01:00
Olivier Fourdan
99f32a2339 xkb: Prevent overflow in XkbSetCompatMap()
The XkbCompatMap structure stores its "num_si" and "size_si" fields
using an unsigned short.

However, the function _XkbSetCompatMap() will store the sum of the
input data "firstSI" and "nSI" in both XkbCompatMap's "num_si" and
"size_si" without first checking if the sum overflows the maximum
unsigned short value, leading to a possible overflow.

To avoid the issue, check whether the sum does not exceed the maximum
unsigned short value, or return a "BadValue" error otherwise.

CVE-2025-62231, ZDI-CAN-27560

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: Michel Dänzer <mdaenzer@redhat.com>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/2086>
2025-10-28 19:36:27 +01:00
Olivier Fourdan
f74d828668 xkb: Free the XKB resource when freeing XkbInterest
XkbRemoveResourceClient() would free the XkbInterest data associated
with the device, but not the resource associated with it.

As a result, when the client terminates, the resource delete function
gets called and accesses already freed memory:

 | Invalid read of size 8
 |   at 0x5BC0C0: XkbRemoveResourceClient (xkbEvents.c:1047)
 |   by 0x5B3391: XkbClientGone (xkb.c:7094)
 |   by 0x4DF138: doFreeResource (resource.c:890)
 |   by 0x4DFB50: FreeClientResources (resource.c:1156)
 |   by 0x4A9A59: CloseDownClient (dispatch.c:3550)
 |   by 0x5E0A53: ClientReady (connection.c:601)
 |   by 0x5E4FEF: ospoll_wait (ospoll.c:657)
 |   by 0x5DC834: WaitForSomething (WaitFor.c:206)
 |   by 0x4A1BA5: Dispatch (dispatch.c:491)
 |   by 0x4B0070: dix_main (main.c:277)
 |   by 0x4285E7: main (stubmain.c:34)
 | Address 0x1893e278 is 184 bytes inside a block of size 928 free'd
 |   at 0x4842E43: free (vg_replace_malloc.c:989)
 |   by 0x49C1A6: CloseDevice (devices.c:1067)
 |   by 0x49C522: CloseOneDevice (devices.c:1193)
 |   by 0x49C6E4: RemoveDevice (devices.c:1244)
 |   by 0x5873D4: remove_master (xichangehierarchy.c:348)
 |   by 0x587921: ProcXIChangeHierarchy (xichangehierarchy.c:504)
 |   by 0x579BF1: ProcIDispatch (extinit.c:390)
 |   by 0x4A1D85: Dispatch (dispatch.c:551)
 |   by 0x4B0070: dix_main (main.c:277)
 |   by 0x4285E7: main (stubmain.c:34)
 | Block was alloc'd at
 |   at 0x48473F3: calloc (vg_replace_malloc.c:1675)
 |   by 0x49A118: AddInputDevice (devices.c:262)
 |   by 0x4A0E58: AllocDevicePair (devices.c:2846)
 |   by 0x5866EE: add_master (xichangehierarchy.c:153)
 |   by 0x5878C2: ProcXIChangeHierarchy (xichangehierarchy.c:493)
 |   by 0x579BF1: ProcIDispatch (extinit.c:390)
 |   by 0x4A1D85: Dispatch (dispatch.c:551)
 |   by 0x4B0070: dix_main (main.c:277)
 |   by 0x4285E7: main (stubmain.c:34)

To avoid that issue, make sure to free the resources when freeing the
device XkbInterest data.

CVE-2025-62230, ZDI-CAN-27545

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: Michel Dänzer <mdaenzer@redhat.com>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/2086>
2025-10-28 19:36:27 +01:00
Olivier Fourdan
d7344f366a xkb: Make the RT_XKBCLIENT resource private
Currently, the resource in only available to the xkb.c source file.

In preparation for the next commit, to be able to free the resources
from XkbRemoveResourceClient(), make that variable private instead.

This is related to:

CVE-2025-62230, ZDI-CAN-27545

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: Michel Dänzer <mdaenzer@redhat.com>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/2086>
2025-10-28 19:36:27 +01:00
Enrico Weigelt, metux IT consult
c971a9d641 xkb: inline SProcXkbGetKbdByName()
No need to have whole extra functions for just a few LoC.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-10-26 13:57:12 +01:00
Enrico Weigelt, metux IT consult
0c981140cf xkb: inline SProcXkbSetCompatMap()
No need to have whole extra functions for just a few LoC.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-10-23 13:10:35 +02:00
Enrico Weigelt, metux IT consult
89a75202ad xkb: inline SProcXkbSetIndicatorMap()
No need to have whole extra functions for just a few LoC.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-10-22 14:05:45 +02:00
Enrico Weigelt, metux IT consult
db5062c041 xkb: variable cleanup in SetUpRemap()
declare variables where necessary.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-10-21 14:27:33 +02:00
Enrico Weigelt, metux IT consult
2d71f0579f xkb: inline SProcXkbGetGeometry()
No need to have whole extra functions for just a few LoC.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-10-21 10:26:57 +02:00
Enrico Weigelt, metux IT consult
335dd555fe xkb: inline SProcXkbSetDeviceInfo()
No need to have whole extra functions for just a few LoC.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-10-21 10:26:21 +02:00
Enrico Weigelt, metux IT consult
5330084bd5 xkb: inline SProcXkbSetMap()
No need to have whole extra functions for just a few LoC.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-10-20 10:00:41 +02:00
Enrico Weigelt, metux IT consult
81a8619bda dix: replace XACE_CLIENT_ACCESS by direct callback
Replace complicated xace hook by simple and cheap callback.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-10-07 10:52:54 +02:00
Enrico Weigelt, metux IT consult
24c422177f xkb: inline SProcXkbLatchLockState()
No need to have whole extra functions for just a few LoC.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-09-30 10:00:56 +02:00
Enrico Weigelt, metux IT consult
2c657eb932 xkb: inline SProcXkbPerClientFlags()
No need to have whole extra functions for just a few LoC.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-09-29 11:21:50 +02:00
Enrico Weigelt, metux IT consult
6df2a9a01a xkb: inline SProcXkbSetDebuggingFlags()
No need to have whole extra functions for just a few LoC.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-09-29 11:21:35 +02:00
Enrico Weigelt, metux IT consult
d497375eaa xkb: inline SProcXkbGetState()
No need to have whole extra functions for just a few LoC.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-09-29 11:21:19 +02:00
Enrico Weigelt, metux IT consult
25bd1d3b69 xkb: inline SProcXkbSetControls()
No need to have whole extra functions for just a few LoC.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-09-29 11:20:02 +02:00
Enrico Weigelt, metux IT consult
3e9c40015f xkb: inline SProcXkbSetNamedIndicator()
No need to have whole extra functions for just a few LoC.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-09-29 11:19:47 +02:00
Enrico Weigelt, metux IT consult
a5796a80f8 xkb: inline SProcXkbGetIndicatorMap()
No need to have whole extra functions for just a few LoC.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-09-29 11:19:33 +02:00
Enrico Weigelt, metux IT consult
6cb3338c0b xkb: inline SProcXkbUseExtension()
No need to have whole extra functions for just a few LoC.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-09-26 11:47:04 +02:00
Enrico Weigelt, metux IT consult
8daa5bc8b9 xkb: inline SProcXkbBell()
No need to have whole extra functions for just a few LoC.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-09-26 11:46:50 +02:00
Enrico Weigelt, metux IT consult
8d100100af xkb: inline SProcXkbGetControls()
No need to have whole extra functions for just a few LoC.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-09-26 11:46:38 +02:00
Enrico Weigelt, metux IT consult
9879290e2f xkb: inline SProcXkbGetMap()
No need to have whole extra functions for just a few LoC.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-09-26 11:46:26 +02:00
Enrico Weigelt, metux IT consult
39f9bbd827 xkb: inline SProcXkbGetIndicatorState()
No need to have whole extra functions for just a few LoC.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-09-26 11:46:13 +02:00
Enrico Weigelt, metux IT consult
3d787e4c48 xkb: inline SProcXkbGetNamedIndicator()
No need to have whole extra functions for just a few LoC.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-09-26 11:46:01 +02:00
Enrico Weigelt, metux IT consult
68e134de44 xkb: inline SProcXkbGetNames() and SProcXkbSetNames()
No need to have whole extra functions for just a few LoC.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-09-26 11:45:49 +02:00
Enrico Weigelt, metux IT consult
1cddcc087f xkb: inline SProcXkbGetCompatMap()
No need to have whole extra functions for just a few LoC.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-09-26 11:45:25 +02:00
Enrico Weigelt, metux IT consult
8c545a6528 xkb: inline SProcXkbGetDeviceInfo()
No need to have whole extra functions for just a few LoC.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-09-26 11:45:12 +02:00
Enrico Weigelt, metux IT consult
9eba2365c9 xkb: inline SProcXkbListComponents()
No need to have whole extra functions for just a few LoC.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-09-26 11:44:59 +02:00
Enrico Weigelt, metux IT consult
25adcbfd5a xkb: inline SProcXkbSetGeometry()
No need to have whole extra functions for just a few LoC.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-09-26 11:44:47 +02:00
Enrico Weigelt, metux IT consult
6168868906 dix: replace XACE_SERVER_ACCESS by direct callback
Move the callbacks directly into DIX, since it's actually core infrastructure.
Also simplifying the whole machinery, by just using a simpel CallbackListPtr.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-09-25 14:27:41 +02:00
Enrico Weigelt, metux IT consult
36facd71b5 dix: move request/response related functions to new request_priv.h header
Move functions/macros dealing with request parsing or reply assembly/write
out of the big dix_priv.h into their own headers. This new header will also
get more of those function/macros soon (yet still in the pipeline).

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-09-24 11:32:50 +02:00
Enrico Weigelt, metux IT consult
898251b461 xkb: ProcXkbGetKbdByName(): use return code of X_SEND_REPLY_WITH_RPCBUF()
The macro will automatically return BadAlloc if the buffer is broken,
otherwise Success. Thus, we don't need extra prior rpcbuf check.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-09-17 09:35:36 +02:00
Enrico Weigelt, metux IT consult
eb9a9e0708 xkb: ProcXkbGetKbdByName(): rename child buffers to childbuf
rename them to indicate that they're not the global payload buffer,
but temporary childs for sub-replies.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-09-15 11:20:36 +02:00
sesankm
71d0f66365 xkb: XKBMisc: use C99 declarations in XkbApplyCompatMapToKey
Signed-off-by: sesankm <26676400+sesankm@users.noreply.github.com>
2025-09-15 10:47:40 +02:00