From: sashiko-bot@kernel.org
To: chenyuan_fl@163.com
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH 1/2] bpf: Fix queue/stack map u32 index overflow
Date: Fri, 07 Aug 2026 02:15:59 +0000 [thread overview]
Message-ID: <20260807021600.DE8C61F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260807020548.1376979-2-chenyuan_fl@163.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [Medium] When `attr->max_entries` is exactly `U32_MAX` and `attr->value_size` is 1, the internal map capacity tracker `qs->size` silently truncates to 0, permanently breaking the map while still allocating 4GB of kernel memory.
--
--- Patch [1]: [PATCH 1/2] bpf: Fix queue/stack map u32 index overflow ---
commit 47dbebc907a9c220d2feebeadd6501394e5a0348
Author: Yuan Chen <chenyuan@kylinos.cn>
Subject: bpf: Fix queue/stack map u32 index overflow
The queue/stack map addresses elements[] with the product of a u32
head/tail index and value_size, but the storage itself is allocated in
64-bit arithmetic. This patch restores a bound check to reject maps whose
element storage would exceed U32_MAX bytes.
> --- a/kernel/bpf/queue_stack_maps.c
> +++ b/kernel/bpf/queue_stack_maps.c
> @@ -59,6 +59,13 @@ static int queue_stack_map_alloc_check(union bpf_attr *attr)
> */
> return -E2BIG;
>
> + /*
> + * The u32 head/tail index is multiplied by value_size to address
> + * elements[]. Bound the map size so the product cannot overflow.
> + */
> + if ((u64)attr->max_entries * attr->value_size > U32_MAX)
> + return -E2BIG;
> +
[Severity: Medium]
This is a pre-existing issue, but could this check still allow a truncation
in qs->size when attr->max_entries is exactly U32_MAX and attr->value_size
is 1?
If a map is created with those attributes, it bypasses the bounds check
above. Then in queue_stack_map_alloc(), the size is incremented by 1:
kernel/bpf/queue_stack_maps.c:queue_stack_map_alloc() {
...
u64 size, queue_size, cost;
...
size = attr->max_entries + 1;
...
qs->size = size;
...
}
Because qs->size is declared as a u32 in struct bpf_queue_stack:
u32 size; /* max_entries + 1 */
does assigning size (which is U32_MAX + 1) cause qs->size to silently
truncate to 0? This appears to result in a 4GB map allocation that remains
permanently empty since its capacity tracker is 0.
> return 0;
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260807020548.1376979-1-chenyuan_fl@163.com?part=1
next prev parent reply other threads:[~2026-08-07 2:16 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-07 2:05 [PATCH bpf 0/2] bpf: Fix queue/stack map u32 index overflow chenyuan_fl
2026-08-07 2:05 ` [PATCH 1/2] " chenyuan_fl
2026-08-07 2:15 ` sashiko-bot [this message]
2026-08-07 2:05 ` [PATCH 2/2] selftests/bpf: Add regression test for queue/stack map size limit chenyuan_fl
2026-08-07 2:13 ` sashiko-bot
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=20260807021600.DE8C61F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=chenyuan_fl@163.com \
--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.