From: sashiko-bot@kernel.org
To: "Qiliang Yuan" <odys.yuan@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v2 07/22] bpf: Let the patch list remove instructions
Date: Fri, 30 Oct 2026 12:11:12 +0000 [thread overview]
Message-ID: <sashiko-outbox-190997@kernel.org> (raw)
In-Reply-To: <20261030-bpf-verifier-patch-batch-v2-7-55cd43439f7c@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] bpf: premature prog->len update breaks bpf_find_subprog() in bpf_patch_list_commit()
--
commit 36c5b3c1e86de2cef14800f7c3faaea5d0fafe3d
Author: Qiliang Yuan <odys.yuan@gmail.com>
bpf: Let the patch list remove instructions
This commit adds bpf_patch_list_del() to allow the verifier's patch list to
queue instruction removals alongside replacements, updating line info,
subprogs, function pointers, instruction arrays, and offloaded programs when
committed.
> diff --git a/kernel/bpf/fixups.c b/kernel/bpf/fixups.c
> index 940265cb80ebf..1a1a374a076b1 100644
> --- a/kernel/bpf/fixups.c
> +++ b/kernel/bpf/fixups.c
[ ... ]
> @@ -514,25 +624,43 @@ int bpf_patch_list_commit(struct bpf_verifier_env *env)
> env->insn_aux_data_len = img.new_cnt;
> data = NULL;
>
> + /* before subprogs are removed, since it looks at them */
> for (i = 0; i < env->func_ptr_cnt; i++) {
> struct bpf_func_ptr *fp = &env->func_ptrs[i];
> + int subprog;
>
> if (fp->xlated_off == BPF_FUNC_PTR_DELETED)
> continue;
> + if (bpf_patch_image_deleted(&img, fp->xlated_off)) {
> + subprog = bpf_find_subprog(env, fp->xlated_off);
> + if (subprog <= 0 ||
> + img.new_off[env->subprog_info[subprog].start] ==
> + img.new_off[env->subprog_info[subprog + 1].start]) {
> + fp->xlated_off = BPF_FUNC_PTR_DELETED;
> + continue;
> + }
> + }
[Severity: High]
Can calling bpf_find_subprog() here with the old-image offset fp->xlated_off
falsely mark a live function pointer as BPF_FUNC_PTR_DELETED when the program
shrinks?
Earlier in bpf_patch_list_commit(), bpf_patch_image_install() updates
prog->len to img.new_cnt:
kernel/bpf/core.c:bpf_patch_image_install() {
memcpy(prog->insnsi, img->insns, sizeof(*img->insns) * img->new_cnt);
prog->len = img->new_cnt;
...
}
When bpf_patch_list_commit() then calls
bpf_find_subprog()->bpf_find_containing_subprog(), it checks the old-image
offset against the already-shrunk env->prog->len:
kernel/bpf/verifier.c:bpf_find_containing_subprog() {
if (off >= env->prog->len || off < 0 || env->subprog_cnt == 0)
return NULL;
...
}
If a live static subprogram near the end of the program has its entry
instruction removed (for example, a nop or simplified branch removed in
bpf_opt_remove_nops()) and earlier instruction removals shrink the program
such that fp->xlated_off >= img.new_cnt, bpf_find_subprog() will return
-ENOENT.
Wouldn't that cause the subprog <= 0 check to set fp->xlated_off to
BPF_FUNC_PTR_DELETED even though the subprogram still has live instructions,
causing resolve_func_ptrs() during bpf_jit_subprogs() to write NULL into the
read-only map slot used by callx?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261030-bpf-verifier-patch-batch-v2-0-55cd43439f7c@gmail.com?part=7
next prev parent reply other threads:[~2026-10-30 12:11 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-30 11:51 [PATCH bpf-next v2 00/22] bpf: Replace bpf_patch_insn_data() with a list of deferred patches Qiliang Yuan
2026-10-30 11:51 ` [PATCH bpf-next v2 01/22] bpf: Add a list of deferred instruction patches Qiliang Yuan
2026-10-30 11:51 ` [PATCH bpf-next v2 02/22] bpf: Remap the verifier state through the patch list Qiliang Yuan
2026-10-30 11:51 ` [PATCH bpf-next v2 03/22] bpf: Apply single-instruction patches of the verifier in place Qiliang Yuan
2026-10-30 11:51 ` [PATCH bpf-next v2 04/22] bpf: Queue the rewrites of bpf_do_misc_fixups() Qiliang Yuan
2026-10-30 11:51 ` [PATCH bpf-next v2 05/22] bpf: Expand a backward may_goto to gotol when patches push it out of range Qiliang Yuan
2026-10-30 11:51 ` [PATCH bpf-next v2 06/22] bpf: Drop the constant delta from bpf_do_misc_fixups() Qiliang Yuan
2026-10-30 11:51 ` [PATCH bpf-next v2 07/22] bpf: Let the patch list remove instructions Qiliang Yuan
2026-10-30 12:11 ` sashiko-bot [this message]
2026-10-30 11:51 ` [PATCH bpf-next v2 08/22] bpf: Remove dead code through the patch list Qiliang Yuan
2026-10-30 11:51 ` [PATCH bpf-next v2 09/22] bpf: Strip nops " Qiliang Yuan
2026-10-30 11:51 ` [PATCH bpf-next v2 10/22] bpf: Batch the patches of bpf_opt_subreg_zext_lo32_rnd_hi32() Qiliang Yuan
2026-10-30 11:51 ` [PATCH bpf-next v2 11/22] bpf: Allow patching an instruction twice through the patch list Qiliang Yuan
2026-10-30 11:51 ` [PATCH bpf-next v2 12/22] bpf: Teach the patch list to insert in front of an instruction Qiliang Yuan
2026-10-30 11:51 ` [PATCH bpf-next v2 13/22] bpf: Allow inserting in front of a queued patch Qiliang Yuan
2026-10-30 11:51 ` [PATCH bpf-next v2 14/22] bpf: Move bpf_convert_ctx_accesses() to the patch list Qiliang Yuan
2026-10-30 11:52 ` [PATCH bpf-next v2 15/22] bpf: Insert the may_goto counter setup through " Qiliang Yuan
2026-10-30 11:52 ` [PATCH bpf-next v2 16/22] bpf: Append the hidden subprog " Qiliang Yuan
2026-10-30 11:52 ` [PATCH bpf-next v2 17/22] bpf: Inline bpf_loop() calls " Qiliang Yuan
2026-10-30 11:52 ` [PATCH bpf-next v2 18/22] bpf: Apply the patch list without a verifier env Qiliang Yuan
2026-10-30 11:52 ` [PATCH bpf-next v2 19/22] bpf: Blind constants through the patch list Qiliang Yuan
2026-10-30 11:52 ` [PATCH bpf-next v2 20/22] bpf: Remove the old instruction patching code Qiliang Yuan
2026-10-30 11:52 ` [PATCH bpf-next v2 21/22] selftests/bpf: Test jumps around patches of bpf_do_misc_fixups() Qiliang Yuan
2026-10-30 11:52 ` [PATCH bpf-next v2 22/22] selftests/bpf: Cover a backward may_goto pushed out of range by patches Qiliang Yuan
2026-10-30 12:13 ` sashiko-bot
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-190997@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=odys.yuan@gmail.com \
--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