bpf: Support bpf_kptr_xchg into local kptr
authorDave Marchevsky <davemarchevsky@fb.com>
Tue, 13 Aug 2024 21:24:23 +0000 (21:24 +0000)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 23 Aug 2024 18:39:33 +0000 (11:39 -0700)
commitb0966c724584a5a9fd7fb529de19807c31f27a45
treee86b3cdd3565ea6cb866b565cf8503c992be0522
parentd59232afb0344e33e9399f308d9b4a03876e7676
bpf: Support bpf_kptr_xchg into local kptr

Currently, users can only stash kptr into map values with bpf_kptr_xchg().
This patch further supports stashing kptr into local kptr by adding local
kptr as a valid destination type.

When stashing into local kptr, btf_record in program BTF is used instead
of btf_record in map to search for the btf_field of the local kptr.

The local kptr specific checks in check_reg_type() only apply when the
source argument of bpf_kptr_xchg() is local kptr. Therefore, we make the
scope of the check explicit as the destination now can also be local kptr.

Acked-by: Martin KaFai Lau <martin.lau@kernel.org>
Signed-off-by: Dave Marchevsky <davemarchevsky@fb.com>
Signed-off-by: Amery Hung <amery.hung@bytedance.com>
Link: https://lore.kernel.org/r/20240813212424.2871455-5-amery.hung@bytedance.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
include/uapi/linux/bpf.h
kernel/bpf/helpers.c
kernel/bpf/verifier.c