[PATCH v6 04/10] perf ui hists: Fix stack use-after-return in symbol_filter_str
From: Ian Rogers
Date: Thu Jul 16 2026 - 03:24:58 EST
In evsel__hists_browse(), the local stack array 'buf' is assigned
directly to the persistent 'hists->symbol_filter_str' pointer. When the
browser returns or is exited, this dangling pointer remains active in
the 'hists' struct and is read asynchronously by the perf top background
timer, triggering a stack use-after-return.
Fix it by properly duplicating the input string using strdup(), safely
invoking zfree() to prevent memory leaks when overwriting, and cleanly
resetting and freeing the symbol filter string upon exiting the browser.
Assisted-by: Antigravity:gemini-3.5-flash
Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
tools/perf/ui/browsers/hists.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index 9a3844dc3246..675910893644 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -3213,7 +3213,10 @@ static int evsel__hists_browse(struct evsel *evsel, int nr_events, const char *h
"To remove the filter later, press / + ENTER.",
buf, "ENTER: OK, ESC: Cancel",
delay_secs * 2) == K_ENTER) {
- hists->symbol_filter_str = *buf ? buf : NULL;
+ char *new_filter = *buf ? strdup(buf) : NULL;
+
+ zfree(&hists->symbol_filter_str);
+ hists->symbol_filter_str = new_filter;
hists__filter_by_symbol(hists);
hist_browser__reset(browser);
}
@@ -3447,6 +3450,8 @@ static int evsel__hists_browse(struct evsel *evsel, int nr_events, const char *h
}
out_free_stack:
pstack__delete(browser->pstack);
+ zfree(&hists->symbol_filter_str);
+ hists__filter_by_symbol(hists);
out:
hist_browser__delete(browser);
free_popup_options(options, MAX_OPTIONS);
--
2.55.0.141.g00534a21ce-goog