From patchwork Tue Jan 12 10:12:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 59603 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp2645035lbb; Tue, 12 Jan 2016 02:12:46 -0800 (PST) X-Received: by 10.98.72.130 with SMTP id q2mr32996603pfi.154.1452593566254; Tue, 12 Jan 2016 02:12:46 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id wb3si9081744pab.114.2016.01.12.02.12.45; Tue, 12 Jan 2016 02:12:46 -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 S964919AbcALKMn (ORCPT + 29 others); Tue, 12 Jan 2016 05:12:43 -0500 Received: from szxga02-in.huawei.com ([119.145.14.65]:12915 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964849AbcALKMk (ORCPT ); Tue, 12 Jan 2016 05:12:40 -0500 Received: from 172.24.1.51 (EHLO szxeml430-hub.china.huawei.com) ([172.24.1.51]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id CZT24849; Tue, 12 Jan 2016 18:12:27 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by szxeml430-hub.china.huawei.com (10.82.67.185) with Microsoft SMTP Server id 14.3.235.1; Tue, 12 Jan 2016 18:12:18 +0800 From: Wang Nan To: CC: , , Wang Nan , Arnaldo Carvalho de Melo , He Kuang , Masami Hiramatsu , Namhyung Kim , Zefan Li , Subject: [PATCH 16/53 v2] perf tools: Fix mmap2 event allocation in synthesize code Date: Tue, 12 Jan 2016 10:12:04 +0000 Message-ID: <1452593524-138970-1-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <20160111210327.GG18367@kernel.org> References: <20160111210327.GG18367@kernel.org> MIME-Version: 1.0 X-Originating-IP: [10.107.193.248] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020201.5694D18D.003D, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 2f643693485ad234c14ff26a93c94452 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Acked-by: Jiri Olsa Cc: Arnaldo Carvalho de Melo Cc: He Kuang Cc: Masami Hiramatsu Cc: Namhyung Kim Cc: Zefan Li Cc: pi3orama@163.com --- v1 -> v2: Don't rename mmap to mmap2. --- tools/perf/util/event.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 1.8.3.4 diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c index cd61bb1..85155e9 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;