]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
bpf: add support for fixed-size memory pointer returns for kfuncs
authorAndrii Nakryiko <andrii@kernel.org>
Thu, 2 Mar 2023 23:50:10 +0000 (15:50 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Sat, 4 Mar 2023 19:14:32 +0000 (11:14 -0800)
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>
kernel/bpf/verifier.c

index c4151c9efe245089834f4002ec6a02b0cf10fb47..b2116ca78d9a34ca11b480661a2c5a16ac722d1c 100644 (file)
@@ -10336,6 +10336,14 @@ static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
                                return -EFAULT;
                        }
                } 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);