From: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>
To: "Yuan Chen" <chenyuan@kylinos.cn>, <bpf@vger.kernel.org>
Cc: <netdev@vger.kernel.org>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Eduard Zingerman" <eddyz87@gmail.com>,
"Martin KaFai Lau" <martin.lau@linux.dev>,
"Shuah Khan" <shuah@kernel.org>,
<linux-kselftest@vger.kernel.org>
Subject: Re: [PATCH bpf-next 1/2] bpf: Use a 32-bit compare in the array map gen_lookups
Date: Wed, 25 Nov 2026 04:48:39 +0000 [thread overview]
Message-ID: <DN40QM3CLBU9.3GC3UR9AVWNZF@gmail.com> (raw)
In-Reply-To: <20261115102559.465375-2-chenyuan@kylinos.cn>
On Sun, Nov 15, 2026 at 02:25 AM Yuan Chen <chenyuan@kylinos.cn> wrote:
> Use BPF_JMP32_IMM() for the three compares, as commit 70504de0bb62
> ("xsk: Use a 32-bit compare in xsk_map_gen_lookup") did for
> xsk_map_gen_lookup().
bpf-ci is right. The sparc64 JIT has no BPF_JMP32.
build_insn() returns -EINVAL for the new compare.
Every prog with a lookup in an array loses the JIT there.
With CONFIG_BPF_JIT_ALWAYS_ON the load fails with -ENOTSUPP.
The riscv64 JIT adds two zero extensions, one for r0 and one for the imm.
The bug needs a map of 16 Gbytes.
imo it's not worth changing the code of every lookup for that.
can we skip the inlining for such maps ?
map_gen_lookup() returns -EOPNOTSUPP, like for BPF_F_INNER_MAP.
bpf_do_misc_fixups() then calls ops->map_lookup_elem().
All three compare u32 with u32.
The emitted code stays the same for all other maps.
Then patch 2 has nothing to check. Drop it.
bpf_do_misc_fixups() has the same compare in front of bpf_tail_call().
With max_entries 0x80000000 the index 0x80000005 calls prog 5.
The diff doesn't fix that one.
diff --git a/kernel/bpf/arraymap.c b/kernel/bpf/arraymap.c
index 508706d..89c22c7 100644
--- a/kernel/bpf/arraymap.c
+++ b/kernel/bpf/arraymap.c
@@ -227,6 +227,10 @@ static int array_map_gen_lookup(struct bpf_map *map, struct bpf_insn *insn_buf)
if (map->map_flags & BPF_F_INNER_MAP)
return -EOPNOTSUPP;
+ /* The imm of BPF_JGE is sign extended. It cannot hold such max_entries. */
+ if (map->max_entries > S32_MAX)
+ return -EOPNOTSUPP;
+
*insn++ = BPF_ALU64_IMM(BPF_ADD, map_ptr, offsetof(struct bpf_array, value));
*insn++ = BPF_LDX_MEM(BPF_W, ret, index, 0);
if (!map->bypass_spec_v1) {
@@ -302,6 +306,10 @@ static int percpu_array_map_gen_lookup(struct bpf_map *map, struct bpf_insn *ins
if (map->map_flags & BPF_F_INNER_MAP)
return -EOPNOTSUPP;
+ /* The imm of BPF_JGE is sign extended. It cannot hold such max_entries. */
+ if (map->max_entries > S32_MAX)
+ return -EOPNOTSUPP;
+
BUILD_BUG_ON(offsetof(struct bpf_array, map) != 0);
*insn++ = BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, offsetof(struct bpf_array, pptrs));
@@ -1496,6 +1504,10 @@ static int array_of_map_gen_lookup(struct bpf_map *map,
const int map_ptr = BPF_REG_1;
const int index = BPF_REG_2;
+ /* The imm of BPF_JGE is sign extended. It cannot hold such max_entries. */
+ if (map->max_entries > S32_MAX)
+ return -EOPNOTSUPP;
+
*insn++ = BPF_ALU64_IMM(BPF_ADD, map_ptr, offsetof(struct bpf_array, value));
*insn++ = BPF_LDX_MEM(BPF_W, ret, index, 0);
if (!map->bypass_spec_v1) {
> Fixes: b2157399cc98 ("bpf: prevent out-of-bounds speculation")
Wrong tag. At that commit array_map_alloc() has:
if (array_size >= U32_MAX - PAGE_SIZE)
return ERR_PTR(-ENOMEM);
elem_size is 8 or more, so max_entries is below 0x20000000.
The same is true at 81ed18ab3098, which bpf-ci proposes.
The limit went away in commit 1bc5975613ed ("bpf: Eliminate
rlimit-based memory accounting for arraymap maps").
pw-bot: cr
next prev parent reply other threads:[~2026-11-25 4:48 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-15 10:25 [PATCH bpf-next 0/2] bpf: Fix the array map gen_lookup index bounds check Yuan Chen
2026-11-15 10:25 ` [PATCH bpf-next 1/2] bpf: Use a 32-bit compare in the array map gen_lookups Yuan Chen
2026-11-15 11:00 ` bot+bpf-ci
2026-11-25 4:48 ` Alexei Starovoitov [this message]
2026-11-15 10:25 ` [PATCH bpf-next 2/2] selftests/bpf: Test the emitted bounds check of the array gen_lookup Yuan Chen
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=DN40QM3CLBU9.3GC3UR9AVWNZF@gmail.com \
--to=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=chenyuan@kylinos.cn \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=netdev@vger.kernel.org \
--cc=shuah@kernel.org \
/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