summaryrefslogtreecommitdiffstats
path: root/kernel/bpf
diff options
context:
space:
mode:
authorThadeu Lima de Souza Cascardo <cascardo@canonical.com>2021-04-27 10:12:12 -0300
committerDaniel Borkmann <daniel@iogearbox.net>2021-05-11 13:30:45 +0200
commit4b81ccebaeee885ab1aa1438133f2991e3a2b6ea (patch)
treed6a39026c5a8218d08d1038b967088eaf597d088 /kernel/bpf
parent049c4e13714ecbca567b4d5f6d563f05d431c80e (diff)
downloadlinux-stable-4b81ccebaeee885ab1aa1438133f2991e3a2b6ea.tar.gz
linux-stable-4b81ccebaeee885ab1aa1438133f2991e3a2b6ea.tar.bz2
linux-stable-4b81ccebaeee885ab1aa1438133f2991e3a2b6ea.zip
bpf, ringbuf: Deny reserve of buffers larger than ringbuf
A BPF program might try to reserve a buffer larger than the ringbuf size. If the consumer pointer is way ahead of the producer, that would be successfully reserved, allowing the BPF program to read or write out of the ringbuf allocated area. Reported-by: Ryota Shiga (Flatt Security) Fixes: 457f44363a88 ("bpf: Implement BPF ring buffer and verifier support for it") Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Andrii Nakryiko <andrii@kernel.org> Acked-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'kernel/bpf')
-rw-r--r--kernel/bpf/ringbuf.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/kernel/bpf/ringbuf.c b/kernel/bpf/ringbuf.c
index f25b719ac786..b86d80c9cd59 100644
--- a/kernel/bpf/ringbuf.c
+++ b/kernel/bpf/ringbuf.c
@@ -315,6 +315,9 @@ static void *__bpf_ringbuf_reserve(struct bpf_ringbuf *rb, u64 size)
return NULL;
len = round_up(size + BPF_RINGBUF_HDR_SZ, 8);
+ if (len > rb->mask + 1)
+ return NULL;
+
cons_pos = smp_load_acquire(&rb->consumer_pos);
if (in_nmi()) {