From: Andrei Matei <andreimatei1@gmail.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Edward Adam Davis <eadavis@qq.com>,
Andrii Nakryiko <andrii@kernel.org>,
Alexei Starovoitov <ast@kernel.org>, bpf <bpf@vger.kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Eddy Z <eddyz87@gmail.com>, Hao Luo <haoluo@google.com>,
John Fastabend <john.fastabend@gmail.com>,
Jiri Olsa <jolsa@kernel.org>, KP Singh <kpsingh@kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Network Development <netdev@vger.kernel.org>,
Stanislav Fomichev <sdf@google.com>, Song Liu <song@kernel.org>,
syzkaller-bugs <syzkaller-bugs@googlegroups.com>,
Yonghong Song <yonghong.song@linux.dev>
Subject: Re: stack access issue. Re: [syzbot] [bpf?] UBSAN: array-index-out-of-bounds in check_stack_range_initialized
Date: Mon, 25 Mar 2024 22:48:05 -0400 [thread overview]
Message-ID: <CABWLses5ZpokYC==6cVKkAz25rYtgtMYn+GpxOd4TuJ7jwcNBw@mail.gmail.com> (raw)
In-Reply-To: <CAADnVQ+oqe6EtC8rc9TSFeUPE1Rbf11Oi-CfTyDxfXT9qM0Vpg@mail.gmail.com>
Fixing in https://lore.kernel.org/bpf/20240324230323.1097685-1-andreimatei1@gmail.com/
FWIW, I managed to decode the BPF program that syzkaller used:
0: (18) r0 = 0x0
2: (18) r1 = map[id:4]
4: (b7) r8 = 0
5: (7b) *(u64 *)(r10 -8) = r8
6: (bf) r2 = r10
7: (07) r2 += -8
8: (b7) r3 = 8
9: (b7) r4 = 0
10: (85) call bloom_map_peek_elem#322320
11: (95) exit
Where the map is a bloom filter (as Alexei somehow already knew on the patch
thread) with a humongous value size.
4: type 30 flags 0x0
key 0B value 2147483649B max_entries 255 memlock 720B
On Sat, Mar 23, 2024 at 10:55 PM Alexei Starovoitov
<alexei.starovoitov@gmail.com> wrote:
>
> On Sat, Mar 23, 2024 at 7:12 PM Andrei Matei <andreimatei1@gmail.com> wrote:
> >
> > On Sat, Mar 23, 2024 at 8:52 PM Alexei Starovoitov
> > <alexei.starovoitov@gmail.com> wrote:
> > >
> > > On Sat, Mar 23, 2024 at 5:50 PM Andrei Matei <andreimatei1@gmail.com> wrote:
> > > >
> > > > + Edward
> > > >
> > > > On Thu, Mar 21, 2024 at 3:33 AM Alexei Starovoitov
> > > > <alexei.starovoitov@gmail.com> wrote:
> > > > >
> > > > > Hi Andrei,
> > > > >
> > > > > looks like the refactoring of stack access introduced a bug.
> > > > > See the reproducer below.
> > > > > positive offsets are not caught by check_stack_access_within_bounds().
> > > >
> > > > check_stack_access_within_bounds() tries to catch positive offsets;
> > > > It does: [1]
> > > >
> > > > err = check_stack_slot_within_bounds(env, min_off, state, type);
> > > > if (!err && max_off > 0)
> > > > err = -EINVAL; /* out of stack access into non-negative offsets */
> > > >
> > > > Notice the max_off > 0 in there.
> > > > And we have various tests that seem to check that positive offsets are
> > > > rejected. Do you know what the bug is?
> > > > I'm thinking maybe there's some overflow going on, except that UBSAN
> > > > reported an index of -1 as being the problem.
> > > >
> > > > Edward, I see that you've been tickling the robot trying to narrow the issue;
> > > > perhaps you've figured it out?
> > > >
> > > > If the bug is not immediately apparent to anyone, I would really appreciate a
> > > > bit of tutoring around how to reproduce and get verifier logs.
> > >
> > > The repro is right there in the email I forwarded:
> > >
> > > > C reproducer: https://syzkaller.appspot.com/x/repro.c?x=15c38711180000
> >
> > I understand, but how does one go from this to either BPF assembly,
> > or to running it in such a way that you also get verifier logs?
>
> Adding logs to repro.c is too hard, but you can
> hack the kernel with printk-s.
>
> Like the following:
>
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index de7813947981..d158b83ed16c 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -7179,6 +7179,7 @@ static int check_stack_range_initialized(
> return -EFAULT;
> }
>
> + printk("slot %d %d spi %d\n", slot, slot % BPF_REG_SIZE, spi);
> stype = &state->stack[spi].slot_type[slot % BPF_REG_SIZE];
>
>
> shows that spi and slot get negative: -1, -2, ...
next prev parent reply other threads:[~2024-03-26 2:48 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-19 18:12 [syzbot] [bpf?] UBSAN: array-index-out-of-bounds in check_stack_range_initialized syzbot
2024-03-21 7:33 ` stack access issue. " Alexei Starovoitov
2024-03-21 14:07 ` Andrei Matei
2024-03-24 0:50 ` Andrei Matei
2024-03-24 0:52 ` Alexei Starovoitov
2024-03-24 2:12 ` Andrei Matei
2024-03-24 2:55 ` Alexei Starovoitov
2024-03-26 2:48 ` Andrei Matei [this message]
-- strict thread matches above, loose matches on Subject: below --
2024-03-26 21:11 Kaiming Huang
2024-03-26 22:06 Kaiming Huang
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='CABWLses5ZpokYC==6cVKkAz25rYtgtMYn+GpxOd4TuJ7jwcNBw@mail.gmail.com' \
--to=andreimatei1@gmail.com \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eadavis@qq.com \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=netdev@vger.kernel.org \
--cc=sdf@google.com \
--cc=song@kernel.org \
--cc=syzkaller-bugs@googlegroups.com \
--cc=yonghong.song@linux.dev \
/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;
as well as URLs for NNTP newsgroup(s).