[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <5f87ca47436f3_b7602088f@john-XPS-13-9370.notmuch>
Date: Wed, 14 Oct 2020 21:04:23 -0700
From: John Fastabend <john.fastabend@...il.com>
To: Andrii Nakryiko <andrii.nakryiko@...il.com>,
Alexei Starovoitov <alexei.starovoitov@...il.com>
Cc: "David S. Miller" <davem@...emloft.net>,
Daniel Borkmann <daniel@...earbox.net>,
john fastabend <john.fastabend@...il.com>,
Networking <netdev@...r.kernel.org>, bpf <bpf@...r.kernel.org>,
Kernel Team <kernel-team@...com>
Subject: Re: [PATCH bpf-next] bpf: Fix register equivalence tracking.
Andrii Nakryiko wrote:
> On Wed, Oct 14, 2020 at 10:59 AM Alexei Starovoitov
> <alexei.starovoitov@...il.com> wrote:
> >
> > From: Alexei Starovoitov <ast@...nel.org>
> >
> > The 64-bit JEQ/JNE handling in reg_set_min_max() was clearing reg->id in either
> > true or false branch. In the case 'if (reg->id)' check was done on the other
> > branch the counter part register would have reg->id == 0 when called into
> > find_equal_scalars(). In such case the helper would incorrectly identify other
> > registers with id == 0 as equivalent and propagate the state incorrectly.
One thought. It seems we should never have reg->id=0 in find_equal_scalars()
would it be worthwhile to add an additional check here? Something like,
if (known_reg->id == 0)
return
Or even a WARN_ON_ONCE() there? Not sold either way, but maybe worth thinking
about.
> > Fix it by preserving ID across reg_set_min_max().
> > In other words any kind of comparison operator on the scalar register
> > should preserve its ID to recognize:
> > r1 = r2
> > if (r1 == 20) {
> > #1 here both r1 and r2 == 20
> > } else if (r2 < 20) {
> > #2 here both r1 and r2 < 20
> > }
> >
> > The patch is addressing #1 case. The #2 was working correctly already.
> >
> > Fixes: 75748837b7e5 ("bpf: Propagate scalar ranges through register assignments.")
> > Signed-off-by: Alexei Starovoitov <ast@...nel.org>
> > ---
>
> Number of underscores is a bit subtle a difference, but this fixes the bug, so:
>
> Acked-by: Andrii Nakryiko <andrii@...nel.org>
>
Nice catch,
Acked-by: John Fastabend <john.fastabend@...il.com>
>
> > kernel/bpf/verifier.c | 38 ++++++++++++-------
> > .../testing/selftests/bpf/verifier/regalloc.c | 26 +++++++++++++
> > 2 files changed, 51 insertions(+), 13 deletions(-)
> >
>
> [...]
Powered by blists - more mailing lists