public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Eduard Zingerman <eddyz87@gmail.com>
To: Harishankar Vishwanathan <harishankar.vishwanathan@gmail.com>
Cc: bpf@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann	 <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Paul Chaignon	 <paul.chaignon@gmail.com>,
	Shung-Hsi Yu <shung-hsi.yu@suse.com>,
	Srinivas Narayana <srinivas.narayana@rutgers.edu>,
	Santosh Nagarakatte <santosh.nagarakatte@rutgers.edu>
Subject: Re: [PATCH bpf-next 1/2] bpf/verifier: Use intersection checks when simulating to detect dead branches
Date: Fri, 17 Apr 2026 16:19:37 -0700	[thread overview]
Message-ID: <ea37be7028d20e962816ff10631da383b5910c57.camel@gmail.com> (raw)
In-Reply-To: <f622c0166e9c1809184673c1bffda7e43ae495ea.camel@gmail.com>

On Fri, 2026-04-17 at 14:17 -0700, Eduard Zingerman wrote:
> On Fri, 2026-04-17 at 01:34 -0400, Harishankar Vishwanathan wrote:
> 
> [...]
> 
> > > Could you please comment about the witness idea?
> > > Suppose reg_bounds_sync() is modified to preserve the properties I
> > > described above, would it be sufficient to check two candidates:
> > > tmin and tnum_step(tmin) to identify a register in an invalid state?
> > 
> > IIUC, your idea is, if there is a witness, it should be one
> > of tmin, tnum_step(tmin).
> > 
> > - I don't think tmin, tnum_step(tmin) works, because you might
> > need several applications of tnum_step from tmin to reach umin.
> > 
> > - Assuming tnum_step(umin) to reach the first intersection of umin
> > with the tnum (let's say x), x might not intersect with the s64.
> > 
> > -  I think one of tnum_step(umin), tnum_step(smin), smin, umin works
> > to find the common intersection point among u64, s64 and tnum.
> > 
> > - But even then that particular intersection point must also intersect
> > with the u32 and s32 (when mapped to those domains). That
> > complicates the reasoning.
> > 
> > Also how would you ensure property 2 described above
> > in reg_bounds_sync()?
> 
> Continuing this train of thoughts, consider the function
> find_witness_aux() from [1]:
> 
>     /* pre-conditions:
>      * - (u32)a_min <= b_min
>      * - b_max <= (u32)a_max
>      */
>     static bool find_witness_aux(u64 a_min, u64 a_max, u32 b_min, u32 b_max,
>                                 struct tnum tnum, u64 *out)
> 
> If there is a tnum T, a 64-bit range A and a 32-bit range B, such that
> `(u32)a_min <= b_min && b_max <= (u32)a_max`,
> it can find a value that belongs to A, B and T if such value exist.
> 
> I believe that this function can be used as a basis for complete
> witness check including signed and unsigned ranges:
> - Each intersection between signed and unsigned ranges produces one or
>   two unsigned ranges. 
> - If e.g. (u32)a_min <= b_min does not hold, further subdivision is
>   possible.
> 
> Meaning that final witness check will need to enumerate several ranges
> and call find_witness_aux() several times.
> 
> Wdyt?
> 
> [1] https://github.com/eddyz87/find-witness

Pushed complete find_witness() implementation in [1].
cbmc verification passes.

    bool find_witness(struct bpf_reg_state *reg, u64 *out)

Takes a register as an input and produces a value satisfying all
domains if such value exist. Assumes that register is well-formed:
- min < max
- tnum.mask & tnum.value == 0

Required some incantations to make cbmc understand function contracts,
I might want to switch to some more mainstream checker.

In any case, please let me know what you think.

  reply	other threads:[~2026-04-17 23:19 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-15 16:07 [PATCH bpf-next 0/2] Detect and prune dead branches using intersection checks Harishankar Vishwanathan
2026-04-15 16:07 ` [PATCH bpf-next 1/2] bpf/verifier: Use intersection checks when simulating to detect dead branches Harishankar Vishwanathan
2026-04-15 17:04   ` bot+bpf-ci
2026-04-15 19:02   ` Paul Chaignon
2026-04-16  1:10   ` Eduard Zingerman
2026-04-16 17:23     ` Eduard Zingerman
2026-04-16 23:13     ` Harishankar Vishwanathan
2026-04-16 23:33       ` Eduard Zingerman
2026-04-17  5:24         ` Eduard Zingerman
2026-04-17  5:34         ` Harishankar Vishwanathan
2026-04-17 21:17           ` Eduard Zingerman
2026-04-17 23:19             ` Eduard Zingerman [this message]
2026-04-18  0:38               ` Harishankar Vishwanathan
2026-04-18  0:45                 ` Eduard Zingerman
2026-04-18  0:22             ` Harishankar Vishwanathan
2026-04-15 16:07 ` [PATCH bpf-next 2/2] selftests/bpf: Test for empty intersection of tnum and u64 Harishankar Vishwanathan
2026-04-15 18:29   ` sashiko-bot
2026-04-16 17:51     ` Paul Chaignon

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=ea37be7028d20e962816ff10631da383b5910c57.camel@gmail.com \
    --to=eddyz87@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=harishankar.vishwanathan@gmail.com \
    --cc=paul.chaignon@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