Skip to contentSkip to conversation

bpf: fix bpf_prog_get_info_by_fd to return 0 func_lens for unpriv

PATCH Applied Daniel Borkmann 3 participants 3 messages Nov 2, 2018 – Nov 3, 2018

Subsystems (4)
lore
Share & tools
lore

Daniel Borkmann

author maintainer
#0 lore raw

PATCH 1/1 bpf: fix bpf_prog_get_info_by_fd to return 0 func_lens for unpriv

While dbecd7388476 ("bpf: get kernel symbol addresses via syscall") zeroed info.nr_jited_ksyms in bpf_prog_get_info_by_fd() for queries from unprivileged users, commit 815581c11cc2 ("bpf: get JITed image lengths of functions via syscall") forgot about doing so and therefore returns the #elems of the user set up buffer which is incorrect. It also needs to indicate a info.nr_jited_func_lens of zero.

Fixes 815581c11cc2 ("bpf: get JITed image lengths of functions via syscall")
Cc Sandipan Das <[email protected]>
Cc Song Liu <[email protected]>
---
 kernel/bpf/syscall.c | 1 +
 1 file changed, 1 insertion(+)
kernel/bpf/syscall.c +1 -0
index ccb9327..1ea5ce1 100644
@@ -2078,6 +2078,7 @@ static int bpf_prog_get_info_by_fd(struct bpf_prog *prog,
 		info.jited_prog_len = 0;
 		info.xlated_prog_len = 0;
 		info.nr_jited_ksyms = 0;
+		info.nr_jited_func_lens = 0;
 		goto done;
 	}
 
Signature · 1 line
2.9.5
#1 lore raw
Quoted 20 lines · Daniel Borkmann

While dbecd7388476 ("bpf: get kernel symbol addresses via syscall") zeroed info.nr_jited_ksyms in bpf_prog_get_info_by_fd() for queries from unprivileged users, commit 815581c11cc2 ("bpf: get JITed image lengths of functions via syscall") forgot about doing so and therefore returns the #elems of the user set up buffer which is incorrect. It also needs to indicate a info.nr_jited_func_lens of zero.

Fixes 815581c11cc2 ("bpf: get JITed image lengths of functions via syscall")
Cc Sandipan Das <[email protected]>
Cc Song Liu <[email protected]>
---
 kernel/bpf/syscall.c | 1 +
 1 file changed, 1 insertion(+)
kernel/bpf/syscall.c +0 -0
index ccb9327..1ea5ce1 100644

kernel/bpf/syscall.c static int bpf_prog_get_info_by_fd(struct bpf_prog *prog, · line 2084

Quoted 7 lines
kernel/bpf/syscall.c +1 -0
@@ -2078,6 +2078,7 @@ static int bpf_prog_get_info_by_fd(struct bpf_prog *prog,
 		info.jited_prog_len = 0;
 		info.xlated_prog_len = 0;
 		info.nr_jited_ksyms = 0;
+		info.nr_jited_func_lens = 0;
 		goto done;
 	}
 

Looks good. Thanks for fixing this.

- Sandipan

#2 lore raw
In reply to Daniel Borkmann
Quoted 11 lines · Daniel Borkmann

While dbecd7388476 ("bpf: get kernel symbol addresses via syscall") zeroed info.nr_jited_ksyms in bpf_prog_get_info_by_fd() for queries from unprivileged users, commit 815581c11cc2 ("bpf: get JITed image lengths of functions via syscall") forgot about doing so and therefore returns the #elems of the user set up buffer which is incorrect. It also needs to indicate a info.nr_jited_func_lens of zero.

Fixes 815581c11cc2 ("bpf: get JITed image lengths of functions via syscall")
Cc Sandipan Das <[email protected]>
Cc Song Liu <[email protected]>

Applied, Thanks