From: sashiko-bot@kernel.org
To: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>, bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next 10/21] bpf: Remove the limits on tables of functions
Date: Mon, 16 Nov 2026 06:14:40 +0000 [thread overview]
Message-ID: <sashiko-outbox-216249@kernel.org> (raw)
In-Reply-To: <20261116055638.4171529-11-alexei.starovoitov@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] bpf: dangling func_set_index entry on alloc failure in
mark_reg_func_set()
--
commit 6c238cf296ed857f2bdb0c90315601a5bb923f5c
Author: Alexei Starovoitov <ast@kernel.org>
bpf: Remove the limits on tables of functions
This commit removes the fixed limits on function pointer sets, read
targets, and total function pointers across maps by indexing sets in a
hash table, collecting read targets in a bitmap, and dynamically growing
the function pointer table.
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index f4e2a9f9f7873..e29eb7d7162b6 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
[ ... ]
> @@ -7179,49 +7161,39 @@ static int cmp_u16(const void *a, const void *b)
> * Equal sets have the same number, so registers are compared as they are.
> */
> static int mark_reg_func_set(struct bpf_verifier_env *env, struct bpf_reg_state *regs, int regno,
> - u16 *subprogs, u32 cnt)
> + const u32 *subprogs, u32 n)
> {
> - struct bpf_func_set **sets, *set;
> - u32 i, n = 0;
> + struct bpf_func_set *set;
> + u64 key;
> + int i;
>
> - sort(subprogs, cnt, sizeof(*subprogs), cmp_u16, NULL);
> - for (i = 0; i < cnt; i++)
> - if (!n || subprogs[n - 1] != subprogs[i])
> - subprogs[n++] = subprogs[i];
> mark_reg_func_ptr(env, regs, regno, n == 1 ? subprogs[0] : 0);
> if (n == 1)
> return 0;
>
> - for (i = 0; i < env->func_set_cnt; i++) {
> + /* sets with the same hash have keys in a row */
> + key = (u64)jhash2(subprogs, n, 0) << 32;
> + for (; (i = bpf_index_find(&env->func_set_index, key)) >= 0; key++) {
> set = env->func_sets[i];
> if (set->cnt == n && !memcmp(set->subprog, subprogs, n * sizeof(*subprogs)))
> break;
> }
> - if (i == env->func_set_cnt) {
> - if (i == BPF_MAX_FUNC_SETS) {
> - verbose(env, "more than %d sets of functions\n", BPF_MAX_FUNC_SETS);
> - return -E2BIG;
> - }
> - sets = krealloc_array(env->func_sets, i + 1, sizeof(*sets), BPF_VERIFIER_GFP);
> - if (!sets)
> + if (i < 0) {
> + i = env->func_set_cnt;
> + if (!bpf_table_next(env->func_sets, i) ||
> + bpf_index_add(&env->func_set_index, key, i))
> return -ENOMEM;
> - env->func_sets = sets;
> - set = kzalloc_flex(*set, subprog, n, BPF_VERIFIER_GFP);
> + set = kvzalloc_flex(*set, subprog, n, BPF_VERIFIER_GFP);
> if (!set)
> return -ENOMEM;
> set->cnt = n;
> memcpy(set->subprog, subprogs, n * sizeof(*subprogs));
> - sets[env->func_set_cnt++] = set;
> + env->func_sets[env->func_set_cnt++] = set;
> }
> regs[regno].func_set = i + 1;
> return 0;
> }
[Severity: Medium]
Can a failed kvzalloc_flex() here leave a dangling entry in
env->func_set_index pointing to an uninitialized env->func_sets[i] slot?
bpf_index_add() inserts key -> i before set is allocated, and
bpf_table_next() grows env->func_sets via kvrealloc() without zeroing the
new slots. If kvzalloc_flex() returns NULL, mark_reg_func_set() returns
-ENOMEM without initializing env->func_sets[i] or incrementing
env->func_set_cnt. When round_is_dropped(env) is true, do_check_all()
ignores the error and starts a new round that reuses env->func_set_index:
kernel/bpf/verifier.c:do_check_all() {
for (;;) {
bpf_flow_new_round(env);
ret = do_check_main(env);
ret = ret ?: do_check_subprogs(env);
if (!round_is_dropped(env))
return ret;
...
}
Looking up key again in the next round will find i in env->func_set_index
and dereference the uninitialized env->func_sets[i] pointer. Allocating
set before calling bpf_index_add() (or freeing set if bpf_index_add()
fails) would avoid this.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116055638.4171529-1-alexei.starovoitov@gmail.com?part=10
next prev parent reply other threads:[~2026-11-16 6:14 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 5:56 [PATCH bpf-next 00/21] bpf: Remove the limits on maps, kfuncs, subprogs and special fields Alexei Starovoitov
2026-11-16 5:56 ` [PATCH bpf-next 01/21] bpf: Stop a load only when the loader is killed or has to freeze Alexei Starovoitov
2026-11-16 6:39 ` bot+bpf-ci
2026-11-16 6:49 ` sashiko-bot
2026-11-16 5:56 ` [PATCH bpf-next 02/21] bpf: Fail the load when there is no memory Alexei Starovoitov
2026-11-16 6:29 ` sashiko-bot
2026-11-16 5:56 ` [PATCH bpf-next 03/21] bpf: Give a syscall program the largest context when it does tail calls Alexei Starovoitov
2026-11-16 5:56 ` [PATCH bpf-next 04/21] bpf: Do not inline bpf_loop() when its callback is dead code Alexei Starovoitov
2026-11-16 5:56 ` [PATCH bpf-next 05/21] bpf: Dump programs that have more than 524288 insns Alexei Starovoitov
2026-11-16 5:56 ` [PATCH bpf-next 06/21] bpf: Resolve BTF structs and arrays first Alexei Starovoitov
2026-11-16 6:13 ` sashiko-bot
2026-11-16 5:56 ` [PATCH bpf-next 07/21] bpf: Remove the limits on maps, BTFs and fd_array of a program Alexei Starovoitov
2026-11-16 6:39 ` bot+bpf-ci
2026-11-16 5:56 ` [PATCH bpf-next 08/21] bpf: Do not scan all maps for each insn and each subprog Alexei Starovoitov
2026-11-16 6:16 ` sashiko-bot
2026-11-16 5:56 ` [PATCH bpf-next 09/21] bpf: Remove the limits on kfuncs of a program Alexei Starovoitov
2026-11-16 6:39 ` bot+bpf-ci
2026-11-16 5:56 ` [PATCH bpf-next 10/21] bpf: Remove the limits on tables of functions Alexei Starovoitov
2026-11-16 6:14 ` sashiko-bot [this message]
2026-11-16 5:56 ` [PATCH bpf-next 11/21] libbpf: Size the tables of the loader program from the object Alexei Starovoitov
2026-11-16 6:20 ` sashiko-bot
2026-11-16 5:56 ` [PATCH bpf-next 12/21] bpf: Relax jumps that patches push out of range Alexei Starovoitov
2026-11-16 6:52 ` bot+bpf-ci
2026-11-16 5:56 ` [PATCH bpf-next 13/21] bpf: Keep the call graph in lists of edges Alexei Starovoitov
2026-11-16 6:39 ` sashiko-bot
2026-11-16 5:56 ` [PATCH bpf-next 14/21] bpf: Find the effects of callees on the call graph Alexei Starovoitov
2026-11-16 5:56 ` [PATCH bpf-next 15/21] bpf: Link the decl tags of a type Alexei Starovoitov
2026-11-16 5:56 ` [PATCH bpf-next 16/21] bpf: Remove BPF_MAX_SUBPROGS Alexei Starovoitov
2026-11-16 5:56 ` [PATCH bpf-next 17/21] bpf: Walk each type once when looking for special fields Alexei Starovoitov
2026-11-16 5:56 ` [PATCH bpf-next 18/21] bpf: Raise the limit on the length of BTF names Alexei Starovoitov
2026-11-16 5:56 ` [PATCH bpf-next 19/21] bpf: Find dominators in O(n log n) Alexei Starovoitov
2026-11-16 5:56 ` [PATCH bpf-next 20/21] selftests/bpf: Test programs above the old limits Alexei Starovoitov
2026-11-16 6:33 ` sashiko-bot
2026-11-16 6:39 ` bot+bpf-ci
2026-11-16 5:56 ` [PATCH bpf-next 21/21] selftests/bpf: Test limits of the load with raw programs Alexei Starovoitov
2026-11-16 6:39 ` 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-216249@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