From: Jiayuan Chen <mrpre@163.com>
To: bpf@vger.kernel.org, ast@kernel.org
Cc: daniel@iogearbox.net, john.fastabend@gmail.com,
andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com,
song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org,
sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org,
mykolal@fb.com, shuah@kernel.org, Jiayuan Chen <mrpre@163.com>
Subject: [PATCH bpf-next v1 0/2] bpf: Fix array bounds error with may_goto and add selftest
Date: Wed, 12 Feb 2025 21:52:49 +0800 [thread overview]
Message-ID: <20250212135251.85487-1-mrpre@163.com> (raw)
Syzbot caught an array out-of-bounds bug [1]. It turns out that when the
BPF program runs through do_misc_fixups(), it allocates an extra 8 bytes
on the call stack, which eventually causes stack_depth to exceed 512.
I was able to reproduce this issue probabilistically by enabling
CONFIG_UBSAN=y and disabling CONFIG_BPF_JIT_ALWAYS_ON with the selfttest
I provide in second patch(although it doesn't happen every time - I didn't
dig deeper into why UBSAN behaves this way).
To fix this, I came up with three possible solutions:
1. Run check_max_stack_depth() again after do_misc_fixups(), but I don't
think it's fair to make users pay for the extra stack overhead caused by
our optimization. Especially when users write assembly code that directly
allocates 512 bytes (like my selftest), it's gonna fail and leave them
confused.
2. Force JIT when using may_goto, but that's not ideal if we want may_goto
to work with both interpreters and JIT.
3. Simply extend interpreters, which seems like the most reasonable
approach to me. And if I had to choose a second best, it would be option 1.
[1] https://syzkaller.appspot.com/bug?extid=d2a2c639d03ac200a4f1
---
Jiayuan Chen (2):
bpf: Fix array bounds error with may_goto
bpf/selftest: add selftest for may_goto
kernel/bpf/core.c | 11 +++++--
.../selftests/bpf/progs/verifier_stack_ptr.c | 33 +++++++++++++++++++
2 files changed, 41 insertions(+), 3 deletions(-)
--
2.47.1
next reply other threads:[~2025-02-12 13:54 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-12 13:52 Jiayuan Chen [this message]
2025-02-12 13:52 ` [PATCH bpf-next v1 1/2] bpf: Fix array bounds error with may_goto Jiayuan Chen
2025-02-12 15:52 ` Alexei Starovoitov
2025-02-12 13:52 ` [PATCH bpf-next v1 2/2] bpf/selftest: add selftest for may_goto Jiayuan Chen
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=20250212135251.85487-1-mrpre@163.com \
--to=mrpre@163.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=martin.lau@linux.dev \
--cc=mykolal@fb.com \
--cc=sdf@fomichev.me \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--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 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.