Skip to content

Commit 6f55b2f

Browse files
committed
bpf: Move off_reg into sanitize_ptr_alu
Small refactor to drag off_reg into sanitize_ptr_alu(), so we later on can use off_reg for generalizing some of the checks for all pointer types. Signed-off-by: Daniel Borkmann <[email protected]> Reviewed-by: John Fastabend <[email protected]> Acked-by: Alexei Starovoitov <[email protected]>
1 parent 9601148 commit 6f55b2f

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

kernel/bpf/verifier.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5929,11 +5929,12 @@ static int sanitize_val_alu(struct bpf_verifier_env *env,
59295929
static int sanitize_ptr_alu(struct bpf_verifier_env *env,
59305930
struct bpf_insn *insn,
59315931
const struct bpf_reg_state *ptr_reg,
5932-
struct bpf_reg_state *dst_reg,
5933-
bool off_is_neg)
5932+
const struct bpf_reg_state *off_reg,
5933+
struct bpf_reg_state *dst_reg)
59345934
{
59355935
struct bpf_verifier_state *vstate = env->cur_state;
59365936
struct bpf_insn_aux_data *aux = cur_aux(env);
5937+
bool off_is_neg = off_reg->smin_value < 0;
59375938
bool ptr_is_dst_reg = ptr_reg == dst_reg;
59385939
u8 opcode = BPF_OP(insn->code);
59395940
u32 alu_state, alu_limit;
@@ -6110,7 +6111,7 @@ static int adjust_ptr_min_max_vals(struct bpf_verifier_env *env,
61106111

61116112
switch (opcode) {
61126113
case BPF_ADD:
6113-
ret = sanitize_ptr_alu(env, insn, ptr_reg, dst_reg, smin_val < 0);
6114+
ret = sanitize_ptr_alu(env, insn, ptr_reg, off_reg, dst_reg);
61146115
if (ret < 0) {
61156116
verbose(env, "R%d tried to add from different maps, paths, or prohibited types\n", dst);
61166117
return ret;
@@ -6165,7 +6166,7 @@ static int adjust_ptr_min_max_vals(struct bpf_verifier_env *env,
61656166
}
61666167
break;
61676168
case BPF_SUB:
6168-
ret = sanitize_ptr_alu(env, insn, ptr_reg, dst_reg, smin_val < 0);
6169+
ret = sanitize_ptr_alu(env, insn, ptr_reg, off_reg, dst_reg);
61696170
if (ret < 0) {
61706171
verbose(env, "R%d tried to sub from different maps, paths, or prohibited types\n", dst);
61716172
return ret;

0 commit comments

Comments
 (0)