[PATCH v2] perf tools: perf_event_paranoid and kptr_restrict may crash on 'perf top'

From: Jackie Liu
Date: Thu Feb 25 2021 - 01:28:10 EST


After install the libelf-dev package and compiling perf, kptr_restrict=2
and perf_event_paranoid=3 will cause perf top to crash, because the
value of /proc/kallsyms cannot be obtained, which leads to
info->jited_ksyms == NULL. In order to solve this problem, Add a
judgment before use.

Suggested-by: Jiri Olsa <jolsa@xxxxxxxxxx>
Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
Cc: Mark Rutland <mark.rutland@xxxxxxx>
Cc: Alexander Shishkin <alexander.shishkin@xxxxxxxxxxxxxxx>
Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
Signed-off-by: Jackie Liu <liuyun01@xxxxxxxxxx>
---
tools/perf/util/bpf-event.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/tools/perf/util/bpf-event.c b/tools/perf/util/bpf-event.c
index 57d58c81a5f8..b1ce2d189d37 100644
--- a/tools/perf/util/bpf-event.c
+++ b/tools/perf/util/bpf-event.c
@@ -225,6 +225,11 @@ static int perf_event__synthesize_one_bpf_prog(struct perf_session *session,
perf_env__fetch_btf(env, info->btf_id, btf);
}

+ if (!info->jited_ksyms) {
+ err = -1;
+ goto out;
+ }
+
/* Synthesize PERF_RECORD_KSYMBOL */
for (i = 0; i < sub_prog_cnt; i++) {
__u32 *prog_lens = (__u32 *)(uintptr_t)(info->jited_func_lens);
--
2.25.1