bpf: Fix PTR_TO_BTF_ID var_off check
[linux-2.6-microblaze.git] / kernel / bpf / btf.c
index b472cf0..7f6a0ae 100644 (file)
@@ -5726,7 +5726,7 @@ static int btf_check_func_arg_match(struct bpf_verifier_env *env,
        const char *func_name, *ref_tname;
        const struct btf_type *t, *ref_t;
        const struct btf_param *args;
-       int ref_regno = 0;
+       int ref_regno = 0, ret;
        bool rel = false;
 
        t = btf_type_by_id(btf, func_id);
@@ -5776,6 +5776,11 @@ static int btf_check_func_arg_match(struct bpf_verifier_env *env,
 
                ref_t = btf_type_skip_modifiers(btf, t->type, &ref_id);
                ref_tname = btf_name_by_offset(btf, ref_t->name_off);
+
+               ret = check_func_arg_reg_off(env, reg, regno, ARG_DONTCARE);
+               if (ret < 0)
+                       return ret;
+
                if (btf_get_prog_ctx_type(log, btf, t,
                                          env->prog->type, i)) {
                        /* If function expects ctx type in BTF check that caller
@@ -5787,8 +5792,6 @@ static int btf_check_func_arg_match(struct bpf_verifier_env *env,
                                        i, btf_type_str(t));
                                return -EINVAL;
                        }
-                       if (check_ptr_off_reg(env, reg, regno))
-                               return -EINVAL;
                } else if (is_kfunc && (reg->type == PTR_TO_BTF_ID ||
                           (reg2btf_ids[base_type(reg->type)] && !type_flag(reg->type)))) {
                        const struct btf_type *reg_ref_t;