]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
bpf/verifier: replace calls to mark_reg_unknown.
authorCupertino Miranda <cupertino.miranda@oracle.com>
Mon, 6 May 2024 14:18:44 +0000 (15:18 +0100)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 7 May 2024 00:09:11 +0000 (17:09 -0700)
In order to further simplify the code in adjust_scalar_min_max_vals all
the calls to mark_reg_unknown are replaced by __mark_reg_unknown.

static void mark_reg_unknown(struct bpf_verifier_env *env,
        struct bpf_reg_state *regs, u32 regno)
{
if (WARN_ON(regno >= MAX_BPF_REG)) {
... mark all regs not init ...
return;
    }
__mark_reg_unknown(env, regs + regno);
}

The 'regno >= MAX_BPF_REG' does not apply to
adjust_scalar_min_max_vals(), because it is only called from the
following stack:
  - check_alu_op
    - adjust_reg_min_max_vals
      - adjust_scalar_min_max_vals

The check_alu_op() does check_reg_arg() which verifies that both src and
dst register numbers are within bounds.

Signed-off-by: Cupertino Miranda <cupertino.miranda@oracle.com>
Acked-by: Eduard Zingerman <eddyz87@gmail.com>
Cc: Yonghong Song <yonghong.song@linux.dev>
Cc: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: David Faust <david.faust@oracle.com>
Cc: Jose Marchesi <jose.marchesi@oracle.com>
Cc: Elena Zannoni <elena.zannoni@oracle.com>
Cc: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Link: https://lore.kernel.org/r/20240506141849.185293-2-cupertino.miranda@oracle.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/verifier.c

index 7360f04f9ec7ba188bcc6058d31ef899ba33a8d9..41c66cc6db80fd3a6899f41af8c742265729589d 100644 (file)
@@ -13887,7 +13887,6 @@ static int adjust_scalar_min_max_vals(struct bpf_verifier_env *env,
                                      struct bpf_reg_state *dst_reg,
                                      struct bpf_reg_state src_reg)
 {
-       struct bpf_reg_state *regs = cur_regs(env);
        u8 opcode = BPF_OP(insn->code);
        bool src_known;
        s64 smin_val, smax_val;
@@ -13994,7 +13993,7 @@ static int adjust_scalar_min_max_vals(struct bpf_verifier_env *env,
                        /* Shifts greater than 31 or 63 are undefined.
                         * This includes shifts by a negative number.
                         */
-                       mark_reg_unknown(env, regs, insn->dst_reg);
+                       __mark_reg_unknown(env, dst_reg);
                        break;
                }
                if (alu32)
@@ -14007,7 +14006,7 @@ static int adjust_scalar_min_max_vals(struct bpf_verifier_env *env,
                        /* Shifts greater than 31 or 63 are undefined.
                         * This includes shifts by a negative number.
                         */
-                       mark_reg_unknown(env, regs, insn->dst_reg);
+                       __mark_reg_unknown(env, dst_reg);
                        break;
                }
                if (alu32)
@@ -14020,7 +14019,7 @@ static int adjust_scalar_min_max_vals(struct bpf_verifier_env *env,
                        /* Shifts greater than 31 or 63 are undefined.
                         * This includes shifts by a negative number.
                         */
-                       mark_reg_unknown(env, regs, insn->dst_reg);
+                       __mark_reg_unknown(env, dst_reg);
                        break;
                }
                if (alu32)
@@ -14029,7 +14028,7 @@ static int adjust_scalar_min_max_vals(struct bpf_verifier_env *env,
                        scalar_min_max_arsh(dst_reg, &src_reg);
                break;
        default:
-               mark_reg_unknown(env, regs, insn->dst_reg);
+               __mark_reg_unknown(env, dst_reg);
                break;
        }