Commit 5ca0732
committed
bpf: Fix ringbuf memory type confusion when passing to helpers
jira VULN-72
cve CVE-2021-4204
commit-author Daniel Borkmann <daniel@iogearbox.net>
commit a672b2e
The bpf_ringbuf_submit() and bpf_ringbuf_discard() have ARG_PTR_TO_ALLOC_MEM
in their bpf_func_proto definition as their first argument, and thus both expect
the result from a prior bpf_ringbuf_reserve() call which has a return type of
RET_PTR_TO_ALLOC_MEM_OR_NULL.
While the non-NULL memory from bpf_ringbuf_reserve() can be passed to other
helpers, the two sinks (bpf_ringbuf_submit(), bpf_ringbuf_discard()) right now
only enforce a register type of PTR_TO_MEM.
This can lead to potential type confusion since it would allow other PTR_TO_MEM
memory to be passed into the two sinks which did not come from bpf_ringbuf_reserve().
Add a new MEM_ALLOC composable type attribute for PTR_TO_MEM, and enforce that:
- bpf_ringbuf_reserve() returns NULL or PTR_TO_MEM | MEM_ALLOC
- bpf_ringbuf_submit() and bpf_ringbuf_discard() only take PTR_TO_MEM | MEM_ALLOC
but not plain PTR_TO_MEM arguments via ARG_PTR_TO_ALLOC_MEM
- however, other helpers might treat PTR_TO_MEM | MEM_ALLOC as plain PTR_TO_MEM
to populate the memory area when they use ARG_PTR_TO_{UNINIT_,}MEM in their
func proto description
Fixes: 457f443 ("bpf: Implement BPF ring buffer and verifier support for it")
Reported-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
(cherry picked from commit a672b2e)
Signed-off-by: Brett Mastbergen <bmastbergen@ciq.com>1 parent 2340247 commit 5ca0732
2 files changed
+12
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
298 | 298 | | |
299 | 299 | | |
300 | 300 | | |
301 | | - | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
302 | 307 | | |
303 | 308 | | |
304 | 309 | | |
| |||
381 | 386 | | |
382 | 387 | | |
383 | 388 | | |
384 | | - | |
| 389 | + | |
385 | 390 | | |
386 | 391 | | |
387 | 392 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
574 | 574 | | |
575 | 575 | | |
576 | 576 | | |
| 577 | + | |
| 578 | + | |
577 | 579 | | |
578 | 580 | | |
579 | 581 | | |
| |||
4758 | 4760 | | |
4759 | 4761 | | |
4760 | 4762 | | |
| 4763 | + | |
4761 | 4764 | | |
4762 | 4765 | | |
4763 | 4766 | | |
| |||
4775 | 4778 | | |
4776 | 4779 | | |
4777 | 4780 | | |
4778 | | - | |
| 4781 | + | |
4779 | 4782 | | |
4780 | 4783 | | |
4781 | 4784 | | |
| |||
4936 | 4939 | | |
4937 | 4940 | | |
4938 | 4941 | | |
| 4942 | + | |
4939 | 4943 | | |
4940 | 4944 | | |
4941 | 4945 | | |
| |||
0 commit comments