]> git.baikalelectronics.ru Git - kernel.git/commit
bpf: Make per_cpu_ptr return rdonly PTR_TO_MEM.
authorHao Luo <haoluo@google.com>
Fri, 17 Dec 2021 00:31:50 +0000 (16:31 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Sat, 18 Dec 2021 21:27:41 +0000 (13:27 -0800)
commita6c797fd1942ddc47521d8efd2dd9d8b0c9833a1
treed0a60ddfc12cc916d80923b04d80f01ae69c1301
parentd01ac534157ef03cc33932de537d51f33e2a296e
bpf: Make per_cpu_ptr return rdonly PTR_TO_MEM.

Tag the return type of {per, this}_cpu_ptr with RDONLY_MEM. The
returned value of this pair of helpers is kernel object, which
can not be updated by bpf programs. Previously these two helpers
return PTR_OT_MEM for kernel objects of scalar type, which allows
one to directly modify the memory. Now with RDONLY_MEM tagging,
the verifier will reject programs that write into RDONLY_MEM.

Fixes: 8ce8b3318b85 ("bpf: Introducte bpf_this_cpu_ptr()")
Fixes: c43edca94f4c ("bpf: Introduce bpf_per_cpu_ptr()")
Fixes: 8cfdf0b426e5 ("bpf: Introduce pseudo_btf_id")
Signed-off-by: Hao Luo <haoluo@google.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20211217003152.48334-8-haoluo@google.com
kernel/bpf/helpers.c
kernel/bpf/verifier.c