Skip to content

Commit 44f8fc6

Browse files
borkmanngregkh
authored andcommitted
bpf: restrict unknown scalars of mixed signed bounds for unprivileged
[ commit 9d7ecee upstream ] For unknown scalars of mixed signed bounds, meaning their smin_value is negative and their smax_value is positive, we need to reject arithmetic with pointer to map value. For unprivileged the goal is to mask every map pointer arithmetic and this cannot reliably be done when it is unknown at verification time whether the scalar value is negative or positive. Given this is a corner case, the likelihood of breaking should be very small. Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 5332dda commit 44f8fc6

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

‎kernel/bpf/verifier.c‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2712,8 +2712,8 @@ static int adjust_ptr_min_max_vals(struct bpf_verifier_env *env,
27122712
smin_ptr = ptr_reg->smin_value, smax_ptr = ptr_reg->smax_value;
27132713
u64 umin_val = off_reg->umin_value, umax_val = off_reg->umax_value,
27142714
umin_ptr = ptr_reg->umin_value, umax_ptr = ptr_reg->umax_value;
2715+
u32 dst = insn->dst_reg, src = insn->src_reg;
27152716
u8 opcode = BPF_OP(insn->code);
2716-
u32 dst = insn->dst_reg;
27172717

27182718
dst_reg = &regs[dst];
27192719

@@ -2749,6 +2749,12 @@ static int adjust_ptr_min_max_vals(struct bpf_verifier_env *env,
27492749
dst);
27502750
return -EACCES;
27512751
}
2752+
if (ptr_reg->type == PTR_TO_MAP_VALUE &&
2753+
!env->allow_ptr_leaks && !known && (smin_val < 0) != (smax_val < 0)) {
2754+
verbose(env, "R%d has unknown scalar with mixed signed bounds, pointer arithmetic with it prohibited for !root\n",
2755+
off_reg == dst_reg ? dst : src);
2756+
return -EACCES;
2757+
}
27522758

27532759
/* In case of 'scalar += pointer', dst_reg inherits pointer type and id.
27542760
* The id may be overwritten later if we create a new variable offset.

0 commit comments

Comments
 (0)