Commit 1a096ae4 authored by Jackie Liu's avatar Jackie Liu Committed by Arnaldo Carvalho de Melo

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: default avatarJiri Olsa <jolsa@redhat.com>
Signed-off-by: default avatarJackie Liu <liuyun01@kylinos.cn>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: jackie liu <liuyun01@kylinos.cn>
Link: http://lore.kernel.org/lkml/20210316012453.1156-1-liuyun01@kylinos.cnSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent e4064776
...@@ -196,25 +196,32 @@ static int perf_event__synthesize_one_bpf_prog(struct perf_session *session, ...@@ -196,25 +196,32 @@ static int perf_event__synthesize_one_bpf_prog(struct perf_session *session,
} }
if (info_linear->info_len < offsetof(struct bpf_prog_info, prog_tags)) { if (info_linear->info_len < offsetof(struct bpf_prog_info, prog_tags)) {
free(info_linear);
pr_debug("%s: the kernel is too old, aborting\n", __func__); pr_debug("%s: the kernel is too old, aborting\n", __func__);
return -2; return -2;
} }
info = &info_linear->info; info = &info_linear->info;
if (!info->jited_ksyms) {
free(info_linear);
return -1;
}
/* number of ksyms, func_lengths, and tags should match */ /* number of ksyms, func_lengths, and tags should match */
sub_prog_cnt = info->nr_jited_ksyms; sub_prog_cnt = info->nr_jited_ksyms;
if (sub_prog_cnt != info->nr_prog_tags || if (sub_prog_cnt != info->nr_prog_tags ||
sub_prog_cnt != info->nr_jited_func_lens) sub_prog_cnt != info->nr_jited_func_lens) {
free(info_linear);
return -1; return -1;
}
/* check BTF func info support */ /* check BTF func info support */
if (info->btf_id && info->nr_func_info && info->func_info_rec_size) { if (info->btf_id && info->nr_func_info && info->func_info_rec_size) {
/* btf func info number should be same as sub_prog_cnt */ /* btf func info number should be same as sub_prog_cnt */
if (sub_prog_cnt != info->nr_func_info) { if (sub_prog_cnt != info->nr_func_info) {
pr_debug("%s: mismatch in BPF sub program count and BTF function info count, aborting\n", __func__); pr_debug("%s: mismatch in BPF sub program count and BTF function info count, aborting\n", __func__);
err = -1; free(info_linear);
goto out; return -1;
} }
if (btf__get_from_id(info->btf_id, &btf)) { if (btf__get_from_id(info->btf_id, &btf)) {
pr_debug("%s: failed to get BTF of id %u, aborting\n", __func__, info->btf_id); pr_debug("%s: failed to get BTF of id %u, aborting\n", __func__, info->btf_id);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment