Commit Graph

19444 Commits

Author SHA1 Message Date
Olivier Fourdan 11fcda8753 xkb: Fix buffer overflow in XkbVModMaskText()
The code in XkbVModMaskText() allocates a fixed sized buffer on the
stack and copies the virtual mod name.

There's actually two issues in the code that can lead to a buffer
overflow.

First, the bound check mixes pointers and integers using misplaced
parenthesis, defeating the bound check.

But even though, if the check fails, the data is still copied, so the
stack overflow will occur regardless.

Change the logic to skip the copy entirely if the bound check fails.

CVE-2025-26595, ZDI-CAN-25545

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
Peter Hutterer b0a09ba602 dix: keep a ref to the rootCursor
CreateCursor returns a cursor with refcount 1 - that refcount is used by
the resource system, any caller needs to call RefCursor to get their own
reference. That happens correctly for normal cursors but for our
rootCursor we keep a variable to the cursor despite not having a ref for
ourselves.

Fix this by reffing/unreffing the rootCursor to ensure our pointer is
valid.

Related to CVE-2025-26594, ZDI-CAN-25544

Reviewed-by: Olivier Fourdan <ofourdan@redhat.com>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1828>
2025-02-25 11:43:01 +01:00
Olivier Fourdan 01642f263f Cursor: Refuse to free the root cursor
If a cursor reference count drops to 0, the cursor is freed.

The root cursor however is referenced with a specific global variable,
and when the root cursor is freed, the global variable may still point
to freed memory.

Make sure to prevent the rootCursor from being explicitly freed by a
client.

CVE-2025-26594, ZDI-CAN-25544

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

v2: Explicitly forbid XFreeCursor() on the root cursor (Peter Hutterer
<peter.hutterer@who-t.net>)
v3: Return BadCursor instead of BadValue (Michel Dänzer
<michel@daenzer.net>)

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Suggested-by: Peter Hutterer <peter.hutterer@who-t.net>
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
Jan Engelhardt 530e80375e glamor: explicitly draw endpoints of line segments
The OpenGL 4.6 specification §14.5.1 "Basic Line Rasterization"
figure 14.2 says:

"""A diamond shaped region of height 1 is placed around each fragment
center; those regions that the line segment **exits** cause
rasterization to produce corresponding fragments."""

As the line does not necessarily exit the last diamond,
it is necessary to explicitly paint a pixel at line ends.

Fixes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1434
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1755>
2025-02-24 20:39:12 +00:00
Enrico Weigelt, metux IT consult 6fad884ce7 randr: RRScreenInit(): drop unnecessary zero'ing
The whole struct is already allocated by calloc(), so no need to explicitly
zero-out individual fields.

Fixes: 479b2be4ba - Clear allocated RandR screen private structure
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1794>
2025-02-24 20:30:26 +00:00
Enrico Weigelt, metux IT consult 73467faeb2 randr: ProcRRQueryOutputProperty(): use SwapShort()/SwapLong()
Simplify reply payload preparation and sendout by using SwapShort()
and SwapLong() instead of WriteToClientSwapped() and callbacks.

This also allows even further simplifications by using generic macros
for the request send path.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1794>
2025-02-24 20:30:26 +00:00
Enrico Weigelt, metux IT consult e3001b71b3 randr: ProcRRListOutputProperties(): use SwapShort()/SwapLong()
Simplify reply payload preparation and sendout by using SwapShort()
and SwapLong() instead of WriteToClientSwapped() and callbacks.

This also allows even further simplifications by using generic macros
for the request send path.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1794>
2025-02-24 20:30:26 +00:00
Enrico Weigelt, metux IT consult d9863f7cb0 randr: ProcRRGetCrtcGamma(): use SwapShort()/SwapLong()
Simplify reply payload preparation and sendout by using SwapShort()
and SwapLong() instead of WriteToClientSwapped() and callbacks.

This also allows even further simplifications by using generic macros
for the request send path.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1794>
2025-02-24 20:30:26 +00:00
Enrico Weigelt, metux IT consult 62b8497999 randr: ProcRRGetProviderProperty(): use SwapShort()/SwapLong()
Simplify reply payload preparation and sendout by using SwapShort()
and SwapLong() instead of WriteToClientSwapped() and callbacks.

This also allows even further simplifications by using generic macros
for the request send path.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1794>
2025-02-24 20:30:26 +00:00
Enrico Weigelt, metux IT consult 8789be52a4 randr: ProcRRGetOutputProperty(): use SwapShort()/SwapLong()
Simplify reply payload preparation and sendout by using SwapShort()
and SwapLong() instead of WriteToClientSwapped() and callbacks.

This also allows even further simplifications by using generic macros
for the request send path.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1794>
2025-02-24 20:30:26 +00:00
Enrico Weigelt, metux IT consult 53d43bd8dc randr: ProcRRGetOutputProperty(): rename reply struct to "rep"
Harmonize it with all the other reply struct fields, so we can later
use generic macros for final preparation and writeout.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1794>
2025-02-24 20:30:26 +00:00
Enrico Weigelt, metux IT consult 05188ccec1 randr: RRCreateProviderProperty(): use calloc()
We can rely on everything being cleared. And usually even faster, as the
compiler can emit optimized instructions for clearing a whole block at once.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1794>
2025-02-24 20:30:26 +00:00
Enrico Weigelt, metux IT consult 3d3137513a randr: RROutputCreate(): use calloc()
We can rely on everything being cleared. And usually even faster, as the
compiler can emit optimized instructions for clearing a whole block at once.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1794>
2025-02-24 20:30:26 +00:00
Enrico Weigelt, metux IT consult 1bc6ca30a9 randr: ProcRRGetMonitors(): collect reply payload in temporary buffer
Instead of arbitrary count of individual WriteToClient() calls on small
chunks, collect the whole payload in a buffer and write it out all at once.

This also makes possible to use generic macros for reply sending, as well
as further simplifications in the write-out path.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1794>
2025-02-24 20:30:26 +00:00
Enrico Weigelt, metux IT consult 203f59c6d3 randr: ProcRRGetMonitors() use SwapLongs instead of callbacks
WriteSwappedDataToClient() calls a callback on each single field.
We can have it easier and more efficient by just using SwapLongs()

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1794>
2025-02-24 20:30:26 +00:00
Enrico Weigelt, metux IT consult c6f1b8a735 randr: ProcRRGetCrtcTransform(): split reply header and payload
Using struct initializer for the reply header and only allocating the
payload on heap. This allows using generic macros for reply preparation
and send-out later.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1794>
2025-02-24 20:30:26 +00:00
Enrico Weigelt, metux IT consult 90abc95c85 randr: ProcRRGetCrtcInfo(): use locally scoped variables
Improve readability by moving the variables into local scopes.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1794>
2025-02-24 20:30:26 +00:00
Enrico Weigelt, metux IT consult 7eff742ef2 randr: use struct initializer for reply structs
Improve readability, move the declarations to where they're needed first
and get rid of extra individual assignments. In some cases this should also
allow the compiler to produce a bit more efficient code.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1794>
2025-02-24 20:30:26 +00:00
Enrico Weigelt, metux IT consult 6d2c42d0c8 randr: RRCrtcCreate(): drop unnecessary zero assigments
The struct is already zero'ed out by calloc(), so no need to additionally
clear individual fields.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1794>
2025-02-24 20:30:26 +00:00
Enrico Weigelt, metux IT consult 058815bed1 randr: use explicit case statement instead of SProcRandrVector table
No need to go indirectly through a vector table, since everything's fixed
anyways. It's not a pretty robust programming style: any changes need great
care, in order to not mix up things.

Replacing this by direct switch/case statement, which is using the defines
from the xrandr protocol headers. Also adding a little bit more protection
against subtle programming errors and reducing cognitive load (source size)
on understanding the code by using a tiny macro for deducing define name and
function name from the request's name.

This approach actually uncovered some subtle bug that had been waiting in
the dark for over 15 years.

As collateral benefit, getting a tiny bit better performance.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1794>
2025-02-24 20:30:26 +00:00
Enrico Weigelt, metux IT consult 42677ae1e3 randr: use explicit case statement instead of ProcRandrVector table
No need to go indirectly through a vector table, since everything's fixed
anyways. It's not a pretty robust programming style: any changes need great
care, in order to not mix up things.

Replacing this by direct switch/case statement, which is using the defines
from the xrandr protocol headers. Also adding a little bit more protection
against subtle programming errors and reducing cognitive load (source size)
on understanding the code by using a tiny macro for deducing define name and
function name from the request's name.

This approach actually uncovered some subtle bug that had been waiting in the
dark for over 15 years (see commit b87314c876)

As collateral benefit, getting a tiny bit better performance.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1794>
2025-02-24 20:30:26 +00:00
Enrico Weigelt, metux IT consult ed17224403 randr: let SProc*'s call their Proc*'s directly
No need to go indirectly through an vector table. It's much clearer and
easier to understand when calling them directly. And a tiny bit performance
improvement as collateral benefit.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1794>
2025-02-24 20:30:26 +00:00
Enrico Weigelt, metux IT consult 1fc9a26afd drop not needed includes of geext.h
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1810>
2025-02-24 20:19:55 +00:00
Enrico Weigelt, metux IT consult a955b83848 Xext: dpms: need to include geext.h
It's calling GERegisterExtension(), which is defined in geext.h

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1810>
2025-02-24 20:19:55 +00:00
Enrico Weigelt, metux IT consult ce1f0c9375 present: need to include geext.h
It's calling GERegisterExtension(), which is defined in geext.h

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1810>
2025-02-24 20:19:55 +00:00
Enrico Weigelt, metux IT consult 80593ab279 misc.h: move out MAXEXTENSIONS to geext.c
The only user of it is geext.c, so no need to have that define
in a public include file.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1810>
2025-02-24 20:19:55 +00:00
Enrico Weigelt, metux IT consult 3f469acb96 panoramix: don't install panoramiX.h and panoramiXsrv.h
Not used by any drivers/modules, so no need to keep them public.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1815>
2025-02-24 20:06:30 +00:00
Enrico Weigelt, metux IT consult 86244ff36f dbe: fix byte swapping in SProcDbeSwapBuffers()
The loop forgot to move the SwapInfo pointer, so the same list entry
gets swapped over and over again, while the remaining ones get ignored.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1822>
2025-02-24 16:24:53 +01:00
Enrico Weigelt, metux IT consult de0aed0543 misc.h: move out checked_int64_(add|subtract)
These inline functions are used only in exactly one place,
so no need to keep them in a public header.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1808>
2025-02-23 18:08:45 +00:00
Enrico Weigelt, metux IT consult b664b44869 present: fix prototype for present_select_input()
Wants XID instead of CARD32 for 2nd parameter.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1809>
2025-02-23 18:01:02 +00:00
Enrico Weigelt, metux IT consult 90bc995016 Xext: geext: move geeint.h stuff into geext.c
Everything in here only used by geext.c, so no need to keep
a separate header file for that.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1811>
2025-02-23 17:53:25 +00:00
Enrico Weigelt, metux IT consult 658f1b34ee Xext: geext.h: fix missing include of Xfuncproto.h
Needed for _X_EXPORT.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1811>
2025-02-23 17:53:25 +00:00
Enrico Weigelt, metux IT consult 20d4c40df4 Xext: geext.h: don't include <dix-config.h>
Really no need to ever include it from here.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1811>
2025-02-23 17:53:25 +00:00
Enrico Weigelt, metux IT consult a7600ac884 Xext: geext: move struct _GEExtension into geext.c
Not used anywhere outside geext implementation itself,
so shouldn't be public at all.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1811>
2025-02-23 17:53:25 +00:00
Enrico Weigelt, metux IT consult 896937298b Xext: geext: unexport GEExtensions[]
This field isn't used by anybody outside, nor should it be accessed
directly. So better make it local.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1811>
2025-02-23 17:53:25 +00:00
Enrico Weigelt, metux IT consult 6fa340c578 Xext: geext: drop unused GEInitEvent()
This function isn't called by anybody, so no need to keep it.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1811>
2025-02-23 17:53:25 +00:00
Enrico Weigelt, metux IT consult 480a7e4b11 Xext: geext: drop unused GEV() macro
Not used anywhere, so no need to keep it around any longer.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1811>
2025-02-23 17:53:25 +00:00
Enrico Weigelt, metux IT consult ae7bbd36df Xext: geext: drop unused GEEXT() macro
Not used by anybody, so no need to keep it around any longer.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1811>
2025-02-23 17:53:25 +00:00
Enrico Weigelt, metux IT consult b865f44f5e Xext: geext: drop unused GEEXTIDX() macro
Not used anywhere, so no need to keep it around any longer.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1811>
2025-02-23 17:53:25 +00:00
Enrico Weigelt, metux IT consult 1006a37f7d Xext: geext: drop unused GEMaskIsSet() macro
Not used anywhere, so no need to keep it around any longer.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1811>
2025-02-23 17:53:25 +00:00
Enrico Weigelt, metux IT consult c1d49e19b9 Xext: geext: drop unused GECLIENT() macro
Not used anywhere, so no need to keep it around any longer.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1811>
2025-02-23 17:53:25 +00:00
Enrico Weigelt, metux IT consult 01ad88b8c8 Xext: geext: drop unused GEIsType() macro
Not used anywhere, so no need to keep it around any longer.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1811>
2025-02-23 17:53:25 +00:00
Enrico Weigelt, metux IT consult bdb5d4867a Xext: geext: drop unused GEEventFill() macro
It's not used anywhere, so no need to keep it around any longer.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1811>
2025-02-23 17:53:25 +00:00
Enrico Weigelt, metux IT consult 1dc648b1b7 os: drop unused TimerCheck()
This isn't used anywhere, so can be dropped.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1789>
2025-02-23 17:46:13 +00:00
Enrico Weigelt, metux IT consult d973c43810 os: unexport SetCriticalOutputPending()
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/1814>
2025-02-23 17:39:18 +00:00
Enrico Weigelt, metux IT consult 573d70ae25 xwin: don't need NULL check before free()
free() is safe against NULL arguments.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1818>
2025-02-23 17:32:49 +00:00
Enrico Weigelt, metux IT consult eafec5836a glamor: don't need NULL check before free()
free() is safe against NULL arguments.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1818>
2025-02-23 17:32:49 +00:00
Enrico Weigelt, metux IT consult e4e3b69626 Xext: geext: fix regression in SProcGEQueryVersion()
Commit 36dd28129b had an ugly typo
(probably broke on rebase - shame on myself) causing SProcGEQueryVersion()
calling itself recursively. Obviously, ProcGEQueryVersion() needs
to be called instead.

Fixes: 36dd28129b
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1817>
2025-02-23 17:25:29 +00:00
Enrico Weigelt, metux IT consult 7ca8c1518c present: need to include <X11/Xfuncproto.h>
Some headers making use of X_EXPORT macro, so Xfuncproto.h should be
included explicitly, instead of silently relying any other include
already doing that.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1813>
2025-02-23 17:18:46 +00:00
Enrico Weigelt, metux IT consult b55d726a7b present: need to include dix-config.h
dix-config.h always needs to be included first, otherwise things
can get messed up in really obscure ways, eg. certain types silently
changing in size and causing mysterious crashes.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1813>
2025-02-23 17:18:46 +00:00