Re: [PATCH] perf tools: Fix perf_evlist__alloc_mmap() failure path

From: Arnaldo Carvalho de Melo
Date: Wed Jun 01 2016 - 08:43:22 EST


Em Tue, May 31, 2016 at 10:27:43PM +0900, Masami Hiramatsu escreveu:
> On Tue, 31 May 2016 13:06:15 +0000
> Wang Nan <wangnan0@xxxxxxxxxx> 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@xxxxxxxxxx>

Applied, after adding a:

Fixes: d4c6fb36ac2c ("perf evsel: Record fd into perf_mmap")

> Thanks!
>
> >
> > Signed-off-by: Wang Nan <wangnan0@xxxxxxxxxx>
> > Cc: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
> > Cc: He Kuang <hekuang@xxxxxxxxxx>
> > Cc: Jiri Olsa <jolsa@xxxxxxxxxx>
> > Cc: Masami Hiramatsu <mhiramat@xxxxxxxxxx>
> > Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
> > Cc: Zefan Li <lizefan@xxxxxxxxxx>
> > Cc: pi3orama@xxxxxxx
> > ---
> > 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@xxxxxxxxxx>