summaryrefslogtreecommitdiff
path: root/dix
AgeCommit message (Collapse)AuthorFilesLines
2023-10-25mi: reset the PointerWindows reference on screen switchPeter Hutterer1-2/+0
PointerWindows[] keeps a reference to the last window our sprite entered - changes are usually handled by CheckMotion(). If we switch between screens via XWarpPointer our dev->spriteInfo->sprite->win is set to the new screen's root window. If there's another window at the cursor location CheckMotion() will trigger the right enter/leave events later. If there is not, it skips that process and we never trigger LeaveWindow() - PointerWindows[] for the device still refers to the previous window. If that window is destroyed we have a dangling reference that will eventually cause a use-after-free bug when checking the window hierarchy later. To trigger this, we require: - two protocol screens - XWarpPointer to the other screen's root window - XDestroyWindow before entering any other window This is a niche bug so we hack around it by making sure we reset the PointerWindows[] entry so we cannot have a dangling pointer. This doesn't handle Enter/Leave events correctly but the previous code didn't either. CVE-2023-5380, ZDI-CAN-21608 This vulnerability was discovered by: Sri working with Trend Micro Zero Day Initiative Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Adam Jackson <ajax@redhat.com> (cherry picked from commit 564ccf2ce9616620456102727acb8b0256b7bbd7)
2023-02-07dix: Use CopyPartialInternalEvent in EnqueueEventMike Gorse1-1/+1
The event might be a DeviceEvent allocated on the stack, in AccessXKeyboardEvent for instance. Fixes out-of-bounds read. Signed-off-by: Mike Gorse <mgorse@suse.com> (cherry picked from commit 2ef5ef57bd37a8bec2ac454053b283c6f87c3b40)
2023-01-11dix: Fix overzealous caching of ResourceClientBits()Olivier Fourdan1-4/+7
Commit c7311654 cached the value of ResourceClientBits(), but that value depends on the `MaxClients` value set either from the command line or from the configuration file. For the latter, a call to ResourceClientBits() is issued before the configuration file is read, meaning that the cached value is from the default, not from the maximum number of clients set in the configuration file. That obviously causes all sort of issues, including memory corruption and crashes of the Xserver when reaching the default limit value. To avoid that issue, also keep the LimitClient value, and recompute the ilog2() value if that changes, as on startup when the value is set from the the xorg.conf ServerFlags section. v2: Drop the `cache == 0` test Rename cache vars Fixes: c7311654 - dix: cache ResourceClientBits() value Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1310 Signed-off-by: Olivier Fourdan <ofourdan@redhat.com> Reviewed-by: Adam Jackson <ajax@redhat.com> (cherry picked from commit 2efa6d659508346358a1ef27b2393e18843f66a3)
2022-12-14Xi: avoid integer truncation in length check of ProcXIChangePropertyPeter Hutterer1-1/+2
This fixes an OOB read and the resulting information disclosure. Length calculation for the request was clipped to a 32-bit integer. With the correct stuff->num_items value the expected request size was truncated, passing the REQUEST_FIXED_SIZE check. The server then proceeded with reading at least stuff->num_items bytes (depending on stuff->format) from the request and stuffing whatever it finds into the property. In the process it would also allocate at least stuff->num_items bytes, i.e. 4GB. The same bug exists in ProcChangeProperty and ProcXChangeDeviceProperty, so let's fix that too. CVE-2022-46344, ZDI-CAN 19405 This vulnerability was discovered by: Jan-Niklas Sohn working with Trend Micro Zero Day Initiative Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Acked-by: Olivier Fourdan <ofourdan@redhat.com> (cherry picked from commit 8f454b793e1f13c99872c15f0eed1d7f3b823fe8)
2022-07-01dix: Don't send touch end to clients that do async grab without touchesPovilas Kanapickas1-9/+6
GTK3 menu widget creates a selection for touch and other events and after receiving touch events creates an async grab that excludes touch events. Unfortunately it relies on X server not sending the touch end event in order to function properly. Sending touch end event will cause it to think that the initiating touch ended and when it actually ends, the ButtonRelease event will make it think that the menu should be closed. As a result, the menu will be open only for the duration of the touch making it useless. This commit reverts f682e0563f736ed2c2c612ed575e05b6e3db945e. Fixes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1255 Signed-off-by: Povilas Kanapickas <povilas@radix.lt> (cherry picked from commit 43e934a19f644cddedae73602e86429c9dc5074a)
2022-07-01dix: Correctly save replayed event into GrabInfoRecPovilas Kanapickas1-2/+16
When processing events we operate on InternalEvent pointers. They may actually refer to a an instance of DeviceEvent, GestureEvent or any other event that comprises the InternalEvent union. This works well in practice because we always look into event type before doing anything, except in the case of copying the event. *dst_event = *src_event would copy whole InternalEvent event and would cause out of bounds read in case the pointed to event was not InternalEvent but e.g. DeviceEvent. This regression has been introduced in 23a8b62d34344575f9df9d057fb74bfefa94a77b. Fixes https://gitlab.freedesktop.org/xorg/xserver/-/issues/1261 Signed-off-by: Povilas Kanapickas <povilas@radix.lt> (cherry picked from commit 6ef5c05728f8b18170fbc8415d7502495a08670b)
2021-12-19Convert more funcs to use InternalEvent.Matthieu Herrb1-26/+27
This fixes a crash when a DeviceEvent struct converted to InteralEvent was beeing copied as InternalEvent (and thus causing out of bounds reads) in ActivateGrabNoDelivery() in events.c: 3876 *grabinfo->sync.event = *real_event; Possible fix for https://gitlab.freedesktop.org/xorg/xserver/-/issues/1253 Signed-off-by: Matthieu Herrb <matthieu@herrb.eu> (cherry picked from commit 5b8817a019845e1066c373022133985a0e2d718f)
2021-10-08dix/privates.c: Avoid undefined behaviour after realloc()Alex Richardson1-9/+7
Adding the offset between the realloc result and the old allocation to update pointers into the new allocation is undefined behaviour: the old pointers are no longer valid after realloc() according to the C standard. While this works on almost all architectures and compilers, it causes problems on architectures that track pointer bounds (e.g. CHERI or Arm's Morello): the DevPrivateKey pointers will still have the bounds of the previous allocation and therefore any dereference will result in a run-time trap. I found this due to a crash (dereferencing an invalid capability) while trying to run `XVnc` on a CHERI-RISC-V system. With this commit I can successfully connect to the XVnc instance running inside a QEMU with a VNC viewer on my host. This also changes the check whether the allocation was moved to use uintptr_t instead of a pointer since according to the C standard: "The value of a pointer becomes indeterminate when the object it points to (or just past) reaches the end of its lifetime." Casting to an integer type avoids this undefined behaviour. Signed-off-by: Alex Richardson <Alexander.Richardson@cl.cam.ac.uk> (cherry picked from commit f9f705bf3cf0d169d54a70f235cc99e106dbda43)
2021-09-07touchevents: set the screen pointer after checking the device is enabledIgnacio Casal Quinteiro1-1/+3
If the device is disabled the sprite is NULL so we get a seg fault
2021-09-06xwayland: add -noTouchPointerEmulationSimon Ser1-1/+3
In some scenarios, the Wayland compositor might have more knowledge than the X11 server and may be able to perform pointer emulation for touch events better. Add a command-line switch to allow compositors to turn Xwayland pointer emulation off. Signed-off-by: Simon Ser <contact@emersion.fr>
2021-07-30Mark the dixChangeWindowProperty() value argument as constAlex Richardson1-1/+1
It is copied using memcpy() and not modified so we can add const. This fixes a -Wincompatible-pointer-types-discards-qualifiers compiler warning that was failing a -Werror XVnc build for me. Signed-off-by: Alex Richardson <Alexander.Richardson@cl.cam.ac.uk>
2021-06-07dix: Add optional terminate delayOlivier Fourdan1-2/+41
When the command line option "-terminate" is used, it could be interesting to give it an optional grace period to let the Xserver running for a little longer in case a new connection occurs. This adds an optional parameter to the "-terminate" command line option for this purpose. v2: Use a delay in seconds instead of milliseconds (Martin Peres <martin.peres@mupuf.org>) v3: Clarify man page entry, ensure terminateDelay is always >= 0, simplify TimerFree(). (Peter Hutterer <peter.hutterer@who-t.net>) Signed-off-by: Olivier Fourdan <ofourdan@redhat.com> Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-06-07xfixes: Add ClientDisconnectModeOlivier Fourdan1-0/+20
With Wayland compositors now being able to start Xwayland on demand, the next logical step is to be able to stop Xwayland when there is no more need for it. The Xserver itself is capable of terminating itself once all X11 clients are gone, yet in a typical full session, there are a number of X11 clients running continuously (e.g. the Xsettings daemon, IBus, etc.). Those always-running clients will prevent the Xserver from terminating, because the actual number of X11 clients will never drop to 0. Worse, the X11 window manager of a Wayland compositor also counts as an X11 client, hence also preventing Xwayland from stopping. Some compositors such as mutter use the XRes extension to query the X11 clients connected, match their PID with the actual executable name and compare those with a list of executables that can be ignored when deciding to kill the Xserver. But that's not just clumsy, it is also racy, because a new X11 client might initiate a connection the X11 server right when the compositor is about to kill it. To solve this issue directly at the Xserver level, this add new entries to the XFixes extension to let the X11 clients themselves specify the disconnect mode they expect. Typically, those X11 daemon clients would specify the disconnect mode XFixesClientDisconnectFlagTerminate to let the Xserver know that they should not be accounted for when checking the remaining clients prior to terminate. Signed-off-by: Olivier Fourdan <ofourdan@redhat.com> Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-05-30Implement gesture processing logicPovilas Kanapickas5-0/+385
2021-05-30dix: Implement gesture event submission code pathPovilas Kanapickas2-0/+151
2021-05-30dix: Implement internal gesture state handlingPovilas Kanapickas4-0/+85
2021-05-30dix: Implement gesture event fixups before deliveryPovilas Kanapickas1-0/+50
2021-05-30xi: Implement conversions from internal to Xi2 gesture event structsPovilas Kanapickas1-0/+104
2021-05-30xi: Implement grab support for new gesture event typesPovilas Kanapickas1-0/+7
2021-05-30dix: Add new internal event enums for gesture eventsPovilas Kanapickas1-0/+60
2021-03-25dix: Fix URL to description of focus in/out modelPovilas Kanapickas1-1/+1
The current URL points to an unrelated patch for acpid. Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2021-02-17dix: Use correct listener to deliver touch end eventsPovilas Kanapickas1-4/+3
This fixes an problem left in f682e0563f736ed2c2c612ed575e05b6e3db945e due to an incorrect cherry-pick. We must use old listener->listener to deliver the touch event. Otherwise grab won't let the event through and the abovementioned commit has no effect. Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2021-02-16dix: Guard against non-existing PtrFeedbackPtrOlivier Fourdan1-0/+3
Trying to change the pointer control settings on a device without PtrFeedbackPtr would be a bug and a crash in the Xserver. Guard against that case by returning early with a BadImplementation error, that might kill the X11 client but the Xserver would survive. Signed-off-by: Olivier Fourdan <ofourdan@redhat.com> Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net> Related: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1137
2021-02-15dix: Add POINTER_RAWONLY flagOlivier Fourdan1-24/+29
This add a new flag POINTER_RAWONLY for GetPointerEvents() which does pretty much the opposite of POINTER_NORAW. Basically, this tells GetPointerEvents() that we only want the DeviceChanged events and any raw events for this motion but no actual motion events. This is preliminary work for Xwayland to be able to use relative motion events for raw events. Xwayland would use absolute events for raw events, but some X11 clients (wrongly) assume raw events to be always relative. To allow such clients to work with Xwayland, it needs to switch to relative raw events (if those are available from the Wayland compositor). However, Xwayland cannot use relative motion events for actual pointer location because that would cause a drift over time, the pointer being actually controlled by the Wayland compositor. So Xwayland needs to be able to send only relative raw events, hence this API. Bump the ABI_XINPUT_VERSION minor version to reflect that API addition. v2: Actually avoid sending motion events (Peter) v3: Keep sending raw emulated events with RAWONLY (Peter) Suggested-by: Peter Hutterer <peter.hutterer@who-t.net> Signed-off-by: Olivier Fourdan <ofourdan@redhat.com> Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net> Related: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1130
2021-02-08dix: Send touch end to clients that do async grab without touch eventsPovilas Kanapickas1-3/+16
If a XI2 client started listening to touches due to a selection and then creates an active async grab that does not include touch events, then it currently won't get the touch end event which will produce inconsistent view of the pending touches. Note that we only need to consider touch listeners and can ignore pointer emulation. Under XI2 if a active grab replaces a passive implicit grab and the active grab does not include the button release event, the client won't get it either.
2020-11-25dix: Extract FreezeThisEventIfNeededForSyncGrab()Povilas Kanapickas1-20/+29
2020-11-25dix: Extract ActivateGrabNoDeliver()Povilas Kanapickas1-6/+21
2020-11-25dix: Store replayed event into GrabInfoRec struct as InternalEvent*Povilas Kanapickas3-21/+23
2020-11-25dix: Rename LISTENER_* to TOUCH_LISTENER_*Povilas Kanapickas2-16/+18
2020-11-25dix: Extract DeliverDeviceClassesChangedEvent() utility functionPovilas Kanapickas3-27/+25
2020-11-25dix: Extract CopySprite() utilityPovilas Kanapickas2-16/+27
2020-11-25dix: Extract FixUpXI2DeviceEventFromWindow()Povilas Kanapickas1-27/+31
2020-11-17AddInputDevice: only need to check once if we failed to calloc devAlan Coopersmith1-3/+0
Resolves warning from Oracle Parfait static analyser: Warning: Impossible or redundant condition Impossible or redundant condition [impossible-redundant-condition]: Condition 'dev != NULL' of branch is determined by previous branch at line 270 of dix/devices.c in function 'AddInputDevice'. Condition 'dev != NULL' from this branch implies following branch is always true at line 262 Fixes: commit 493ad83323 Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2020-07-31fix for ZDI-11426Matthieu Herrb1-1/+1
Avoid leaking un-initalized memory to clients by zeroing the whole pixmap on initial allocation. This vulnerability was discovered by: Jan-Niklas Sohn working with Trend Micro Zero Day Initiative Signed-off-by: Matthieu Herrb <matthieu@herrb.eu> Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2020-07-10xserver/output: rename some badly named variables/APIs.Dave Airlie2-52/+52
This is an API and ABI break Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-07-05Fix spelling/wording issuesAlan Coopersmith12-30/+30
Most (but not all) of these were found by using codespell --builtin clear,rare,usage,informal,code,names but not everything reported by that was fixed. Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2019-11-19os: Don't crash in AttendClient if the client is goneAaron Plattner1-8/+1
If a client is in the process of being closed down, then its client->osPrivate pointer will be set to NULL by CloseDownConnection. This can cause a crash if freeing the client's resources results in a call to AttendClient. For example, if the client has a pending sync fence: Thread 1 "X" received signal SIGSEGV, Segmentation fault. AttendClient (client=0x5571c4aed9a0) at ../os/connection.c:942 (gdb) bt #0 AttendClient (client=0x5571c4aed9a0) at ../os/connection.c:942 #1 0x00005571c3dbb865 in SyncAwaitTriggerFired (pTrigger=<optimized out>) at ../Xext/sync.c:694 #2 0x00005571c3dd5749 in miSyncDestroyFence (pFence=0x5571c5063980) at ../miext/sync/misync.c:120 #3 0x00005571c3dbbc69 in FreeFence (obj=<optimized out>, id=<optimized out>) at ../Xext/sync.c:1909 #4 0x00005571c3d7a01d in doFreeResource (res=0x5571c506e3d0, skip=skip@entry=0) at ../dix/resource.c:880 #5 0x00005571c3d7b1dc in FreeClientResources (client=0x5571c4aed9a0) at ../dix/resource.c:1146 #6 FreeClientResources (client=0x5571c4aed9a0) at ../dix/resource.c:1109 #7 0x00005571c3d5525f in CloseDownClient (client=0x5571c4aed9a0) at ../dix/dispatch.c:3473 #8 0x00005571c3d55eeb in Dispatch () at ../dix/dispatch.c:492 #9 0x00005571c3d59e96 in dix_main (argc=3, argv=0x7ffe7854bc28, envp=<optimized out>) at ../dix/main.c:276 #10 0x00007fea4837cb6b in __libc_start_main (main=0x5571c3d1d060 <main>, argc=3, argv=0x7ffe7854bc28, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7ffe7854bc18) at ../csu/libc-start.c:308 #11 0x00005571c3d1d09a in _start () at ../Xext/sync.c:2378 (gdb) print client->osPrivate $1 = (void *) 0x0 Since the client is about to be freed, its ignore count doesn't matter and AttendClient can simply be a no-op. Check for client->clientGone in AttendClient and remove similar checks from two callers that had them. Signed-off-by: Aaron Plattner <aplattner@nvidia.com>
2019-10-30dix: Call SourceValidate before GetImageAdam Jackson1-1/+4
This ensures that any prep work for the drawable we're about to read from is already done before we call down to GetImage. This should be no functional change as most of the callers with a non-trivial SourceValidate are already wrapping GetImage and doing the equivalent thing, but we'll be simplifying that shortly. More importantly this ensures that if any of that prep work would generate events - like automatic compositing flushing rendering to a parent pixmap which then triggers damage - then it happens entirely before we start writing the GetImage reply header. Note that we do not do the same for GetSpans, but that's okay. The only way to get to GetSpans is through miCopyArea or miCopyPlane - where the callers must already call SourceValidate - or miGetImage - which this commit now protects with SourceValidate. Fixes: xorg/xserver#902 Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
2019-10-30mi: Add a default no-op miSourceValidateAdam Jackson1-1/+2
Slightly simplifies the callers since they don't need to check for non-NULL anymore. I do extremely hate the workarounds here to suppress misprite taking the cursor down though. Surely there's a better way. Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
2019-10-30include: Remove now-empty site.hAdam Jackson5-5/+0
2019-10-30dix: Move default screensaver defaults into globals.cAdam Jackson1-4/+5
2019-10-30dix: Remove -to option to set the default connection timeoutAdam Jackson1-2/+0
One minute is admittedly arbitrary, but again, pretty sure this never gets set on the command line in practice.
2019-10-30dix: Remove -fn and -fc options to set default text/cursor fontsAdam Jackson3-6/+4
I strongly suspect these never get used in the wild, and it's not an especially useful thing to do in any case.
2019-10-30dix: Remove now-unused SetVendorStringAdam Jackson1-7/+1
2019-10-15dix: Fix undefined memset in _dixInitScreenPrivatesAdam Jackson1-1/+2
Again, memset(0, ...) is undefined.
2019-10-15dix: Fix undefined shift in HashResourceIDAdam Jackson1-2/+2
Again, we need all of the bits of an unsigned int to make this work.
2019-10-15dix: Fix undefined memset in dixInitPrivatesAdam Jackson1-1/+2
When we set these up initially, no subsystems have allocated any privates yet, so the storage address will be null, and memset(NULL, ...) is undefined.
2019-10-12dix: Add GetCurrentClient helperHans de Goede1-1/+22
Request-handlers as registered in the requestVector array, always get passed the clientPtr for the client which sent the request. But the implementation of many request-handlers typically consists of a generic handler calling implementation specific callbacks and / or various helpers often multiple levels deep and in many cases the clientPtr does not get passed to the callbacks / helpers. This means that in some places where we would like to have access to the current-client, we cannot easily access it and fixing this would require a lot of work and often would involve ABI breakage. This commit adds a GetCurrentClient helper which can be used as a shortcut to get access to the clienPtr for the currently being processed request without needing a lot of refactoring and ABI breakage. Note using this new GetCurrentClient helper is only safe for code which only runs from the main thread, this new variable MUST NOT be used by code which runs from signal handlers or from the input-thread. The specific use-case which resulted in the creation of this patch is adding support for emulation of randr / vidmode resolution changes to Xwayland. This emulation will not actually change the monitor resolution instead it will scale any window with a size which exactly matches the requested resolution to fill the entire monitor. The main use-case for this is games which are hard-coded to render at a specific resolution and have sofar relied on randr / vidmode to change the monitor resolution when going fullscreen. To make this emulation as robust as possible (e.g. avoid accidentally scaling windows from other apps) we want to make the emulated resolution a per client state. But e.g. the RRSetCrtc function does not take a client pointer; and is a (used) part of the Xorg server ABI (note the problem is not just limited to RRSetCrtc). Reviewed-by: Olivier Fourdan <ofourdan@redhat.com> Reviewed-by: Michel Dänzer <mdaenzer@redhat.com> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2019-10-06dix: Check for NULL spriteInfo in GetPairedDeviceArthur Williams1-1/+1
There is a race when reseting the XServer that causes spriteInfo to be NULL in GetPairedDevice resulting a segfault and subsequent crash. The problem was noticed when opening a connection, creating master devices, destroying master devices and closing the connection during testing. Signed-off-by: Arthur Williams <taaparthur@gmail.com>
2019-08-27meson: Add dtrace supportAdam Jackson1-1/+13