Skip to content

Commit 12d790e

Browse files
Luigi Rizzokernel-patches-bot
authored andcommitted
use valid btf in bpf_program__set_attach_target(prog, 0, ...);
bpf_program__set_attach_target() will always fail with fd=0 (attach to a kernel symbol) because obj->btf_vmlinux is NULL and there is no way to set it. Fix this by explicitly calling libbpf_find_kernel_btf() in the function. Signed-off-by: Luigi Rizzo <[email protected]>
1 parent 3aceec8 commit 12d790e

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

tools/lib/bpf/libbpf.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10438,10 +10438,13 @@ int bpf_program__set_attach_target(struct bpf_program *prog,
1043810438
if (attach_prog_fd)
1043910439
btf_id = libbpf_find_prog_btf_id(attach_func_name,
1044010440
attach_prog_fd);
10441-
else
10442-
btf_id = __find_vmlinux_btf_id(prog->obj->btf_vmlinux,
10443-
attach_func_name,
10441+
else {
10442+
struct btf *btf = libbpf_find_kernel_btf();
10443+
10444+
btf_id = __find_vmlinux_btf_id(btf, attach_func_name,
1044410445
prog->expected_attach_type);
10446+
btf__free(btf);
10447+
}
1044510448

1044610449
if (btf_id < 0)
1044710450
return btf_id;

0 commit comments

Comments
 (0)