From: sashiko-bot@kernel.org
To: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>, bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next 22/26] bpf: Remove scalar ids from regsafe()
Date: Mon, 09 Nov 2026 07:06:09 +0000 [thread overview]
Message-ID: <sashiko-outbox-204525@kernel.org> (raw)
In-Reply-To: <20261109064715.2382452-23-alexei.starovoitov@gmail.com>
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] bpf: alpha-renaming of struct_ops ctx_arg_info ref_id in
check_ids() [1]
--
commit 4ddf1d7e2a622751a128b84cb218611e091c605f
Author: Alexei Starovoitov <ast@kernel.org>
bpf: Remove scalar ids from regsafe()
This commit removes check_scalar_ids() and the scalar ID comparison logic from
regsafe(), as scalar registers no longer carry IDs.
> diff --git a/kernel/bpf/states.c b/kernel/bpf/states.c
> index b606763496552..48359e789faad 100644
> --- a/kernel/bpf/states.c
> +++ b/kernel/bpf/states.c
> @@ -58,7 +58,7 @@ static bool check_ids(u32 old_id, u32 cur_id, struct bpf_idmap *idmap)
> return true;
>
> /* a name of what the caller has, see BPF_INHERITED_ID */
> - if (((old_id | cur_id) & ~BPF_ADD_CONST) >= BPF_INHERITED_ID)
> + if ((old_id | cur_id) >= BPF_INHERITED_ID)
> return old_id == cur_id;
[Severity: Critical]
This problem wasn't introduced by this patch, but can check_ids() [1]
map an unrelated reference ID in cur->refs[] to a struct_ops __ref context
argument's fixed aux->ctx_arg_info[i].ref_id during refsafe()?
In do_check_common(), the verifier acquires a reference for each __ref
struct_ops context argument and stores the literal ID in
aux->ctx_arg_info[i].ref_id, while BPF_REG_1 (PTR_TO_CTX) keeps id == 0.
When the program later loads that argument from PTR_TO_CTX, btf_ctx_access()
populates info->ref_id from ctx_arg_info[i].ref_id, and __check_ctx_access()
checks whether that literal ID is still in env->cur_state->refs[]:
kernel/bpf/verifier.c:__check_ctx_access() {
...
if (base_type(info->reg_type) == PTR_TO_BTF_ID) {
if (info->ref_id &&
!find_reference_state(env->cur_state, info->ref_id)) {
verbose(env, "invalid bpf_context access off=%d. Reference may already be released\n",
off);
return -EACCES;
}
}
...
}
Because ctx_arg_info[i].ref_id is a normal ID below BPF_INHERITED_ID and is
not anchored to PTR_TO_CTX, refsafe() -> check_ids() allows alpha-renaming it.
If an earlier branch keeps the initial context reference (id = 1) and a later
branch releases id = 1, acquires an unrelated reference (id = 2), and reaches
the same pruning point with PTR_TO_CTX still live, check_ids() maps cur_id = 2
to old_id = 1 and prunes the second branch. If the code after the merge point
reloads the __ref argument from PTR_TO_CTX, the second path uses or releases
the already-released context object, causing a use-after-free, double free, or
reference leak.
[1] https://sashiko.dev/#/bug/linux-3dbabad3-179e-4dd4-a907-20f15cf47b12
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261109064715.2382452-1-alexei.starovoitov@gmail.com?part=22
next prev parent reply other threads:[~2026-11-09 7:06 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-09 6:46 [PATCH bpf-next 00/26] bpf: Find linked registers by scalar evolution, remove scalar ids Alexei Starovoitov
2026-11-09 6:46 ` [PATCH bpf-next 01/26] bpf: Keep the 32-bit range across a no-op sign extension Alexei Starovoitov
2026-11-09 6:46 ` [PATCH bpf-next 02/26] bpf: Model 32-bit shifts and divisions exactly in scalar evolution Alexei Starovoitov
2026-11-09 6:46 ` [PATCH bpf-next 03/26] bpf: Construct scalar evolution expressions without allocations Alexei Starovoitov
2026-11-09 6:46 ` [PATCH bpf-next 04/26] bpf: Don't join dead registers in scalar evolution Alexei Starovoitov
2026-11-09 6:46 ` [PATCH bpf-next 05/26] bpf: Simplify scalar evolution expressions at construction Alexei Starovoitov
2026-11-09 6:46 ` [PATCH bpf-next 06/26] bpf: Give SSA names to the values that scalar evolution does not track Alexei Starovoitov
2026-11-09 7:45 ` bot+bpf-ci
2026-11-09 6:46 ` [PATCH bpf-next 07/26] bpf: Compute scalar evolution expressions for whole subprogs Alexei Starovoitov
2026-11-09 6:46 ` [PATCH bpf-next 08/26] bpf: Mark the attr argument of bpf_sys_bpf() as MEM_WRITE Alexei Starovoitov
2026-11-09 7:17 ` bot+bpf-ci
2026-11-09 6:46 ` [PATCH bpf-next 09/26] bpf: Check writes to the stack against bpf_may_write_mask() Alexei Starovoitov
2026-11-09 7:42 ` sashiko-bot
2026-11-09 6:46 ` [PATCH bpf-next 10/26] bpf: Detect a dead branch when a range and var_off don't overlap Alexei Starovoitov
2026-11-09 6:46 ` [PATCH bpf-next 11/26] bpf: Don't treat half of a 64-bit spill as a 32-bit spill on big endian Alexei Starovoitov
2026-11-09 6:46 ` [PATCH bpf-next 12/26] bpf: Refine registers linked by scalar evolution at conditional jumps Alexei Starovoitov
2026-11-09 7:41 ` sashiko-bot
2026-11-09 7:45 ` bot+bpf-ci
2026-11-09 6:46 ` [PATCH bpf-next 13/26] selftests/bpf: Test registers linked by scalar evolution Alexei Starovoitov
2026-11-09 6:46 ` [PATCH bpf-next 14/26] selftests/bpf: Test sign extensions of a range and of a linked register Alexei Starovoitov
2026-11-09 6:46 ` [PATCH bpf-next 15/26] bpf: Recompute a pointer after the jump that bounds its index Alexei Starovoitov
2026-11-09 7:32 ` sashiko-bot
2026-11-09 6:47 ` [PATCH bpf-next 16/26] selftests/bpf: Test a pointer computed before its index is bounded Alexei Starovoitov
2026-11-09 6:47 ` [PATCH bpf-next 17/26] bpf: Find a copy of an induction variable without scalar ids Alexei Starovoitov
2026-11-09 7:30 ` bot+bpf-ci
2026-11-09 6:47 ` [PATCH bpf-next 18/26] bpf: Find linked registers in the basic blocks of irreducible loops Alexei Starovoitov
2026-11-09 6:47 ` [PATCH bpf-next 19/26] bpf: Remove sync_linked_regs(), refine by scalar evolution only Alexei Starovoitov
2026-11-09 6:47 ` [PATCH bpf-next 20/26] bpf: Recognize copies of a scalar by their ranges in flow_join_makes_up() Alexei Starovoitov
2026-11-09 6:47 ` [PATCH bpf-next 21/26] bpf: Stop assigning ids to scalars Alexei Starovoitov
2026-11-09 7:08 ` sashiko-bot
2026-11-09 6:47 ` [PATCH bpf-next 22/26] bpf: Remove scalar ids from regsafe() Alexei Starovoitov
2026-11-09 7:06 ` sashiko-bot [this message]
2026-11-09 6:47 ` [PATCH bpf-next 23/26] bpf: Remove scalar ids from the join of states Alexei Starovoitov
2026-11-09 6:47 ` [PATCH bpf-next 24/26] bpf: Remove scalar ids from the log and from bpf_verifier.h Alexei Starovoitov
2026-11-09 6:47 ` [PATCH bpf-next 25/26] bpf: Support sign-extended 32-bit linear scalar evolution Alexei Starovoitov
2026-11-09 6:47 ` [PATCH bpf-next 26/26] selftests/bpf: Test loops with a sign-extended 32-bit induction variable Alexei Starovoitov
2026-11-09 18:16 ` [PATCH bpf-next 00/26] bpf: Find linked registers by scalar evolution, remove scalar ids Alexei Starovoitov
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=sashiko-outbox-204525@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=alexei.starovoitov@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