Bug 493027 - KWin segfault crash in KWin::TabletToolV2Interface::sendProximityIn() when moving a drawing tablet pen close to the screen
Summary: KWin segfault crash in KWin::TabletToolV2Interface::sendProximityIn() when mo...
Status: RESOLVED FIXED
Alias: None
Product: kwin
Classification: Plasma
Component: input (show other bugs)
Version: 6.1.4
Platform: Other Linux
: NOR crash
Target Milestone: ---
Assignee: KWin default assignee
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-09-12 18:25 UTC by xeirla
Modified: 2024-10-30 22:53 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In: 6.3.0
Sentry Crash Report:


Attachments
Initial backtrace output after running the command reccommended at: https://community.kde.org/KWin/Debugging (227.12 KB, text/plain)
2024-09-12 18:25 UTC, xeirla
Details

Note You need to log in before you can comment on or make changes to this bug.
Description xeirla 2024-09-12 18:25:15 UTC
Created attachment 173590 [details]
Initial backtrace output after running the command reccommended at: https://community.kde.org/KWin/Debugging

SUMMARY
KWin segfaults upon moving my drawing tablet pen close to the screen, enough to hover the cursor. This has happened under various circumstances, but the exact cause is still unknown to me, as trying to reproduce the crash has been inconsistent. I initially thought this may be related to Nvidia sleep or system idling, however this has happened now multiple times while actively using the computer (for example, browsing the internet, and then immediately after picking up my pen and moving to draw on the tablet)

A backtrace has been attached, however it is incomplete and probably not as useful. I tried to retrieve one with debugging symbols to the best of my ability, however could not get `gdb` to attach to kwin_wayland with symbols active. See Additional Information below.

STEPS TO REPRODUCE
1. Move a drawing tablet pen close to the display,

OBSERVED RESULT
Upon moving the drawing tablet pen close to the screen, Kwin crashes and subsequently takes down other apps with it (Waterfox, Krita, Discord, Telegram, Konsole). System Settings and Dolphin file explorer does not crash however.

EXPECTED RESULT
Kwin should not crash.

SOFTWARE/OS VERSIONS
Windows: 
macOS: 
(available in the Info Center app, or by running `kinfo` in a terminal window)
Operating System: Garuda Linux 
KDE Plasma Version: 6.1.4
KDE Frameworks Version: 6.5.0
Qt Version: 6.7.2
Kernel Version: 6.10.9-zen1-2-zen (64-bit)
Graphics Platform: Wayland
Processors: 12 × AMD Ryzen 5 2600X Six-Core Processor
Memory: 15.5 GiB of RAM
Graphics Processor: NVIDIA GeForce GTX 1070 Ti/PCIe/SSE2


ADDITIONAL INFORMATION
The backtrace provided is unfortunately without complete debugging symbols. I followed the instructions provided at the following links to obtain a more useful backtrace, but had a lot of trouble doing so:
- https://community.kde.org/KWin/Debugging
- https://community.kde.org/Guidelines_and_HOWTOs/Debugging/How_to_create_useful_crash_reports#Install_debugging_packages
- https://wiki.archlinux.org/title/Debugging/Getting_traces

As well as other linked sources at those pages. They all point to Arch utilizing `debuginfod` for obtaining debug symbols in `gdb`, however I have been unable to run the recommended commands:
```
echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
sudo gdb -pid $(pidof kwin_wayland) -batch -ex "set logging file kwin_wayland.gdb" -ex "set logging on" -ex "continue" -ex "thread apply all backtrace" -ex "quit"
```

while also having `debuginfod` enabled and working. I've set the correct environment variable ahead of time as well as tried running the command with the environment variable set immediately after `sudo` however in doing so the output to the console shows that debuginfod is automatically disabled. Runing the command as-is also does not offer any prompt about using debuginfod either. 

Am willing to try and get a good backtrace, however I am lost as to how to do so as the additional information at the various wiki pages and alternate methods are very confusing. Hopefully the one provided for now is sufficient to start a bug report on this at least. I am relatively new to using Linux and am unfamiliar with using `gdb` and other debugging tools for more technical bug reports, so I appreciate any help and guidance in how to obtain the necessary info for anyone who ends up looking into this crash. 

Additionally, the graphics tablet in question is a Wacom Mobile Studio Pro 13 (1st Gen), connected via the Wacom Link peripheral (Thunderbolt 3 USB-C to HDMI/microUSB adaptor, essentially). The device itself can also be used as a standalone computer, however connecting it to another PC in this way allows for it to be used as a secondary display, acting as a more common Wacom Cintiq drawing tablet. I'm aware this hardware stack is a bit niche, however I've found since switching to Linux, it is seemingly well supported all things considered. Worth mentioning at least as I do not know if this crash affects more traditional display drawing tablets, however I can also try to reproduce the issue using a Huion display tablet instead, if that would help at all. Needless to say in either case I first need to be able to get a better backtrace from the crash either way. 

Finally, I have a few other bad backtraces saved, as well as related coredumps, info from journalctl, and general notes I've taken in trying to troubleshoot the issue. I can provide those as well if requested, however as noted several times now, I don't know if that will be any helpful to diagnosing the problem due to missing symbols, and don't want to clutter the initial report.
Comment 1 xeirla 2024-09-12 18:35:32 UTC
Almost forgot, here is the output of `qdbus org.kde.KWin /KWin supportInformation`:
https://pastebin.com/Chxg8uAt
Comment 2 David Edmundson 2024-09-14 21:53:35 UTC
Thread 1 (Thread 0x7ba2801b3a80 (LWP 10863) "kwin_wayland"):
#0  0x00007ba293ce5bac in KWin::TabletToolV2Interface::sendProximityIn(KWin::TabletV2Interface*) () from /usr/lib/libkwin.so.6
#1  0x00007ba293a17402 in ?? () from /usr/lib/libkwin.so.6
#2  0x00007ba293b200f8 in ?? () from /usr/lib/libkwin.so.6
#3  0x00007ba293a19ead in ?? () from /usr/lib/libkwin.so.6
#4  0x00007ba2911a3397 in ?? () from /usr/lib/libQt6Core.so.6
#5  0x00007ba293971d5c in KWin::InputDevice::tabletToolEvent(KWin::InputRedirection::TabletEventType, QPointF const&, double, int, int, double, bool, bool, KWin::TabletToolId const&, std::chrono::duration<long, std::ratio<1l, 1000000l> >) () from /usr/lib/libkwin.so.6
Comment 3 Vlad Zahorodnii 2024-09-24 14:27:57 UTC
I can see how the code may crash, the bug is in pad <-> tool pairing code. The fix will likely be 6.3 only for a while.
Comment 4 Bug Janitor Service 2024-09-24 14:33:07 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/kwin/-/merge_requests/6482
Comment 5 Vlad Zahorodnii 2024-09-24 20:05:58 UTC
Git commit 479c8a7533b25c3b9d789643c5bd455ce6354074 by Vlad Zahorodnii.
Committed on 24/09/2024 at 14:32.
Pushed by vladz into branch 'Plasma/6.2'.

Work around a crash in TabletToolV2Interface::sendProximityIn()

The tablet object can be removed earlier than expected.

M  +4    -2    src/input.cpp

https://invent.kde.org/plasma/kwin/-/commit/479c8a7533b25c3b9d789643c5bd455ce6354074
Comment 6 Vlad Zahorodnii 2024-10-30 10:12:05 UTC
Git commit d31b9033f32504561521b105e8e89d8594e13594 by Vlad Zahorodnii.
Committed on 30/10/2024 at 09:31.
Pushed by vladz into branch 'master'.

Fix registration of tablet tool and pad devices

Tablet pad and tablet tool input devices can be announced in any order.
The problem with the current code is that it is going to create a
TabletV2Interface object when a tablet pad is registered first. In addition
to that, it unsets the user data (TabletV2Interface) in libinput device
group without checking whether the tablet tool is actually removed.

Another issue is that if a tablet pad is registered first, then the
TabletV2Interface is going to have the metadata of the tablet pad input
device. Tablet pad and tablet tool devices are often represented separately.

M  +13   -8    src/tablet_input.cpp

https://invent.kde.org/plasma/kwin/-/commit/d31b9033f32504561521b105e8e89d8594e13594