]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
bpf: verifier: bail out if the argument is not a map
authorBenjamin Tissoires <bentiss@kernel.org>
Sat, 20 Apr 2024 09:09:07 +0000 (11:09 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 24 Apr 2024 01:31:24 +0000 (18:31 -0700)
When a kfunc is declared with a KF_ARG_PTR_TO_MAP, we should have
reg->map_ptr set to a non NULL value, otherwise, that means that the
underlying type is not a map.

Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>
Link: https://lore.kernel.org/r/20240420-bpf_wq-v2-7-6c986a5a741f@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/verifier.c

index 89490a95b120300474ea98381889369caeb2858d..4adf7fc33e5af4d46bcbff7c35c8c90d2c9def50 100644 (file)
@@ -11720,6 +11720,11 @@ static int check_kfunc_args(struct bpf_verifier_env *env, struct bpf_kfunc_call_
                case KF_ARG_PTR_TO_NULL:
                        continue;
                case KF_ARG_PTR_TO_MAP:
+                       if (!reg->map_ptr) {
+                               verbose(env, "pointer in R%d isn't map pointer\n", regno);
+                               return -EINVAL;
+                       }
+                       fallthrough;
                case KF_ARG_PTR_TO_ALLOC_BTF_ID:
                case KF_ARG_PTR_TO_BTF_ID:
                        if (!is_kfunc_trusted_args(meta) && !is_kfunc_rcu(meta))