bpf: teach refsafe() to take into account ID remapping
[platform/kernel/linux-starfive.git] / kernel / bpf / verifier.c
index faa358b..ab8337f 100644 (file)
@@ -13223,12 +13223,20 @@ static bool stacksafe(struct bpf_verifier_env *env, struct bpf_func_state *old,
        return true;
 }
 
-static bool refsafe(struct bpf_func_state *old, struct bpf_func_state *cur)
+static bool refsafe(struct bpf_func_state *old, struct bpf_func_state *cur,
+                   struct bpf_id_pair *idmap)
 {
+       int i;
+
        if (old->acquired_refs != cur->acquired_refs)
                return false;
-       return !memcmp(old->refs, cur->refs,
-                      sizeof(*old->refs) * old->acquired_refs);
+
+       for (i = 0; i < old->acquired_refs; i++) {
+               if (!check_ids(old->refs[i].id, cur->refs[i].id, idmap))
+                       return false;
+       }
+
+       return true;
 }
 
 /* compare two verifier states
@@ -13270,7 +13278,7 @@ static bool func_states_equal(struct bpf_verifier_env *env, struct bpf_func_stat
        if (!stacksafe(env, old, cur, env->idmap_scratch))
                return false;
 
-       if (!refsafe(old, cur))
+       if (!refsafe(old, cur, env->idmap_scratch))
                return false;
 
        return true;