From: Paul Chaignon <paul.chaignon@gmail.com>
To: Eduard Zingerman <eddyz87@gmail.com>
Cc: Harishankar Vishwanathan <harishankar.vishwanathan@gmail.com>,
bpf@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Shung-Hsi Yu <shung-hsi.yu@suse.com>,
Srinivas Narayana <srinivas.narayana@rutgers.edu>,
Santosh Nagarakatte <santosh.nagarakatte@rutgers.edu>
Subject: Re: [PATCH v2 bpf-next 3/6] bpf: Exit early if reg_bounds_sync gets invalid inputs
Date: Wed, 1 Apr 2026 14:21:16 +0200 [thread overview]
Message-ID: <ac0NvOIc7AhifyNM@mail.gmail.com> (raw)
In-Reply-To: <54d5347331905486d367542613b71b09fd81134c.camel@gmail.com>
On Tue, Mar 24, 2026 at 12:33:51PM -0700, Eduard Zingerman wrote:
> On Tue, 2026-03-24 at 15:28 -0400, Harishankar Vishwanathan wrote:
> > On Mon, Mar 23, 2026 at 2:47 PM Eduard Zingerman <eddyz87@gmail.com> wrote:
> > >
> > > On Fri, 2026-03-20 at 17:49 +0100, Paul Chaignon wrote:
> > >
> > > [...]
> > >
> > > > @@ -2786,8 +2786,13 @@ static void __reg_bound_offset(struct bpf_reg_state *reg)
> > > > reg->var_off = tnum_or(tnum_clear_subreg(var64_off), var32_off);
> > > > }
> > > >
> > > > +static bool range_bounds_violation(struct bpf_reg_state *reg);
> > > > +
> > > > static void reg_bounds_sync(struct bpf_reg_state *reg)
> > > > {
> > > > + /* If the input reg_state is invalid, we can exit early */
> > > > + if (range_bounds_violation(reg))
> > > > + return;
> > > > /* We might have learned new bounds from the var_off. */
> > > > __update_reg_bounds(reg);
> > > > /* We might have learned something about the sign bit. */
> > >
> > > Is it possible for the invariants violation to manifest after
> > > __update_reg{32,64}_bounds() calls, once cross domain boundaries are
> > > propagated?
> >
> > The short answer is yes.
> >
> > The sub-sync functions, i.e. __update_reg_bounds, __reg_deduce_bounds,
> > __reg_bound_offset are individually sound (checked by Agni).
> > This means that they preserve any concrete value x that is contained in all
> > the range bounds and tnum inputs, after refinement.
> >
> > But if in the input, there is no concrete value x that is contained in
> > ALL the range bounds and tnum, then an invariant violation can
> > manifest. Note that this can happen in the presence
> > of the current early exit commit, i.e., even if
> > range_bounds_violation(reg) is false.
> >
> > For example,
> >
> > before reg_bounds_sync: s64=[1, 1], tnum=0
> > after reg_bounds_sync: s64=[1, 0] tnum=0
> >
> > Could you elaborate on your concern? Did you perhaps imply that we should
> > be checking for reg_bounds_violation in
> > simulate_both_branches_taken after each sub-sync function?
>
> My main concern is that we might loose useful signal.
> It would be nice to adjust reg_bounds_sync() such
> that it would stop (e.g. return false, as you suggested previously)
> if it hits invariant violation mid-step.
We discussed this with Hari and agree it would be good to use
transient/mid-step invariant violations as a signal to improve
precision. I'd however prefer to implement that as a follow-up, to keep
the current patchset small and focused on fixing the invariant
violations that cause kernel warnings and program rejections. It sounds
like we may want to backport this at some point, so it's easier if it
keeps a restrained scope.
The "transient" invariant violations already exist today and using them
will only improve precision (potentially allow the verifier to accept
more program than it does today). I would see that as an improvement
rather than a fix we'd want to backport.
Hari thinks we can also use the empty intersection checks he mentioned
in the other thread [1] to avoid/use these transient invariant
violations. It would allow us to use this as a signal to improve
precision without making reg_bounds_sync more complex (and harder for
Agni to verify). I'll let him explain, but as mentioned in the other
thread, it still needs a bit of benchmarking.
1: https://lore.kernel.org/bpf/CAM=Ch05-XWF-x_VzUZAWhRO9eum-bjdutuwvPXEcOvnx_0omAA@mail.gmail.com/
next prev parent reply other threads:[~2026-04-01 12:21 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-20 16:45 [PATCH v2 bpf-next 0/6] Fix invariant violations and improve branch detection Paul Chaignon
2026-03-20 16:47 ` [PATCH v2 bpf-next 1/6] bpf: Refactor reg_bounds_sanity_check Paul Chaignon
2026-03-23 8:01 ` Shung-Hsi Yu
2026-03-23 14:16 ` Mykyta Yatsenko
2026-03-24 16:56 ` Harishankar Vishwanathan
2026-03-24 18:16 ` Mykyta Yatsenko
2026-03-20 16:49 ` [PATCH v2 bpf-next 2/6] bpf: Use bpf_verifier_env buffers for reg_set_min_max Paul Chaignon
2026-03-23 8:15 ` Shung-Hsi Yu
2026-03-23 15:33 ` Mykyta Yatsenko
2026-03-23 18:42 ` Eduard Zingerman
2026-03-30 12:05 ` Paul Chaignon
2026-03-31 1:51 ` Eduard Zingerman
2026-03-31 14:56 ` Paul Chaignon
2026-03-31 14:28 ` KaFai Wan
2026-04-01 11:15 ` Paul Chaignon
2026-03-20 16:49 ` [PATCH v2 bpf-next 3/6] bpf: Exit early if reg_bounds_sync gets invalid inputs Paul Chaignon
2026-03-23 12:12 ` Shung-Hsi Yu
2026-03-24 17:46 ` Harishankar Vishwanathan
2026-03-23 18:47 ` Eduard Zingerman
2026-03-24 19:28 ` Harishankar Vishwanathan
2026-03-24 19:33 ` Eduard Zingerman
2026-04-01 12:21 ` Paul Chaignon [this message]
2026-04-01 19:36 ` Harishankar Vishwanathan
2026-04-01 20:21 ` Eduard Zingerman
2026-04-01 21:19 ` Paul Chaignon
2026-03-20 16:49 ` [PATCH v2 bpf-next 4/6] bpf: Simulate branches to prune based on range violations Paul Chaignon
2026-03-23 12:23 ` Shung-Hsi Yu
2026-03-23 16:19 ` Mykyta Yatsenko
2026-03-24 20:36 ` Harishankar Vishwanathan
2026-03-25 13:52 ` Mykyta Yatsenko
2026-03-23 19:05 ` Eduard Zingerman
2026-03-24 23:59 ` Harishankar Vishwanathan
2026-03-25 0:08 ` Eduard Zingerman
2026-03-20 16:50 ` [PATCH v2 bpf-next 5/6] selftests/bpf: Cover invariant violation cases from syzbot Paul Chaignon
2026-03-23 17:46 ` Mykyta Yatsenko
2026-03-28 16:20 ` Paul Chaignon
2026-03-28 17:31 ` Alexei Starovoitov
2026-03-20 16:50 ` [PATCH v2 bpf-next 6/6] selftests/bpf: Remove invariant violation flags Paul Chaignon
2026-03-23 18:04 ` Mykyta Yatsenko
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=ac0NvOIc7AhifyNM@mail.gmail.com \
--to=paul.chaignon@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=harishankar.vishwanathan@gmail.com \
--cc=santosh.nagarakatte@rutgers.edu \
--cc=shung-hsi.yu@suse.com \
--cc=srinivas.narayana@rutgers.edu \
/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