fix(privacy): segfault due to use-after-free from get_children()#5114
Open
jaschiu wants to merge 2 commits into
Open
fix(privacy): segfault due to use-after-free from get_children()#5114jaschiu wants to merge 2 commits into
jaschiu wants to merge 2 commits into
Conversation
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.
Hi, waybar was crashing for me when I was using the privacy module. My LLM wrote the below description for me and debugged it for me.
Summary
Waybar segfaults on startup when the
privacymodule is configured. The crash is a use-after-free in Privacy::update() caused by iterating the transient C++ wrappers returned byGtk::Container::get_children().Steps to reproduce
Minimal config:
{ "modules-right": ["privacy"], }Start waybar; it crashes shortly after the bar is configured.
Crash
The crash is in
dynamic_cast<PrivacyItem*>(widget)while looping overbox_.get_children().Root cause
Privacy::update() iterated the children of
box_anddynamic_cast-ed each one back toPrivacyItem*:Gtk::Container::get_children()returns astd::vector<Gtk::Widget*>built by wrapping each childGtkWidgetviaGlib::wrap()over a shallowly-ownedGList. Rather than returning the originalPrivacyItemwrappers, it can hand back freshly-created wrappers that are freed immediately, so the pointers in the returned vector dangle. Dereferencing them indynamic_castreads a garbage vtable and crashes.Confirmed under gdb: the
PrivacyItemobjects created in the constructor remain alive with valid vtables, butget_children()returns a different, already-freed pointer:This is the same class of issue already fixed for the niri workspaces module, which stopped relying on
get_children()wrappers.Fix
Stop round-tripping through
get_children()+dynamic_cast. ThePrivacyItems are owned bybox_(added viaGtk::make_managed) and stay valid for the lifetime of the module, so we store the pointers we create and iterate those directly.std::vector<PrivacyItem*> modules_;to Privacy.PrivacyItem*intomodules_when it is created in the constructor.modules_in update() instead ofbox_.get_children(), removing the now-unnecessarydynamic_cast/null check.Testing
privacy-only config.