* [PATCH net] bpf: fix bpf_prog_get_info_by_fd to dump correct xlated_prog_len
@ 2017-07-28 15:05 Daniel Borkmann
2017-07-29 8:18 ` Martin KaFai Lau
2017-07-30 6:30 ` David Miller
0 siblings, 2 replies; 3+ messages in thread
From: Daniel Borkmann @ 2017-07-28 15:05 UTC (permalink / raw)
To: davem; +Cc: kafai, alexei.starovoitov, netdev, Daniel Borkmann
bpf_prog_size(prog->len) is not the correct length we want to dump
back to user space. The code in bpf_prog_get_info_by_fd() uses this
to copy prog->insnsi to user space, but bpf_prog_size(prog->len) also
includes the size of struct bpf_prog itself plus program instructions
and is usually used either in context of accounting or for bpf_prog_alloc()
et al, thus we copy out of bounds in bpf_prog_get_info_by_fd()
potentially. Use the correct bpf_prog_insn_size() instead.
Fixes: 1e2709769086 ("bpf: Add BPF_OBJ_GET_INFO_BY_FD")
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
---
kernel/bpf/syscall.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 84bb399..6c772ad 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -1312,7 +1312,7 @@ static int bpf_prog_get_info_by_fd(struct bpf_prog *prog,
}
ulen = info.xlated_prog_len;
- info.xlated_prog_len = bpf_prog_size(prog->len);
+ info.xlated_prog_len = bpf_prog_insn_size(prog);
if (info.xlated_prog_len && ulen) {
uinsns = u64_to_user_ptr(info.xlated_prog_insns);
ulen = min_t(u32, info.xlated_prog_len, ulen);
--
1.9.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net] bpf: fix bpf_prog_get_info_by_fd to dump correct xlated_prog_len
2017-07-28 15:05 [PATCH net] bpf: fix bpf_prog_get_info_by_fd to dump correct xlated_prog_len Daniel Borkmann
@ 2017-07-29 8:18 ` Martin KaFai Lau
2017-07-30 6:30 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: Martin KaFai Lau @ 2017-07-29 8:18 UTC (permalink / raw)
To: Daniel Borkmann; +Cc: davem, kafai, alexei.starovoitov, netdev
On Fri, Jul 28, 2017 at 11:05 PM, Daniel Borkmann <daniel@iogearbox.net> wrote:
> bpf_prog_size(prog->len) is not the correct length we want to dump
> back to user space. The code in bpf_prog_get_info_by_fd() uses this
> to copy prog->insnsi to user space, but bpf_prog_size(prog->len) also
> includes the size of struct bpf_prog itself plus program instructions
> and is usually used either in context of accounting or for bpf_prog_alloc()
> et al, thus we copy out of bounds in bpf_prog_get_info_by_fd()
> potentially. Use the correct bpf_prog_insn_size() instead.
Acked-by: Martin KaFai Lau <kafai@fb.com>
>
> Fixes: 1e2709769086 ("bpf: Add BPF_OBJ_GET_INFO_BY_FD")
> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
> ---
> kernel/bpf/syscall.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
> index 84bb399..6c772ad 100644
> --- a/kernel/bpf/syscall.c
> +++ b/kernel/bpf/syscall.c
> @@ -1312,7 +1312,7 @@ static int bpf_prog_get_info_by_fd(struct bpf_prog *prog,
> }
>
> ulen = info.xlated_prog_len;
> - info.xlated_prog_len = bpf_prog_size(prog->len);
> + info.xlated_prog_len = bpf_prog_insn_size(prog);
> if (info.xlated_prog_len && ulen) {
> uinsns = u64_to_user_ptr(info.xlated_prog_insns);
> ulen = min_t(u32, info.xlated_prog_len, ulen);
> --
> 1.9.3
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net] bpf: fix bpf_prog_get_info_by_fd to dump correct xlated_prog_len
2017-07-28 15:05 [PATCH net] bpf: fix bpf_prog_get_info_by_fd to dump correct xlated_prog_len Daniel Borkmann
2017-07-29 8:18 ` Martin KaFai Lau
@ 2017-07-30 6:30 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2017-07-30 6:30 UTC (permalink / raw)
To: daniel; +Cc: kafai, alexei.starovoitov, netdev
From: Daniel Borkmann <daniel@iogearbox.net>
Date: Fri, 28 Jul 2017 17:05:25 +0200
> bpf_prog_size(prog->len) is not the correct length we want to dump
> back to user space. The code in bpf_prog_get_info_by_fd() uses this
> to copy prog->insnsi to user space, but bpf_prog_size(prog->len) also
> includes the size of struct bpf_prog itself plus program instructions
> and is usually used either in context of accounting or for bpf_prog_alloc()
> et al, thus we copy out of bounds in bpf_prog_get_info_by_fd()
> potentially. Use the correct bpf_prog_insn_size() instead.
>
> Fixes: 1e2709769086 ("bpf: Add BPF_OBJ_GET_INFO_BY_FD")
> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Applied, thanks Daniel.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-07-30 6:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-28 15:05 [PATCH net] bpf: fix bpf_prog_get_info_by_fd to dump correct xlated_prog_len Daniel Borkmann
2017-07-29 8:18 ` Martin KaFai Lau
2017-07-30 6:30 ` David Miller
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.