aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRavi Bangoria <ravi.bangoria@linux.ibm.com>2018-06-25 08:42:20 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2018-06-25 10:59:37 -0400
commit92ead7ee30c80f8852d28735cbcb9d79bc85f715 (patch)
treec0ba6baeb43852f95f77f33b2f993e55e5f2e30c
parenta3af66f51bd0bca72881ead4bf2bd19cb366582b (diff)
perf tools: Fix crash caused by accessing feat_ops[HEADER_LAST_FEATURE]
perf_event__process_feature() accesses feat_ops[HEADER_LAST_FEATURE] which is not defined and thus perf is crashing. HEADER_LAST_FEATURE is used as an end marker for the perf report but it's unused for perf script/annotate. Ignore HEADER_LAST_FEATURE for perf script/annotate, just like it is done in 'perf report'. Before: # perf record -o - ls | perf script <SNIP 'ls' output> Segmentation fault (core dumped) # After: # perf record -o - ls | perf script <SNIP 'ls' output> Segmentation fault (core dumped) ls 7031 4392.099856: 250000 cpu-clock:uhH: 7f5e0ce7cd60 ls 7031 4392.100355: 250000 cpu-clock:uhH: 7f5e0c706ef7 # Signed-off-by: Ravi Bangoria <ravi.bangoria@linux.ibm.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: David Carrillo-Cisneros <davidcc@google.com> Cc: Jin Yao <yao.jin@linux.intel.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Fixes: 57b5de463925 ("perf report: Support forced leader feature in pipe mode") Link: http://lkml.kernel.org/r/20180625124220.6434-4-ravi.bangoria@linux.ibm.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/builtin-annotate.c11
-rw-r--r--tools/perf/builtin-report.c3
-rw-r--r--tools/perf/builtin-script.c11
-rw-r--r--tools/perf/util/header.c2
4 files changed, 23 insertions, 4 deletions
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index 5eb22cc56363..8180319285af 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -283,6 +283,15 @@ out_put:
283 return ret; 283 return ret;
284} 284}
285 285
286static int process_feature_event(struct perf_tool *tool,
287 union perf_event *event,
288 struct perf_session *session)
289{
290 if (event->feat.feat_id < HEADER_LAST_FEATURE)
291 return perf_event__process_feature(tool, event, session);
292 return 0;
293}
294
286static int hist_entry__tty_annotate(struct hist_entry *he, 295static int hist_entry__tty_annotate(struct hist_entry *he,
287 struct perf_evsel *evsel, 296 struct perf_evsel *evsel,
288 struct perf_annotate *ann) 297 struct perf_annotate *ann)
@@ -471,7 +480,7 @@ int cmd_annotate(int argc, const char **argv)
471 .attr = perf_event__process_attr, 480 .attr = perf_event__process_attr,
472 .build_id = perf_event__process_build_id, 481 .build_id = perf_event__process_build_id,
473 .tracing_data = perf_event__process_tracing_data, 482 .tracing_data = perf_event__process_tracing_data,
474 .feature = perf_event__process_feature, 483 .feature = process_feature_event,
475 .ordered_events = true, 484 .ordered_events = true,
476 .ordering_requires_timestamps = true, 485 .ordering_requires_timestamps = true,
477 }, 486 },
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index cdb5b6949832..c04dc7b53797 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -217,7 +217,8 @@ static int process_feature_event(struct perf_tool *tool,
217 } 217 }
218 218
219 /* 219 /*
220 * All features are received, we can force the 220 * (feat_id = HEADER_LAST_FEATURE) is the end marker which
221 * means all features are received, now we can force the
221 * group if needed. 222 * group if needed.
222 */ 223 */
223 setup_forced_leader(rep, session->evlist); 224 setup_forced_leader(rep, session->evlist);
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index ad2ac1300420..568ddfac3213 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -3044,6 +3044,15 @@ int process_cpu_map_event(struct perf_tool *tool __maybe_unused,
3044 return set_maps(script); 3044 return set_maps(script);
3045} 3045}
3046 3046
3047static int process_feature_event(struct perf_tool *tool,
3048 union perf_event *event,
3049 struct perf_session *session)
3050{
3051 if (event->feat.feat_id < HEADER_LAST_FEATURE)
3052 return perf_event__process_feature(tool, event, session);
3053 return 0;
3054}
3055
3047#ifdef HAVE_AUXTRACE_SUPPORT 3056#ifdef HAVE_AUXTRACE_SUPPORT
3048static int perf_script__process_auxtrace_info(struct perf_tool *tool, 3057static int perf_script__process_auxtrace_info(struct perf_tool *tool,
3049 union perf_event *event, 3058 union perf_event *event,
@@ -3088,7 +3097,7 @@ int cmd_script(int argc, const char **argv)
3088 .attr = process_attr, 3097 .attr = process_attr,
3089 .event_update = perf_event__process_event_update, 3098 .event_update = perf_event__process_event_update,
3090 .tracing_data = perf_event__process_tracing_data, 3099 .tracing_data = perf_event__process_tracing_data,
3091 .feature = perf_event__process_feature, 3100 .feature = process_feature_event,
3092 .build_id = perf_event__process_build_id, 3101 .build_id = perf_event__process_build_id,
3093 .id_index = perf_event__process_id_index, 3102 .id_index = perf_event__process_id_index,
3094 .auxtrace_info = perf_script__process_auxtrace_info, 3103 .auxtrace_info = perf_script__process_auxtrace_info,
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 59fcc790c865..653ff65aa2c3 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -3464,7 +3464,7 @@ int perf_event__process_feature(struct perf_tool *tool,
3464 pr_warning("invalid record type %d in pipe-mode\n", type); 3464 pr_warning("invalid record type %d in pipe-mode\n", type);
3465 return 0; 3465 return 0;
3466 } 3466 }
3467 if (feat == HEADER_RESERVED || feat > HEADER_LAST_FEATURE) { 3467 if (feat == HEADER_RESERVED || feat >= HEADER_LAST_FEATURE) {
3468 pr_warning("invalid record type %d in pipe-mode\n", type); 3468 pr_warning("invalid record type %d in pipe-mode\n", type);
3469 return -1; 3469 return -1;
3470 } 3470 }