Skip to contentSkip to conversation

perf util: Fix use after free in metric__new

PATCH Superseded José Expósito 4 participants 6 messages Dec 8, 2021 – Jan 14, 2022 perf events

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf util: Fix use after free in metric__new

Addresses-Coverity-ID: 1494000

---
 tools/perf/util/metricgroup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/metricgroup.c +1 -1
index fffe02aae3ed..4d2fed3aefd1 100644
@@ -209,8 +209,8 @@ static struct metric *metric__new(const struct pmu_event *pe,
 	m->metric_name = pe->metric_name;
 	m->modifier = modifier ? strdup(modifier) : NULL;
 	if (modifier && !m->modifier) {
-		free(m);
 		expr__ctx_free(m->pctx);
+		free(m);
 		return NULL;
 	}
 	m->metric_expr = pe->metric_expr;
Signature · 1 line
2.25.1
reviewer Acked-by on v1 1/1
#1 lore raw
Quoted 3 lines · José Expósito

Addresses-Coverity-ID: 1494000

This can only happen in the ENOMEM case, but it is a good fix.

Fixes b85a4d61d302 (perf metric: Allow modifiers on metrics)

Thanks,
Ian

Quoted 21 lines
---
 tools/perf/util/metricgroup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/metricgroup.c +1 -2
index fffe02aae3ed..4d2fed3aefd1 100644
@@ -209,8 +209,8 @@ static struct metric *metric__new(const struct pmu_event *pe,
        m->metric_name = pe->metric_name;
        m->modifier = modifier ? strdup(modifier) : NULL;
        if (modifier && !m->modifier) {
-               free(m);
                expr__ctx_free(m->pctx);
+               free(m);
                return NULL;
        }
        m->metric_expr = pe->metric_expr;
--

2.25.1

#2 lore raw

Em Wed, Dec 08, 2021 at 09:33:14AM -0800, Ian Rogers escreveu:

Quoted 10 lines · José Expósito
Quoted 3 lines

Addresses-Coverity-ID: 1494000

This can only happen in the ENOMEM case, but it is a good fix.

Fixes b85a4d61d302 (perf metric: Allow modifiers on metrics)

Sorry, I missed this one _as well_, sigh...

- Arnaldo

Quoted 24 lines

Thanks,
Ian

Quoted 21 lines
---
 tools/perf/util/metricgroup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/metricgroup.c +1 -2
index fffe02aae3ed..4d2fed3aefd1 100644
@@ -209,8 +209,8 @@ static struct metric *metric__new(const struct pmu_event *pe,
        m->metric_name = pe->metric_name;
        m->modifier = modifier ? strdup(modifier) : NULL;
        if (modifier && !m->modifier) {
-               free(m);
                expr__ctx_free(m->pctx);
+               free(m);
                return NULL;
        }
        m->metric_expr = pe->metric_expr;
--

2.25.1

Signature · 1 line
- Arnaldo
#3 lore raw
Quoted 11 lines · Arnaldo Carvalho de Melo
Quoted 7 lines
Quoted 2 lines

Addresses-Coverity-ID: 1494000

This can only happen in the ENOMEM case, but it is a good fix.

Fixes b85a4d61d302 (perf metric: Allow modifiers on metrics)

Sorry, I missed this one_as well_, sigh...

- Arnaldo

Isn't there a v3 out there? Not sure if you noticed...

Cheers

#4 lore raw
Quoted 8 lines · John Garry
Quoted 7 lines · Arnaldo Carvalho de Melo
Quoted 7 lines
Quoted 2 lines

Addresses-Coverity-ID: 1494000

This can only happen in the ENOMEM case, but it is a good fix.

Fixes b85a4d61d302 (perf metric: Allow modifiers on metrics)
Quoted 8 lines
Quoted 3 lines

Sorry, I missed this one_as well_, sigh...

- Arnaldo

Isn't there a v3 out there? Not sure if you noticed...

Cheers

Yes, here is v3 including the Fixes, Acked-by and Reviewed-by tags:

https://lore.kernel.org/linux-perf-users/[email protected]/

#5 lore raw
In reply to José Expósito

Em Wed, Dec 08, 2021 at 06:11:13PM +0100, José Expósito escreveu:

Quoted 2 lines

Addresses-Coverity-ID: 1494000

Sorry, overlooked this one, now processing.

You forgot to add:

Fixes b85a4d61d3022608 ("perf metric: Allow modifiers on metrics")

Ian, I'm taking this one, obvious fix.

- Arnaldo

Quoted 20 lines
---
 tools/perf/util/metricgroup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/metricgroup.c +1 -1
index fffe02aae3ed..4d2fed3aefd1 100644
@@ -209,8 +209,8 @@ static struct metric *metric__new(const struct pmu_event *pe,
 	m->metric_name = pe->metric_name;
 	m->modifier = modifier ? strdup(modifier) : NULL;
 	if (modifier && !m->modifier) {
-		free(m);
 		expr__ctx_free(m->pctx);
+		free(m);
 		return NULL;
 	}
 	m->metric_expr = pe->metric_expr;
Signature · 1 line
2.25.1
Signature · 1 line
- Arnaldo