From: Yuan Chen <chenyuan@kylinos.cn>
To: bpf@vger.kernel.org
Cc: netdev@vger.kernel.org, Alexei Starovoitov <ast@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, Yuan Chen <chenyuan@kylinos.cn>
Subject: [PATCH bpf-next 0/2] bpf: Fix the array map gen_lookup index bounds check
Date: Sun, 15 Nov 2026 18:25:57 +0800 [thread overview]
Message-ID: <20261115102559.465375-1-chenyuan@kylinos.cn> (raw)
The inlined bpf_map_lookup_elem() of the array map flavors bounds the
index with a 64-bit JGE against map->max_entries. The index is a
zero-extended u32, but the immediate of a 64-bit JGE is sign-extended,
so for max_entries >= 0x80000000 the compare is never true.
With bypass_spec_v1 the inlined code then addresses the array out of
bounds; without it the index_mask AND keeps the access in bounds, but an
out-of-range key returns a masked element instead of NULL.
Patch 1 switches the three compares to BPF_JMP32_IMM(). Patch 2 adds a
selftest that checks the emitted compare in the translated program.
Yuan Chen (2):
bpf: Use a 32-bit compare in the array map gen_lookups
selftests/bpf: Test the emitted bounds check of the array gen_lookup
kernel/bpf/arraymap.c | 12 +-
.../bpf/prog_tests/array_gen_lookup_jmp32.c | 204 ++++++++++++++++++
2 files changed, 210 insertions(+), 6 deletions(-)
create mode 100644 tools/testing/selftests/bpf/prog_tests/array_gen_lookup_jmp32.c
--
2.54.0
next reply other threads:[~2026-11-15 10:26 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-15 10:25 Yuan Chen [this message]
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-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=20261115102559.465375-1-chenyuan@kylinos.cn \
--to=chenyuan@kylinos.cn \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--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