From: Eduard Zingerman <eddyz87@gmail.com>
To: Helen Koike <koike@igalia.com>,
andrii@kernel.org, shung-hsi.yu@suse.com,
yonghong.song@linux.dev, ast@kernel.org, bpf@vger.kernel.org,
linux-kernel@vger.kernel.org, kernel-dev@igalia.com
Subject: Re: [PATCH] bpf: fix umin/umax when lower bits fall outside u32 range
Date: Fri, 27 Mar 2026 13:18:15 -0700 [thread overview]
Message-ID: <c213b7ac01155249d5010c785bc2e6e3e280cd69.camel@gmail.com> (raw)
In-Reply-To: <20260327194849.855397-1-koike@igalia.com>
On Fri, 2026-03-27 at 16:48 -0300, Helen Koike wrote:
[...]
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index a965b2c45bbe..ddac09c8a9e5 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -2702,9 +2702,29 @@ static void __reg_deduce_mixed_bounds(struct bpf_reg_state *reg)
> __u64 new_umin, new_umax;
> __s64 new_smin, new_smax;
>
> - /* u32 -> u64 tightening, it's always well-formed */
> - new_umin = (reg->umin_value & ~0xffffffffULL) | reg->u32_min_value;
> - new_umax = (reg->umax_value & ~0xffffffffULL) | reg->u32_max_value;
> + /*
> + * If (u32)umin > u32_max, no value in the current upper-32-bit block
> + * satisfies [u32_min, u32_max] while being >= umin; advance umin to
> + * the next block. Otherwise apply standard u32->u64 tightening.
> + */
> + if ((u32)reg->umin_value > reg->u32_max_value)
> + new_umin = (reg->umin_value & ~0xffffffffULL) + (1ULL << 32) |
> + reg->u32_min_value;
> + else
> + new_umin = (reg->umin_value & ~0xffffffffULL) |
> + reg->u32_min_value;
> +
> + /*
> + * Symmetrically, if (u32)umax < u32_min, retreat umax to the
> + * previous block. Otherwise apply standard u32->u64 tightening.
> + */
> + if ((u32)reg->umax_value < reg->u32_min_value)
> + new_umax = (reg->umax_value & ~0xffffffffULL) - (1ULL << 32) |
> + reg->u32_max_value;
> + else
> + new_umax = (reg->umax_value & ~0xffffffffULL) |
> + reg->u32_max_value;
> +
> reg->umin_value = max_t(u64, reg->umin_value, new_umin);
> reg->umax_value = min_t(u64, reg->umax_value, new_umax);
> /* u32 -> s64 tightening, u32 range embedded into s64 preserves range validity */
Looks like it is the same case I identified in RFC [1].
[1] https://lore.kernel.org/bpf/20260318-cnum-sync-bounds-v1-4-1f2e455ea711@gmail.com/
next prev parent reply other threads:[~2026-03-27 20:18 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-27 19:48 [PATCH] bpf: fix umin/umax when lower bits fall outside u32 range Helen Koike
2026-03-27 20:18 ` Eduard Zingerman [this message]
2026-03-27 20:46 ` Eduard Zingerman
2026-03-30 12:09 ` Helen Koike
2026-03-30 16:24 ` kernel test robot
2026-03-30 17:53 ` kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c213b7ac01155249d5010c785bc2e6e3e280cd69.camel@gmail.com \
--to=eddyz87@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=kernel-dev@igalia.com \
--cc=koike@igalia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=shung-hsi.yu@suse.com \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox