Skip to content

Commit 1a096ae

Browse files
Jackie Liuacmel
authored andcommitted
perf top: Fix BPF support related crash with perf_event_paranoid=3 + kptr_restrict
After installing the libelf-dev package and compiling perf, if we have kptr_restrict=2 and perf_event_paranoid=3 'perf top' will 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 check before use. Also plug some leaks on the error path. Suggested-by: Jiri Olsa <[email protected]> Signed-off-by: Jackie Liu <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: jackie liu <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent e406477 commit 1a096ae

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

tools/perf/util/bpf-event.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,25 +196,32 @@ static int perf_event__synthesize_one_bpf_prog(struct perf_session *session,
196196
}
197197

198198
if (info_linear->info_len < offsetof(struct bpf_prog_info, prog_tags)) {
199+
free(info_linear);
199200
pr_debug("%s: the kernel is too old, aborting\n", __func__);
200201
return -2;
201202
}
202203

203204
info = &info_linear->info;
205+
if (!info->jited_ksyms) {
206+
free(info_linear);
207+
return -1;
208+
}
204209

205210
/* number of ksyms, func_lengths, and tags should match */
206211
sub_prog_cnt = info->nr_jited_ksyms;
207212
if (sub_prog_cnt != info->nr_prog_tags ||
208-
sub_prog_cnt != info->nr_jited_func_lens)
213+
sub_prog_cnt != info->nr_jited_func_lens) {
214+
free(info_linear);
209215
return -1;
216+
}
210217

211218
/* check BTF func info support */
212219
if (info->btf_id && info->nr_func_info && info->func_info_rec_size) {
213220
/* btf func info number should be same as sub_prog_cnt */
214221
if (sub_prog_cnt != info->nr_func_info) {
215222
pr_debug("%s: mismatch in BPF sub program count and BTF function info count, aborting\n", __func__);
216-
err = -1;
217-
goto out;
223+
free(info_linear);
224+
return -1;
218225
}
219226
if (btf__get_from_id(info->btf_id, &btf)) {
220227
pr_debug("%s: failed to get BTF of id %u, aborting\n", __func__, info->btf_id);

0 commit comments

Comments
 (0)