* [PATCH] perf parse-events: Fix potential null pointer dereference in __add_event()
@ 2025-08-12 8:59 zhaoguohan
2025-08-12 9:22 ` Markus Elfring
0 siblings, 1 reply; 2+ messages in thread
From: zhaoguohan @ 2025-08-12 8:59 UTC (permalink / raw)
To: peterz, mingo, acme, namhyung, mark.rutland, alexander.shishkin,
jolsa, irogers, adrian.hunter, kan.liang, thomas.falcon
Cc: linux-perf-users, linux-kernel, GuoHan Zhao
From: GuoHan Zhao <zhaoguohan@kylinos.cn>
In the error handling path of __add_event(), if evsel__new_idx() fails
and returns NULL, the subsequent calls to zfree(&evsel->name) and
zfree(&evsel->metric_id) will cause null pointer dereference.
Add a null check before accessing evsel members in the error path.
Signed-off-by: GuoHan Zhao <zhaoguohan@kylinos.cn>
---
tools/perf/util/parse-events.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 8282ddf68b98..251f1b31b62f 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -313,9 +313,13 @@ __add_event(struct list_head *list, int *idx,
out_err:
perf_cpu_map__put(cpus);
perf_cpu_map__put(pmu_cpus);
- zfree(&evsel->name);
- zfree(&evsel->metric_id);
- free(evsel);
+
+ if (evsel) {
+ zfree(&evsel->name);
+ zfree(&evsel->metric_id);
+ free(evsel);
+ }
+
return NULL;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] perf parse-events: Fix potential null pointer dereference in __add_event()
2025-08-12 8:59 [PATCH] perf parse-events: Fix potential null pointer dereference in __add_event() zhaoguohan
@ 2025-08-12 9:22 ` Markus Elfring
0 siblings, 0 replies; 2+ messages in thread
From: Markus Elfring @ 2025-08-12 9:22 UTC (permalink / raw)
To: GuoHan Zhao, linux-perf-users
Cc: LKML, Adrian Hunter, Alexander Shishkin, Arnaldo Carvalho de Melo,
Ian Rogers, Ingo Molnar, Jiri Olsa, Kan Liang, Mark Rutland,
Namhyung Kim, Peter Zijlstra, Thomas Falcon
…
> Add a null check before accessing evsel members in the error path.
* Please extend the goto chain instead for better exception handling.
You may reorder jump targets accordingly.
* How do you think about to add any tags (like “Fixes” and “Cc”) accordingly?
* Would a summary phrase like “Prevent null pointer dereference in __add_event()”
be nicer?
Regards,
Markus
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-08-12 9:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-12 8:59 [PATCH] perf parse-events: Fix potential null pointer dereference in __add_event() zhaoguohan
2025-08-12 9:22 ` Markus Elfring
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).