From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: Camila Alvarez Inostroza <cam.alvarez.i@gmail.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>, bpf <bpf@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
syzbot+d2a2c639d03ac200a4f1@syzkaller.appspotmail.com
Subject: Re: [PATCH] fix array-index-out-of-bounds in bpf_prog_select_runtime
Date: Mon, 6 May 2024 16:35:55 -0700 [thread overview]
Message-ID: <CAADnVQ+eQ36rc8Ew5a4YfFbB0rgbJhXXwwgPASjFVQ7=QFyM1A@mail.gmail.com> (raw)
In-Reply-To: <43a0853d-e7f3-702b-e7c4-f360ae1e3a70@macbook-pro-de-camila.local>
On Sun, May 5, 2024 at 4:18 PM Camila Alvarez Inostroza
<cam.alvarez.i@gmail.com> wrote:
>
>
>
> On Sun, 5 May 2024, Alexei Starovoitov wrote:
>
> > On Sat, May 4, 2024 at 6:49 PM Camila Alvarez <cam.alvarez.i@gmail.com> wrote:
> >>
> >> The error indicates that the verifier is letting through a program with
> >> a stack depth bigger than 512.
> >>
> >> This is due to the verifier not checking the stack depth after
> >> instruction rewrites are perfomed. For example, the MAY_GOTO instruction
> >> adds 8 bytes to the stack, which means that if the stack at the moment
> >> was already 512 bytes it would overflow after rewriting the instruction.
> >
> > This is by design. may_goto and other constructs like bpf_loop
> > inlining can consume a few words above 512 limit.
> >
>
> Is this the only case where the verifier should allow the stack to go over
> the 512 limit? If that's the case, maybe we could use the extra stack
> depth to store how much the rewrites affect the stack depth? This would
> only be used to obtain the correct interpreter when
> CONFIG_BPF_JIT_ALWAYS_ON is not set.
> That would allow choosing the interpreter by considering the stack depth
> before the rewrites.
>
> >> The fix involves adding a stack depth check after all instruction
> >> rewrites are performed.
> >>
> >> Reported-by: syzbot+d2a2c639d03ac200a4f1@syzkaller.appspotmail.com
> >
> > This syzbot report is likely unrelated.
> > It says that it bisected it to may_goto, but it has this report
> > before may_goto was introduced, so bisection is incorrect.
> >
> > pw-bot: cr
>
> I can see that may_goto was introduced on march 6th, and the first report
> was on march 13th. Is there any report I'm missing?
Could you please craft a selftest for this issue then?
It will be much easier to reason about the fix.
We can either add another interpreter to interpreters_args[]
or just gate may_goto with prog->jit_requested.
next prev parent reply other threads:[~2024-05-06 23:36 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-05 1:46 [PATCH] fix array-index-out-of-bounds in bpf_prog_select_runtime Camila Alvarez
2024-05-05 8:21 ` Alexei Starovoitov
2024-05-05 23:18 ` Camila Alvarez Inostroza
2024-05-06 23:35 ` Alexei Starovoitov [this message]
-- strict thread matches above, loose matches on Subject: below --
2024-03-26 0:38 Camila Alvarez
2024-03-27 22:14 ` 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='CAADnVQ+eQ36rc8Ew5a4YfFbB0rgbJhXXwwgPASjFVQ7=QFyM1A@mail.gmail.com' \
--to=alexei.starovoitov@gmail.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=cam.alvarez.i@gmail.com \
--cc=daniel@iogearbox.net \
--cc=linux-kernel@vger.kernel.org \
--cc=syzbot+d2a2c639d03ac200a4f1@syzkaller.appspotmail.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).