[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <5fjhzkvgvbpcm2vvqlxhgcobbkiwvo36aalj5lbqrfbznbpynf@jzokg4ba2mwp>
Date: Fri, 26 Sep 2025 06:34:11 +0530
From: Brahmajit Das <listout@...tout.xyz>
To: KaFai Wan <kafai.wan@...ux.dev>
Cc: Alexei Starovoitov <alexei.starovoitov@...il.com>,
syzbot+d36d5ae81e1b0a53ef58@...kaller.appspotmail.com, Andrii Nakryiko <andrii@...nel.org>,
Alexei Starovoitov <ast@...nel.org>, bpf <bpf@...r.kernel.org>,
Daniel Borkmann <daniel@...earbox.net>, Eduard <eddyz87@...il.com>, Hao Luo <haoluo@...gle.com>,
John Fastabend <john.fastabend@...il.com>, Jiri Olsa <jolsa@...nel.org>, KP Singh <kpsingh@...nel.org>,
LKML <linux-kernel@...r.kernel.org>, Martin KaFai Lau <martin.lau@...ux.dev>,
Stanislav Fomichev <sdf@...ichev.me>, Song Liu <song@...nel.org>,
syzkaller-bugs <syzkaller-bugs@...glegroups.com>, Yonghong Song <yonghong.song@...ux.dev>
Subject: Re: [PATCH v2] bpf: fix NULL pointer dereference in print_reg_state()
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@...tout.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...
> > >
> > > Looks like we're getting somewhere.
> > > It seems the verifier is not clearing reg->type.
> > > adjust_scalar_min_max_vals() should be called on scalar types only.
> >
> > Right, there is a check in check_alu_op
> >
> > if (is_pointer_value(env, insn->dst_reg)) {
> > verbose(env, "R%d pointer arithmetic
> > prohibited\n",
> > insn->dst_reg);
> > return -EACCES;
> > }
> >
> > is_pointer_value calls __is_pointer_value which takes bool
> > allow_ptr_leaks as the first argument. Now for some reason in this
> > case
> > allow_ptr_leaks is being passed as true, as a result
> > __is_pointer_value
> > (and in turn is_pointer_value) returns false when even when register
> > type is CONST_PTR_TO_MAP.
> >
>
> IIUC, `env->allow_ptr_leaks` set true means privileged mode (
> CAP_PERFMON or CAP_SYS_ADMIN ), false for unprivileged mode.
>
>
> We can use __is_pointer_value to check if the register type is a
> pointer. For pointers, we check as before (before checking BPF_NEG
> separately), and for scalars, it remains unchanged. Perhaps this way we
> can fix the error.
>
> if (opcode == BPF_NEG) {
> if (__is_pointer_value(false, ®s[insn->dst_reg])) {
> err = check_reg_arg(env, insn->dst_reg, DST_OP);
> } else {
> err = check_reg_arg(env, insn->dst_reg,
> DST_OP_NO_MARK);
> err = err ?: adjust_scalar_min_max_vals(env, insn,
> ®s[insn->dst_reg],
> regs[insn->dst_reg]);
> }
> } else {
>
>
> --
> Thanks,
> KaFai
Yep, that works.
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -15505,10 +15505,17 @@ static int check_alu_op(struct bpf_verifier_env *env, struct bpf_insn *insn)
/* check dest operand */
if (opcode == BPF_NEG) {
- err = check_reg_arg(env, insn->dst_reg, DST_OP_NO_MARK);
- err = err ?: adjust_scalar_min_max_vals(env, insn,
- ®s[insn->dst_reg],
- regs[insn->dst_reg]);
+ if (__is_pointer_value(false, ®s[insn->dst_reg])) {
+ err = check_reg_arg(env, insn->dst_reg, DST_OP);
+ } else {
+ err = check_reg_arg(env, insn->dst_reg,
+ DST_OP_NO_MARK);
+ err = err ?:
+ adjust_scalar_min_max_vals(
+ env, insn,
+ ®s[insn->dst_reg],
+ regs[insn->dst_reg]);
+ }
} else {
err = check_reg_arg(env, insn->dst_reg, DST_OP);
}
I'll just wait for other developer or Alexei, in case they have any
feedback before sending a v3.
--
Regards,
listout
Powered by blists - more mailing lists