Skip to content

Commit 752bcf8

Browse files
olsajiriborkmann
authored andcommitted
bpftool: Fix prog dump by tag
Lance reported an issue with bpftool not being able to dump program if there are more programs loaded and you want to dump any but the first program, like: # bpftool prog 28: kprobe name trace_req_start tag 1dfc28ba8b3dd597 gpl loaded_at 2019-01-18T17:02:40+1100 uid 0 xlated 112B jited 109B memlock 4096B map_ids 13 29: kprobe name trace_req_compl tag 5b6a5ecc6030a683 gpl loaded_at 2019-01-18T17:02:40+1100 uid 0 xlated 928B jited 575B memlock 4096B map_ids 13,14 # bpftool prog dum jited tag 1dfc28ba8b3dd597 0: push %rbp 1: mov %rsp,%rbp ... # bpftool prog dum jited tag 5b6a5ecc6030a683 Error: can't get prog info (29): Bad address The problem is in the prog_fd_by_tag function not cleaning the struct bpf_prog_info before another request, so the previous program length is still in there and kernel assumes it needs to dump the program, which fails because there's no user pointer set. Moving the struct bpf_prog_info declaration into the loop, so it gets cleaned before each query. Fixes: 71bb428 ("tools: bpf: add bpftool") Reported-by: Lance Digby <[email protected]> Signed-off-by: Jiri Olsa <[email protected]> Reviewed-by: Quentin Monnet <[email protected]> Acked-by: Jakub Kicinski <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]>
1 parent ab06418 commit 752bcf8

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

tools/bpf/bpftool/prog.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,14 @@ static void print_boot_time(__u64 nsecs, char *buf, unsigned int size)
7878

7979
static int prog_fd_by_tag(unsigned char *tag)
8080
{
81-
struct bpf_prog_info info = {};
82-
__u32 len = sizeof(info);
8381
unsigned int id = 0;
8482
int err;
8583
int fd;
8684

8785
while (true) {
86+
struct bpf_prog_info info = {};
87+
__u32 len = sizeof(info);
88+
8889
err = bpf_prog_get_next_id(id, &id);
8990
if (err) {
9091
p_err("%s", strerror(errno));

0 commit comments

Comments
 (0)