public inbox for linux-perf-users@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf parse-events: Fix evsel allocation failure
@ 2025-09-22 18:08 Faisal Bukhari
  2026-01-06 21:55 ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 3+ messages in thread
From: Faisal Bukhari @ 2025-09-22 18:08 UTC (permalink / raw)
  To: peterz, mingo, acme, namhyung, mark.rutland, alexander.shishkin,
	jolsa, irogers, adrian.hunter, kan.liang, thomas.falcon,
	linux-perf-users, linux-kernel

If evsel__new_idx() returns NULL, the function currently jumps 
to label 'out_err'.
Here, references to `cpus` and `pmu_cpus` are dropped.
Also, resources held by evsel->name and evsel->metric_id are freed.
But if evsel__new_idx() returns NULL, 
it can lead to NULL pointer dereference.

Signed-off-by: Faisal Bukhari <faisalbukhari523@gmail.com>
---
 tools/perf/util/parse-events.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 452f12191f6e..02e7ff94a2d2 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -286,8 +286,11 @@ __add_event(struct list_head *list, int *idx,
 		event_attr_init(attr);
 
 	evsel = evsel__new_idx(attr, *idx);
-	if (!evsel)
-		goto out_err;
+	if (!evsel) {
+		perf_cpu_map__put(cpus);
+		perf_cpu_map__put(pmu_cpus);
+		return NULL;
+	}
 
 	if (name) {
 		evsel->name = strdup(name);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] perf parse-events: Fix evsel allocation failure
  2025-09-22 18:08 [PATCH] perf parse-events: Fix evsel allocation failure Faisal Bukhari
@ 2026-01-06 21:55 ` Arnaldo Carvalho de Melo
  2026-01-06 22:54   ` Namhyung Kim
  0 siblings, 1 reply; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2026-01-06 21:55 UTC (permalink / raw)
  To: Namhyung Kim, Faisal Bukhari, Ian Rogers
  Cc: James Clark, Peter Zijlstra, Ingo Molnar, mark.rutland,
	alexander.shishkin, Jiri Olsa, Adrian Hunter, thomas.falcon,
	linux-perf-users, linux-kernel

On Mon, Sep 22, 2025 at 11:38:34PM +0530, Faisal Bukhari wrote:
> If evsel__new_idx() returns NULL, the function currently jumps 
> to label 'out_err'.
> Here, references to `cpus` and `pmu_cpus` are dropped.
> Also, resources held by evsel->name and evsel->metric_id are freed.
> But if evsel__new_idx() returns NULL, 
> it can lead to NULL pointer dereference.

You forgot to add:

Fixes: cd63c22168257a0b ("perf parse-events: Minor __add_event refactoring")

Reviewed-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Namhyung, I think this should go into v6.19-rc,

- Arnaldo
 
> Signed-off-by: Faisal Bukhari <faisalbukhari523@gmail.com>
> ---
>  tools/perf/util/parse-events.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
> index 452f12191f6e..02e7ff94a2d2 100644
> --- a/tools/perf/util/parse-events.c
> +++ b/tools/perf/util/parse-events.c
> @@ -286,8 +286,11 @@ __add_event(struct list_head *list, int *idx,
>  		event_attr_init(attr);
>  
>  	evsel = evsel__new_idx(attr, *idx);
> -	if (!evsel)
> -		goto out_err;
> +	if (!evsel) {
> +		perf_cpu_map__put(cpus);
> +		perf_cpu_map__put(pmu_cpus);
> +		return NULL;
> +	}
>  
>  	if (name) {
>  		evsel->name = strdup(name);
> -- 
> 2.43.0

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] perf parse-events: Fix evsel allocation failure
  2026-01-06 21:55 ` Arnaldo Carvalho de Melo
@ 2026-01-06 22:54   ` Namhyung Kim
  0 siblings, 0 replies; 3+ messages in thread
From: Namhyung Kim @ 2026-01-06 22:54 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Faisal Bukhari, Ian Rogers, James Clark, Peter Zijlstra,
	Ingo Molnar, mark.rutland, alexander.shishkin, Jiri Olsa,
	Adrian Hunter, thomas.falcon, linux-perf-users, linux-kernel

On Tue, Jan 06, 2026 at 06:55:57PM -0300, Arnaldo Carvalho de Melo wrote:
> On Mon, Sep 22, 2025 at 11:38:34PM +0530, Faisal Bukhari wrote:
> > If evsel__new_idx() returns NULL, the function currently jumps 
> > to label 'out_err'.
> > Here, references to `cpus` and `pmu_cpus` are dropped.
> > Also, resources held by evsel->name and evsel->metric_id are freed.
> > But if evsel__new_idx() returns NULL, 
> > it can lead to NULL pointer dereference.
> 
> You forgot to add:
> 
> Fixes: cd63c22168257a0b ("perf parse-events: Minor __add_event refactoring")
> 
> Reviewed-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> 
> Namhyung, I think this should go into v6.19-rc,

Sure, will add.

Thanks,
Namhyung


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-01-06 22:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-22 18:08 [PATCH] perf parse-events: Fix evsel allocation failure Faisal Bukhari
2026-01-06 21:55 ` Arnaldo Carvalho de Melo
2026-01-06 22:54   ` Namhyung Kim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox