From: Eduard Zingerman <eddyz87@gmail.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Andrii Nakryiko <andrii.nakryiko@gmail.com>,
bpf@vger.kernel.org, ast@kernel.org, andrii@kernel.org,
daniel@iogearbox.net, martin.lau@linux.dev, kernel-team@fb.com,
yhs@fb.com
Subject: Re: [PATCH bpf-next v2 1/4] bpf: verify scalar ids mapping in regsafe() using check_ids()
Date: Thu, 01 Jun 2023 19:57:14 +0300 [thread overview]
Message-ID: <81e2e47c71b6a0bc014c204e18c6be2736fed338.camel@gmail.com> (raw)
In-Reply-To: <20230601020514.vhnlnmowbo6dxwfj@MacBook-Pro-8.local>
On Wed, 2023-05-31 at 19:05 -0700, Alexei Starovoitov wrote:
> [...]
> > Suppose that current verification path is 1-7:
> > - On a way down 1-6 r7 will not be marked as precise, because
> > condition (r7 > X) is not predictable (see check_cond_jmp_op());
> > - When (7) is reached mark_chain_precision() will start moving up
> > marking the following registers as precise:
> >
> > 4: if (r6 > r7) goto +1 ; r6, r7
> > 5: r7 = r6 ; r6
> > 6: if (r7 > X) goto ... ; r6
> > 7: r9 += r6 ; r6
> >
> > - Thus, if checkpoint is created for (6) r7 would be marked as read,
> > but will not be marked as precise.
> >
> > Next, suppose that jump from 4 to 6 is verified and checkpoint for (6)
> > is considered:
> > - r6 is not precise, so check_ids() is not called for it and it is not
> > added to idmap;
> > - r7 is precise, so check_ids() is called for it, but it is a sole
> > register in the idmap;
>
> typos in above?
> r6 is precise and r7 is not precise.
Yes, it should be the other way around in the description:
r6 precise, r7 not precise. Sorry for confusion.
> > - States are considered equal.
> >
> > Here is the log (I added a few prints for states cache comparison):
> >
> > from 10 to 13: safe
> > steq hit 10, cur:
> > R0=scalar(id=2) R6=scalar(id=2) R7=scalar(id=1) R9=fp-8 R10=fp0 fp-8=00000000
> > steq hit 10, old:
> > R6_rD=Pscalar(id=2) R7_rwD=scalar(id=2) R9_rD=fp-8 R10=fp0 fp-8_rD=00000000
>
> the log is correct, thouhg.
> r6_old = Pscalar which will go through check_ids() successfully and both are unbounded.
> r7_old is not precise. different id-s don't matter and different ranges don't matter.
>
> As another potential fix...
> can we mark_chain_precision() right at the time of R1 = R2 when we do
> src_reg->id = ++env->id_gen
> and copy_register_state();
> for both regs?
This won't help, e.g. for the original example precise markings would be:
4: if (r6 > r7) goto +1 ; r6, r7
5: r7 = r6 ; r6, r7
6: if (r7 > X) goto ... ; r6 <-- mark for r7 is still missing
7: r9 += r6 ; r6
What might help is to call mark_chain_precision() from
find_equal_scalars(), but I expect this to be very expensive.
> I think
> if (rold->precise && !check_ids(rold->id, rcur->id, idmap))
> would be good property to have.
> I don't like u32_hashset either.
> It's more or less saying that scalar id-s are incompatible with precision.
>
> I hope we don't need to do:
> + u32 reg_ids[MAX_CALL_FRAMES];
> for backtracking either.
> Hacking id-s into jmp history is equally bad.
>
> Let's figure out a minimal fix.
Solution discussed with Andrii yesterday seems to work.
There is still a performance regression, but much less severe:
$ ./veristat -e file,prog,states -f "states_pct>5" -C master-baseline.log current.log
File Program States (A) States (B) States (DIFF)
------------------------ ------------------------------ ---------- ---------- -----------------
bpf_host.o cil_to_host 188 198 +10 (+5.32%)
bpf_host.o tail_handle_ipv4_from_host 225 243 +18 (+8.00%)
bpf_host.o tail_ipv6_host_policy_ingress 98 104 +6 (+6.12%)
bpf_xdp.o tail_handle_nat_fwd_ipv6 648 806 +158 (+24.38%)
bpf_xdp.o tail_lb_ipv4 2491 2930 +439 (+17.62%)
bpf_xdp.o tail_nodeport_nat_egress_ipv4 749 868 +119 (+15.89%)
bpf_xdp.o tail_nodeport_nat_ingress_ipv4 375 477 +102 (+27.20%)
bpf_xdp.o tail_rev_nodeport_lb4 398 486 +88 (+22.11%)
loop6.bpf.o trace_virtqueue_add_sgs 226 251 +25 (+11.06%)
pyperf600.bpf.o on_event 22200 45095 +22895 (+103.13%)
pyperf600_nounroll.bpf.o on_event 34169 37235 +3066 (+8.97%)
I need to add a bunch of tests and take a look at pyperf600.bpf.o
before submitting next patch-set version.
next prev parent reply other threads:[~2023-06-01 16:57 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-30 17:27 [PATCH bpf-next v2 0/4] verify scalar ids mapping in regsafe() Eduard Zingerman
2023-05-30 17:27 ` [PATCH bpf-next v2 1/4] bpf: verify scalar ids mapping in regsafe() using check_ids() Eduard Zingerman
2023-05-30 21:37 ` Andrii Nakryiko
2023-05-30 23:02 ` Eduard Zingerman
2023-06-01 2:05 ` Alexei Starovoitov
2023-06-01 16:57 ` Eduard Zingerman [this message]
2023-06-01 17:13 ` Alexei Starovoitov
2023-06-01 18:52 ` Eduard Zingerman
2023-06-02 18:50 ` Andrii Nakryiko
2023-06-02 19:13 ` Eduard Zingerman
2023-06-02 19:27 ` Alexei Starovoitov
2023-06-02 19:37 ` Eduard Zingerman
2023-06-02 19:43 ` Alexei Starovoitov
2023-06-02 19:51 ` Eduard Zingerman
2023-06-02 20:03 ` Alexei Starovoitov
2023-06-02 20:22 ` Eduard Zingerman
2023-06-02 20:17 ` Andrii Nakryiko
2023-06-02 21:13 ` Eduard Zingerman
2023-06-02 22:07 ` Andrii Nakryiko
2023-06-02 23:20 ` Eduard Zingerman
2023-06-05 20:43 ` Eduard Zingerman
[not found] ` <f2abf39bcd4de841a89bb248de9e242a880aaa93.camel@gmail.com>
2023-05-31 18:29 ` Andrii Nakryiko
2023-05-31 19:30 ` Eduard Zingerman
2023-05-31 20:12 ` Andrii Nakryiko
2023-05-31 20:31 ` Eduard Zingerman
2023-05-31 21:14 ` Andrii Nakryiko
2023-05-31 22:15 ` Eduard Zingerman
2023-05-31 22:54 ` Andrii Nakryiko
2023-05-31 23:42 ` Eduard Zingerman
2023-06-01 0:23 ` Andrii Nakryiko
2023-05-30 17:27 ` [PATCH bpf-next v2 2/4] selftests/bpf: verify that check_ids() is used for scalars in regsafe() Eduard Zingerman
2023-05-30 17:27 ` [PATCH bpf-next v2 3/4] bpf: filter out scalar ids not used for range transfer " Eduard Zingerman
2023-05-30 17:27 ` [PATCH bpf-next v2 4/4] selftests/bpf: check env->that range_transfer_ids has effect Eduard Zingerman
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=81e2e47c71b6a0bc014c204e18c6be2736fed338.camel@gmail.com \
--to=eddyz87@gmail.com \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.com \
--cc=martin.lau@linux.dev \
--cc=yhs@fb.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.