]> git.baikalelectronics.ru Git - kernel.git/commit
bpf: Do write access check for kfunc and global func
authorKumar Kartikeya Dwivedi <memxor@gmail.com>
Sat, 19 Mar 2022 08:08:23 +0000 (13:38 +0530)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 6 Apr 2022 17:32:12 +0000 (10:32 -0700)
commit5ad3cf5e98ee8e4145daccdaff4bc9f7e09ddbac
tree41583e459f138fe44366ed0beb6a0900c9955d1f
parent3a29ef2299e6f4ef120f2b3ee742d57b1aa573fc
bpf: Do write access check for kfunc and global func

When passing pointer to some map value to kfunc or global func, in
verifier we are passing meta as NULL to various functions, which uses
meta->raw_mode to check whether memory is being written to. Since some
kfunc or global funcs may also write to memory pointers they receive as
arguments, we must check for write access to memory. E.g. in some case
map may be read only and this will be missed by current checks.

However meta->raw_mode allows for uninitialized memory (e.g. on stack),
since there is not enough info available through BTF, we must perform
one call for read access (raw_mode = false), and one for write access
(raw_mode = true).

Fixes: 48aef838dcd2 ("bpf: Support pointers in global func args")
Fixes: d68c8ac846fb ("bpf: Introduce mem, size argument pair support for kfunc")
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Link: https://lore.kernel.org/r/20220319080827.73251-2-memxor@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/verifier.c