From patchwork Mon Feb 1 03:21:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 60864 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp2733833lbb; Sun, 31 Jan 2016 19:21:57 -0800 (PST) X-Received: by 10.66.65.109 with SMTP id w13mr34192672pas.142.1454296917047; Sun, 31 Jan 2016 19:21:57 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id rl8si14818194pac.190.2016.01.31.19.21.56; Sun, 31 Jan 2016 19:21:57 -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 S933651AbcBADVu (ORCPT + 30 others); Sun, 31 Jan 2016 22:21:50 -0500 Received: from szxga02-in.huawei.com ([119.145.14.65]:64797 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757583AbcBADVq (ORCPT ); Sun, 31 Jan 2016 22:21:46 -0500 Received: from 172.24.1.50 (EHLO szxeml427-hub.china.huawei.com) ([172.24.1.50]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DAT03829; Mon, 01 Feb 2016 11:21:22 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by szxeml427-hub.china.huawei.com (10.82.67.182) with Microsoft SMTP Server id 14.3.235.1; Mon, 1 Feb 2016 11:21:11 +0800 From: Wang Nan To: CC: , Wang Nan , "Adrian Hunter" , Arnaldo Carvalho de Melo , Tong Zhang , Josh Poimboeuf Subject: [PATCH 2/2] perf tools: Fix fault in tracepoint_error if NULL is passed to parse_event Date: Mon, 1 Feb 2016 03:21:05 +0000 Message-ID: <1454296865-19749-2-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1454296865-19749-1-git-send-email-wangnan0@huawei.com> References: <1454296865-19749-1-git-send-email-wangnan0@huawei.com> 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.0A0B0206.56AECF33.00BC, 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: d66f6bda66b6214d56b14e903e8f90f8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Following segfault can happen with a non-root user: $ ./perf record -I -e intel_pt/tsc=1,noretcomp=1/u /bin/ls WARNING: Kernel address maps (/proc/{kallsyms,modules}) are restricted, check /proc/sys/kernel/kptr_restrict. Samples in kernel functions may not be resolved if a suitable vmlinux file is not found in the buildid cache or in the vmlinux path. Samples in kernel modules won't be resolved at all. If some relocation was applied (e.g. kexec) symbols may be misresolved even with a suitable vmlinux or kallsyms file. Segmentation fault (core dumped) The error is in tracepoint_error: it assumes 'e' is valid. However, there are many situation a parse_event can be called without parse_events_error. See result of 'grep 'parse_events(.*NULL)' ./tools/perf/ -r'. This patch makes tracepoint_error() directly return when !e. Signed-off-by: Wang Nan Cc: Adrian Hunter Cc: Arnaldo Carvalho de Melo Cc: Tong Zhang Cc: Josh Poimboeuf --- tools/perf/util/parse-events.c | 3 +++ 1 file changed, 3 insertions(+) -- 1.8.3.4 diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 4f7b0ef..813d9b2 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -399,6 +399,9 @@ static void tracepoint_error(struct parse_events_error *e, int err, { char help[BUFSIZ]; + if (!e) + return; + /* * We get error directly from syscall errno ( > 0), * or from encoded pointer's error ( < 0).