Skip to content

Commit ef3ba8c

Browse files
amiremohamadiAlexei Starovoitov
authored andcommitted
bpftool: fix potential NULL pointer dereferencing in prog_dump()
A NULL pointer dereference could occur if ksyms is not properly checked before usage in the prog_dump() function. Fixes: b053b43 ("bpf: libbpf: bpftool: Print bpf_line_info during prog dump") Signed-off-by: Amir Mohammadi <amiremohamadi@yahoo.com> Reviewed-by: Quentin Monnet <qmo@kernel.org> Acked-by: John Fastabend <john.fastabend@gmail.com> Link: https://lore.kernel.org/r/20241121083413.7214-1-amiremohamadi@yahoo.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent ac9a48a commit ef3ba8c

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

tools/bpf/bpftool/prog.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -822,11 +822,18 @@ prog_dump(struct bpf_prog_info *info, enum dump_mode mode,
822822
printf("%s:\n", sym_name);
823823
}
824824

825-
if (disasm_print_insn(img, lens[i], opcodes,
826-
name, disasm_opt, btf,
827-
prog_linfo, ksyms[i], i,
828-
linum))
829-
goto exit_free;
825+
if (ksyms) {
826+
if (disasm_print_insn(img, lens[i], opcodes,
827+
name, disasm_opt, btf,
828+
prog_linfo, ksyms[i], i,
829+
linum))
830+
goto exit_free;
831+
} else {
832+
if (disasm_print_insn(img, lens[i], opcodes,
833+
name, disasm_opt, btf,
834+
NULL, 0, 0, false))
835+
goto exit_free;
836+
}
830837

831838
img += lens[i];
832839

0 commit comments

Comments
 (0)