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

bpftool: Don't crash on missing xlated program instructions

Turns out the xlated program instructions can also be missing if
kptr_restrict sysctl is set. This means that the previous fix to check the
jited_prog_insns pointer was insufficient; add another check of the
xlated_prog_insns pointer as well.

Fixes: 5b79bcdf0362 ("bpftool: Don't crash on missing jited insns or ksyms")
Fixes: cae73f233923 ("bpftool: use bpf_program__get_prog_info_linear() in prog.c:do_dump()")
Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Reviewed-by: Quentin Monnet <quentin@isovalent.com>
Link: https://lore.kernel.org/bpf/20200206102906.112551-1-toke@redhat.com

authored by

Toke Høiland-Jørgensen and committed by
Daniel Borkmann
d95f1e8b 85b8ac01

+1 -1
+1 -1
tools/bpf/bpftool/prog.c
··· 536 536 buf = (unsigned char *)(info->jited_prog_insns); 537 537 member_len = info->jited_prog_len; 538 538 } else { /* DUMP_XLATED */ 539 - if (info->xlated_prog_len == 0) { 539 + if (info->xlated_prog_len == 0 || !info->xlated_prog_insns) { 540 540 p_err("error retrieving insn dump: kernel.kptr_restrict set?"); 541 541 return -1; 542 542 }