mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [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	[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

all inboxes | Powered by JetHome®