From: sashiko-bot@kernel.org
To: "Jérémy Jean" <Jeremy.Jean@oss.cyber.gouv.fr>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf] bpf: harden bloom filter allocation sizing on 32-bit kernels
Date: Fri, 31 Jul 2026 21:22:46 +0000 [thread overview]
Message-ID: <20260731212246.D4C351F00AC4@smtp.kernel.org> (raw)
In-Reply-To: <20260731204917.3845309-1-Jeremy.Jean@oss.cyber.gouv.fr>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [Critical] The patch prevents a 0-byte allocation on 32-bit architectures, but fails to address a critical out-of-bounds access bug caused by negative indexing when `bitset_mask == U32_MAX`.
--
--- Patch [1]: [PATCH bpf] bpf: harden bloom filter allocation sizing on 32-bit kernels ---
commit 02e5a6622a3bf43a5a551fa2588059c5317afd7d
Author: Jérémy Jean <Jeremy.Jean@oss.cyber.gouv.fr>
bpf: harden bloom filter allocation sizing on 32-bit kernels
This commit addresses an under-allocation issue for bloom filter maps on
32-bit kernels by computing the required bitset size using u64 arithmetic,
preventing an integer overflow during allocation.
> --- a/kernel/bpf/bloom_filter.c
> +++ b/kernel/bpf/bloom_filter.c
> @@ -127,23 +128,21 @@ static struct bpf_map *bloom_map_alloc(union bpf_attr *attr)
> if (check_mul_overflow(attr->max_entries, nr_hash_funcs, &nr_bits) ||
> check_mul_overflow(nr_bits / 5, (u32)7, &nr_bits) ||
> nr_bits > (1UL << 31)) {
> - /* The bit array size is 2^32 bits but to avoid overflowing the
> - * u32, we use U32_MAX, which will round up to the equivalent
> - * number of bytes
> - */
> - bitset_bytes = BITS_TO_BYTES(U32_MAX);
> bitset_mask = U32_MAX;
[Severity: Critical]
This is a pre-existing issue, but does setting bitset_mask to U32_MAX leave
the map vulnerable to backward out-of-bounds accesses on 32-bit architectures?
When the map is accessed, the generated u32 hash is masked and passed to
test_bit() and set_bit():
kernel/bpf/bloom_filter.c:bloom_map_peek_elem() {
...
if (!test_bit(h, bloom->bitset))
return -ENOENT;
...
}
kernel/bpf/bloom_filter.c:bloom_map_push_elem() {
...
set_bit(h, bloom->bitset);
...
}
On 32-bit systems, test_bit() and set_bit() expect a signed long index.
If the u32 hash value is greater than or equal to 0x80000000, it is
implicitly converted to a negative bit offset.
Because some architectures handle this as a signed offset relative to the
memory base, could this result in reading or writing memory before the
allocated bloom->bitset buffer and corrupting the bpf_bloom_filter struct?
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260731204917.3845309-1-Jeremy.Jean@oss.cyber.gouv.fr?part=1
next prev parent reply other threads:[~2026-07-31 21:22 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-31 20:48 [PATCH bpf] bpf: harden bloom filter allocation sizing on 32-bit kernels Jérémy Jean
2026-07-31 21:22 ` sashiko-bot [this message]
2026-07-31 22:14 ` bot+bpf-ci
2026-08-01 8:42 ` Jérémy Jean
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=20260731212246.D4C351F00AC4@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Jeremy.Jean@oss.cyber.gouv.fr \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.