Commit c3416c9
committed
bpf: Check PTR_TO_MEM | MEM_RDONLY in check_helper_mem_access
jira VULN-136
cve CVE-2022-0500
commit-author Kumar Kartikeya Dwivedi <[email protected]>
commit 97e6d7d
The commit being fixed was aiming to disallow users from incorrectly
obtaining writable pointer to memory that is only meant to be read. This
is enforced now using a MEM_RDONLY flag.
For instance, in case of global percpu variables, when the BTF type is
not struct (e.g. bpf_prog_active), the verifier marks register type as
PTR_TO_MEM | MEM_RDONLY from bpf_this_cpu_ptr or bpf_per_cpu_ptr
helpers. However, when passing such pointer to kfunc, global funcs, or
BPF helpers, in check_helper_mem_access, there is no expectation
MEM_RDONLY flag will be set, hence it is checked as pointer to writable
memory. Later, verifier sets up argument type of global func as
PTR_TO_MEM | PTR_MAYBE_NULL, so user can use a global func to get around
the limitations imposed by this flag.
This check will also cover global non-percpu variables that may be
introduced in kernel BTF in future.
Also, we update the log message for PTR_TO_BUF case to be similar to
PTR_TO_MEM case, so that the reason for error is clear to user.
Fixes: 34d3a78 ("bpf: Make per_cpu_ptr return rdonly PTR_TO_MEM.")
Reviewed-by: Hao Luo <[email protected]>
Signed-off-by: Kumar Kartikeya Dwivedi <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Alexei Starovoitov <[email protected]>
(cherry picked from commit 97e6d7d)
Signed-off-by: Brett Mastbergen <[email protected]>1 parent 007ca93 commit c3416c9
1 file changed
+11
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4496 | 4496 | | |
4497 | 4497 | | |
4498 | 4498 | | |
| 4499 | + | |
| 4500 | + | |
| 4501 | + | |
| 4502 | + | |
| 4503 | + | |
| 4504 | + | |
| 4505 | + | |
4499 | 4506 | | |
4500 | 4507 | | |
4501 | 4508 | | |
4502 | 4509 | | |
4503 | 4510 | | |
4504 | | - | |
| 4511 | + | |
| 4512 | + | |
| 4513 | + | |
4505 | 4514 | | |
| 4515 | + | |
4506 | 4516 | | |
4507 | 4517 | | |
4508 | 4518 | | |
| |||
0 commit comments