Re: [PATCH 2/2] perf parse-events: Avoid an uninitialized read.

From: Jiri Olsa
Date: Wed Aug 26 2020 - 07:39:48 EST


On Tue, Aug 25, 2020 at 09:29:10PM -0700, Ian Rogers wrote:
> With a fake_pmu the pmu_info isn't populated by perf_pmu__check_alias.
> In this case, don't try to copy the uninitialized values to the evsel.
>
> Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>

Acked-by: Jiri Olsa <jolsa@xxxxxxxxxx>

thanks,
jirka

> ---
> tools/perf/util/parse-events.c | 30 +++++++++++++++++-------------
> 1 file changed, 17 insertions(+), 13 deletions(-)
>
> diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
> index 9f7260e69113..3d7a48b488ed 100644
> --- a/tools/perf/util/parse-events.c
> +++ b/tools/perf/util/parse-events.c
> @@ -1533,19 +1533,23 @@ int parse_events_add_pmu(struct parse_events_state *parse_state,
> evsel = __add_event(list, &parse_state->idx, &attr, true,
> get_config_name(head_config), pmu,
> &config_terms, auto_merge_stats, NULL);
> - if (evsel) {
> - evsel->unit = info.unit;
> - evsel->scale = info.scale;
> - evsel->per_pkg = info.per_pkg;
> - evsel->snapshot = info.snapshot;
> - evsel->metric_expr = info.metric_expr;
> - evsel->metric_name = info.metric_name;
> - evsel->pmu_name = name ? strdup(name) : NULL;
> - evsel->use_uncore_alias = use_uncore_alias;
> - evsel->percore = config_term_percore(&evsel->config_terms);
> - }
> -
> - return evsel ? 0 : -ENOMEM;
> + if (!evsel)
> + return -ENOMEM;
> +
> + evsel->pmu_name = name ? strdup(name) : NULL;
> + evsel->use_uncore_alias = use_uncore_alias;
> + evsel->percore = config_term_percore(&evsel->config_terms);
> +
> + if (parse_state->fake_pmu)
> + return 0;
> +
> + evsel->unit = info.unit;
> + evsel->scale = info.scale;
> + evsel->per_pkg = info.per_pkg;
> + evsel->snapshot = info.snapshot;
> + evsel->metric_expr = info.metric_expr;
> + evsel->metric_name = info.metric_name;
> + return 0;
> }
>
> int parse_events_multi_pmu_add(struct parse_events_state *parse_state,
> --
> 2.28.0.297.g1956fa8f8d-goog
>