[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <tencent_410B8166C55CD2AB64BDEA8E92204619180A@qq.com>
Date: Thu, 5 Dec 2024 17:08:34 +0800
From: Rong Tao <rtoax@...mail.com>
To: rongtao@...tc.cn,
qmo@...nel.org,
ast@...nel.org
Cc: rtoax@...mail.com,
Daniel Borkmann <daniel@...earbox.net>,
Andrii Nakryiko <andrii@...nel.org>,
Martin KaFai Lau <martin.lau@...ux.dev>,
Eduard Zingerman <eddyz87@...il.com>,
Song Liu <song@...nel.org>,
Yonghong Song <yonghong.song@...ux.dev>,
John Fastabend <john.fastabend@...il.com>,
KP Singh <kpsingh@...nel.org>,
Stanislav Fomichev <sdf@...ichev.me>,
Hao Luo <haoluo@...gle.com>,
Jiri Olsa <jolsa@...nel.org>,
bpf@...r.kernel.org (open list:BPF [TOOLING] (bpftool)),
linux-kernel@...r.kernel.org (open list)
Subject: [PATCH bpf-next] bpftool: Fix gen object segfault
From: Rong Tao <rongtao@...tc.cn>
If the input file and output file are the same, the input file is cleared
due to opening, resulting in a NULL pointer access by libbpf.
$ sudo ./bpftool gen object prog.o prog.o
libbpf: failed to get ELF header for prog.o: invalid `Elf' handle
Segmentation fault
(gdb) bt
#0 0x0000000000450285 in linker_append_elf_syms (linker=0x4feda0, obj=0x7fffffffe100) at linker.c:1296
#1 bpf_linker__add_file (linker=0x4feda0, filename=<optimized out>, opts=<optimized out>) at linker.c:453
#2 0x000000000040c235 in do_object ()
#3 0x00000000004021d7 in main ()
(gdb) frame 0
#0 0x0000000000450285 in linker_append_elf_syms (linker=0x4feda0, obj=0x7fffffffe100) at linker.c:1296
1296 Elf64_Sym *sym = symtab->data->d_buf;
Signed-off-by: Rong Tao <rongtao@...tc.cn>
---
tools/bpf/bpftool/gen.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c
index 5a4d3240689e..4cd135726758 100644
--- a/tools/bpf/bpftool/gen.c
+++ b/tools/bpf/bpftool/gen.c
@@ -1896,6 +1896,11 @@ static int do_object(int argc, char **argv)
while (argc) {
file = GET_ARG();
+ if (!strcmp(file, output_file)) {
+ p_err("Input/Output file couldn't be same.");
+ goto out;
+ }
+
err = bpf_linker__add_file(linker, file, NULL);
if (err) {
p_err("failed to link '%s': %s (%d)", file, strerror(errno), errno);
--
2.47.1
Powered by blists - more mailing lists