[PATCH 6.6 234/244] perf metrics: Avoid segv if default metricgroup isnt set

Greg Kroah-Hartman gregkh at linuxfoundation.org
Mon Dec 11 10:22:07 PST 2023


6.6-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Ian Rogers <irogers at google.com>

commit e2b005d6ec0e738df584190e21d2c7ada37266a0 upstream.

A metric is default by having "Default" within its groups. The default
metricgroup name needn't be set and this can result in segv in
default_metricgroup_cmp and perf_stat__print_shadow_stats_metricgroup
that assume it has a value when there is a Default metric group. To
avoid the segv initialize the value to "".

Fixes: 1c0e47956a8e ("perf metrics: Sort the Default metricgroup")
Signed-off-by: Ian Rogers <irogers at google.com>
Reviewed-and-tested-by: Ilkka Koskinen <ilkka at os.amperecomputing.com>
Cc: James Clark <james.clark at arm.com>
Cc: Will Deacon <will at kernel.org>
Cc: Leo Yan <leo.yan at linaro.org>
Cc: Mike Leach <mike.leach at linaro.org>
Cc: Kajol Jain <kjain at linux.ibm.com>
Cc: Kan Liang <kan.liang at linux.intel.com>
Cc: John Garry <john.g.garry at oracle.com>
Cc: stable at vger.kernel.org
Cc: linux-arm-kernel at lists.infradead.org
Link: https://lore.kernel.org/r/20231204182330.654255-1-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung at kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh at linuxfoundation.org>
---
 tools/perf/util/metricgroup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c
index 0484736d9fe4..ca3e0404f187 100644
--- a/tools/perf/util/metricgroup.c
+++ b/tools/perf/util/metricgroup.c
@@ -225,7 +225,7 @@ static struct metric *metric__new(const struct pmu_metric *pm,
 
 	m->pmu = pm->pmu ?: "cpu";
 	m->metric_name = pm->metric_name;
-	m->default_metricgroup_name = pm->default_metricgroup_name;
+	m->default_metricgroup_name = pm->default_metricgroup_name ?: "";
 	m->modifier = NULL;
 	if (modifier) {
 		m->modifier = strdup(modifier);
-- 
2.43.0






More information about the linux-arm-kernel mailing list