From: sashiko-bot@kernel.org
To: "Zhiling Zou" <zhilinz@nebusec.ai>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf 1/1] xsk: use a 32-bit compare in xsk_map_gen_lookup
Date: Thu, 10 Sep 2026 16:34:51 +0000 [thread overview]
Message-ID: <20260910163452.220CC1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <7d2cb8e8dfaa9eb8fdff85156987a60960787dc3.1789056660.git.zhilinz@nebusec.ai>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The patch addresses a 64-bit sign-extension bounds check bypass in `xsk_map_gen_lookup` by replacing `BPF_JMP_IMM` with `BPF_JMP32_IMM`, but fails to apply the exact same necessary fix to identical vulnerable patterns in `kernel/bpf/arraymap.c` and `kernel/bpf/fixups.c`. `BPF_JMP_IMM` sign-extends its 32-bit immediate argument to 64 bits before performing the comparison. A `max_entries` value >= `0x80000000` becomes a large negative number in a 64-bit context, meaning the unsigned `BPF_JGE` check against a zero-extended 32-bit index will never jump, skipping the bounds check entirely.
--
commit c7773394d23ffdacd886a0d61cfe827025fc2bfb
Author: Zhiling Zou <zhilinz@nebusec.ai>
xsk: use a 32-bit compare in xsk_map_gen_lookup
This commit fixes a bounds check bypass in xsk_map_gen_lookup() by
switching to a 32-bit compare for the max_entries check. BPF immediates
are sign-extended to 64 bits, which previously caused large max_entries
values to become large negative numbers in a 64-bit context, bypassing
the bounds check.
Cc: stable@vger.kernel.org
> diff --git a/net/xdp/xskmap.c b/net/xdp/xskmap.c
> index 3bff346308d0f..bf00d6463c191 100644
> --- a/net/xdp/xskmap.c
> +++ b/net/xdp/xskmap.c
> @@ -124,7 +124,7 @@ static int xsk_map_gen_lookup(struct bpf_map *map, struct bpf_insn *insn_buf)
> struct bpf_insn *insn = insn_buf;
>
> *insn++ = BPF_LDX_MEM(BPF_W, ret, index, 0);
> - *insn++ = BPF_JMP_IMM(BPF_JGE, ret, map->max_entries, 5);
> + *insn++ = BPF_JMP32_IMM(BPF_JGE, ret, map->max_entries, 5);
[Severity: High]
This is a pre-existing issue, but while you are fixing this sign-extension
bounds check bypass here, should the exact same fix be applied to identical
vulnerable patterns in kernel/bpf/arraymap.c and kernel/bpf/fixups.c?
For example, in kernel/bpf/arraymap.c:array_map_gen_lookup():
*insn++ = BPF_JMP_IMM(BPF_JGE, ret, map->max_entries, 4);
*insn++ = BPF_ALU32_IMM(BPF_AND, ret, array->index_mask);
} else {
*insn++ = BPF_JMP_IMM(BPF_JGE, ret, map->max_entries, 3);
}
The same pattern exists in kernel/bpf/arraymap.c:percpu_array_map_gen_lookup():
*insn++ = BPF_JMP_IMM(BPF_JGE, BPF_REG_0, map->max_entries, 6);
*insn++ = BPF_ALU32_IMM(BPF_AND, BPF_REG_0, array->index_mask);
} else {
*insn++ = BPF_JMP_IMM(BPF_JGE, BPF_REG_0, map->max_entries, 5);
}
And also in kernel/bpf/arraymap.c:array_of_map_gen_lookup() as well as
kernel/bpf/fixups.c:fixup_bpf_calls() for tail calls.
Since BPF_JMP_IMM sign-extends its 32-bit immediate argument to 64 bits,
a max_entries value >= 0x80000000 becomes a large negative number in a
64-bit context.
This means the unsigned BPF_JGE check against a zero-extended 32-bit index
will never jump, skipping the bounds check entirely. For array maps with
bypass_spec_v1 == true, does this completely bypass memory bounds checks?
Similarly, for tail calls in fixup_bpf_calls(), does this bypass the
architectural bounds check and defeat the speculative execution mitigation
since the bound check branch is never taken for out-of-bound indices?
> *insn++ = BPF_ALU64_IMM(BPF_LSH, ret, ilog2(sizeof(struct xsk_sock *)));
> *insn++ = BPF_ALU64_IMM(BPF_ADD, mp, offsetof(struct xsk_map, xsk_map));
> *insn++ = BPF_ALU64_REG(BPF_ADD, ret, mp);
--
Sashiko AI review · https://sashiko.dev/#/patchset/7d2cb8e8dfaa9eb8fdff85156987a60960787dc3.1789056660.git.zhilinz@nebusec.ai?part=1
prev parent reply other threads:[~2026-09-10 16:34 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-10 16:18 [PATCH bpf 0/1] xsk: use a 32-bit compare in xsk_map_gen_lookup Zhiling Zou
2026-09-10 16:18 ` [PATCH bpf 1/1] " Zhiling Zou
2026-09-10 16:34 ` sashiko-bot [this message]
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=20260910163452.220CC1F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=zhilinz@nebusec.ai \
/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