Re: [PATCH 1/2] bpf: deduce_bounds_64_from_32 tightening with circular range logic

Eduard Zingerman
2026-04-15T18:12:57Z

On Fri, 2026-04-10 at 09:40 -0300, Helen Koike wrote:
> Unify handling of signed and unsigned using circular range logic.
>
> Signed and unsigned numbers follows the same order in bit
> representation. We can think of it as a clock, were 12h is
> 0x0000_0000 and 11h is 0xFFFF_FFFF, regardless of its sign.
>
> Then, instead of dealing with max and min, we deal with a base and len,
> where len = max - min.
>
> Example:
> range [-1, 3] is represented by base=0xFFFF_FFFF len=4
> since (u32)3 - (u32)-1 is 4.
>
> And we can verify if a value v is in range if:
> (u32)(v - base) <= len
> which is true if v is signed -1 or v is unsigned 0xFFFF_FFFF.
>
> This automatically handles the wrapping case, discarding the need to
> check if it crosses the signed range or not and handle each case.
>
> It also fixes the following current issues:
> * [(u32)umin, (u32)umax] falling outside of [u32_min_value, u32_max_value]
> * [(u32)umin, (u32)umax] falling in the gap [(u32)s32_max_value, (u32)s32_min_value]
>
> Fixes: c51d5ad6543c ("bpf: improve deduction of 64-bit bounds from 32-bit bounds")
> [Circular representation]
> Suggested-by: Eduard Zingerman <eddyz87@gmail.com>
> Signed-off-by: Helen Koike <koike@igalia.com>
>
> ---

Acked-by: Eduard Zingerman <eddyz87@gmail.com> …