bpf: Remove duplicate PTR_TO_BTF_ID RO check
authorDaniel Xu <dxu@dxuuu.xyz>
Wed, 7 Sep 2022 16:40:36 +0000 (10:40 -0600)
committerAlexei Starovoitov <ast@kernel.org>
Sun, 11 Sep 2022 00:27:32 +0000 (17:27 -0700)
Since commit 27ae7997a661 ("bpf: Introduce BPF_PROG_TYPE_STRUCT_OPS")
there has existed bpf_verifier_ops:btf_struct_access. When
btf_struct_access is _unset_ for a prog type, the verifier runs the
default implementation, which is to enforce read only:

        if (env->ops->btf_struct_access) {
                [...]
        } else {
                if (atype != BPF_READ) {
                        verbose(env, "only read is supported\n");
                        return -EACCES;
                }

                [...]
        }

When btf_struct_access is _set_, the expectation is that
btf_struct_access has full control over accesses, including if writes
are allowed.

Rather than carve out an exception for each prog type that may write to
BTF ptrs, delete the redundant check and give full control to
btf_struct_access.

Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
Acked-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Link: https://lore.kernel.org/r/962da2bff1238746589e332ff1aecc49403cd7ce.1662568410.git.dxu@dxuuu.xyz
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/verifier.c

index c0f175ac187af05b0d3f5fa7f19e205c62e2f54f..c3efd461f36c93580b874f77eb057beef99a668f 100644 (file)
@@ -13406,9 +13406,6 @@ static int convert_ctx_accesses(struct bpf_verifier_env *env)
                                insn->code = BPF_LDX | BPF_PROBE_MEM |
                                        BPF_SIZE((insn)->code);
                                env->prog->aux->num_exentries++;
-                       } else if (resolve_prog_type(env->prog) != BPF_PROG_TYPE_STRUCT_OPS) {
-                               verbose(env, "Writes through BTF pointers are not allowed\n");
-                               return -EINVAL;
                        }
                        continue;
                default: