From: KaFai Wan <kafai.wan@linux.dev>
To: Brahmajit Das <listout@listout.xyz>
Cc: Alexei Starovoitov <alexei.starovoitov@gmail.com>,
syzbot+d36d5ae81e1b0a53ef58@syzkaller.appspotmail.com,
Andrii Nakryiko <andrii@kernel.org>,
Alexei Starovoitov <ast@kernel.org>, bpf <bpf@vger.kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Eduard <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>,
Stanislav Fomichev <sdf@fomichev.me>, Song Liu <song@kernel.org>,
syzkaller-bugs <syzkaller-bugs@googlegroups.com>,
Yonghong Song <yonghong.song@linux.dev>
Subject: Re: [PATCH v2] bpf: fix NULL pointer dereference in print_reg_state()
Date: Wed, 01 Oct 2025 13:08:02 +0800 [thread overview]
Message-ID: <417a8038817ce69e438a59e6916dc04372a47593.camel@linux.dev> (raw)
In-Reply-To: <vgtxqzgqxtyfd3pzfngq4l43eeocpputr5syqstbnw2yibl6bv@3yep75dnifgp>
[-- Attachment #1: Type: text/plain, Size: 2101 bytes --]
On Tue, 2025-09-30 at 23:51 +0530, Brahmajit Das wrote:
> On 26.09.2025 18:36, KaFai Wan wrote:
> > On Fri, 2025-09-26 at 06:34 +0530, Brahmajit Das wrote:
> > > On 25.09.2025 23:31, KaFai Wan wrote:
> > > > On Wed, 2025-09-24 at 23:58 +0530, Brahmajit Das wrote:
> > > > > On 25.09.2025 01:38, KaFai Wan wrote:
> > > > > > On Wed, 2025-09-24 at 21:10 +0530, Brahmajit Das wrote:
> > > > > > > On 24.09.2025 09:32, Alexei Starovoitov wrote:
> > > > > > > > On Wed, Sep 24, 2025 at 1:43 AM Brahmajit Das
> > > > > > > > <listout@listout.xyz>
> > > > > > > > wrote:
> > > > > > > > >
> > > > > > > > > Syzkaller reported a general protection fault due to a
> > > > > > > > > NULL
> > > > > > > > > pointer
> > > > > > > > > dereference in print_reg_state() when accessing reg-
> > > > > > > > > > map_ptr
> > > > > > > > > without
> > > > > > > > > checking if it is NULL.
> > > > > > > > >
> ...snip...
> >
> > You should add a Fixes label in the commit log and add selftest for it
> > in V3.
> > Fixes label is Fixes: aced132599b3 ("bpf: Add range tracking for
> > BPF_NEG")
> > For selftest you may check the test in verifier_value_illegal_alu.c and
> > other files.
> >
> > The code in your next post would change the behavior of BPF_NEG and
> > BPF_END, you can run the selftest to check that.
> >
>
> KaFai, I'm quite new to kernel development. I'm been trying to write a
> selftest for this unfortunately been having a hard time. I would really
> appreciate some help. For now I tried to create on from the initial test
> you used to verify this bug i.e. r0 -= r0.
>
> I have tried testing my changes via sending a pull request on the
> kernel-patches/bpf repository, but seems like it's failing.
> My pull request: https://github.com/kernel-patches/bpf/pull/9900
>
The attachment is the patch for selftest, you can apply it.
The patch#1 in your PR, Add the Oops call trace or the Closes label in commit
log could be better.
Closes: https://lore.kernel.org/all/68d26227.a70a0220.1b52b.02a4.GAE@google.com/
--
Thanks,
KaFai
[-- Attachment #2: 0001-selftests-bpf-Add-test-for-BPF_NEG-alu-on-CONST_PTR_.patch --]
[-- Type: text/x-patch, Size: 1652 bytes --]
From 2cb7fe5d4c707d8f5663829bacf2606648be185a Mon Sep 17 00:00:00 2001
From: KaFai Wan <kafai.wan@linux.dev>
Date: Wed, 1 Oct 2025 11:56:51 +0800
Subject: [PATCH] selftests/bpf: Add test for BPF_NEG alu on CONST_PTR_TO_MAP
From: KaFai Wan <kafai.wan@linux.dev>
Add a test case for BPF_NEG operation on CONST_PTR_TO_MAP. Tests if
BPF_NEG operation on map_ptr is rejected in unprivileged mode and is a
scalar value and do not trigger Oops in privileged mode.
Signed-off-by: KaFai Wan <kafai.wan@linux.dev>
---
.../bpf/progs/verifier_value_illegal_alu.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/tools/testing/selftests/bpf/progs/verifier_value_illegal_alu.c b/tools/testing/selftests/bpf/progs/verifier_value_illegal_alu.c
index a99b86c506f7..a850dde95d0e 100644
--- a/tools/testing/selftests/bpf/progs/verifier_value_illegal_alu.c
+++ b/tools/testing/selftests/bpf/progs/verifier_value_illegal_alu.c
@@ -182,6 +182,24 @@ __naked void map_ptr_illegal_alu_op(void)
: __clobber_all);
}
+SEC("socket")
+__description("map_ptr illegal alu op, map_ptr = -map_ptr")
+__failure __msg("R0 invalid mem access 'scalar'")
+__failure_unpriv __msg_unpriv("R0 pointer arithmetic prohibited")
+__flag(BPF_F_ANY_ALIGNMENT)
+__naked void map_ptr_illegal_alu_op(void)
+{
+ asm volatile (" \
+ r0 = %[map_hash_48b] ll; \
+ r0 = -r0; \
+ r1 = 22; \
+ *(u64*)(r0 + 0) = r1; \
+ exit; \
+" :
+ : __imm_addr(map_hash_48b)
+ : __clobber_all);
+}
+
SEC("flow_dissector")
__description("flow_keys illegal alu op with variable offset")
__failure __msg("R7 pointer arithmetic on flow_keys prohibited")
--
2.43.0
next prev parent reply other threads:[~2025-10-01 5:08 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-23 9:02 [syzbot] [bpf?] general protection fault in print_reg_state syzbot
2025-09-23 16:41 ` [PATCH 1/1] bpf: fix NULL pointer dereference in print_reg_state() Brahmajit Das
2025-10-01 19:17 ` [PATCH v4 0/2] bpf: Fix verifier crash on BPF_NEG with pointer register Brahmajit Das
2025-10-01 19:17 ` [PATCH v4 1/2] bpf: Skip scalar adjustment for BPF_NEG if dst is a pointer Brahmajit Das
2025-10-01 19:32 ` Eduard Zingerman
2025-10-01 19:17 ` [PATCH v4 2/2] selftests/bpf: Add test for BPF_NEG alu on CONST_PTR_TO_MAP Brahmajit Das
2025-10-01 19:33 ` Eduard Zingerman
2025-10-01 21:10 ` [PATCH v4 0/2] bpf: Fix verifier crash on BPF_NEG with pointer register patchwork-bot+netdevbpf
2025-09-23 16:43 ` [PATCH 1/1] bpf: fix NULL pointer dereference in print_reg_state() Brahmajit Das
2025-09-23 18:52 ` Alexei Starovoitov
2025-09-23 17:10 ` Forwarded: [PATCH] " syzbot
2025-09-23 17:47 ` [PATCH v2] " Brahmajit Das
2025-09-24 7:32 ` Alexei Starovoitov
2025-09-24 9:09 ` Brahmajit Das
2025-09-24 15:40 ` Brahmajit Das
2025-09-24 17:28 ` Alexei Starovoitov
2025-09-24 17:38 ` KaFai Wan
2025-09-24 18:28 ` Brahmajit Das
2025-09-25 15:31 ` KaFai Wan
2025-09-26 1:04 ` Brahmajit Das
2025-09-26 1:56 ` Brahmajit Das
2025-09-26 10:36 ` KaFai Wan
2025-09-30 18:21 ` Brahmajit Das
2025-10-01 5:08 ` KaFai Wan [this message]
2025-09-29 18:23 ` [syzbot] [bpf?] general protection fault in print_reg_state syzbot
2025-10-01 9:56 ` [PATCH v3 0/2] bpf: Fix verifier crash on BPF_NEG with pointer register Brahmajit Das
2025-10-01 9:56 ` [PATCH v3 1/2] bpf: Skip scalar adjustment for BPF_NEG if dst is a pointer Brahmajit Das
2025-10-01 16:55 ` Alexei Starovoitov
2025-10-01 18:29 ` Eduard Zingerman
2025-10-01 18:49 ` Brahmajit Das
2025-10-01 18:54 ` Eduard Zingerman
2025-10-01 9:56 ` [PATCH v3 2/2] selftests/bpf: Add test for BPF_NEG alu on CONST_PTR_TO_MAP Brahmajit Das
2025-10-01 18:37 ` Eduard Zingerman
2025-10-01 18:40 ` [PATCH v3 0/2] bpf: Fix verifier crash on BPF_NEG with pointer register Eduard Zingerman
2025-10-01 19:28 ` [PATCH v4 " Brahmajit Das
2025-10-01 19:28 ` [PATCH v4 1/2] bpf: Skip scalar adjustment for BPF_NEG if dst is a pointer Brahmajit Das
2025-10-01 21:10 ` patchwork-bot+netdevbpf
2025-10-01 19:28 ` [PATCH v4 2/2] selftests/bpf: Add test for BPF_NEG alu on CONST_PTR_TO_MAP Brahmajit Das
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=417a8038817ce69e438a59e6916dc04372a47593.camel@linux.dev \
--to=kafai.wan@linux.dev \
--cc=alexei.starovoitov@gmail.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=linux-kernel@vger.kernel.org \
--cc=listout@listout.xyz \
--cc=martin.lau@linux.dev \
--cc=sdf@fomichev.me \
--cc=song@kernel.org \
--cc=syzbot+d36d5ae81e1b0a53ef58@syzkaller.appspotmail.com \
--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 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.