[PATCH 1/2] perf tools: Fix seg fault with Intel PT

From: Adrian Hunter
Date: Tue Jan 26 2016 - 07:15:58 EST


Fix segmentation fault using:

perf record -e intel_pt//u uname

Back trace:

0 tracepoint_error (err=13, err@entry=-13, sys=sys@entry=0x18706c0 "sched", name=name@entry=0x1871c70 "sched_switch", e=<optimized out>, e=<optimized out>) at util/parse-events.c:416
1 0x000000000049791c in add_tracepoint (head_config=0x0, err=0x0, evt_name=0x1871c70 "sched_switch", sys_name=0x18706c0 "sched", idx=<optimized out>, list=<optimized out>)
at util/parse-events.c:433
2 add_tracepoint_event (list=<optimized out>, idx=<optimized out>, sys_name=0x18706c0 "sched", evt_name=0x1871c70 "sched_switch", err=0x0, head_config=0x0) at util/parse-events.c:498
3 0x0000000000498ec4 in parse_events_add_tracepoint (list=list@entry=0x1871c90, idx=idx@entry=0x7fffffffba30, sys=0x18706c0 "sched", event=0x1871c70 "sched_switch", err=err@entry=0x0,
head_config=head_config@entry=0x0) at util/parse-events.c:936
4 0x00000000004ccff2 in parse_events_parse (_data=_data@entry=0x7fffffffba20, scanner=0x18705f0) at util/parse-events.y:391
5 0x000000000049a567 in parse_events__scanner (start_token=258, data=0x7fffffffba20, str=0x0) at util/parse-events.c:1361
6 parse_events (evlist=evlist@entry=0x1871150, str=str@entry=0x55ef6c "sched:sched_switch", err=err@entry=0x0) at util/parse-events.c:1401
7 0x00000000004eb4b6 in perf_evlist__can_select_event (evlist=evlist@entry=0x186fb90, str=str@entry=0x55ef6c "sched:sched_switch") at util/record.c:253
8 0x000000000051e1d3 in intel_pt_track_switches (evlist=0x186fb90) at arch/x86/util/intel-pt.c:362
9 intel_pt_recording_options (itr=0x186ef70, evlist=0x186fb90, opts=0x7c3e08 <record+232>) at arch/x86/util/intel-pt.c:662
10 0x000000000042e244 in cmd_record (argc=1, argv=0x7fffffffe270, prefix=<optimized out>) at builtin-record.c:1260
11 0x000000000047cbd3 in run_builtin (p=p@entry=0x7cf2e8 <commands+168>, argc=argc@entry=4, argv=argv@entry=0x7fffffffe270) at perf.c:390
12 0x00000000004216a7 in handle_internal_command (argv=0x7fffffffe270, argc=4) at perf.c:451
13 run_argv (argv=0x7fffffffdff0, argcp=0x7fffffffdffc) at perf.c:495
14 main (argc=4, argv=0x7fffffffe270) at perf.c:618

Intel PT attempts to find the sched:sched_switch tracepoint but that
seg faults if tracefs is not readable, because the error reporting
structure is null, as errors are not reported when automatically
adding tracepoints. Fix by checking before using.

Signed-off-by: Adrian Hunter <adrian.hunter@xxxxxxxxx>
Fixes: 196581717d85 ("perf tools: Enhance parsing events tracepoint error output")
Cc: stable@xxxxxxxxxxxxxxx # v4.4+
---
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 4f7b0efdde2f..813d9b272c81 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.9.1