[PATCH v6 09/10] perf ui hists: Fix dso_filter reference leak and exit zoom cleanup

From: Ian Rogers

Date: Thu Jul 16 2026 - 03:26:46 EST


In hists_browser__zoom_map(), the active dso is assigned as a raw
pointer to hists->dso_filter without acquiring a reference using
dso__get(). This creates a potential use-after-free defect if the
underlying dso is released while the filter remains active.

Fix it by properly acquiring a reference via dso__get() when assigning
the filter, and releasing it with dso__put() when clearing it.
Additionally, since the browser stack relies on pstack__new() and deletes
it completely upon exiting, we must fully reset the persistent hists
structure by un-eliding columns and recalculating histogram filter
states for dso, thread, socket, and symbols upon exit to guarantee
immaculate, uncorrupted state across browser tab switching.

Closes: https://lore.kernel.org/linux-perf-users/20260709170834.52F1A1F000E9@xxxxxxxxxxxxxxx/
Assisted-by: Antigravity:gemini-3.5-flash
Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
tools/perf/ui/browsers/hists.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index 55dd1af9c81f..570d1c07ca23 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -2648,13 +2648,14 @@ static int hists_browser__zoom_map(struct hist_browser *browser, struct map *map
if (browser->hists->dso_filter) {
pstack__remove(browser->pstack, &browser->hists->dso_filter);
perf_hpp__set_elide(HISTC_DSO, false);
+ dso__put((struct dso *)browser->hists->dso_filter);
browser->hists->dso_filter = NULL;
ui_helpline__pop();
} else {
struct dso *dso = map__dso(map);
ui_helpline__fpush("To zoom out press ESC or ENTER + \"Zoom out of %s DSO\"",
__map__is_kernel(map) ? "the Kernel" : dso__short_name(dso));
- browser->hists->dso_filter = dso;
+ browser->hists->dso_filter = dso__get(dso);
perf_hpp__set_elide(HISTC_DSO, true);
pstack__push(browser->pstack, &browser->hists->dso_filter);
}
@@ -3491,6 +3492,16 @@ static int evsel__hists_browse(struct evsel *evsel, int nr_events, const char *h
out_free_stack:
pstack__delete(browser->pstack);
free_popup_actions(actions, MAX_OPTIONS);
+ thread__zput(hists->thread_filter);
+ dso__put((struct dso *)hists->dso_filter);
+ hists->dso_filter = NULL;
+ hists->socket_filter = -1;
+ perf_hpp__set_elide(HISTC_DSO, false);
+ perf_hpp__set_elide(HISTC_THREAD, false);
+ perf_hpp__set_elide(HISTC_SOCKET, false);
+ hists__filter_by_dso(hists);
+ hists__filter_by_thread(hists);
+ hists__filter_by_socket(hists);
zfree(&hists->symbol_filter_str);
hists__filter_by_symbol(hists);
out:
--
2.55.0.141.g00534a21ce-goog