From: Shung-Hsi Yu <shung-hsi.yu@suse.com>
To: Yiyang Chen <chenyy23@mails.tsinghua.edu.cn>,
sashiko-reviews@lists.linux.dev
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH 1/2] bpf: Preserve stack frame number for commuted arithmetic
Date: Wed, 22 Jul 2026 15:44:19 +0800 [thread overview]
Message-ID: <amByrnAG0NWd0dLK@u94a> (raw)
In-Reply-To: <20260721094829.3D0C71F00A3A@smtp.kernel.org>
On Tue, Jul 21, 2026 at 09:48:28AM +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Critical] The patch completely breaks the security check that prohibits subtracting a pointer from a scalar (`scalar -= pointer`), allowing unprivileged eBPF programs to bypass memory isolation and achieve arbitrary kernel memory read/write.
> --
>
> --- Patch [1]: [PATCH 1/2] bpf: Preserve stack frame number for commuted arithmetic ---
> commit 3b8c2832d6eb05fc6ef4d1f2af9ee96ccdf5566e
> Author: Yiyang Chen <chenyy23@mails.tsinghua.edu.cn>
>
> bpf: Preserve stack frame number for commuted arithmetic
>
> This patch modifies how commuted pointer arithmetic is handled in
> adjust_reg_min_max_vals(). It uses a temporary off_reg to copy the
> destination register before calling adjust_ptr_min_max_vals().
>
> > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> > index 52be0a118cce0..3c0af83db4672 100644
> > --- a/kernel/bpf/verifier.c
> > +++ b/kernel/bpf/verifier.c
>
> [ ... ]
>
> > @@ -14854,15 +14855,18 @@ static int adjust_reg_min_max_vals(struct bpf_verifier_env *env,
> > bpf_alu_string[opcode >> 4]);
> > return -EACCES;
> > } else {
> > + struct bpf_reg_state off_reg;
> > +
> > /* scalar += pointer
> > * This is legal, but we have to reverse our
> > * src/dest handling in computing the range
> > */
> > + off_reg = *dst_reg;
> > err = mark_chain_precision(env, insn->dst_reg);
> > if (err)
> > return err;
> > return adjust_ptr_min_max_vals(env, insn,
> > - src_reg, dst_reg);
> > + src_reg, &off_reg);
>
> [Severity: Critical]
> Does passing a pointer to the local stack variable off_reg here break the
> pointer equality check in adjust_ptr_min_max_vals()?
>
> In adjust_ptr_min_max_vals(), we have this check to prevent subtracting a
> pointer from a scalar:
>
> case BPF_SUB:
> if (dst_reg == off_reg) {
> /* scalar -= pointer. Creates an unknown scalar */
> verbose(env, "R%d tried to subtract pointer from scalar\n",
> dst);
> return -EACCES;
> }
>
> Since off_reg is now a stack pointer from adjust_reg_min_max_vals(), it will
> never equal the verifier state array pointer dst_reg. Could this regression
> allow eBPF programs to bypass the restriction and execute scalar -= pointer,
> potentially breaking memory isolation?
This seems right. adjust_ptr_min_max_vals() has the assumptions that
either one of these cases has to be true
1. off_reg == dst_reg && ptr_reg == src_reg
2. ptr_reg == dst_reg && off_reg == src_reg
By passing neither dst_reg and src_reg as off_reg we're breaking the
assumption. Perhaps we should have add a ptr_is_dst_reg argument for
adjust_ptr_min_max_vals(), which could also then passed down to
sanitize_ptr_alu() as well (which currently computes ptr_is_dst_reg
itself).
next prev parent reply other threads:[~2026-07-22 7:44 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-21 9:39 [bpf-next v2 0/2] bpf: Preserve stack frame number for commuted arithmetic Yiyang Chen
2026-07-21 9:39 ` [PATCH 1/2] " Yiyang Chen
2026-07-21 9:48 ` sashiko-bot
2026-07-22 7:44 ` Shung-Hsi Yu [this message]
2026-07-22 0:12 ` Eduard Zingerman
2026-07-22 8:46 ` Shung-Hsi Yu
2026-07-21 9:39 ` [PATCH 2/2] selftests/bpf: Cover stack frame number after scalar plus fp Yiyang Chen
2026-07-21 10:29 ` bot+bpf-ci
2026-07-21 23:53 ` 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=amByrnAG0NWd0dLK@u94a \
--to=shung-hsi.yu@suse.com \
--cc=bpf@vger.kernel.org \
--cc=chenyy23@mails.tsinghua.edu.cn \
--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 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.