linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Wang Nan <wangnan0@huawei.com>
To: <acme@kernel.org>
Cc: <linux-kernel@vger.kernel.org>, Wang Nan <wangnan0@huawei.com>,
	"Adrian Hunter" <adrian.hunter@intel.com>,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Tong Zhang <ztong@vt.edu>, Josh Poimboeuf <jpoimboe@redhat.com>
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	[thread overview]
Message-ID: <1454296865-19749-2-git-send-email-wangnan0@huawei.com> (raw)
In-Reply-To: <1454296865-19749-1-git-send-email-wangnan0@huawei.com>

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 <wangnan0@huawei.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Tong Zhang <ztong@vt.edu>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
---
 tools/perf/util/parse-events.c | 3 +++
 1 file changed, 3 insertions(+)

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).
-- 
1.8.3.4

  reply	other threads:[~2016-02-01  3:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-01  3:21 [PATCH 1/2] perf tools: Fix fault in error patch of intel_pt_process_auxtrace_info() Wang Nan
2016-02-01  3:21 ` Wang Nan [this message]
2016-02-01  8:53   ` [PATCH 2/2] perf tools: Fix fault in tracepoint_error if NULL is passed to parse_event Adrian Hunter
2016-02-01 14:47     ` Arnaldo Carvalho de Melo
2016-02-01  8:51 ` [PATCH 1/2] perf tools: Fix fault in error patch of intel_pt_process_auxtrace_info() Adrian Hunter
2016-02-04  7:57 ` [tip:perf/urgent] perf tools: Fix thread lifetime related segfaut in intel_pt tip-bot for Adrian Hunter

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=1454296865-19749-2-git-send-email-wangnan0@huawei.com \
    --to=wangnan0@huawei.com \
    --cc=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ztong@vt.edu \
    /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).