Skip to content

Commit e60b0d1

Browse files
borkmannAlexei Starovoitov
authored andcommitted
bpf: Don't promote bogus looking registers after null check.
If we ever get to a point again where we convert a bogus looking <ptr>_or_null typed register containing a non-zero fixed or variable offset, then lets not reset these bounds to zero since they are not and also don't promote the register to a <ptr> type, but instead leave it as <ptr>_or_null. Converting to a unknown register could be an avenue as well, but then if we run into this case it would allow to leak a kernel pointer this way. Fixes: f1174f7 ("bpf/verifier: rework value tracking") Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 218d747 commit e60b0d1

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

kernel/bpf/verifier.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9079,15 +9079,15 @@ static void mark_ptr_or_null_reg(struct bpf_func_state *state,
90799079
{
90809080
if (type_may_be_null(reg->type) && reg->id == id &&
90819081
!WARN_ON_ONCE(!reg->id)) {
9082-
/* Old offset (both fixed and variable parts) should
9083-
* have been known-zero, because we don't allow pointer
9084-
* arithmetic on pointers that might be NULL.
9085-
*/
90869082
if (WARN_ON_ONCE(reg->smin_value || reg->smax_value ||
90879083
!tnum_equals_const(reg->var_off, 0) ||
90889084
reg->off)) {
9089-
__mark_reg_known_zero(reg);
9090-
reg->off = 0;
9085+
/* Old offset (both fixed and variable parts) should
9086+
* have been known-zero, because we don't allow pointer
9087+
* arithmetic on pointers that might be NULL. If we
9088+
* see this happening, don't convert the register.
9089+
*/
9090+
return;
90919091
}
90929092
if (is_null) {
90939093
reg->type = SCALAR_VALUE;

0 commit comments

Comments
 (0)