All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: John Fastabend <john.fastabend@gmail.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>, bpf <bpf@vger.kernel.org>,
	Yonghong Song <yhs@fb.com>, Alexei Starovoitov <ast@kernel.org>
Subject: Re: [bpf PATCH v3] bpf: verifier, do_refine_retval_range may clamp umin to 0 incorrectly
Date: Wed, 29 Jan 2020 16:04:17 -0800	[thread overview]
Message-ID: <20200130000415.dwd7zn6wj7qlms7g@ast-mbp> (raw)
In-Reply-To: <5e320c9a30f64_2a332aadcd1385bc3f@john-XPS-13-9370.notmuch>

On Wed, Jan 29, 2020 at 02:52:10PM -0800, John Fastabend wrote:
> Daniel Borkmann wrote:
> > On 1/29/20 8:28 PM, Alexei Starovoitov wrote:
> > > On Wed, Jan 29, 2020 at 8:25 AM Daniel Borkmann <daniel@iogearbox.net> wrote:
> > >>>
> > >>> Fixes: 849fa50662fbc ("bpf/verifier: refine retval R0 state for bpf_get_stack helper")
> > >>> Signed-off-by: John Fastabend <john.fastabend@gmail.com>
> > >>
> > >> Applied, thanks!
> > > 
> > > Daniel,
> > > did you run the selftests before applying?
> > > This patch breaks two.
> > > We have to find a different fix.
> > > 
> > > ./test_progs -t get_stack
> > > 68: (85) call bpf_get_stack#67
> > >   R0=inv(id=0,smax_value=800) R1_w=ctx(id=0,off=0,imm=0)
> > > R2_w=map_value(id=0,off=0,ks=4,vs=1600,umax_value=4294967295,var_off=(0x0;
> > > 0xffffffff)) R3_w=inv(id=0,umax_value=4294967295,var_off=(0x0;
> > > 0xffffffff)) R4_w=inv0 R6=ctx(id=0,off=0,im?
> > > R2 unbounded memory access, make sure to bounds check any array access
> > > into a map
> > 
> > Sigh, had it in my wip pre-rebase tree when running tests. I've revert it from the
> > tree since this needs to be addressed. Sorry for the trouble.
> 
> Thanks I'm looking into it now. Not sure how I missed it on
> selftests either older branch or I missed the test somehow. I've
> updated toolchain and kernel now so shouldn't happen again.

Looks like smax_value was nuked by <<32 >>32 shifts.
53: (bf) r8 = r0   // R0=inv(id=0,smax_value=800)
54: (67) r8 <<= 32  // R8->smax_value = S64_MAX; in adjust_scalar_min_max_vals()
55: (c7) r8 s>>= 32
; if (usize < 0)
56: (c5) if r8 s< 0x0 goto pc+28
// and here "less than zero check" doesn't help anymore.

Not sure how to fix it yet, but the code pattern used in
progs/test_get_stack_rawtp.c
is real. Plenty of bpf progs rely on this.

  reply	other threads:[~2020-01-30  0:04 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-27 19:29 [bpf PATCH v3] bpf: verifier, do_refine_retval_range may clamp umin to 0 incorrectly John Fastabend
2020-01-29 16:25 ` Daniel Borkmann
2020-01-29 19:28   ` Alexei Starovoitov
2020-01-29 22:20     ` Daniel Borkmann
2020-01-29 22:52       ` John Fastabend
2020-01-30  0:04         ` Alexei Starovoitov [this message]
2020-01-30 17:38           ` John Fastabend
2020-01-30 17:59             ` Alexei Starovoitov
2020-01-30 23:34               ` John Fastabend
2020-01-31  0:15                 ` Yonghong Song
2020-01-31  0:44                   ` John Fastabend
2020-01-31  0:52                     ` Yonghong Song
2020-01-31  2:50                     ` Alexei Starovoitov
2020-01-31  0:28                 ` Yonghong Song
2020-01-31  0:48                   ` John Fastabend
2020-01-31  2:46                 ` Alexei Starovoitov
2020-01-31  5:48                   ` John Fastabend
2020-01-31  6:18                     ` Alexei Starovoitov
2020-01-31 17:16                       ` John Fastabend
2020-01-31 21:36                         ` Alexei Starovoitov
2020-02-04 19:55                           ` John Fastabend
2020-02-05  1:21                             ` Yonghong Song
2020-02-05  3:05                               ` John Fastabend
2020-02-06  1:24                                 ` Yonghong Song
2020-02-07 20:47                                   ` John Fastabend
2020-02-08  6:23                                     ` Yonghong Song
2020-04-09 15:03 ` Lorenzo Fontana

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=20200130000415.dwd7zn6wj7qlms7g@ast-mbp \
    --to=alexei.starovoitov@gmail.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=john.fastabend@gmail.com \
    --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.