BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Daniel Borkmann" <daniel@iogearbox.net>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf 2/6] bpf: Bound the number of indirect jump edges in a program
Date: Wed, 09 Sep 2026 20:57:00 +0000	[thread overview]
Message-ID: <20260909205701.9C76C1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260909204035.24289-2-daniel@iogearbox.net>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [Critical] Integer overflow in jump table size calculation leads to massive out-of-bounds memory access.
--

commit 4185a35dbc8e33f3114fd8855cb5ca01b0ecf5a9
Author: Daniel Borkmann <daniel@iogearbox.net>

bpf: Bound the number of indirect jump edges in a program

Bounds the total number of gotox edges across the program at
BPF_COMPLEXITY_LIMIT_INSNS to prevent excessive memory and CPU usage
during program loading.

Reported-by: STAR Labs SG <info@starlabs.sg>

[ ... ]

> diff --git a/kernel/bpf/cfg.c b/kernel/bpf/cfg.c
> index 081f7003eae66..e9910228da587 100644
> --- a/kernel/bpf/cfg.c
> +++ b/kernel/bpf/cfg.c
> @@ -388,6 +390,19 @@ static int visit_gotox_insn(int t, struct bpf_verifier_env *env)
>  			return PTR_ERR(jt);
>  
>  		env->insn_aux_data[t].jt = jt;
> +
> +		if (check_add_overflow(env->cfg.gotox_edges, jt->cnt,
> +				       &env->cfg.gotox_edges) ||
> +		    env->cfg.gotox_edges > BPF_MAX_GOTOX_EDGES) {
> +			verbose(env, "number of indirect jump edges in the program exceeds %u\n",
> +				BPF_MAX_GOTOX_EDGES);
> +			bpf_diag_program_structure(
> +				env, t, "too many indirect jump edges",
> +				"Reduce the number of indirect jumps, or the number of distinct targets they can reach.",
> +				"The program has more than %u indirect jump edges in total, counted over every gotox instruction.",
> +				BPF_MAX_GOTOX_EDGES);
> +			return -E2BIG;
> +		}

[Severity: Critical]
This isn't a bug introduced by this patch, but it is a pre-existing issue
in the CFG discovery logic that remains unfixed in this patch series.

Can jt_from_subprog() in kernel/bpf/cfg.c overflow the shift operation
when calculating the size for memcpy()?

If a user with CAP_BPF creates an INSN_ARRAY map with a very large
max_entries (e.g., 0x20000000) and populates it, jt_cur->cnt can be up to
map->max_entries.

In kernel/bpf/cfg.c:jt_from_subprog():

    memcpy(jt->items + old_cnt, jt_cur->items, jt_cur->cnt << 2);

If jt_cur->cnt reaches 0x20000000, the expression jt_cur->cnt << 2
evaluates as a signed 32-bit integer, resulting in -2147483648.

When passed to memcpy(), which expects a size_t, this negative value is
sign-extended to 0xFFFFFFFF80000000 on 64-bit systems. memcpy() attempts
to copy over 18 exabytes of data, causing a catastrophic page fault.

Additionally, if max_entries is 0x40000000, the shift results in 0,
leaving jt->items uninitialized before it is passed to
sort_insn_array_uniq().

>  	}
>  
>  	mark_prune_point(env, t);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260909204035.24289-1-daniel@iogearbox.net?part=2

  reply	other threads:[~2026-09-09 20:57 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-09 20:40 [PATCH bpf 1/6] bpf: Avoid quadratic successor rescan in bpf_compute_scc Daniel Borkmann
2026-09-09 20:40 ` [PATCH bpf 2/6] bpf: Bound the number of indirect jump edges in a program Daniel Borkmann
2026-09-09 20:57   ` sashiko-bot [this message]
2026-09-10 11:15     ` Daniel Borkmann
2026-09-10 11:44   ` Anton Protopopov
2026-09-09 20:40 ` [PATCH bpf 3/6] bpf: Cache the jump table of a subprogram during CFG discovery Daniel Borkmann
2026-09-09 21:34   ` bot+bpf-ci
2026-09-10 11:21     ` Daniel Borkmann
2026-09-10 11:46   ` Anton Protopopov
2026-09-10 21:02   ` Eduard Zingerman
2026-09-09 20:40 ` [PATCH bpf 4/6] bpf: Reject indirect jumps that leave their subprogram Daniel Borkmann
2026-09-09 21:50   ` bot+bpf-ci
2026-09-10 12:10   ` Anton Protopopov
2026-09-10 19:37   ` Eduard Zingerman
2026-09-09 20:40 ` [PATCH bpf 5/6] selftests/bpf: Add tests for the indirect jump edge limit Daniel Borkmann
2026-09-09 21:34   ` bot+bpf-ci
2026-09-10 12:14   ` Anton Protopopov
2026-09-09 20:40 ` [PATCH bpf 6/6] selftests/bpf: Add tests for indirect jumps across subprograms Daniel Borkmann
2026-09-09 21:34   ` bot+bpf-ci
2026-09-10 12:22   ` Anton Protopopov
2026-09-10 18:54 ` [PATCH bpf 1/6] bpf: Avoid quadratic successor rescan in bpf_compute_scc 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=20260909205701.9C76C1F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --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