Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1410310
| From | Masami Hiramatsu <mhiramat@kernel.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH] perf tools: Fix perf_evlist__alloc_mmap() failure path |
| Date | 2016-05-31 15:30 +0200 |
| Message-ID | <rERU6-3h1-29@gated-at.bofh.it> (permalink) |
| References | <rERAJ-38J-23@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On Tue, 31 May 2016 13:06:15 +0000
Wang Nan <wangnan0@huawei.com> wrote:
> If zalloc fail, setting evlist->mmap[i].fd is unsafe.
> perf_evlist__alloc_mmap() should fail right after zalloc() fail.
Good catch!!
Reviewed-by: Masami Hiramatsu <mhiramat@kernel.org>
Thanks!
>
> Signed-off-by: Wang Nan <wangnan0@huawei.com>
> Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
> Cc: He Kuang <hekuang@huawei.com>
> Cc: Jiri Olsa <jolsa@kernel.org>
> Cc: Masami Hiramatsu <mhiramat@kernel.org>
> Cc: Namhyung Kim <namhyung@kernel.org>
> Cc: Zefan Li <lizefan@huawei.com>
> Cc: pi3orama@163.com
> ---
> tools/perf/util/evlist.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
> index e0f3094..1b918aa 100644
> --- a/tools/perf/util/evlist.c
> +++ b/tools/perf/util/evlist.c
> @@ -946,9 +946,12 @@ static int perf_evlist__alloc_mmap(struct perf_evlist *evlist)
> if (cpu_map__empty(evlist->cpus))
> evlist->nr_mmaps = thread_map__nr(evlist->threads);
> evlist->mmap = zalloc(evlist->nr_mmaps * sizeof(struct perf_mmap));
> + if (!evlist->mmap)
> + return -ENOMEM;
> +
> for (i = 0; i < evlist->nr_mmaps; i++)
> evlist->mmap[i].fd = -1;
> - return evlist->mmap != NULL ? 0 : -ENOMEM;
> + return 0;
> }
>
> struct mmap_params {
> --
> 1.8.3.4
>
--
Masami Hiramatsu <mhiramat@kernel.org>
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH] perf tools: Fix perf_evlist__alloc_mmap() failure path Wang Nan <wangnan0@huawei.com> - 2016-05-31 15:10 +0200
Re: [PATCH] perf tools: Fix perf_evlist__alloc_mmap() failure path Masami Hiramatsu <mhiramat@kernel.org> - 2016-05-31 15:30 +0200
Re: [PATCH] perf tools: Fix perf_evlist__alloc_mmap() failure path Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-06-01 14:50 +0200
[tip:perf/core] perf evlist: Fix alloc_mmap() failure path tip-bot for Wang Nan <tipbot@zytor.com> - 2016-06-08 10:40 +0200
csiph-web