Skip to content

Commit 4a163b1

Browse files
borkmanngregkh
authored andcommitted
bpf: Move off_reg into sanitize_ptr_alu
commit 6f55b2f upstream. 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 <daniel@iogearbox.net> Reviewed-by: John Fastabend <john.fastabend@gmail.com> Acked-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 19bfeb4 commit 4a163b1

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

kernel/bpf/verifier.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4336,11 +4336,12 @@ static int sanitize_val_alu(struct bpf_verifier_env *env,
43364336
static int sanitize_ptr_alu(struct bpf_verifier_env *env,
43374337
struct bpf_insn *insn,
43384338
const struct bpf_reg_state *ptr_reg,
4339-
struct bpf_reg_state *dst_reg,
4340-
bool off_is_neg)
4339+
const struct bpf_reg_state *off_reg,
4340+
struct bpf_reg_state *dst_reg)
43414341
{
43424342
struct bpf_verifier_state *vstate = env->cur_state;
43434343
struct bpf_insn_aux_data *aux = cur_aux(env);
4344+
bool off_is_neg = off_reg->smin_value < 0;
43444345
bool ptr_is_dst_reg = ptr_reg == dst_reg;
43454346
u8 opcode = BPF_OP(insn->code);
43464347
u32 alu_state, alu_limit;
@@ -4474,7 +4475,7 @@ static int adjust_ptr_min_max_vals(struct bpf_verifier_env *env,
44744475

44754476
switch (opcode) {
44764477
case BPF_ADD:
4477-
ret = sanitize_ptr_alu(env, insn, ptr_reg, dst_reg, smin_val < 0);
4478+
ret = sanitize_ptr_alu(env, insn, ptr_reg, off_reg, dst_reg);
44784479
if (ret < 0) {
44794480
verbose(env, "R%d tried to add from different maps, paths, or prohibited types\n", dst);
44804481
return ret;
@@ -4529,7 +4530,7 @@ static int adjust_ptr_min_max_vals(struct bpf_verifier_env *env,
45294530
}
45304531
break;
45314532
case BPF_SUB:
4532-
ret = sanitize_ptr_alu(env, insn, ptr_reg, dst_reg, smin_val < 0);
4533+
ret = sanitize_ptr_alu(env, insn, ptr_reg, off_reg, dst_reg);
45334534
if (ret < 0) {
45344535
verbose(env, "R%d tried to sub from different maps, paths, or prohibited types\n", dst);
45354536
return ret;

0 commit comments

Comments
 (0)