Commit Graph

21933 Commits

Author SHA1 Message Date
Olivier Fourdan
a073975fa3 present: Fix use-after-free in present_create_notifies()
Using the Present extension, if an error occurs while processing and
adding the notifications after presenting a pixmap, the function
present_create_notifies() will clean up and remove the notifications
it added.

However, there are two different code paths that can lead to an error
creating the notify, one being before the notify is being added to the
list, and another one after the notify is added.

When the error occurs before it's been added, it removes the elements up
to the last added element, instead of the actual number of elements
which were added.

As a result, in case of error, as with an invalid window for example, it
leaves a dangling pointer to the last element, leading to a use after
free case later:

 |  Invalid write of size 8
 |     at 0x5361D5: present_clear_window_notifies (present_notify.c:42)
 |     by 0x534A56: present_destroy_window (present_screen.c:107)
 |     by 0x41E441: xwl_destroy_window (xwayland-window.c:1959)
 |     by 0x4F9EC9: compDestroyWindow (compwindow.c:622)
 |     by 0x51EAC4: damageDestroyWindow (damage.c:1592)
 |     by 0x4FDC29: DbeDestroyWindow (dbe.c:1291)
 |     by 0x4EAC55: FreeWindowResources (window.c:1023)
 |     by 0x4EAF59: DeleteWindow (window.c:1091)
 |     by 0x4DE59A: doFreeResource (resource.c:890)
 |     by 0x4DEFB2: FreeClientResources (resource.c:1156)
 |     by 0x4A9AFB: CloseDownClient (dispatch.c:3567)
 |     by 0x5DCC78: ClientReady (connection.c:603)
 |   Address 0x16126200 is 16 bytes inside a block of size 2,048 free'd
 |     at 0x4841E43: free (vg_replace_malloc.c:989)
 |     by 0x5363DD: present_destroy_notifies (present_notify.c:111)
 |     by 0x53638D: present_create_notifies (present_notify.c:100)
 |     by 0x5368E9: proc_present_pixmap_common (present_request.c:164)
 |     by 0x536A7D: proc_present_pixmap (present_request.c:189)
 |     by 0x536FA9: proc_present_dispatch (present_request.c:337)
 |     by 0x4A1E4E: Dispatch (dispatch.c:561)
 |     by 0x4B00F1: dix_main (main.c:284)
 |     by 0x42879D: main (stubmain.c:34)
 |   Block was alloc'd at
 |     at 0x48463F3: calloc (vg_replace_malloc.c:1675)
 |     by 0x5362A1: present_create_notifies (present_notify.c:81)
 |     by 0x5368E9: proc_present_pixmap_common (present_request.c:164)
 |     by 0x536A7D: proc_present_pixmap (present_request.c:189)
 |     by 0x536FA9: proc_present_dispatch (present_request.c:337)
 |     by 0x4A1E4E: Dispatch (dispatch.c:561)
 |     by 0x4B00F1: dix_main (main.c:284)
 |     by 0x42879D: main (stubmain.c:34)

To fix the issue, count and remove the actual number of notify elements
added in case of error.

CVE-2025-62229, ZDI-CAN-27238

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

Signed-off-by: Olivier Fourdan <ofourdan@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
bf8c7d27fe xfree86: compat: re-add GEInitEvent() for proprietary nvidia driver
Yet another very internal function that the proprietary Nvidia driver
is using for unknown reasons. NVidia really needs a separate function
for just for some trivial struct initialization and don't manage to
add three simple lines to their code, so we have to make an extra
function for them.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-10-28 16:26:44 +01:00
Enrico Weigelt, metux IT consult
7ef8400df5 xfree86: compat: re-add TimeCheck() for proprietary nvidia driver
Yet another very internal function that the proprietary Nvidia driver
is using for unknown reasons.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-10-28 16:26:44 +01:00
Enrico Weigelt, metux IT consult
7f74632448 dix: rename DevScreenPrivateKey to DevScreenPrivateKeyPtr
Be a bit more consistent in naming. We call all our pointer-to-struct
types <xyz>Ptr.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-10-28 15:40:42 +01:00
stefan11111
011d7bfac3 modesetting: handle some allocation failures
Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-10-27 15:16:12 +01:00
stefan11111
d220a0a9f0 shm: Fix segfault when the last X client closes
Fixes: https://github.com/X11Libre/xserver/pull/1236

Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-10-27 09:27:52 +01:00
Enrico Weigelt, metux IT consult
8051613229 Xi: inline SProcXIQueryVersion()
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-10-26 13:59:05 +01:00
Enrico Weigelt, metux IT consult
7d9fb7b4a0 Xi: inline SProcXIPassiveGrabDevice() and SProcXIPassiveUngrabDevice()
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-10-26 13:58:17 +01:00
Enrico Weigelt, metux IT consult
7a0efe7da5 xv: use embedded private instead of pointer
The private struct is pretty small and it needs to be allocated anyways,
so save an extra allocation by directly embedding it.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-10-26 13:57:49 +01:00
Enrico Weigelt, metux IT consult
1119ccc9be render: consolidate byte-swapping in ProcRenderAddTraps()
No need for extra functions and call tables for the few trivial lines.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-10-26 13:57:30 +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
25818f04c3 Xi: inline SProcXIGetClientPointer() and SProcXISetClientPointer()
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-10-26 13:56:58 +01:00
Enrico Weigelt, metux IT consult
0293e34b2e dix: inline SProcInternAtom()
No need for having an extra function for just few lines.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-10-26 13:55:46 +01:00
stefan11111
3109a95e56 glx: vndcmds: Update a comment
Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-10-24 12:47:15 +02:00
stefan11111
9c53dd0a87 glx: vndcmds: revert 22a51912d1 "glx: vndcmds: save unecessary calls to clear current context for same vendor"
Looks like the answer to the commented question:
```
        // TODO: For switching contexts in a single vendor, just make one
        // makeCurrent call?
```
is no.

Fixes: https://github.com/X11Libre/xserver/issues/1246
Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-10-24 12:47:15 +02:00
Enrico Weigelt, metux IT consult
feb50d2293 dix: ProcPolyText(): drop unused variable
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-10-23 13:11:55 +02:00
Enrico Weigelt, metux IT consult
e2baf112f1 Xi: inline SProcXIBarrierReleasePointer()
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-10-23 13:11:22 +02:00
Enrico Weigelt, metux IT consult
4d41eaa043 render: consolidate byte-swapping in ProcRenderSetPictureFilter()
No need for extra functions and call tables for the few trivial lines.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-10-23 13:10:59 +02: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
0a7df3a828 Xi: inline SProcXUngrabDeviceKey()
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-10-22 14:05:24 +02:00
Enrico Weigelt, metux IT consult
fc14d32a1a dix: replace XACE_SCREEN_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-22 13:53:25 +02:00
Enrico Weigelt, metux IT consult
38eedc3de5 Xext: shm: move ShmDescRec definition into shm.c
Only used inside shm.c, not anywhere else, so no need to keep it
in a public header file.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-10-21 20:36:44 +02:00
Enrico Weigelt, metux IT consult
182385af12 dix: add some bit of documentation to privates subsystem
Document some non-trivial aspects and add warnings what not to
touch in order to not breaking ABI.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-10-21 20:36:13 +02:00
Enrico Weigelt, metux IT consult
88bced1643 render: consolidate byte-swapping in ProcRenderTriFan()
No need for extra functions and call tables for the few trivial lines.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-10-21 20:35:15 +02:00
Enrico Weigelt, metux IT consult
007538d86f render: XineramaRenderChangePicture(): don't patch request buffer anymore
No need for patching up the request buffer anymore - just pass in the correct
value directly.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-10-21 20:02:45 +02:00
stefan11111
8b8cde2cb2 modesetting: add "CursorSize" option
On certain setups, it might still be useful to force a particular cursor
size via xorg.conf.
For example, if on a system the automatic probes fail, or if the user wants
a particular cursor size, that is higher that the minimum size.

Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-10-21 16:12:46 +02:00
stefan11111
cf092cd469 modesetting: probe using the old method if SIZE_HINTS isn't available
On most cards, SIZE_HINTS isn't available.
Without this, most users would have to set the fallback cursor size themselves,
or rely on the 64x64 default.

Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-10-21 16:12:46 +02:00
stefan11111
6f7731c44c modesetting: Fix cursor buffer not getting cleared when the pitch changes.
Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-10-21 16:12:46 +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
fb5274d7ac render: consolidate byte-swapping in ProcRenderFillRectangles()
No need for extra functions and call tables for the few trivial lines.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-10-21 14:17:56 +02:00
stefan11111
7e8d887085 CI: Build Xfbdev on linux CI, and only on linux CI
Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-10-21 14:13:21 +02:00
Enrico Weigelt, metux IT consult
a2068d6662 Xext: shm: drop obsolete ShmScreenClose()
Since it's now doing nothing more than unhooking itself, we really
don't need it anymore.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-10-21 13:53:41 +02:00
Alan Coopersmith
37226395ad Xi: set value for led_values in CopySwapKbdFeedback()
(The existing setting of led_mask is probably wrong, but has been set
 like this since X11R5 and going back as far as the first version in
 the X Consortium source control archives.)

Reported in https://gitlab.freedesktop.org/xorg/xserver/-/issues/1817:

xwayland-24.1.6/redhat-linux-build/../Xi/getfctl.c:108:9:
 warning[-Wanalyzer-use-of-uninitialized-value]:
 use of uninitialized value ‘*k2.led_values’
108|->         swapl(&k2->led_values);

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/2075>
2025-10-21 13:02:04 +02:00
Alan Coopersmith
e26cad2421 Xi: avoid null dereference if wOtherInputMasks() returns NULL
The wOtherInputMasks(win) macro will return NULL if
win->optional is NULL.

Reported in https://gitlab.freedesktop.org/xorg/xserver/-/issues/1817:

xwayland-24.1.6/redhat-linux-build/../Xi/exevents.c:1390:13:
 warning[-Wanalyzer-null-dereference]: dereference of NULL ‘0’

xwayland-24.1.6/redhat-linux-build/../Xi/exevents.c:1404:13:
 warning[-Wanalyzer-null-dereference]: dereference of NULL ‘0’

xwayland-24.1.6/redhat-linux-build/../Xi/exevents.c:2293:9:
 warning[-Wanalyzer-null-dereference]: dereference of NULL ‘0’

xwayland-24.1.6/redhat-linux-build/../Xi/exevents.c:3244:22:
 warning[-Wanalyzer-null-dereference]: dereference of NULL ‘inputMasks’

xwayland-24.1.6/redhat-linux-build/../Xi/exevents.c:3338:9:
 warning[-Wanalyzer-null-dereference]: dereference of NULL ‘0’

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/2075>
2025-10-21 13:02:04 +02:00
Alan Coopersmith
238c1ccf4b Xext/xtest: avoid null dereference in ProcXTestFakeInput()
Reported in https://gitlab.freedesktop.org/xorg/xserver/-/issues/1817:

xwayland-24.1.6/redhat-linux-build/../Xext/xtest.c:383:14: warning[-Wanalyzer-null-dereference]: dereference of NULL ‘dev’
xwayland-24.1.6/redhat-linux-build/../Xext/xtest.c:348:9: release_memory: ‘dev’ is NULL
xwayland-24.1.6/redhat-linux-build/../Xext/xtest.c:383:14: danger: dereference of NULL ‘dev’

xwayland-24.1.6/redhat-linux-build/../Xext/xtest.c:395:14: warning[-Wanalyzer-null-dereference]: dereference of NULL ‘dev’
xwayland-24.1.6/redhat-linux-build/../Xext/xtest.c:348:9: release_memory: ‘dev’ is NULL
xwayland-24.1.6/redhat-linux-build/../Xext/xtest.c:395:14: danger: dereference of NULL ‘dev’

xwayland-24.1.6/redhat-linux-build/../Xext/xtest.c:426:14: warning[-Wanalyzer-null-dereference]: dereference of NULL ‘dev’
xwayland-24.1.6/redhat-linux-build/../Xext
/xtest.c:348:9: release_memory: ‘dev’ is NULL
xwayland-24.1.6/redhat-linux-build/../Xext/xtest.c:426:14: danger: dereference of NULL ...
2025-10-21 13:02:04 +02:00
Alan Coopersmith
640a9cf51e Xext/xselinux: avoid memory leak in SELinuxAtomToSID()
Reported in https://gitlab.freedesktop.org/xorg/xserver/-/issues/1817:

xwayland-24.1.6/redhat-linux-build/../Xext/xselinux_label.c:142:13: warning[-Wanalyzer-malloc-leak]: leak of ‘rec’
xwayland-24.1.6/redhat-linux-build/../Xext/xselinux_label.c:133:1: enter_function: entry to ‘SELinuxAtomToSID’
xwayland-24.1.6/redhat-linux-build/../Xext/xselinux_label.c:141:15: acquire_memory: allocated here
xwayland-24.1.6/redhat-linux-build/../Xext/xselinux_label.c:69:12: branch_true: following ‘true’ branch...
xwayland-24.1.6/redhat-linux-build/../Xext/xselinux_label.c:142:13: danger: ‘rec’ leaks here; was allocated at [(2)](sarif:/runs/0/results/0/codeFlows/0/threadFlows/0/locations/1)
  140|       if (!rec) {
  141|           rec = calloc(1, sizeof(SELinuxAtomRec));
  142|->         if (!rec || !SELinuxArraySet(&arr_atoms, atom, rec))
  143|               return BadAlloc;
  144|       }

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/2072>
2025-10-21 13:02:04 +02:00
Alan Coopersmith
c45edc0c51 Xext/xselinux: add fast path to ProcSELinuxListSelections()
If there's nothing to send, skip over a bunch of code to make a list
that won't be used, and hopefully make the code path clearer to both
humans and static analyzers, who raise errors as seen in https://gitlab.freedesktop.org/xorg/xserver/-/issues/1817 of
dereferencing NULL pointers when count == 0.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/2072>
2025-10-21 13:02:04 +02:00
Alan Coopersmith
5a8effe1e7 Xext/sync: Avoid dereference of invalid pointer if malloc() failed
Reported incorrectly in https://gitlab.freedesktop.org/xorg/xserver/-/issues/1817 as:

xwayland-24.1.6/redhat-linux-build/../Xext/sync.c:2835:33: acquire_memory: allocated here
xwayland-24.1.6/redhat-linux-build/../Xext/sync.c:2843:12: danger: ‘priv’ leaks here; was allocated at [(30)](sarif:/runs/0/results/5/codeFlows/0/threadFlows/0/locations/29)

but the "leak" is really saving the pointer in an uninitalized pointer in
a structure that was already freed when the malloc of the SysCounterInfo
struct failed in SyncCreateSystemCounter(), because it returned the address
of the freed struct instead of NULL to indicate failure.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/2072>
2025-10-21 13:02:04 +02:00
Alan Coopersmith
446baf6b15 Xext/sync: avoid null dereference if SysCounterGetPrivate() returns NULL
Reported in https://gitlab.freedesktop.org/xorg/xserver/-/issues/1817:

xwayland-24.1.6/redhat-linux-build/../Xext/sync.c:2664:9: danger: dereference of NULL ‘SysCounterGetPrivate(pCounter)’

xwayland-24.1.6/redhat-linux-build/../Xext/sync.c:2677:14: danger: dereference of NULL ‘SysCounterGetPrivate(pCounter)’

xwayland-24.1.6/redhat-linux-build/../Xext/sync.c:2767:14: danger: dereference of NULL ‘SysCounterGetPrivate(pCounter)’

xwayland-24.1.6/redhat-linux-build/../Xext/sync.c:2800:14: danger: dereference of NULL ‘SysCounterGetPrivate(pCounter)’

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/2072>
2025-10-21 13:02:04 +02:00
Enrico Weigelt, metux IT consult
c046c7629e dix: inline SProcPolyText()
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-10-21 10:49:37 +02:00
Enrico Weigelt, metux IT consult
202c452b5f dix: replace XACE_SCREENSAVER_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-21 10:49:08 +02:00
Enrico Weigelt, metux IT consult
8d19217b56 Xext: shm: move per-screen private structure into privates area
Instead of having a pointer to a struct just consisting of a pointer,
just move that struct directly into the privates area, so we not just
save one extra indirection, but also not having to care about an extra
chunk of malloc'ed memory anymore (thus getting rid of a potential
OOM bug)

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-10-21 10:40:32 +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
Alan Coopersmith
e446fdc14a xfree86: add missing headers to build sun_init.c on Solaris/SPARC
Fixes: 0f715b4ca4 ("xfree86: os-support: move hidden Solaris-specific symbols out of public header")
Fixes: e2fa0d2ae0 ("fix including <sys/mman.h>")

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/2070>

Further explanation about this commit by @alanc:

This particular set of `#ifdefs` matches the ones around the code using the fbio ioctls and mmap calls in the `xf86CloseConsole()` code later in the file:
c62cd2feaa/hw/xfree86/os-support/solaris/sun_init.c (L281)
reflecting the lack of /dev/fb style drivers on x86 systems on Solaris.
2025-10-21 10:25:32 +02:00
Alan Coopersmith
855aa4ef86 xfree86: Fix -Wdiscarded-qualifiers warnings in SPARC Sbus probe code
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/2070>
2025-10-21 10:25:32 +02:00
Alan Coopersmith
c179700b99 xfree86: fix meson build on 64-bit Solaris/SPARC systems
For cpu_family(), meson returns "sparc" for 32-bit sparc,
and "sparc64" for 64-bit sparc, regardless of the OS in use.

For cpu(), meson returns values like "sun4v" on Solaris/SPARC,
and doesn't promise stability of the values, or portability across
OS'es, unlike cpu_family().

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/2070>
2025-10-21 10:25:32 +02:00
Enrico Weigelt, metux IT consult
4825c4584a Xext: shm: shmint.h: drop superflous extern on function prototypes
Functions are already `extern` by default.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-10-21 10:23:11 +02:00
Enrico Weigelt, metux IT consult
f19e7a24a1 Xext: shm: unexport ShmSegType variable
Not used by any drivers, so no need to keep it exported.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-10-21 10:22:47 +02:00