Public bug reported:

### Summary

On Wayland compositors that advertise `ext_background_effect_manager_v1`
with the blur capability (Hyprland 0.57.2 here; other implementations of the
protocol are likely affected as well), any Qt 6 application that uses
`KWindowEffects::enableBlurBehind()`
- for example any app using Kvantum's blur support - crashes with SIGSEGV
when a blur region is cleared, typically when a menu or popup is closed.

This is a NULL-pointer dereference inside `wl_region_destroy()`, reached from
`WindowEffects::installBlur()` with `enable == false`.

### Environment

- Ubuntu 26.04.1 LTS (resolute), amd64
- libkf6windowsystem6 6.24.0-0ubuntu1
- libwayland-client0 1.24.0-2
- Qt 6.10.2 (6.10.2+dfsg-7); the qBittorrent package used for the original
  observation was built against Qt 6.9.2
- Hyprland 0.57.2 (Wayland session, `XDG_SESSION_TYPE=wayland`)
- Kvantum 1.1.5 with the Orchis theme (`blurring=true`)

### Steps to reproduce

1. Use a Wayland session on a compositor that supports
   `ext_background_effect_manager_v1` with blur (Hyprland here).
2. Use a Kvantum theme with `blurring=true` (e.g. the stock Orchis theme from
   `qt-style-kvantum-themes`).
3. Compile and run this reproducer (it only shows and hides a QMenu; a copy is
   also attached):

   ```cpp
   #include <QApplication>
   #include <QMenu>
   #include <QTimer>
   #include <QWidget>

   int main(int argc, char **argv)
   {
       QApplication app(argc, argv);
       QWidget w;
       w.resize(400, 250);
       w.show();

       QMenu menu(&w);
       menu.addAction("one");
       menu.addAction("two");

       QTimer::singleShot(500, [&] { menu.popup(w.mapToGlobal(QPoint(50, 50))); 
});
       QTimer::singleShot(1200, [&] { menu.hide(); }); // SIGSEGV on 6.24.0
       QTimer::singleShot(2000, [&] { app.quit(); });
       return app.exec();
   }
   ```

   ```
   g++ -std=c++17 repro.cpp -o repro $(pkg-config --cflags --libs Qt6Widgets)
   QT_QPA_PLATFORM=wayland ./repro -style kvantum
   ```

   (or, with a real application: run qBittorrent 5.1.4 with Qt 6 + Kvantum and
   open and close any context menu).
4. The menu is shown after 500 ms and hidden after 1200 ms.

### Expected result

The menu closes, the application keeps running.

### Actual result

SIGSEGV, 100% reproducible, at the moment the menu is hidden.

### Backtrace

Real application (qBittorrent 5.1.4):

```
 0# getStacktrace[abi:cxx11]() in qbittorrent
 1# 0x000000000020B4FE in qbittorrent
 2# 0x0000000000045CB0 in /usr/lib/x86_64-linux-gnu/libc.so.6
 3# wl_proxy_get_version in /usr/lib/x86_64-linux-gnu/libwayland-client.so.0
 4# 0x0000000000012A51 in 
.../qt6/plugins/kf6/kwindowsystem/KF6WindowSystemKWaylandPlugin.so
 5# Kvantum::BlurHelper::clear(QWidget*) const in 
.../qt6/plugins/styles/libkvantum.so
 6# Kvantum::BlurHelper::update(QWidget*) const in 
.../qt6/plugins/styles/libkvantum.so
 7# 0x0000000000033053 in .../qt6/plugins/styles/libkvantum.so
 8# QObject::event(QEvent*) in /usr/lib/x86_64-linux-gnu/libQt6Core.so.6
 9# QApplicationPrivate::notify_helper(QObject*, QEvent*) in 
/usr/lib/x86_64-linux-gnu/libQt6Widgets.so.6
10# QCoreApplication::notifyInternal2(QObject*, QEvent*) in 
/usr/lib/x86_64-linux-gnu/libQt6Core.so.6
11# QTimerInfoList::activateTimers() in 
/usr/lib/x86_64-linux-gnu/libQt6Core.so.6
...
```

Minimal reproducer, identical stack (plugin offset `0x12a51` in both):

```
#0 wl_proxy_get_version () from libwayland-client.so.0
#1 0x00007ffff0cd6a51 in KF6WindowSystemKWaylandPlugin.so
#2 Kvantum::BlurHelper::clear(QWidget*) const
#3 Kvantum::BlurHelper::update(QWidget*) const
#4 0x00007ffff0f67053 in libkvantum.so
#5 QObject::event(QEvent*)
...
```

Disassembly of the plugin at the caller of `wl_proxy_get_version()`
(`0x12a51` is the return address in the backtrace); this is the inlined
`wl_region_destroy()` from `wayland-client-protocol.h`:

```
12a4c: call wl_proxy_get_version@plt
12a51: mov  -0x8(%rbp),%rdi
...
12a64: jmp  wl_proxy_marshal_flags@plt
```

### Root cause

`src/platforms/wayland/windoweffects.cpp`, `WindowEffects::installBlur()`,
background-effect branch (6.24.0):

```cpp
wl_region *wlRegion = nullptr;
if (enable) {
    if (region.isEmpty()) {
        wlRegion = createRegion(...);
    } else {
        wlRegion = createRegion(region);
    }
}
effect->set_blur_region(wlRegion);
wl_region_destroy(wlRegion);   /* NULL when enable == false */
```

`wl_region_destroy()` is an inline wrapper that calls
`wl_proxy_get_version((struct wl_proxy *)wl_region)` before marshalling, and
that function dereferences the pointer without a NULL check. With
`enable == false`, `wlRegion` is NULL, hence the SIGSEGV.

Kvantum calls `KWindowEffects::enableBlurBehind(win, false)` from
`BlurHelper::clear()`, which is reached from `BlurHelper::update()` when a
menu/popup with a mask is hidden. Only compositors that advertise
`ext_background_effect_manager_v1` enter this branch, which is why this is
not seen on compositors without that protocol.

### Upstream fix

Fixed upstream in kwindowsystem commit 
`b7bfe25a9954435b4cb18350784c6efd231cf629`
("platforms/wayland: Fix a crash in WindowEffects::installBlur()"), first
released in **v6.25.0**:

```diff
         effect->set_blur_region(wlRegion);
-        wl_region_destroy(wlRegion);
+        if (wlRegion) {
+            wl_region_destroy(wlRegion);
+        }
         return;
```

The attached patch is that commit; it applies cleanly to 6.24.0
(`patch -p1 --dry-run` OK). Ubuntu 26.10 (tenacious) already ships
kf6-kwindowsystem 6.30.0, so only resolute needs the backport.

### Impact

Any Qt 6 application using Kvantum's blur (or calling
`KWindowEffects::enableBlurBehind()` itself) is killed when a menu or popup
is closed. Reproduced with qBittorrent 5.1.4 (deb-multimedia build) and with
the 40-line Qt Widgets program above. It is not application-specific.

This is not a security vulnerability: it is a local NULL-pointer
dereference inside the user's own session, with no privilege boundary
crossed and no memory corruption beyond reading address 0.

---

## SRU template

### [ Impact ]

`libkf6windowsystem6` 6.24.0 crashes with SIGSEGV when a Wayland client
clears a blur region on compositors supporting the
`ext_background_effect_manager_v1` blur capability. Any Qt 6 app using
Kvantum blur (e.g. qBittorrent) dies when a menu is closed, losing state
and interrupting downloads.

### [ Test Plan ]

1. Install `libkf6windowsystem6` 6.24.0-0ubuntu1 from `-proposed`.
2. On Hyprland (or any compositor implementing the protocol) with a Kvantum
   theme with `blurring=true`, build and run the reproducer from the
   description:
   `QT_QPA_PLATFORM=wayland ./repro -style kvantum`
3. Before the fix: SIGSEGV when the menu is hidden (~1.2 s).
   After the fix: the program exits normally (exit code 0), repeated 10 times.
4. Also test qBittorrent 5.1.x with Qt 6 + Kvantum: open/close the context
   menu repeatedly; no crash.

### [ Where problems could occur ]

The change only guards a NULL pointer before calling `wl_region_destroy()`.
Non-NULL regions are destroyed exactly as before, so no behavioural change is
expected. Risk is limited to the Wayland window-effects blur path.

### [ Other Info ]

- Upstream commit: 
https://invent.kde.org/frameworks/kwindowsystem/-/commit/b7bfe25a9954435b4cb18350784c6efd231cf629
- Fixed in: kwindowsystem 6.25.0
- Requested: cherry-pick to `resolute`, version `6.24.0-0ubuntu1.1`
- Attachment: upstream patch. The initial Launchpad report form allows only
  one file; the reproducer is inline above and the raw backtrace is added in
  a follow-up comment.

** Affects: kf6-kwindowsystem (Ubuntu)
     Importance: Undecided
         Status: New

** Attachment added: "0001-platforms-wayland-fix-installBlur-crash.patch"
   
https://bugs.launchpad.net/bugs/2178451/+attachment/6022239/+files/0001-platforms-wayland-fix-installBlur-crash.patch

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2178451

Title:
  SIGSEGV in wl_proxy_get_version() from KWindowEffects::installBlur()
  when clearing a blur region (NULL wl_region passed to
  wl_region_destroy)

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/kf6-kwindowsystem/+bug/2178451/+subscriptions


-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to