Daniel Borkmann 64620e0a1e bpf: Fix out of bounds access for ringbuf helpers
Both bpf_ringbuf_submit() and bpf_ringbuf_discard() have ARG_PTR_TO_ALLOC_MEM
in their bpf_func_proto definition as their first argument. They both expect
the result from a prior bpf_ringbuf_reserve() call which has a return type of
RET_PTR_TO_ALLOC_MEM_OR_NULL.

Meaning, after a NULL check in the code, the verifier will promote the register
type in the non-NULL branch to a PTR_TO_MEM and in the NULL branch to a known
zero scalar. Generally, pointer arithmetic on PTR_TO_MEM is allowed, so the
latter could have an offset.

The ARG_PTR_TO_ALLOC_MEM expects a PTR_TO_MEM register type. However, the non-
zero result from bpf_ringbuf_reserve() must be fed into either bpf_ringbuf_submit()
or bpf_ringbuf_discard() but with the original offset given it will then read
out the struct bpf_ringbuf_hdr mapping.

The verifier missed to enforce a zero offset, so that out of bounds access
can be triggered which could be used to escalate privileges if unprivileged
BPF was enabled (disabled by default in kernel).

Fixes: 457f44363a88 ("bpf: Implement BPF ring buffer and verifier support for it")
Reported-by: <tr3e.wang@gmail.com> (SecCoder Security Lab)
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
2022-01-19 01:21:39 +01:00
..
2022-01-10 19:06:09 -08:00
2021-11-09 10:56:41 -08:00
2021-12-01 00:06:43 +01:00
2021-10-19 17:27:05 +02:00
2021-12-14 18:54:34 +00:00
2021-11-01 20:05:19 -07:00
2021-11-18 10:50:45 -08:00
2021-11-01 20:25:38 -07:00
2022-01-10 19:06:09 -08:00
2021-11-01 21:17:39 -07:00
\n
2021-11-06 16:43:20 -07:00
2021-11-01 21:17:39 -07:00
2021-11-01 21:17:39 -07:00
2021-08-11 13:11:12 -07:00
2021-09-08 15:32:35 -07:00
2021-11-09 10:02:51 -08:00
2021-06-18 11:43:08 +02:00
2021-09-08 15:32:34 -07:00
2021-05-07 00:26:33 -07:00
2021-11-01 20:05:19 -07:00
2021-10-14 13:29:18 +02:00
2021-06-18 11:43:09 +02:00
2021-10-07 13:51:11 +02:00
2021-12-09 15:37:18 -06:00
2021-05-07 00:26:34 -07:00