From: Eduard Zingerman <eddyz87@gmail.com>
To: sashiko-reviews@lists.linux.dev
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v2 4/5] bpf: simplify the bpf_is_reg64()
Date: Sun, 02 Aug 2026 04:21:28 -0700 [thread overview]
Message-ID: <c4f702276cffa8d133bea614a9eac94164357870.camel@gmail.com> (raw)
In-Reply-To: <20260801013453.2B6081F00AC4@smtp.kernel.org>
On Sat, 2026-08-01 at 01:34 +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
> - [High] `bpf_is_reg64()` incorrectly identifies 32-bit `BPF_PROBE_MEM` and `BPF_PROBE_MEM32` loads as 64-bit defining instructions, bypassing explicit zero-extensions.
> - [Low] Stale comment referencing a deleted parameter of `bpf_is_reg64`.
> --
>
> --- Patch [4]: [PATCH bpf-next v2 4/5] bpf: simplify the bpf_is_reg64() ---
> commit ee97fd37754941b6dd81dccf5f68e7f82c74ea6d
> Author: Eduard Zingerman <eddyz87@gmail.com>
>
> bpf: simplify the bpf_is_reg64()
>
> This patch simplifies the bpf_is_reg64() function by removing unused
> parameters and code paths related to BPF_JMP instructions. It also
> streamlines the condition expressions for identifying 64-bit registers.
>
> > diff --git a/kernel/bpf/fixups.c b/kernel/bpf/fixups.c
> > index 6125598d16a84..ac0a388b40218 100644
> > --- a/kernel/bpf/fixups.c
> > +++ b/kernel/bpf/fixups.c
> [ ... ]
> > @@ -44,6 +44,42 @@ static int insn_def_regno(const struct bpf_insn *insn)
> > }
> > }
> >
> > +/*
> > + * For use only in combination with insn_def_regno() >= 0.
> > + * Returns TRUE if the destination register operates on 64-bit,
> > + * otherwise return FALSE.
> > + */
> > +static bool bpf_is_reg64(struct bpf_insn *insn)
> > +{
> > + u8 class = BPF_CLASS(insn->code);
> > + u8 mode = BPF_MODE(insn->code);
> > + u8 size = BPF_SIZE(insn->code);
> > + u8 op = BPF_OP(insn->code);
> [ ... ]
> > + /* non 64-bit loads */
> > + if (class == BPF_LDX && mode == BPF_MEM && size != BPF_DW)
> > + return false;
>
> [Severity: High]
> Does this condition miss BPF_PROBE_MEM and BPF_PROBE_MEM32 loads?
>
> Because this check strictly matches the BPF_MEM mode, it seems these other
> 32-bit load modes would bypass this check and fall through to returning true.
>
> Could this cause bpf_insn_def32() to inappropriately return -1, skipping
> necessary zero-extension for architectures that rely on explicit BPF_ZEXT_REG
> patching? If so, the upper 32 bits might contain garbage data, potentially
> leading to out-of-bounds memory accesses if the register is later used in an
> address calculation.
I don't think this is exploitable. Both BPF_PROBE_MEM and BPF_PROBE_MEM32 are
inserted by bpf_convert_ctx_accesses, that directly modify insn->code,
w/o call to bpf_patch_*(). Hence bpf_is_reg64 is not invoked for these
converted instructions second time. Hence the aux->zext_dst flag for such
instructions retains it's original inference.
Nevertheless, I modified condition to include BPF_PROBE_MEM{,32}
to make it future proof.
> > +
> > + /* atomics, see insn_def_regno() */
> > + if (class == BPF_STX && size != BPF_DW)
> > + return false;
> [ ... ]
> > @@ -623,7 +659,7 @@ int bpf_opt_subreg_zext_lo32_rnd_hi32(struct bpf_verifier_env *env,
> > * BPF_STX + SRC_OP, so it is safe to pass NULL
> > * here.
> > */
> > - if (bpf_is_reg64(&insn, load_reg, NULL, DST_OP)) {
> > + if (bpf_is_reg64(&insn)) {
>
> [Severity: Low]
> This isn't a bug, but should the comment directly above this call be removed
> as well?
>
> It references a fourth parameter that has been deleted by this patch, which
> could be confusing for future readers.
>
> > if (class == BPF_LD &&
> > BPF_MODE(code) == BPF_IMM)
> > i++;
next prev parent reply other threads:[~2026-08-02 11:21 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-01 1:09 [PATCH bpf-next v2 0/5] bpf: infer zext_dst based on static register liveness analysis Eduard Zingerman
2026-08-01 1:09 ` [PATCH bpf-next v2 1/5] bpf: do not print a newline after disassembly in bpf_verbose_insn() Eduard Zingerman
2026-08-01 1:09 ` [PATCH bpf-next v2 2/5] bpf: track upper 32-bit register halves' liveness in compute_live_registers() Eduard Zingerman
2026-08-01 1:35 ` sashiko-bot
2026-08-01 4:40 ` Eduard Zingerman
2026-08-01 1:09 ` [PATCH bpf-next v2 3/5] bpf: infer zext_dst based on static register liveness analysis Eduard Zingerman
2026-08-01 1:42 ` sashiko-bot
2026-08-01 5:41 ` Eduard Zingerman
2026-08-01 1:09 ` [PATCH bpf-next v2 4/5] bpf: simplify the bpf_is_reg64() Eduard Zingerman
2026-08-01 1:34 ` sashiko-bot
2026-08-02 11:21 ` Eduard Zingerman [this message]
2026-08-01 1:09 ` [PATCH bpf-next v2 5/5] selftests/bpf: verify zext_dst annotations for various instructions Eduard Zingerman
2026-08-01 1:33 ` sashiko-bot
2026-08-01 4:24 ` Eduard Zingerman
2026-08-01 14:56 ` Min-gyu Kim
2026-08-02 20:21 ` Eduard Zingerman
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=c4f702276cffa8d133bea614a9eac94164357870.camel@gmail.com \
--to=eddyz87@gmail.com \
--cc=bpf@vger.kernel.org \
--cc=sashiko-reviews@lists.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