Commit 5b79bcdf authored by Toke Høiland-Jørgensen's avatar Toke Høiland-Jørgensen Committed by Daniel Borkmann

bpftool: Don't crash on missing jited insns or ksyms

When the kptr_restrict sysctl is set, the kernel can fail to return
jited_ksyms or jited_prog_insns, but still have positive values in
nr_jited_ksyms and jited_prog_len. This causes bpftool to crash when
trying to dump the program because it only checks the len fields not
the actual pointers to the instructions and ksyms.

Fix this by adding the missing checks.

Fixes: 71bb428f ("tools: bpf: add bpftool")
Fixes: f84192ee ("tools: bpftool: resolve calls without using imm field")
Signed-off-by: default avatarToke Høiland-Jørgensen <toke@redhat.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Acked-by: default avatarMartin KaFai Lau <kafai@fb.com>
Link: https://lore.kernel.org/bpf/20191210181412.151226-1-toke@redhat.com
parent 4c80c7bc
...@@ -493,7 +493,7 @@ static int do_dump(int argc, char **argv) ...@@ -493,7 +493,7 @@ static int do_dump(int argc, char **argv)
info = &info_linear->info; info = &info_linear->info;
if (mode == DUMP_JITED) { if (mode == DUMP_JITED) {
if (info->jited_prog_len == 0) { if (info->jited_prog_len == 0 || !info->jited_prog_insns) {
p_info("no instructions returned"); p_info("no instructions returned");
goto err_free; goto err_free;
} }
......
...@@ -174,7 +174,7 @@ static const char *print_call(void *private_data, ...@@ -174,7 +174,7 @@ static const char *print_call(void *private_data,
struct kernel_sym *sym; struct kernel_sym *sym;
if (insn->src_reg == BPF_PSEUDO_CALL && if (insn->src_reg == BPF_PSEUDO_CALL &&
(__u32) insn->imm < dd->nr_jited_ksyms) (__u32) insn->imm < dd->nr_jited_ksyms && dd->jited_ksyms)
address = dd->jited_ksyms[insn->imm]; address = dd->jited_ksyms[insn->imm];
sym = kernel_syms_search(dd, address); sym = kernel_syms_search(dd, address);
......
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