From: Jiri Olsa <jolsa@redhat.com>
To: zhe.he@windriver.com
Cc: acme@redhat.com, jolsa@kernel.org, ak@linux.intel.com,
meyerk@hpe.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] perf: Add NULL pointer check for cpu_map iteration and NULL assignment for all_cpus.
Date: Wed, 18 Mar 2020 11:32:24 +0100 [thread overview]
Message-ID: <20200318103224.GE821557@krava> (raw)
In-Reply-To: <1583665157-349023-1-git-send-email-zhe.he@windriver.com>
On Sun, Mar 08, 2020 at 06:59:17PM +0800, zhe.he@windriver.com wrote:
> From: He Zhe <zhe.he@windriver.com>
>
> NULL pointer may be passed to perf_cpu_map__cpu and then cause crash,
> such as the one commit cb71f7d43ece ("libperf: Setup initial evlist::all_cpus value")
> fix.
>
> Signed-off-by: He Zhe <zhe.he@windriver.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
thanks,
jirka
> ---
> tools/perf/lib/cpumap.c | 2 +-
> tools/perf/lib/evlist.c | 1 +
> 2 files changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/lib/cpumap.c b/tools/perf/lib/cpumap.c
> index f93f4e7..ca02150 100644
> --- a/tools/perf/lib/cpumap.c
> +++ b/tools/perf/lib/cpumap.c
> @@ -247,7 +247,7 @@ struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list)
>
> int perf_cpu_map__cpu(const struct perf_cpu_map *cpus, int idx)
> {
> - if (idx < cpus->nr)
> + if (cpus && idx < cpus->nr)
> return cpus->map[idx];
>
> return -1;
> diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
> index 5b9f2ca..f87a239 100644
> --- a/tools/perf/lib/evlist.c
> +++ b/tools/perf/lib/evlist.c
> @@ -127,6 +127,7 @@ void perf_evlist__exit(struct perf_evlist *evlist)
> perf_cpu_map__put(evlist->cpus);
> perf_thread_map__put(evlist->threads);
> evlist->cpus = NULL;
> + evlist->all_cpus = NULL;
> evlist->threads = NULL;
> fdarray__exit(&evlist->pollfd);
> }
> --
> 2.7.4
>
next prev parent reply other threads:[~2020-03-18 10:32 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-08 10:59 [PATCH] perf: Add NULL pointer check for cpu_map iteration and NULL assignment for all_cpus zhe.he
2020-03-18 10:32 ` Jiri Olsa [this message]
2020-03-18 13:34 ` Arnaldo Carvalho de Melo
2020-04-29 17:49 ` Arnaldo Carvalho de Melo
2020-05-08 13:05 ` [tip: perf/core] libperf: " tip-bot2 for He Zhe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200318103224.GE821557@krava \
--to=jolsa@redhat.com \
--cc=acme@redhat.com \
--cc=ak@linux.intel.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=meyerk@hpe.com \
--cc=zhe.he@windriver.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.