wlroots/types
Simon Ser f56a69aa76 linux_drm_syncobj_v1: fix use-after-free in surface_commit_destroy()
surface_commit_destroy() accesses a field from
struct wlr_linux_drm_syncobj_surface_v1, however that struct may have
been free'd earlier:

    ==1103==ERROR: AddressSanitizer: heap-use-after-free on address 0x7cdef7a6e288 at pc 0x7feefaac335a bp 0x7ffc4de8f570 sp 0x7ffc4de8f560
    READ of size 8 at 0x7cdef7a6e288 thread T0
        #0 0x7feefaac3359 in surface_commit_destroy ../subprojects/wlroots/types/wlr_linux_drm_syncobj_v1.c:195
        #1 0x7feefaac34cd in surface_commit_handle_surface_destroy ../subprojects/wlroots/types/wlr_linux_drm_syncobj_v1.c:211
        #2 0x7feefbd194cf in wl_signal_emit_mutable (/usr/lib/libwayland-server.so.0+0x84cf) (BuildId: b9664217748f523995e3f855fa197cf8e59942d1)
        #3 0x7feefaa52b22 in surface_handle_resource_destroy ../subprojects/wlroots/types/wlr_compositor.c:730
        #4 0x7feefbd1bb9f  (/usr/lib/libwayland-server.so.0+0xab9f) (BuildId: b9664217748f523995e3f855fa197cf8e59942d1)
        #5 0x7feefaa46a18 in surface_handle_destroy ../subprojects/wlroots/types/wlr_compositor.c:65
        #6 0x7feef89afac5  (/usr/lib/libffi.so.8+0x7ac5) (BuildId: d5e3b0d8921923f35438adefa9f864745abc5e90)
        #7 0x7feef89ac76a  (/usr/lib/libffi.so.8+0x476a) (BuildId: d5e3b0d8921923f35438adefa9f864745abc5e90)
        #8 0x7feef89af06d in ffi_call (/usr/lib/libffi.so.8+0x706d) (BuildId: d5e3b0d8921923f35438adefa9f864745abc5e90)
        #9 0x7feefbd17531  (/usr/lib/libwayland-server.so.0+0x6531) (BuildId: b9664217748f523995e3f855fa197cf8e59942d1)
        #10 0x7feefbd1cd2f  (/usr/lib/libwayland-server.so.0+0xbd2f) (BuildId: b9664217748f523995e3f855fa197cf8e59942d1)
        #11 0x7feefbd1b181 in wl_event_loop_dispatch (/usr/lib/libwayland-server.so.0+0xa181) (BuildId: b9664217748f523995e3f855fa197cf8e59942d1)
        #12 0x7feefbd1d296 in wl_display_run (/usr/lib/libwayland-server.so.0+0xc296) (BuildId: b9664217748f523995e3f855fa197cf8e59942d1)
        #13 0x555bf0a55a40 in server_run ../sway/server.c:615
        #14 0x555bf0a4a654 in main ../sway/main.c:376
        #15 0x7feef9227674  (/usr/lib/libc.so.6+0x27674) (BuildId: 4fe011c94a88e8aeb6f2201b9eb369f42b4a1e9e)
        #16 0x7feef9227728 in __libc_start_main (/usr/lib/libc.so.6+0x27728) (BuildId: 4fe011c94a88e8aeb6f2201b9eb369f42b4a1e9e)
        #17 0x555bf0a03f54 in _start (/home/leo/code/stuff/sway/build/sway/sway+0x390f54) (BuildId: e3d4e653af1aa0885f0426c403e16fc87c086d33)

    0x7cdef7a6e288 is located 8 bytes inside of 176-byte region [0x7cdef7a6e280,0x7cdef7a6e330)
    freed by thread T0 here:
        #0 0x7feefb71f79d in free /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_malloc_linux.cpp:51
        #1 0x7feefaac29f1 in surface_destroy ../subprojects/wlroots/types/wlr_linux_drm_syncobj_v1.c:84
        #2 0x7feefaac2e47 in surface_handle_resource_destroy ../subprojects/wlroots/types/wlr_linux_drm_syncobj_v1.c:143
        #3 0x7feefbd1bb9f  (/usr/lib/libwayland-server.so.0+0xab9f) (BuildId: b9664217748f523995e3f855fa197cf8e59942d1)
        #4 0x7feefaac2a12 in surface_handle_destroy ../subprojects/wlroots/types/wlr_linux_drm_syncobj_v1.c:89
        #5 0x7feef89afac5  (/usr/lib/libffi.so.8+0x7ac5) (BuildId: d5e3b0d8921923f35438adefa9f864745abc5e90)

    previously allocated by thread T0 here:
        #0 0x7feefb7205dd in calloc /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_malloc_linux.cpp:74
        #1 0x7feefaac4abd in manager_handle_get_surface ../subprojects/wlroots/types/wlr_linux_drm_syncobj_v1.c:313
        #2 0x7feef89afac5  (/usr/lib/libffi.so.8+0x7ac5) (BuildId: d5e3b0d8921923f35438adefa9f864745abc5e90)

Fix this by storing the struct wlr_surface in the field.

Closes: https://github.com/swaywm/sway/issues/8917
(cherry picked from commit 6d63871f05)
2025-10-21 10:25:29 -04:00
..
buffer wlr_client_buffer: add get_shm implementation 2025-04-13 20:48:59 +00:00
data_device Assert (almost all) signals have no attached listeners on destroy 2025-01-15 19:53:11 +03:00
ext_image_capture_source_v1 ext-image-capture-source: output: Apply transform to cursor 2025-08-27 13:44:11 -04:00
output backend, output: send commit events after applying all in wlr_backend_commit() 2025-09-22 16:00:23 -04:00
scene scene/surface: fix NULL deref when source buffer is destroyed 2025-09-11 09:13:35 -04:00
seat seat/keyboard: optimize wlr_seat_set_keyboard to send the keymap only if it has changed 2025-04-11 16:56:36 +02:00
tablet_v2 tablet-v2: cleanup focused surface on tool destroy 2025-04-27 16:57:50 +00:00
xdg_shell xdg-surface: fix geom for surfaces that don't set it explicitly 2025-04-19 16:42:56 +03:00
meson.build meson: add a missing src file 2025-04-01 11:41:56 +00:00
wlr_alpha_modifier_v1.c alpha-modifier-v1: add a missing NULL check in wlr_alpha_modifier_v1_get_surface_state() 2024-05-01 03:07:16 +03:00
wlr_color_management_v1.c color-management-v1: implement surface_feedback_v1::get_preferred_parametric 2025-04-19 08:20:37 -04:00
wlr_compositor.c compositor: Clean up surface current_outputs last 2025-04-14 12:46:02 +02:00
wlr_content_type_v1.c content-type-v1: use wlr_surface_synced 2023-12-25 11:47:15 +01:00
wlr_cursor.c cursor: use source buffer to signal release timeline point 2025-09-11 09:13:42 -04:00
wlr_cursor_shape_v1.c Assert (almost all) signals have no attached listeners on destroy 2025-01-15 19:53:11 +03:00
wlr_damage_ring.c damage_ring: Remove wlr_damage_ring_set_bounds 2024-10-09 06:31:46 +00:00
wlr_data_control_v1.c Assert (almost all) signals have no attached listeners on destroy 2025-01-15 19:53:11 +03:00
wlr_drm.c Assert (almost all) signals have no attached listeners on destroy 2025-01-15 19:53:11 +03:00
wlr_drm_lease_v1.c drm_lease_v1: initialize device resource link during abnormal exit 2025-09-11 09:13:01 -04:00
wlr_export_dmabuf_v1.c Assert (almost all) signals have no attached listeners on destroy 2025-01-15 19:53:11 +03:00
wlr_ext_data_control_v1.c ext-data-control: add missing listener list assertion 2025-04-06 10:13:40 +03:00
wlr_ext_foreign_toplevel_list_v1.c Fix/cleanup includes a bit 2025-04-15 20:13:29 +03:00
wlr_ext_image_copy_capture_v1.c Remove all calls to pixman_region32_not_empty() 2025-01-29 23:37:06 +01:00
wlr_foreign_toplevel_management_v1.c wlr-foreign-toplevel-management-v1: Simply leave and destroy code 2025-05-06 00:45:09 +02:00
wlr_fractional_scale_v1.c Define _POSIX_C_SOURCE globally 2024-02-15 15:41:12 +01:00
wlr_gamma_control_v1.c Assert (almost all) signals have no attached listeners on destroy 2025-01-15 19:53:11 +03:00
wlr_idle_inhibit_v1.c Assert (almost all) signals have no attached listeners on destroy 2025-01-15 19:53:11 +03:00
wlr_idle_notify_v1.c Implement updated version of ext-idle-notify protocol 2025-02-14 18:57:37 +00:00
wlr_input_device.c Assert (almost all) signals have no attached listeners on destroy 2025-01-15 19:53:11 +03:00
wlr_input_method_v2.c Fix/cleanup includes a bit 2025-04-15 20:13:29 +03:00
wlr_keyboard.c Revert "wlr_keyboard: don't emit key event for duplicated keycodes" 2025-04-25 03:23:21 +09:00
wlr_keyboard_group.c wlr_keyboard_group: fix leak of wlr_keyboard_group->keys 2025-04-25 03:23:26 +09:00
wlr_keyboard_shortcuts_inhibit_v1.c Assert (almost all) signals have no attached listeners on destroy 2025-01-15 19:53:11 +03:00
wlr_layer_shell_v1.c xdg-shell,layer-shell: assert that configure events are only sent to initialized surfaces 2025-03-01 16:07:11 +00:00
wlr_linux_dmabuf_v1.c Assert (almost all) signals have no attached listeners on destroy 2025-01-15 19:53:11 +03:00
wlr_linux_drm_syncobj_v1.c linux_drm_syncobj_v1: fix use-after-free in surface_commit_destroy() 2025-10-21 10:25:29 -04:00
wlr_output_layer.c Assert (almost all) signals have no attached listeners on destroy 2025-01-15 19:53:11 +03:00
wlr_output_layout.c Assert (almost all) signals have no attached listeners on destroy 2025-01-15 19:53:11 +03:00
wlr_output_management_v1.c Assert (almost all) signals have no attached listeners on destroy 2025-01-15 19:53:11 +03:00
wlr_output_power_management_v1.c Assert (almost all) signals have no attached listeners on destroy 2025-01-15 19:53:11 +03:00
wlr_output_swapchain_manager.c swapchain, damage_ring: Drop buffer age 2024-08-21 09:45:54 -04:00
wlr_pointer.c Assert (almost all) signals have no attached listeners on destroy 2025-01-15 19:53:11 +03:00
wlr_pointer_constraints_v1.c Remove all calls to pixman_region32_not_empty() 2025-01-29 23:37:06 +01:00
wlr_pointer_gestures_v1.c Assert (almost all) signals have no attached listeners on destroy 2025-01-15 19:53:11 +03:00
wlr_presentation_time.c presentation-time: make version a uint32_t 2025-04-27 20:42:57 +00:00
wlr_primary_selection.c Assert (almost all) signals have no attached listeners on destroy 2025-01-15 19:53:11 +03:00
wlr_primary_selection_v1.c Assert (almost all) signals have no attached listeners on destroy 2025-01-15 19:53:11 +03:00
wlr_region.c compositor: deprecate wlr/types/wlr_region.h 2023-11-24 15:09:31 +03:00
wlr_relative_pointer_v1.c Assert (almost all) signals have no attached listeners on destroy 2025-01-15 19:53:11 +03:00
wlr_screencopy_v1.c screencopy-v1: drop output_enable listener 2025-03-10 15:33:46 +08:00
wlr_security_context_v1.c Assert (almost all) signals have no attached listeners on destroy 2025-01-15 19:53:11 +03:00
wlr_server_decoration.c Assert (almost all) signals have no attached listeners on destroy 2025-01-15 19:53:11 +03:00
wlr_session_lock_v1.c Define _POSIX_C_SOURCE globally 2024-02-15 15:41:12 +01:00
wlr_shm.c buffer: introduce wlr_buffer_finish() 2025-01-08 16:06:12 +00:00
wlr_single_pixel_buffer_v1.c single-pixel-buffer: Add try_from_buffer() function 2025-04-07 13:25:42 +01:00
wlr_subcompositor.c Assert (almost all) signals have no attached listeners on destroy 2025-01-15 19:53:11 +03:00
wlr_switch.c Assert (almost all) signals have no attached listeners on destroy 2025-01-15 19:53:11 +03:00
wlr_tablet_pad.c Assert (almost all) signals have no attached listeners on destroy 2025-01-15 19:53:11 +03:00
wlr_tablet_tool.c Assert (almost all) signals have no attached listeners on destroy 2025-01-15 19:53:11 +03:00
wlr_tearing_control_v1.c Fix/cleanup includes a bit 2025-04-15 20:13:29 +03:00
wlr_text_input_v3.c Assert (almost all) signals have no attached listeners on destroy 2025-01-15 19:53:11 +03:00
wlr_touch.c Assert (almost all) signals have no attached listeners on destroy 2025-01-15 19:53:11 +03:00
wlr_transient_seat_v1.c transient_seat: initialize seat destroy listener 2025-08-27 13:43:58 -04:00
wlr_viewporter.c Assert (almost all) signals have no attached listeners on destroy 2025-01-15 19:53:11 +03:00
wlr_virtual_keyboard_v1.c Assert (almost all) signals have no attached listeners on destroy 2025-01-15 19:53:11 +03:00
wlr_virtual_pointer_v1.c Assert (almost all) signals have no attached listeners on destroy 2025-01-15 19:53:11 +03:00
wlr_xcursor_manager.c Define _POSIX_C_SOURCE globally 2024-02-15 15:41:12 +01:00
wlr_xdg_activation_v1.c Assert (almost all) signals have no attached listeners on destroy 2025-01-15 19:53:11 +03:00
wlr_xdg_decoration_v1.c Assert (almost all) signals have no attached listeners on destroy 2025-01-15 19:53:11 +03:00
wlr_xdg_dialog_v1.c Assert (almost all) signals have no attached listeners on destroy 2025-01-15 19:53:11 +03:00
wlr_xdg_foreign_registry.c Assert (almost all) signals have no attached listeners on destroy 2025-01-15 19:53:11 +03:00
wlr_xdg_foreign_v1.c Assert (almost all) signals have no attached listeners on destroy 2025-01-15 19:53:11 +03:00
wlr_xdg_foreign_v2.c Fix/cleanup includes a bit 2025-04-15 20:13:29 +03:00
wlr_xdg_output_v1.c Assert (almost all) signals have no attached listeners on destroy 2025-01-15 19:53:11 +03:00
wlr_xdg_system_bell_v1.c xdg-system-bell-v1: set proper global/resource user data 2025-04-11 14:04:23 +00:00
wlr_xdg_toplevel_icon_v1.c Assert (almost all) signals have no attached listeners on destroy 2025-01-15 19:53:11 +03:00