Package: tint2
Version: 17.0.1-1.3
Severity: important
Tags: patch upstream

Dear Maintainer,

tint2 crashes with SIGSEGV shortly after login (or whenever a tray application
registers an icon and removes it again right away, e.g. update notifiers,
nm-applet, nextcloud). Reproduced on Ubuntu 26.04 with 17.0.1-1.2build1; the
code in 17.0.1-1.3 is identical.

Backtrace (from core dump):
  #0 on_change_systray ()
  #1 resize_systray ()
  #2 relayout_fixed ()
  #3 relayout_fixed ()
  #4 render_panel ()
  #5 handle_panel_refresh ()
  #6 run_tint2_event_loop ()

Log before the crash (typical):
  tint2: Couldn't get geometry of window!
  systray 897: cannot embed icon for window ... parent ... pid ...
  tint2: remove_icon: ...

Cause: in on_change_systray() (src/systray/systraybar.c) the loop

  for (i = 1, l = systray.list_icons; l; i++, l = l->next)

calls reparent_icon(traywin). If embedding fails, reparent_icon() calls
remove_icon(), which does g_slist_remove() and g_free() on the current list
node/traywin. The loop then reads l->next from freed memory.

The attached patch saves the next pointer before the loop body and skips an
icon when XGetGeometry() fails (previously the code continued with
uninitialised width/height/xpos/ypos). With the patch built into
17.0.1-1.3+local1 the crash no longer occurs on the affected machine
(several icons are removed during login, see log above, without a crash).

This is also related to the glib 2.76 crash handled by glib2.76.patch, but is
a different location.

Patch: debian/patches/systray-uaf.patch (attached).


-- System Information:
Debian Release: forky/sid
  APT prefers resolute-updates
  APT policy: (500, 'resolute-updates'), (500, 'resolute-security'), (500, 
'resolute'), (100, 'resolute-backports')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 7.0.0-44-generic (SMP w/4 CPU threads; PREEMPT)
Locale: LANG=de_DE.UTF-8, LC_CTYPE=de_DE.UTF-8 (charmap=UTF-8), 
LANGUAGE=de_DE:en
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled
Description: Fix use-after-free in on_change_systray when reparent_icon removes 
the icon
--- tint2-17.0.1.orig/src/systray/systraybar.c
+++ tint2-17.0.1/src/systray/systraybar.c
@@ -292,9 +292,11 @@
     }
 
     TrayWindow *traywin;
-    GSList *l;
+    GSList *l, *next;
     int i;
-    for (i = 1, l = systray.list_icons; l; i++, l = l->next) {
+    for (i = 1, l = systray.list_icons; l; i++, l = next) {
+        // reparent_icon() may call remove_icon(), which frees the list node 
and traywin
+        next = l->next;
         traywin = (TrayWindow *)l->data;
 
         traywin->y = posy;
@@ -334,6 +336,7 @@
         Window root;
         if (!XGetGeometry(server.display, traywin->parent, &root, &xpos, 
&ypos, &width, &height, &border_width, &depth)) {
             fprintf(stderr, RED "tint2: Couldn't get geometry of window!" 
RESET "\n");
+            continue;
         }
         if (width != traywin->width || height != traywin->height || xpos != 
traywin->x || ypos != traywin->y) {
             if (systray_profile)

Reply via email to