linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org, Wang Nan <wangnan0@huawei.com>,
	He Kuang <hekuang@huawei.com>, Namhyung Kim <namhyung@kernel.org>,
	Zefan Li <lizefan@huawei.com>,
	pi3orama@163.com, Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 02/11] perf tools: Fix mmap2 event allocation in synthesize code
Date: Tue, 12 Jan 2016 14:59:07 -0300	[thread overview]
Message-ID: <1452621556-10616-3-git-send-email-acme@kernel.org> (raw)
In-Reply-To: <1452621556-10616-1-git-send-email-acme@kernel.org>

From: Wang Nan <wangnan0@huawei.com>

perf_event__synthesize_mmap_events() issues mmap2 events, but the memory
of that event is allocated using:

 mmap_event = malloc(sizeof(mmap_event->mmap) + machine->id_hdr_size);

If path of mmap source file is long (near PATH_MAX), random crash would
happen. Should use sizeof(mmap_event->mmap2).

Fix two memory allocations.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Reviewed-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: He Kuang <hekuang@huawei.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1452593524-138970-1-git-send-email-wangnan0@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/event.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index cd61bb1f3917..85155e91b61b 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -503,7 +503,7 @@ int perf_event__synthesize_thread_map(struct perf_tool *tool,
 	if (comm_event == NULL)
 		goto out;
 
-	mmap_event = malloc(sizeof(mmap_event->mmap) + machine->id_hdr_size);
+	mmap_event = malloc(sizeof(mmap_event->mmap2) + machine->id_hdr_size);
 	if (mmap_event == NULL)
 		goto out_free_comm;
 
@@ -577,7 +577,7 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
 	if (comm_event == NULL)
 		goto out;
 
-	mmap_event = malloc(sizeof(mmap_event->mmap) + machine->id_hdr_size);
+	mmap_event = malloc(sizeof(mmap_event->mmap2) + machine->id_hdr_size);
 	if (mmap_event == NULL)
 		goto out_free_comm;
 
-- 
2.1.0

  parent reply	other threads:[~2016-01-12 17:59 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-12 17:59 [GIT PULL 00/11] perf/core improvements and fixes Arnaldo Carvalho de Melo
2016-01-12 17:59 ` [PATCH 01/11] perf stat: Fix recort_usage typo Arnaldo Carvalho de Melo
2016-01-12 17:59 ` Arnaldo Carvalho de Melo [this message]
2016-01-12 17:59 ` [PATCH 03/11] tools: Make list.h self-sufficient Arnaldo Carvalho de Melo
2016-01-12 17:59 ` [PATCH 04/11] tools: Fix formatting of the "make -C tools" help message Arnaldo Carvalho de Melo
2016-01-12 17:59 ` [PATCH 05/11] tools subcmd: Add missing NORETURN define for parse-options.h Arnaldo Carvalho de Melo
2016-01-12 17:59 ` [PATCH 06/11] perf record: Add --buildid-all option Arnaldo Carvalho de Melo
2016-01-12 17:59 ` [PATCH 07/11] perf tools: Add more usage tips Arnaldo Carvalho de Melo
2016-01-12 17:59 ` [PATCH 08/11] perf tools: Add file_only config option to strlist Arnaldo Carvalho de Melo
2016-01-12 17:59 ` [PATCH 09/11] perf tools: Set and pass DOCDIR to builtin-report.c Arnaldo Carvalho de Melo
2016-01-12 17:59 ` [PATCH 10/11] perf ui/tui: Print helpline message as is Arnaldo Carvalho de Melo
2016-01-12 17:59 ` [PATCH 11/11] perf tools: Fallback to srcdir/Documentation/tips.txt Arnaldo Carvalho de Melo
2016-01-13  9:37 ` [GIT PULL 00/11] perf/core improvements and fixes Ingo Molnar

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=1452621556-10616-3-git-send-email-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=hekuang@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizefan@huawei.com \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=pi3orama@163.com \
    --cc=wangnan0@huawei.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).