Commit Graph

22183 Commits

Author SHA1 Message Date
Ville Syrjälä
a345c59673 modesetting: Parse the IN_FORMATS_ASYNC blob
The kernel has gained another format/modifier blob to indicate
which formats/modifiers support async flips since Linux 6.16. Parse it.

Signed-off-by: notbabaisyou <though-went-some-simple@proton.me>
2025-11-06 15:56:07 +01:00
Ville Syrjälä
a87fb7577e modesetting: Enable universal planes client cap
Enable the universal planes client cap so that we actually
get access to the primary plane's IN_FORMATS blob. We will
now start to parse the blob.

Signed-off-by: notbabaisyou <though-went-some-simple@proton.me>
2025-11-06 15:56:07 +01:00
Ville Syrjälä
671a8ee04c modesetting: Don't try to use modifiers when allocating the root pixmap
We want the root pixmap to use conservative tiling modifiers in
order to make sure modeset/etc can never fail due to hardware
watermark restictions/etc.

Currenlty this is all dead code anyway because we aren't actually
parsing the IN_FORMATS blob (missing universal plane client cap).
But we want to start parsing that, so let's first make sure we
don't get any behavioural changes from doing so.

Signed-off-by: notbabaisyou <though-went-some-simple@proton.me>
2025-11-06 15:56:07 +01:00
Ville Syrjälä
d26d08cd1e present: Don't ping-pong between sync and async flips
Many Intel GPUs can't switch between sync and async flips
willy nilly. Sometimes that change itself will take one
extra frame. This means that constant ping-pong between
sync and async flips is only going to cause problems.
Stay in async flip mode as long as the client is requesting
it.

The present protocol spec does say:
"If 'options' contains PresentOptionAsync, and the 'target-msc'
 is less than or equal to the current msc for 'window', then
 the operation will be performed as soon as possible, not
 necessarily waiting for the next vertical blank interval."

So there is an expectation that a future target-msc will
still be respected even when PresentOptionAsync is specified.
Staying in async flip mode won't actually change that given
that present_scmd_pixmap() takes the flip mode into account
when calculating exec_msc. So visually the flip should still
happen on the correct target_msc regardles of whether we
executed it as sync or async.

Signed-off-by: notbabaisyou <though-went-some-simple@proton.me>
2025-11-06 15:56:07 +01:00
Ville Syrjälä
003d73441b present: Walk all children when setting window pixmaps
We currently skip setting the window pixmap on any window
not using its parent's pixmap. That does not work correctly
in the presence of reparenting.

Consider the following scenario:
1. window A is created as child of B
2. present starts flipping and sets the whole window
   tree to use pixmap X
3. window C is created (uses the screen pixmap by default)
4. window A is reparented to C
5. present stops flipping and attempts to set the
   whole window tree back to the screen pixmap,
   except the walk terminates at window C
   since it's using an unexpected pixmap, and
   window A is left with the stale pixmap X
6. pixmap X is destroyed
7. the X server segfaults on a rendering operation
   on window A due the stale pixmap

I managed to hit this with mpv (doing present flips)
and crack-attack (keeps alternating between a menu
window and an actual game window):
1. start both applications
2. start a game in crack-attack
3. fullscreen mpv
4. end the game in crack attack
5. unfullscreen mpv
6. the crack-attack menu window has appeared, but
   might be corrupted and doing stuff on it segfaults
   the X server

I suppose the other option might be to make new windows
automatically inherit their parent's pixmap instead
of using the screen pixmap. But I've not looked into
how that would affect eg. composite.

Signed-off-by: notbabaisyou <though-went-some-simple@proton.me>
2025-11-06 15:56:07 +01:00
stefan11111
23fd2bd19f glamor: Set *num_formats to NULL in glamor_get_formats if we don't have any formats.
Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-11-06 15:55:16 +01:00
Chase
a3eab2e968 exa.c: 0x prefix is superfluous 2025-11-06 13:08:13 +01:00
Chase
23c906cb8c exa.c: small formatting fix 2025-11-06 13:08:13 +01:00
Enrico Weigelt, metux IT consult
ea5fade41c test: simple-xinit: ignore compiler warning on write()
This warning doesn't matter in this case:

> ../test/simple-xinit.c: In function ‘handle_sigchld’:
> ../test/simple-xinit.c:69:5: warning: ignoring return value of ‘write’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
>    69 |     write(server_displayfd, server_dead, strlen(server_dead));
>       |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In order to allow building w/ -Werror, it should be suppressed.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-11-06 11:24:15 +01:00
Enrico Weigelt, metux IT consult
f609b18367 render: XineramaRenderSetPictureClipRectangle(): 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-11-06 11:23:19 +01:00
Enrico Weigelt, metux IT consult
99590abe52 render: PanoramiXRenderComposite() drop stuff pointer
This pointer just had been kept in at previous commit for keeping the
diff small and so easier to review. Now accessing the fields within
the local struct directly, dropping the extra pointer.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-11-06 11:21:52 +01:00
Enrico Weigelt, metux IT consult
d9e0c0451d render: PanoramiXRenderComposite(): don't patch request buffer anymore
No need for patching up the original request buffer anymore - just pass
in a modified copy.

Trying to keep this patch small for easier review. Some cleanups coming
with a follow-up.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-11-06 11:21:52 +01:00
stefan11111
32f0c01c14 loader: Tell users to give the modesetting DDX a try
if they are using the proprietary nvidia DDX

Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-11-05 17:47:45 +01:00
stefan11111
c7fa008f68 loader: Print instructions about using old nvidia proprietary ddx drivers
Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-11-05 17:47:45 +01:00
Enrico Weigelt, metux IT consult
03dcb626fe dix: UngrabServer(): clear grabClient pointer
When ungrabbing, clear the grab pointer, so no stale data left
in here.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-11-05 17:16:42 +01:00
Enrico Weigelt, metux IT consult
21db844ea1 dix: MakeRootTile(): constify from field
It's assigned a const char* value and not writing into it,
so it should be const, too (compiler correctly warning about that)

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-11-05 12:16:06 +01:00
Enrico Weigelt, metux IT consult
624ec5d226 os: utils: unexport PanoramiXExtensionDisabledHack
This variable is only used in os layer and PanoramiX, nowhere else,
and shouldn't be visible to drivers at all.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-11-04 15:09:45 +01:00
stefan11111
6073de4461 glamor: fix Option "GlxVendorLibrary"
The old code tried to use a screen pointer that was uninitialized and set to NULL.
This caused it to segfault when this option was set.

Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-11-04 15:08:28 +01:00
Tautvis
16a1be1939 modesetting: call xf86_cursors_fini during CloseScreen
Add matching call for xf86_cursors_init to clean memory, as during
initialization it allocates memory (depends, but is something like ~256Kb)
and it leaks when XServer resets.

Signed-off-by: Tautvis <gtautvis@gmail.com>
2025-11-04 12:12:58 +01:00
Enrico Weigelt, metux IT consult
92e6c75bfc include: globals: add missing includes
Headers should always be self-consistent, thus including anything they need.
Not relying on those already included before by somebody else.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-11-04 11:25:20 +01:00
stefan11111
0e851b9710 xfree86/loader: Apply unloadsubmodule gentoo patch
See: https://github.com/gentoo/gentoo/blob/master/x11-base/xorg-server/files/xorg-server-1.12-unloadsubmodule.patch
See: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=686152#14

Verbatim copy of https://github.com/X11Libre/xserver/issues/319#issuecomment-3033729517 ,which gives more context for this patch:

I took a closer look at that patch.
It is logically equivalent to:
```
diff --git a/hw/xfree86/loader/loadmod.c b/hw/xfree86/loader/loadmod.c
index 2cdf91fd2..49785fdc8 100644
--- a/hw/xfree86/loader/loadmod.c
+++ b/hw/xfree86/loader/loadmod.c
@@ -885,6 +885,7 @@ RemoveChild(ModuleDescPtr child)
     parent = child->parent;
     if (parent->child == child) {
         parent->child = child->sib;
+        child->sib = NULL;
         return;
     }
```
RemoveChild is a static function that is only called in UnloadSubModule:
```
void
UnloadSubModule(ModuleDescPtr mod)
{
    /* Some drivers are calling us on built-in submodules, ignore them */
    if (mod == (ModuleDescPtr) 1)
        return;
    RemoveChild(mod);
    UnloadModule(mod);
}
```
Whether or not child->sib is NULL tells UnloadModule if it should recursively unload child->sib or not:
```
    if (mod->child)
        UnloadModule(mod->child);
    if (mod->sib)
        UnloadModule(mod->sib);
    free(mod);
```
Looking at the source, the module loader uses some weird kind of tree-like structure,
where every node has at most one child and one sibling (but then, if foo has child bar, and bar has sibling baz, shouldn't baz also be foo's child?).
```
typedef struct module_desc {
    struct module_desc *child;
    struct module_desc *sib;
    struct module_desc *parent;
    void *handle;
    ModuleSetupProc SetupProc;
    ModuleTearDownProc TearDownProc;
    void *TearDownData;         /* returned from SetupProc */
    const XF86ModuleVersionInfo *VersionInfo;
} ModuleDesc, *ModuleDescPtr;
```

All in all, this patch makes UnloadSubModule to never unload the sibling of the unloaded module, whereas
as it is now, UnloadSubModule would also unload the module's sibling if `child->parent == child->parent->child`
(master child?).

I don't see how this patch changed the behavior on ia64, or any other arch.

@metux Could you tell me what kind of data structure this is, and whether or not this patch is right?

Fixes: https://github.com/X11Libre/xserver/issues/319

Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-11-04 10:53:42 +01:00
clhin
7468cd4ee0 dispatch.c: const correctness 2025-11-04 10:48:52 +01:00
clhin
b47576420f window.c: const correctness 2025-11-04 10:48:52 +01:00
Enrico Weigelt, metux IT consult
a18480ef84 Xi: drop redundant SProcIDispatch()
Now that all individual swapping request handlers have been merged into the
actual ones, there's no need for a separate dispatcher anymore.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-11-04 10:45:04 +01:00
stefan11111
09d35f1e0d glamor: use GBM_BO_USE_RENDERING for importing gbm bo's
Inspired by 421ce458f1

Glamor should use GBM_BO_USE_RENDERING, since they are image buffers.
This change is mostly cosmetic, as mesa doesn't do anything with
this flag, other than a sanity check.
See: https://gitlab.freedesktop.org/mesa/mesa/-/issues/14130

Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-11-03 17:25:52 +01:00
Enrico Weigelt, metux IT consult
cf105bc990 dix/Xinerama: untwist X_AllocColor request handling
Instead of internally faking requests, factor out the actual logic
into separate function, which is getting everything it needs as
parameters, so no need to fiddle with request buffer anymore.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-11-03 17:24:24 +01:00
Enrico Weigelt, metux IT consult
9b2d3ba167 render: consolidate byte-swapping in ProcRenderCreateConicalGradient()
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-11-03 17:24:07 +01:00
kohnish
05524df68b Build without XINERAMA failing 2025-11-03 17:23:50 +01:00
stefan11111
585810fb13 modesetting: Handle bo allocation failure
Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-11-03 17:15:14 +01:00
Enrico Weigelt, metux IT consult
4c4fb5f5f1 render: consolidate byte-swapping in ProcRenderCreateRadialGradient()
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-31 13:06:31 +01:00
Enrico Weigelt, metux IT consult
45aa28d4d2 dix: inline SProcChangeProperty()
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-10-31 13:06:11 +01:00
stefan11111
cf4b49ac84 modesetting: Create the largest possible cursor image buffer.
Since https://github.com/X11Libre/xserver/pull/1234 landed,
the user has a way to set the hw cursor size to the size they want.

The fallback probe works around driver bugs by probing very late,
so it initializes the cursor image buffer with the largest size the driver supports.

With this change, the SIZE_HINTS probe will also initialize
the cursor image buffer with the largest size it finds,
which is what @notbabaisyou 's code originally did.

Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-10-30 12:34:52 +01:00
stefan11111
7f7462cb14 CI: build xf86-input-{keyboard,mouse} in CI
These drivers build on linux, so we should test them.

Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-10-30 09:51:20 +01:00
Enrico Weigelt, metux IT consult
6057540a6c render: consolidate byte-swapping in ProcRenderCreateLinearGradient()
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-30 09:44:56 +01:00
Enrico Weigelt, metux IT consult
d7eac08a22 Xi: inline SProcXISelectEvents() and SProcXIGetSelectedEvents()
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-10-30 09:44:41 +01:00
Enrico Weigelt, metux IT consult
0fbb681fce treewide: use helper dixGetScreenPtr() for retrieving ScreenPtr's
Instead of directly accessing the global screenInfo.screens[] array,
let everybody go through a little inline helper. This one also checks
for array bounds - if the screen doesn't exist, return NULL.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-10-30 09:44:24 +01:00
stefan11111
d2fcf85214 ramdac: Don't read/write oob if the cursor size is not aligned to the mask interleave
This doesn't mean the unaligned cursor sizes are recommended now,
just that they will no longer segfault.

Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-10-29 13:17:40 +01:00
Enrico Weigelt, metux IT consult
e23f70624f dix: privates: update docs on dixRegisterPrivateKey()
a) move to doxygen-style docs, inside the header instead of code
b) mention that the function can be called many times with the
   same parameters (already registered keys are silently tolerated)

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-10-29 11:45:04 +01:00
Tautvis
a581ba5964 dix: dixFreeScreen call hookPostCreateResources too
Call DeleteCallbackList(&pScreen->hookPostCreateResources) during
dixFreeScreen, because otherwise it will be heap-use-after-free during
DeleteCallbackManager call.

Signed-off-by: Tautvis <gtautvis@gmail.com>
2025-10-29 11:41:26 +01:00
stefan11111
5b8ab55702 shm: Don't mark the globally-initialized privates as uninitialized in a CloseScreen hook.
No need to mark anything, because duplicate dixRegisterPrivateKey() calls with same parameters are perfectly valid.
See: https://github.com/X11Libre/xserver/pull/1300

Fixes: https://github.com/X11Libre/xserver/commit/d220a0a9f0473c15d5001f4730613b482eb0e39

Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-10-29 11:23:33 +01:00
Enrico Weigelt, metux IT consult
04d4986004 dix: split ProcCreateWindow() into upper and lower half
In order to reduce complexity of wrapped core request handlers with PanoramiX,
split the ProcCreateWindow() function into two pieces: the upper half is the
usual (non-PanoramiX) handler, while the lower one is what's called by both
the usual handler, as well as the PanoramiX' one.

We're already passing in the request parameters as separate pointers, so
follow-up commits can easily change PanoramiX handler to not tweaking the
request buffer directly anymore. Another one is letting PanoramiXCreateWindow()
be called by ProcCreateWindow explicitly (when enabled), so we don't need to
wrap the core request proc vector anymore. Once that's done, the swapping can
also be moved into ProcCreateWindow().

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-10-29 11:03:19 +01:00
Enrico Weigelt, metux IT consult
0d4e48188a render: consolidate byte-swapping in ProcRenderCreateSolidFill()
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-29 10:59:12 +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
Enrico Weigelt, metux IT consult
8d46c06965 Xi: inline SProcXIQueryPointer()
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-10-29 10:57:52 +01:00
Enrico Weigelt, metux IT consult
e125d9badb Xi: inline SProcXIWarpPointer()
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-10-29 10:56:57 +01:00
Enrico Weigelt, metux IT consult
48123076f9 dix: inline SProcDeleteProperty()
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-10-29 10:56:22 +01:00
Enrico Weigelt, metux IT consult
8f42a071b7 dix: inline SProcSetSelectionOwner()
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-10-29 10:34:28 +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