diff options
author | Andrii Nakryiko <andrii@kernel.org> | 2023-03-03 00:50:10 +0100 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2023-03-04 20:14:32 +0100 |
commit | f4b4eee6169bb33c5157ebe07e53d7e4be7631c0 (patch) | |
tree | d251cda307aaca61992ee1915cc255f9c2ee6166 /kernel/bpf/verifier.c | |
parent | bpf: generalize dynptr_get_spi to be usable for iters (diff) | |
download | linux-f4b4eee6169bb33c5157ebe07e53d7e4be7631c0.tar.xz linux-f4b4eee6169bb33c5157ebe07e53d7e4be7631c0.zip |
bpf: add support for fixed-size memory pointer returns for kfuncs
Support direct fixed-size (and for now, read-only) memory access when
kfunc's return type is a pointer to non-struct type. Calculate type size
and let BPF program access that many bytes directly. This is crucial for
numbers iterator.
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20230302235015.2044271-13-andrii@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to '')
-rw-r--r-- | kernel/bpf/verifier.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index c4151c9efe24..b2116ca78d9a 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -10337,6 +10337,14 @@ static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn, } } else if (!__btf_type_is_struct(ptr_type)) { if (!meta.r0_size) { + __u32 sz; + + if (!IS_ERR(btf_resolve_size(desc_btf, ptr_type, &sz))) { + meta.r0_size = sz; + meta.r0_rdonly = true; + } + } + if (!meta.r0_size) { ptr_type_name = btf_name_by_offset(desc_btf, ptr_type->name_off); verbose(env, |