fix: nemo-window-manage-views: fix use-after-free crash in desktop sl…#3781
Open
nathan9513-aps wants to merge 1 commit into
Open
fix: nemo-window-manage-views: fix use-after-free crash in desktop sl…#3781nathan9513-aps wants to merge 1 commit into
nathan9513-aps wants to merge 1 commit into
Conversation
…ot callback nemo_file_call_when_ready() was called with a raw NemoWindowSlot * as callback_data. If the slot was destroyed between registration and idle dispatch, the callback received a dangling pointer and crashed immediately on the g_assert(NEMO_IS_WINDOW_SLOT(slot)) inside nemo_window_slot_get_window(). Crash trace: SIGABRT ← g_assert failure nemo_window_slot_get_window() nemo-window-slot.c:528 got_file_info_for_view_selection_callback() nemo-window-manage-views.c:822 desktop_callback_check_done() nemo-desktop-directory-file.c:241 call_ready_callbacks_at_idle() nemo-directory-async.c:1850 Fix: use a GObject weak reference (Solution B). Introduce SlotWeakData, a small heap-allocated sentinel that holds the slot pointer and is registered as a GWeakNotify on the slot. When GObject finalizes the slot, slot_weak_notify() zeroes wd->slot. The callback checks this field at entry and returns safely if the slot is gone. Add slot->determine_view_weak_data to NemoWindowSlot so that free_location_change() can retrieve the correct SlotWeakData pointer, pass it to nemo_file_cancel_call_when_ready() (which matches on both callback and callback_data), remove the weak ref, and free the sentinel without leaving dangling notifiers. The same guard is applied to all three call-sites that register got_file_info_for_view_selection_callback: - begin_location_change() - mount_not_mounted_callback() - the parent-redirect branch inside the callback itself Files changed: src/nemo-window-slot.h add determine_view_weak_data field src/nemo-window-manage-views.c implement weak-ref guard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a
SIGABRTcrash innemo-desktopcaused by a use-after-free (dangling pointer) onNemoWindowSlotinside an async GLib file-info callback.Fixes: linuxmint/nemo#XXXX (update with actual issue number)
Problem
nemo-desktopcrashed with the following assertion failure:Signal:
SIGABRTCrashed process:
/usr/bin/nemo-desktopRoot cause
The crash originates in
got_file_info_for_view_selection_callback()insrc/nemo-window-manage-views.c.When a directory change is initiated,
begin_location_change()callsnemo_file_call_when_ready(), passing the rawNemoWindowSlot *pointer ascallback_data. GLib schedules the callback to fire at idle time(
g_idle_add). If theNemoWindowSlotis destroyed between registrationand dispatch (e.g. the desktop window is torn down during startup), the
pointer becomes a dangling reference. When the idle callback eventually fires,
the first thing it does is call
nemo_window_slot_get_window(slot), whichhits the internal
g_assert (NEMO_IS_WINDOW_SLOT (slot))— and aborts.Relevant stack frames (from coredump)
Solution
Applied GObject weak reference guard (Solution B):
Instead of passing the raw
NemoWindowSlot *directly ascallback_data, wenow allocate a small heap-resident sentinel struct (
SlotWeakData) that holdsthe slot pointer and is registered as a
GWeakNotifyon the slot object.When GObject finalizes the slot, it calls
slot_weak_notify(), which zeroeswd->slot. When the callback eventually fires, it checks whetherwd->slotis still valid before touching the slot — and returns safely if not.
If
free_location_change()cancels a pending call before it fires, itcorrectly retrieves the saved
SlotWeakData *from the newslot->determine_view_weak_datafield, passes it ascallback_datatonemo_file_cancel_call_when_ready()(which matches on both callback pointerand data pointer), removes the weak ref, and frees the sentinel — leaving no
dangling notifiers.
Show: https://bugzilla.redhat.com/show_bug.cgi?id=2481175