Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <jolsa@redhat.com>
Signed-off-by: Jackie 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.cn
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Jackie Liu and committed by
Arnaldo Carvalho de Melo
1a096ae4 e4064776

+10 -3
+10 -3
tools/perf/util/bpf-event.c
··· 196 196 } 197 197 198 198 if (info_linear->info_len < offsetof(struct bpf_prog_info, prog_tags)) { 199 + free(info_linear); 199 200 pr_debug("%s: the kernel is too old, aborting\n", __func__); 200 201 return -2; 201 202 } 202 203 203 204 info = &info_linear->info; 205 + if (!info->jited_ksyms) { 206 + free(info_linear); 207 + return -1; 208 + } 204 209 205 210 /* number of ksyms, func_lengths, and tags should match */ 206 211 sub_prog_cnt = info->nr_jited_ksyms; 207 212 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); 209 215 return -1; 216 + } 210 217 211 218 /* check BTF func info support */ 212 219 if (info->btf_id && info->nr_func_info && info->func_info_rec_size) { 213 220 /* btf func info number should be same as sub_prog_cnt */ 214 221 if (sub_prog_cnt != info->nr_func_info) { 215 222 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; 218 225 } 219 226 if (btf__get_from_id(info->btf_id, &btf)) { 220 227 pr_debug("%s: failed to get BTF of id %u, aborting\n", __func__, info->btf_id);