[PATCH v3] bpftool: fix potential NULL pointer dereferencing in prog_dump()

Amir Mohammadi posted 1 patch 20 hours ago
tools/bpf/bpftool/prog.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
[PATCH v3] bpftool: fix potential NULL pointer dereferencing in prog_dump()
Posted by Amir Mohammadi 20 hours ago
A NULL pointer dereference could occur if ksyms
is not properly checked before usage in the prog_dump() function.

Fixes: b053b439b72a ("bpf: libbpf: bpftool: Print bpf_line_info during prog dump")
Signed-off-by: Amir Mohammadi <amiremohamadi@yahoo.com>
---
 tools/bpf/bpftool/prog.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c
index 2ff949ea8..e71be67f1 100644
--- a/tools/bpf/bpftool/prog.c
+++ b/tools/bpf/bpftool/prog.c
@@ -822,11 +822,18 @@ prog_dump(struct bpf_prog_info *info, enum dump_mode mode,
 					printf("%s:\n", sym_name);
 				}
 
-				if (disasm_print_insn(img, lens[i], opcodes,
-						      name, disasm_opt, btf,
-						      prog_linfo, ksyms[i], i,
-						      linum))
-					goto exit_free;
+				if (ksyms) {
+					if (disasm_print_insn(img, lens[i], opcodes,
+							      name, disasm_opt, btf,
+							      prog_linfo, ksyms[i], i,
+							      linum))
+						goto exit_free;
+				} else {
+					if (disasm_print_insn(img, lens[i], opcodes,
+							      name, disasm_opt, btf,
+							      NULL, 0, 0, false))
+						goto exit_free;
+				}
 
 				img += lens[i];
 
-- 
2.42.0
Re: [PATCH v3] bpftool: fix potential NULL pointer dereferencing in prog_dump()
Posted by Quentin Monnet 17 hours ago
2024-11-21 12:04 UTC+0330 ~ Amir Mohammadi <amirmohammadi1999.am@gmail.com>
> A NULL pointer dereference could occur if ksyms
> is not properly checked before usage in the prog_dump() function.
> 
> Fixes: b053b439b72a ("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>

Thanks!
Re: [PATCH v3] bpftool: fix potential NULL pointer dereferencing in prog_dump()
Posted by John Fastabend 5 hours ago
Quentin Monnet wrote:
> 2024-11-21 12:04 UTC+0330 ~ Amir Mohammadi <amirmohammadi1999.am@gmail.com>
> > A NULL pointer dereference could occur if ksyms
> > is not properly checked before usage in the prog_dump() function.
> > 
> > Fixes: b053b439b72a ("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>
> 
> Thanks!

Acked-by: John Fastabend <john.fastabend@gmail.com>