From: Eduard Zingerman <eddyz87@gmail.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: bpf <bpf@vger.kernel.org>, Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <martin.lau@kernel.org>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
Kernel Team <kernel-team@fb.com>
Subject: Re: [PATCH v5 bpf-next 2/3] bpf: Relax precision marking in open coded iters and may_goto loop.
Date: Thu, 06 Jun 2024 16:39:47 -0700 [thread overview]
Message-ID: <0f197e908df8b33187a6c9a8da34457cb01a746e.camel@gmail.com> (raw)
In-Reply-To: <098d570be9bb15fc804355851b4b99837f18c664.camel@gmail.com>
On Thu, 2024-06-06 at 15:19 -0700, Eduard Zingerman wrote:
[...]
> For the following C code:
>
> long arr1[1024];
>
> SEC("socket")
> __success
> int test1(const void *ctx)
> {
> long i;
>
> for (i = 0; i < 1024 && can_loop; i++)
> arr1[i] = i;
> return 0;
> }
>
> clang generates the following BPF code:
>
> 0000000000000340 <test1>:
> 104: r1 = 0x0
> 105: r2 = 0x0 ll
>
> 0000000000000358 <LBB28_1>:
> 107: may_goto +0x4 <LBB28_3>
> 108: *(u64 *)(r2 + 0x0) = r1
> 109: r2 += 0x8
> 110: r1 += 0x1
> 111: if r1 != 0x400 goto -0x5 <LBB28_1>
>
> 0000000000000380 <LBB28_3>:
> 112: w0 = 0x0
> 113: exit
[...]
I've also took a look why the same program could be verified w/o
can_loop, but fails with can_loop (with this series applied):
0000000000000358 <LBB28_1>:
107: may_goto +0x4 <LBB28_3>
108: *(u64 *)(r2 + 0x0) = r1
109: r2 += 0x8
110: r1 += 0x1
111: if r1 != 0x400 goto -0x5 <LBB28_1>
^^
r1 is no longer marked precise,
thus maybe_widen_reg() forgets the range for it
when widen_imprecise_scalars() is called from
may_goto processing logic.
As a result, verifier enumerates states
{r2=0P,r1=scalar()}, {r2=8P,r1=scalar()}, {r2=16P,r1=scalar()}, ...
eventually hitting the value of r2 that does not fit in 'arr1' bounds.
next prev parent reply other threads:[~2024-06-06 23:39 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-06 0:54 [PATCH v5 bpf-next 1/3] bpf: Relax tuple len requirement for sk helpers Alexei Starovoitov
2024-06-06 0:54 ` [PATCH v5 bpf-next 2/3] bpf: Relax precision marking in open coded iters and may_goto loop Alexei Starovoitov
2024-06-06 11:08 ` Eduard Zingerman
2024-06-06 20:02 ` Alexei Starovoitov
2024-06-06 22:19 ` Eduard Zingerman
2024-06-06 23:39 ` Eduard Zingerman [this message]
2024-06-07 0:28 ` Alexei Starovoitov
2024-06-06 0:54 ` [PATCH v5 bpf-next 3/3] selftests/bpf: Remove i = zero workaround and add new tests Alexei Starovoitov
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=0f197e908df8b33187a6c9a8da34457cb01a746e.camel@gmail.com \
--to=eddyz87@gmail.com \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.com \
--cc=martin.lau@kernel.org \
--cc=memxor@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox