[PATCH v1] perf metrics: Fix segv with --for-each-cgroup

Ian Rogers posted 1 patch 2 years, 9 months ago
tools/perf/util/metricgroup.c | 1 +
1 file changed, 1 insertion(+)
[PATCH v1] perf metrics: Fix segv with --for-each-cgroup
Posted by Ian Rogers 2 years, 9 months ago
Ensure the metric threshold is copied correctly or else a use of
uninitialized memory happens.

Fixes: d0a3052f6fae ("perf metric: Compute and print threshold values")

Reported-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/util/metricgroup.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c
index 4b9a16291b96..c566c6859302 100644
--- a/tools/perf/util/metricgroup.c
+++ b/tools/perf/util/metricgroup.c
@@ -1730,6 +1730,7 @@ int metricgroup__copy_metric_events(struct evlist *evlist, struct cgroup *cgrp,
 				return -ENOMEM;
 
 			new_expr->metric_expr = old_expr->metric_expr;
+			new_expr->metric_threshold = old_expr->metric_threshold;
 			new_expr->metric_name = strdup(old_expr->metric_name);
 			if (!new_expr->metric_name)
 				return -ENOMEM;
-- 
2.40.1.521.gf1e218fcd8-goog
Re: [PATCH v1] perf metrics: Fix segv with --for-each-cgroup
Posted by Namhyung Kim 2 years, 9 months ago
On Fri, May 5, 2023 at 1:41 PM Ian Rogers <irogers@google.com> wrote:
>
> Ensure the metric threshold is copied correctly or else a use of
> uninitialized memory happens.
>
> Fixes: d0a3052f6fae ("perf metric: Compute and print threshold values")
>
> Reported-by: Namhyung Kim <namhyung@kernel.org>
> Signed-off-by: Ian Rogers <irogers@google.com>

Thanks for the fix.  Now it runs ok

  $ sudo ./perf stat -a --bpf-counters \
  > --for-each-cgroup user.slice,system.slice sleep 1

Tested-by: Namhyung Kim <namhyung@kernel.org>

Thanks,
Namhyung


> ---
>  tools/perf/util/metricgroup.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c
> index 4b9a16291b96..c566c6859302 100644
> --- a/tools/perf/util/metricgroup.c
> +++ b/tools/perf/util/metricgroup.c
> @@ -1730,6 +1730,7 @@ int metricgroup__copy_metric_events(struct evlist *evlist, struct cgroup *cgrp,
>                                 return -ENOMEM;
>
>                         new_expr->metric_expr = old_expr->metric_expr;
> +                       new_expr->metric_threshold = old_expr->metric_threshold;
>                         new_expr->metric_name = strdup(old_expr->metric_name);
>                         if (!new_expr->metric_name)
>                                 return -ENOMEM;
> --
> 2.40.1.521.gf1e218fcd8-goog
>