Commit Graph

907 Commits

Author SHA1 Message Date
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
Enrico Weigelt, metux IT consult
b0ffa7b286 treewide: rename dixGetFirstScreenPtr() to dixGetMasterScreen() for correct semantics
In Xinerama/Panoramix configuration there's one screen that's having special
meaning - it's used for simulating as the frontend for all client operations:
the clients (should) only talk to that screen, while panoramix subsystem is
proxying those operations to all the other screens (with certain changed
applied, eg. coordinate transformations).

Historically, this screen happens to be the first one in the system (some of
it's proc's are hooked up in order to achieve desired behaviour). That's why it
used to be accessed via screenInfo.screens[0] - that already had been encapsulated
into a tiny helper `dixGetFirstScreen()`.

a) the correct terminus technicus for a situation where one device (or SW entity)
   entirely controlling others is a master-slave-relationship: the controlling
   device/entity is `master`, the controlled ones are `slave` (to that specific
   master).

b) the term "first screen" is inacurate and misleading here: what the caller's are
   actually interest in isn't the first entry in the screen array, but the screen
   that's controlling the others. With upcoming refactoring of the Xinerama/Panoramix
   subsystem, this might well be a different array index than 0.

c) the term `default` also wouldn't match: `default` implies there's a real practical
   choice, and such value applies when no explicit choice has been made. But in this
   case, it practically doesn't make sense (except perhaps for debugging purpose)
   for a client to use any different screen.

Therefore fixing the function name to the correct technical terminology.
(for sake of patch readability, renaming corresponding variables is left to
subsequent patches).

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-09-12 11:44:05 +02:00
Enrico Weigelt, metux IT consult
6bc438ab5a treewide: use inline helper for accessing first screen
Instead of everybody directly accessing the (internal) screenInfo struct,
let those consumers only interested in first screen use a little helper.

Also caching the value if it's needed several times.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-09-10 13:45:05 +02:00
sesankm
3e610c5fc5 xkb: XKBMisc: use C99 style declarations in XKBMisc functions 2025-09-10 13:40:15 +02:00
Enrico Weigelt, metux IT consult
a324351f67 treewide: drop unnecessary includes of Xi/eglobals.h
Dropping include by sources that don't use anything from this header.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-09-09 14:41:10 +02:00
sesankm
af8b69b710 xkb: XKBMisc: scoped declaration in loops and use int instead of register ints
Signed-off-by: sesankm <26676400+sesankm@users.noreply.github.com>
2025-09-08 17:28:13 +02:00
sesankm
e3ae087bc7 xkb: XKBMisc: simple refactoring to declare variables where needed in XkbKeyTypesForCoreSymbols
Signed-off-by: sesankm <26676400+sesankm@users.noreply.github.com>
2025-09-08 17:28:13 +02:00