From patchwork Tue Jan 12 17:59:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 59633 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp2885784lbb; Tue, 12 Jan 2016 09:59:37 -0800 (PST) X-Received: by 10.66.155.197 with SMTP id vy5mr190718850pab.109.1452621577773; Tue, 12 Jan 2016 09:59:37 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d66si37589855pfj.173.2016.01.12.09.59.37; Tue, 12 Jan 2016 09:59:37 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1762946AbcALR7d (ORCPT + 29 others); Tue, 12 Jan 2016 12:59:33 -0500 Received: from casper.infradead.org ([85.118.1.10]:38709 "EHLO casper.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752218AbcALR73 (ORCPT ); Tue, 12 Jan 2016 12:59:29 -0500 Received: from [187.65.79.54] (helo=zoo.infradead.org) by casper.infradead.org with esmtpsa (Exim 4.80.1 #2 (Red Hat Linux)) id 1aJ3E3-0000k1-TU; Tue, 12 Jan 2016 17:59:24 +0000 Received: by zoo.infradead.org (Postfix, from userid 1000) id DB50B220310; Tue, 12 Jan 2016 14:59:19 -0300 (BRT) From: Arnaldo Carvalho de Melo To: Ingo Molnar Cc: linux-kernel@vger.kernel.org, Wang Nan , He Kuang , Namhyung Kim , Zefan Li , pi3orama@163.com, Arnaldo Carvalho de Melo Subject: [PATCH 02/11] perf tools: Fix mmap2 event allocation in synthesize code Date: Tue, 12 Jan 2016 14:59:07 -0300 Message-Id: <1452621556-10616-3-git-send-email-acme@kernel.org> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1452621556-10616-1-git-send-email-acme@kernel.org> References: <1452621556-10616-1-git-send-email-acme@kernel.org> X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wang Nan 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 Reviewed-by: Masami Hiramatsu Acked-by: Jiri Olsa Cc: He Kuang Cc: Namhyung Kim Cc: Zefan Li 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 --- tools/perf/util/event.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.1.0 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;