On Mon, 2024-04-29 at 13:58 -0700, Andrii Nakryiko wrote: [...] > > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c > > index 8f0f2e21699e..b69c89bc5cfc 100644 > > --- a/kernel/bpf/verifier.c > > +++ b/kernel/bpf/verifier.c > > @@ -13478,6 +13478,28 @@ static void scalar32_min_max_and(struct bpf_reg_state *dst_reg, > > return; > > } > > > > + /* Special case: dst_reg is in range [-1, 0] */ > > + if (dst_reg->s32_min_value == -1 && dst_reg->s32_max_value == 0) { > > + var32_off = tnum_union(src_reg->var_off, tnum_const(0)); > > + dst_reg->var_off = tnum_with_subreg(dst_reg->var_off, var32_off); > > + dst_reg->u32_min_value = var32_off.value; > > + dst_reg->u32_max_value = min(dst_reg->u32_max_value, umax_val); > > can you explain the logic behing u32 min/max updates, especially that > we use completely different values for min/max and it's not clear why > u32_min <= u32_max invariant will always hold. Same below I agree with Andrii here. It appears that dst_reg.{min,max} fields should be set as {min(src.min, 0), max(src.max, 0)} for both signed and unsigned cases. Wdyt? > > > + dst_reg->s32_min_value = min_t(s32, src_reg->s32_min_value, 0); > > + dst_reg->s32_max_value = max_t(s32, src_reg->s32_max_value, 0); > > + return; > > + } > > + > > + /* Special case: src_reg is in range [-1, 0] */ > > + if (src_reg->s32_min_value == -1 && src_reg->s32_max_value == 0) { > > + var32_off = tnum_union(dst_reg->var_off, tnum_const(0)); > > + dst_reg->var_off = tnum_with_subreg(dst_reg->var_off, var32_off); > > + dst_reg->u32_min_value = var32_off.value; > > + dst_reg->u32_max_value = min(dst_reg->u32_max_value, umax_val); > > + dst_reg->s32_min_value = min_t(s32, dst_reg->s32_min_value, 0); > > + dst_reg->s32_max_value = max_t(s32, dst_reg->s32_max_value, 0); > > + return; > > + } > > + > > /* We get our minimum from the var_off, since that's inherently > > * bitwise. Our maximum is the minimum of the operands' maxima. > > */ [...]