Skip to contentSkip to conversation

bpf: Fix queue/stack map u32 index overflow

PATCH Superseded [email protected] 5 participants 19 messages Aug 10 – Sep 2

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v3 cover bpf: Fix queue/stack map u32 index overflow

From: Yuan Chen <[email protected]>

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. When max_entries * value_size exceeds U32_MAX, the product wraps and push/peek/pop operate on the wrong element. Patch 1 restores the dropped bound check; patch 2 adds a regression test.

Changes in v3:
- Fix the Fixes tag: the bound check was removed by a37fb7ef24a4 (which dropped the bpf_map_charge_init() call), not by c85d69135a91 (which moved the check into bpf_map_charge_init()), as pointed out in review. Add Cc: [email protected] since the bug affects v5.11+.
- Define U32_MAX locally in the selftest, as pointed out in review.

Changes in v2:
- Also reject max_entries == U32_MAX: the u32 capacity counter qs->size (max_entries + 1) would wrap to 0 and permanently break the map, as pointed out in review.
- Fix the multi-line comment style in the selftest, as pointed out in review.

Yuan Chen (2):
bpf: Fix queue/stack map u32 index overflow selftests/bpf: Add regression test for queue/stack map size limit

 kernel/bpf/queue_stack_maps.c                 | 10 ++++
 .../bpf/prog_tests/queue_stack_map.c          | 49 +++++++++++++++++++
 2 files changed, 59 insertions(+)
Signature · 1 line
2.54.0
#1 lore raw

PATCH v3 1/2 bpf: Fix queue/stack map u32 index overflow

From: Yuan Chen <[email protected]>

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. When max_entries * value_size exceeds U32_MAX, the product wraps and push/peek/pop operate on the wrong element, corrupting map data and leaking stale values to user space.

The original bound check was removed by commit a37fb7ef24a4 ("bpf:
Eliminate rlimit-based memory accounting for queue_stack_maps maps"), which deleted the bpf_map_charge_init() call and with it the U32_MAX - PAGE_SIZE check that had earlier been moved into bpf_map_charge_init() by c85d69135a91. Oversized queue/stack maps can therefore be created again.

Restore the bound in queue_stack_map_alloc_check(): reject maps whose element storage would exceed U32_MAX bytes, keeping the u32 index multiplication overflow-free. Also reject max_entries == U32_MAX, which would make the u32 capacity counter qs->size (max_entries + 1) wrap to 0 and permanently break the map.

Fixes a37fb7ef24a4 ("bpf: Eliminate rlimit-based memory accounting for queue_stack_maps maps")
---
 kernel/bpf/queue_stack_maps.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
kernel/bpf/queue_stack_maps.c +10 -0
index c1c9dee4dcdd..bb2453693b80 100644
@@ -59,6 +59,16 @@ 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[], and qs->size (max_entries + 1) is stored in a u32.
+	 * Bound the map size so neither the product nor the capacity
+	 * counter can overflow.
+	 */
+	if ((u64)attr->max_entries * attr->value_size > U32_MAX ||
+	    attr->max_entries == U32_MAX)
+		return -E2BIG;
+
 	return 0;
 }
 
Signature · 1 line
2.54.0
#2 lore raw

PATCH v3 2/2 selftests/bpf: Add regression test for queue/stack map size limit

In reply to [email protected]

From: Yuan Chen <[email protected]>

Verify that queue/stack maps whose element storage would overflow the u32 head/tail index multiplication are rejected at creation time, and that max_entries == U32_MAX (which would wrap the u32 capacity counter to 0) is rejected as well.

---
 .../bpf/prog_tests/queue_stack_map.c          | 49 +++++++++++++++++++
 1 file changed, 49 insertions(+)
tools/testing/selftests/bpf/prog_tests/queue_stack_map.c +49 -0
index 41441325e179..043cbe92e2ba 100644
@@ -2,6 +2,8 @@
 #include <test_progs.h>
 #include <network_helpers.h>
 
+#define U32_MAX ((u32)UINT_MAX)
+
 enum {
 	QUEUE,
 	STACK,
@@ -101,8 +103,55 @@ static void test_queue_stack_map_by_type(int type)
 	bpf_object__close(obj);
 }
 
+static void test_queue_stack_map_alloc_check(void)
+{
+	LIBBPF_OPTS(bpf_map_create_opts, opts);
+	const __u32 big_value = 1 << 20; /* 1MB */
+	int fd, saved_errno;
+
+	/*
+	 * Regression test for the u32 index overflow in queue/stack maps:
+	 * a map whose element storage (max_entries * value_size) exceeds
+	 * U32_MAX bytes must be rejected at creation time, otherwise the
+	 * u32 head/tail index multiplication wraps and push/peek/pop
+	 * address the wrong element. 8192 * 1MB = 8GB > U32_MAX.
+	 */
+	fd = bpf_map_create(BPF_MAP_TYPE_QUEUE, NULL, 0, big_value, 8192, &opts);
+	saved_errno = errno;
+	ASSERT_LT(fd, 0, "queue_oversize_fd");
+	ASSERT_EQ(saved_errno, E2BIG, "queue_oversize_errno");
+	if (fd >= 0)
+		close(fd);
+
+	/*
+	 * max_entries == U32_MAX would make the u32 capacity counter
+	 * qs->size (max_entries + 1) wrap to 0, permanently breaking the
+	 * map, so it must be rejected as well.
+	 */
+	fd = bpf_map_create(BPF_MAP_TYPE_QUEUE, NULL, 0, 1, U32_MAX, &opts);
+	saved_errno = errno;
+	ASSERT_LT(fd, 0, "queue_u32max_fd");
+	ASSERT_EQ(saved_errno, E2BIG, "queue_u32max_errno");
+	if (fd >= 0)
+		close(fd);
+
+	fd = bpf_map_create(BPF_MAP_TYPE_STACK, NULL, 0, big_value, 8192, &opts);
+	saved_errno = errno;
+	ASSERT_LT(fd, 0, "stack_oversize_fd");
+	ASSERT_EQ(saved_errno, E2BIG, "stack_oversize_errno");
+	if (fd >= 0)
+		close(fd);
+
+	/* A normal-sized map must still be created successfully. */
+	fd = bpf_map_create(BPF_MAP_TYPE_QUEUE, NULL, 0, 64, 100, &opts);
+	ASSERT_GE(fd, 0, "queue_normal_fd");
+	if (fd >= 0)
+		close(fd);
+}
+
 void test_queue_stack_map(void)
 {
 	test_queue_stack_map_by_type(QUEUE);
 	test_queue_stack_map_by_type(STACK);
+	test_queue_stack_map_alloc_check();
 }
Signature · 1 line
2.54.0
#3 lore raw

Re: [PATCH bpf v3 2/2] selftests/bpf: Add regression test for queue/stack map size limit

This isn't a bug, but for the single use in the test, would UINT32_MAX (already available via <stdint.h>) work instead of adding a local U32_MAX macro that relies on UINT_MAX coming in transitively?

tools/testing/selftests/bpf/prog_tests/queue_stack_map.c line 6

Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/queue_stack_map.c +2 -0
index 41441325e179..043cbe92e2ba 100644
@@ -2,6 +2,8 @@
 #include <test_progs.h>
 #include <network_helpers.h>
 
+#define U32_MAX ((u32)UINT_MAX)
+

This isn't a bug, but for the single use in the test, would UINT32_MAX (already available via <stdint.h>) work instead of adding a local U32_MAX macro that relies on UINT_MAX coming in transitively?

tools/testing/selftests/bpf/prog_tests/queue_stack_map.c static void test_queue_stack_map_by_type(int type) · line 108

Quoted 3 lines
tools/testing/selftests/bpf/prog_tests/queue_stack_map.c +3 -0
+static void test_queue_stack_map_alloc_check(void)
+{
+	LIBBPF_OPTS(bpf_map_create_opts, opts);

This isn't a bug, but since no field of opts is ever set in this function, would passing NULL as the opts argument read more directly?

[ ... ]

tools/testing/selftests/bpf/prog_tests/queue_stack_map.c static void test_queue_stack_map_by_type(int type) · line 118

Quoted 7 lines
tools/testing/selftests/bpf/prog_tests/queue_stack_map.c +7 -0
+	/*
+	 * Regression test for the u32 index overflow in queue/stack maps:
+	 * a map whose element storage (max_entries * value_size) exceeds
+	 * U32_MAX bytes must be rejected at creation time, otherwise the
+	 * u32 head/tail index multiplication wraps and push/peek/pop
+	 * address the wrong element. 8192 * 1MB = 8GB > U32_MAX.
+	 */

This isn't a bug, but could these two comments be condensed to the part specific to the test (why 8192 x 1MB and why E2BIG), leaving the description of the head/tail wrap to the comment the kernel patch adds in queue_stack_maps.c?

---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/31396327144

#4 lore raw

Re: [PATCH bpf v3 2/2] selftests/bpf: Add regression test for queue/stack map size limit

In reply to [email protected]
Quoted 49 lines · On Mon, Aug 10, 2026 at 7:00 AM <[email protected]> wrote:

From: Yuan Chen <[email protected]>

Verify that queue/stack maps whose element storage would overflow the u32 head/tail index multiplication are rejected at creation time, and that max_entries == U32_MAX (which would wrap the u32 capacity counter to 0) is rejected as well.

---
 .../bpf/prog_tests/queue_stack_map.c          | 49 +++++++++++++++++++
 1 file changed, 49 insertions(+)
tools/testing/selftests/bpf/prog_tests/queue_stack_map.c +21 -0
index 41441325e179..043cbe92e2ba 100644
@@ -2,6 +2,8 @@
 #include <test_progs.h>
 #include <network_helpers.h>
 
+#define U32_MAX ((u32)UINT_MAX)
+
 enum {
        QUEUE,
        STACK,
@@ -101,8 +103,55 @@ static void test_queue_stack_map_by_type(int type)
        bpf_object__close(obj);
 }
 
+static void test_queue_stack_map_alloc_check(void)
+{
+       LIBBPF_OPTS(bpf_map_create_opts, opts);
+       const __u32 big_value = 1 << 20; /* 1MB */
+       int fd, saved_errno;
+
+       /*
+        * Regression test for the u32 index overflow in queue/stack maps:
+        * a map whose element storage (max_entries * value_size) exceeds
+        * U32_MAX bytes must be rejected at creation time, otherwise the
+        * u32 head/tail index multiplication wraps and push/peek/pop
+        * address the wrong element. 8192 * 1MB = 8GB > U32_MAX.
+        */
+       fd = bpf_map_create(BPF_MAP_TYPE_QUEUE, NULL, 0, big_value, 8192, &opts);
+       saved_errno = errno;
+       ASSERT_LT(fd, 0, "queue_oversize_fd");
+       ASSERT_EQ(saved_errno, E2BIG, "queue_oversize_errno");
+       if (fd >= 0)
+               close(fd);

tools/testing/selftests/bpf/prog_tests/queue_stack_map.c static void test_queue_stack_map_by_type(int type) · line 134

Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/queue_stack_map.c +10 -0
+
+       /*
+        * max_entries == U32_MAX would make the u32 capacity counter
+        * qs->size (max_entries + 1) wrap to 0, permanently breaking the
+        * map, so it must be rejected as well.
+        */
+       fd = bpf_map_create(BPF_MAP_TYPE_QUEUE, NULL, 0, 1, U32_MAX, &opts);
+       saved_errno = errno;
+       ASSERT_LT(fd, 0, "queue_u32max_fd");
+       ASSERT_EQ(saved_errno, E2BIG, "queue_u32max_errno");

Just ASSERT_EQ(fd, -E2BIG)? libbpf returns an error value directly.

Quoted 26 lines
tools/testing/selftests/bpf/prog_tests/queue_stack_map.c +18 -1
+       if (fd >= 0)
+               close(fd);
+
+       fd = bpf_map_create(BPF_MAP_TYPE_STACK, NULL, 0, big_value, 8192, &opts);
+       saved_errno = errno;
+       ASSERT_LT(fd, 0, "stack_oversize_fd");
+       ASSERT_EQ(saved_errno, E2BIG, "stack_oversize_errno");
+       if (fd >= 0)
+               close(fd);
+
+       /* A normal-sized map must still be created successfully. */
+       fd = bpf_map_create(BPF_MAP_TYPE_QUEUE, NULL, 0, 64, 100, &opts);
+       ASSERT_GE(fd, 0, "queue_normal_fd");
+       if (fd >= 0)
+               close(fd);
+}
+
 void test_queue_stack_map(void)
 {
        test_queue_stack_map_by_type(QUEUE);
        test_queue_stack_map_by_type(STACK);
+       test_queue_stack_map_alloc_check();
 }
--

2.54.0

#5 lore raw

v4 cover bpf: Fix queue/stack map u32 index overflow

From: Yuan Chen <[email protected]>

This series fixes an integer overflow in BPF queue/stack maps. The u32 head/tail index is multiplied by value_size to address elements[], but the storage itself is allocated with 64-bit arithmetic. When max_entries * value_size reaches or exceeds U32_MAX, the index multiplication wraps and push/peek/pop operate on the wrong element, corrupting map data and leaking stale values to user space. max_entries == U32_MAX would also wrap the u32 capacity counter qs->size (max_entries + 1) to 0 and permanently break the map.

Patch 1 restores the size bound in queue_stack_map_alloc_check() that was lost when the check inside bpf_map_charge_init() was removed. A single division-based comparison covers both the index multiplication overflow and the capacity counter wrap.

Patch 2 adds a regression test for both rejection cases.

Many thanks to Andrii Nakryiko for the careful review and the helpful
suggestions: the bound has been simplified to a single max_entries >= U32_MAX / value_size check, and the selftest now asserts the bpf_map_create() return value directly instead of reading errno.

v2 -> v3:
- also reject max_entries == U32_MAX, which would wrap the u32

    capacity counter qs->size (max_entries + 1) to 0

- fix the Fixes tag: the guard was actually dropped by a37fb7ef24a4, which removed the bpf_map_charge_init() call the check had been moved into by c85d69135a91

v3 -> v4:
- simplify the bound to a single `max_entries >= U32_MAX /

    value_size` comparison, which also rejects max_entries == U32_MAX

- check the bpf_map_create() return value directly instead of errno in the selftest

Yuan Chen (2):
bpf: Fix queue/stack map u32 index overflow selftests/bpf: Add regression test for queue/stack map size limit

 kernel/bpf/queue_stack_maps.c                      |  9 ++++++
 .../selftests/bpf/prog_tests/queue_stack_map.c     | 37 ++++++++++++++++++++++
 2 files changed, 46 insertions(+)
#6 lore raw

PATCH v4 1/2 bpf: Fix queue/stack map u32 index overflow

From: Yuan Chen <[email protected]>

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. When max_entries * value_size reaches or exceeds U32_MAX, the product wraps and push/peek/pop operate on the wrong element, corrupting map data and leaking stale values to user space. max_entries == U32_MAX would also make the u32 capacity counter qs->size (max_entries + 1) wrap to 0 and permanently break the map.

The original bound check was removed by commit a37fb7ef24a4 ("bpf:
Eliminate rlimit-based memory accounting for queue_stack_maps maps"), which deleted the bpf_map_charge_init() call and with it the U32_MAX - PAGE_SIZE check that had earlier been moved into bpf_map_charge_init() by c85d69135a91. Oversized queue/stack maps can therefore be created again.

Restore the bound in queue_stack_map_alloc_check() with a single comparison that rejects any max_entries/value_size combination whose element storage would reach or exceed U32_MAX bytes, keeping the u32 index multiplication overflow-free and the capacity counter valid.

Fixes a37fb7ef24a4 ("bpf: Eliminate rlimit-based memory accounting for queue_stack_maps maps")

---
v4: simplify the bound to a single division-based comparison as

    suggested by Andrii Nakryiko; this also rejects max_entries == U32_MAX
 kernel/bpf/queue_stack_maps.c | 9 +++++++++
 1 file changed, 9 insertions(+)
kernel/bpf/queue_stack_maps.c +9 -0
index c1c9dee4dcdd..0d9e0b807a50 100644
@@ -59,6 +59,15 @@ 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[], and qs->size (max_entries + 1) is stored in a u32.
+	 * Bound max_entries so neither the product nor the capacity
+	 * counter can wrap (this also rejects max_entries == U32_MAX).
+	 */
+	if (attr->max_entries >= U32_MAX / attr->value_size)
+		return -E2BIG;
+
 	return 0;
 }
 
Signature · 1 line
2.43.0
#7 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Kfuncs using enum parameters as array indices lack bounds checking for negative values. --

--- Patch [1]: [PATCH bpf v4 1/2] bpf: Fix queue/stack map u32 index overflow --- commit b3cc6df8f8f6a83f377bada50a4de0c2ebde4779
Author: Yuan Chen <[email protected]>

bpf: Fix queue/stack map u32 index overflow

This commit fixes an integer overflow in queue/stack maps by restoring a bounds check in queue_stack_map_alloc_check(). It rejects max_entries and value_size combinations that would reach or exceed U32_MAX bytes.

[ ... ]

While reviewing BPF bounds checking, I noticed a pre-existing issue in mm/bpf_memcontrol.c:

Quoted 7 lines

mm/bpf_memcontrol.c

__bpf_kfunc unsigned long bpf_mem_cgroup_vm_events(struct mem_cgroup *memcg,
enum vm_event_item event)

{
	if (unlikely(!memcg_vm_event_item_valid(event)))
		return (unsigned long)-1;

[Severity: High]
This is a pre-existing issue, but since enums are represented as signed integers in C, could a BPF program bypass this bounds check by passing a negative enum value?

It appears that a negative event value could evade the upper bounds check and lead to an out-of-bounds read when the event is used as an array index.

Quoted 11 lines
	return memcg_events(memcg, event);
}

...

__bpf_kfunc unsigned long bpf_mem_cgroup_memory_events(struct mem_cgroup *memcg,
enum memcg_memory_event event)

{
	if (unlikely(event >= MEMCG_NR_MEMORY_EVENTS))
		return (unsigned long)-1;

[Severity: High]
This isn't a bug introduced by this patch, but does this signed comparison handle negative event values?

Similar to the above, a negative event value would pass this check and subsequently be used as a negative index for the memory_events array. Does this result in an out-of-bounds memory read?

Quoted 3 lines
	return atomic_long_read(&memcg->memory_events[event]);
}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#8 lore raw
In reply to [email protected]
Quoted 38 lines · On Mon, Aug 24, 2026 at 1:34 AM <[email protected]> wrote:

From: Yuan Chen <[email protected]>

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. When max_entries * value_size reaches or exceeds U32_MAX, the product wraps and push/peek/pop operate on the wrong element, corrupting map data and leaking stale values to user space. max_entries == U32_MAX would also make the u32 capacity counter qs->size (max_entries + 1) wrap to 0 and permanently break the map.

The original bound check was removed by commit a37fb7ef24a4 ("bpf:
Eliminate rlimit-based memory accounting for queue_stack_maps maps"), which deleted the bpf_map_charge_init() call and with it the U32_MAX - PAGE_SIZE check that had earlier been moved into bpf_map_charge_init() by c85d69135a91. Oversized queue/stack maps can therefore be created again.

Restore the bound in queue_stack_map_alloc_check() with a single comparison that rejects any max_entries/value_size combination whose element storage would reach or exceed U32_MAX bytes, keeping the u32 index multiplication overflow-free and the capacity counter valid.

Fixes a37fb7ef24a4 ("bpf: Eliminate rlimit-based memory accounting for queue_stack_maps maps")

---
v4: simplify the bound to a single division-based comparison as

    suggested by Andrii Nakryiko; this also rejects max_entries == U32_MAX
 kernel/bpf/queue_stack_maps.c | 9 +++++++++
 1 file changed, 9 insertions(+)
kernel/bpf/queue_stack_maps.c +0 -0
index c1c9dee4dcdd..0d9e0b807a50 100644

kernel/bpf/queue_stack_maps.c static int queue_stack_map_alloc_check(union bpf_attr *attr) · line 67

Quoted 9 lines
kernel/bpf/queue_stack_maps.c +6 -0
@@ -59,6 +59,15 @@ 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[], and qs->size (max_entries + 1) is stored in a u32.
+        * Bound max_entries so neither the product nor the capacity
+        * counter can wrap (this also rejects max_entries == U32_MAX).
+        */

nit: drop the comment, it took me longer to read it than looking at the code would

Quoted 9 lines
kernel/bpf/queue_stack_maps.c +3 -1
+       if (attr->max_entries >= U32_MAX / attr->value_size)
+               return -E2BIG;
+
        return 0;
 }
 
--

2.43.0

#9 lore raw

v5 cover bpf: Fix queue/stack map u32 index overflow

From: Yuan Chen <[email protected]>

This series fixes an integer overflow in BPF queue/stack maps. The u32 head/tail index is multiplied by value_size to address elements[], but the storage itself is allocated with 64-bit arithmetic. When max_entries * value_size reaches or exceeds U32_MAX, the index multiplication wraps and push/peek/pop operate on the wrong element, corrupting map data and leaking stale values to user space. max_entries == U32_MAX would also wrap the u32 capacity counter qs->size (max_entries + 1) to 0 and permanently break the map.

Patch 1 restores the size bound in queue_stack_map_alloc_check() that was lost when the check inside bpf_map_charge_init() was removed. A single division-based comparison covers both the index multiplication overflow and the capacity counter wrap.

Patch 2 adds a regression test for both rejection cases.

Many thanks to Andrii Nakryiko for the careful review and the helpful
suggestions: the bound has been simplified to a single max_entries >= U32_MAX / value_size check, the selftest asserts the bpf_map_create() return value directly instead of reading errno, and the selftest no longer uses an unused opts struct, inlines the 1MB value size, and closes the fd if a map is unexpectedly created.

v2 -> v3:
- also reject max_entries == U32_MAX, which would wrap the u32

    capacity counter qs->size (max_entries + 1) to 0

- fix the Fixes tag: the guard was actually dropped by a37fb7ef24a4, which removed the bpf_map_charge_init() call the check had been moved into by c85d69135a91

v3 -> v4:
- simplify the bound to a single `max_entries >= U32_MAX /

    value_size` comparison, which also rejects max_entries == U32_MAX

- check the bpf_map_create() return value directly instead of errno in the selftest

v4 -> v5:
- drop the explanatory comment in queue_stack_map_alloc_check()
- selftest: drop the unused bpf_map_create_opts, inline the 1MB value size, close the fd if bpf_map_create() unexpectedly returns a valid fd, and drop the verbose comments

Yuan Chen (2):
bpf: Fix queue/stack map u32 index overflow selftests/bpf: Add regression test for queue/stack map size limit

 kernel/bpf/queue_stack_maps.c                      |  3 +++
 .../selftests/bpf/prog_tests/queue_stack_map.c     | 29 ++++++++++++++++++++++
 2 files changed, 32 insertions(+)
#10 lore raw

PATCH v5 1/2 bpf: Fix queue/stack map u32 index overflow

From: Yuan Chen <[email protected]>

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. When max_entries * value_size reaches or exceeds U32_MAX, the product wraps and push/peek/pop operate on the wrong element, corrupting map data and leaking stale values to user space. max_entries == U32_MAX would also make the u32 capacity counter qs->size (max_entries + 1) wrap to 0 and permanently break the map.

The original bound check was removed by commit a37fb7ef24a4 ("bpf:
Eliminate rlimit-based memory accounting for queue_stack_maps maps"), which deleted the bpf_map_charge_init() call and with it the U32_MAX - PAGE_SIZE check that had earlier been moved into bpf_map_charge_init() by c85d69135a91. Oversized queue/stack maps can therefore be created again.

Restore the bound in queue_stack_map_alloc_check() with a single comparison that rejects any max_entries/value_size combination whose element storage would reach or exceed U32_MAX bytes, keeping the u32 index multiplication overflow-free and the capacity counter valid.

Fixes a37fb7ef24a4 ("bpf: Eliminate rlimit-based memory accounting for queue_stack_maps maps")

---
v5: drop the explanatory comment, as suggested by Andrii Nakryiko

v4: simplify the bound to a single division-based comparison as

    suggested by Andrii Nakryiko; this also rejects max_entries == U32_MAX
 kernel/bpf/queue_stack_maps.c | 3 +++
 1 file changed, 3 insertions(+)
kernel/bpf/queue_stack_maps.c +3 -0
index c1c9dee4dcdd..b5628e414981 100644
@@ -59,6 +59,9 @@ static int queue_stack_map_alloc_check(union bpf_attr *attr)
 		 */
 		return -E2BIG;
 
+	if (attr->max_entries >= U32_MAX / attr->value_size)
+		return -E2BIG;
+
 	return 0;
 }
 
Signature · 1 line
2.43.0
#11 lore raw
This isn't a bug, but would it read more precisely to say the product wraps once it exceeds U32_MAX (at 2^32) rather than "reaches or exceeds U32_MAX"?
Quoted 5 lines

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. When max_entries * value_size reaches or exceeds U32_MAX, the product wraps and push/peek/pop operate on the wrong element, corrupting map data and leaking stale values to user space.

This isn't a bug, but would it read more precisely to say the product wraps once it exceeds U32_MAX (at 2^32) rather than "reaches or exceeds U32_MAX"?

A product of exactly U32_MAX is still represented exactly in u32 - the wrap happens one byte later. The new check is deliberately more conservative (rejecting when element storage would reach U32_MAX), so the code is safe either way.

---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/33365692838

#12 lore raw

PATCH v5 2/2 selftests/bpf: Add regression test for queue/stack map size limit

In reply to [email protected]

From: Yuan Chen <[email protected]>

Verify that queue/stack maps whose element storage would overflow the u32 head/tail index multiplication are rejected at creation time, and that max_entries == U32_MAX (which would wrap the u32 capacity counter to 0) is rejected as well.

---
v5: drop the unused opts and verbose comments, inline the 1MB value
size, and close the fd on the rejection paths, as suggested by Andrii Nakryiko

v4: check the bpf_map_create() return value directly instead of errno
as suggested by Andrii Nakryiko

 .../selftests/bpf/prog_tests/queue_stack_map.c     | 29 ++++++++++++++++++++++
 1 file changed, 29 insertions(+)
tools/testing/selftests/bpf/prog_tests/queue_stack_map.c +29 -0
index 41441325e179..a01a0bcbdee7 100644
@@ -2,6 +2,8 @@
 #include <test_progs.h>
 #include <network_helpers.h>
 
+#define U32_MAX ((u32)UINT_MAX)
+
 enum {
 	QUEUE,
 	STACK,
@@ -101,8 +103,35 @@ static void test_queue_stack_map_by_type(int type)
 	bpf_object__close(obj);
 }
 
+static void test_queue_stack_map_alloc_check(void)
+{
+	int fd;
+
+	fd = bpf_map_create(BPF_MAP_TYPE_QUEUE, NULL, 0, 1000000, 8192, NULL);
+	ASSERT_EQ(fd, -E2BIG, "queue_oversize");
+	if (fd >= 0)
+		close(fd);
+
+	fd = bpf_map_create(BPF_MAP_TYPE_QUEUE, NULL, 0, 1, U32_MAX, NULL);
+	ASSERT_EQ(fd, -E2BIG, "queue_u32max");
+	if (fd >= 0)
+		close(fd);
+
+	fd = bpf_map_create(BPF_MAP_TYPE_STACK, NULL, 0, 1000000, 8192, NULL);
+	ASSERT_EQ(fd, -E2BIG, "stack_oversize");
+	if (fd >= 0)
+		close(fd);
+
+	/* A normal-sized map must still be created successfully. */
+	fd = bpf_map_create(BPF_MAP_TYPE_QUEUE, NULL, 0, 64, 100, NULL);
+	ASSERT_GE(fd, 0, "queue_normal");
+	if (fd >= 0)
+		close(fd);
+}
+
 void test_queue_stack_map(void)
 {
 	test_queue_stack_map_by_type(QUEUE);
 	test_queue_stack_map_by_type(STACK);
+	test_queue_stack_map_alloc_check();
 }
Signature · 1 line
2.43.0
#13 lore raw

Re: [PATCH bpf v5 2/2] selftests/bpf: Add regression test for queue/stack map size limit

This isn't a bug, but would using UINT_MAX directly at the single call site read more simply than adding a U32_MAX alias, or is the alias worth keeping for symmetry with reg_bounds.c?

tools/testing/selftests/bpf/prog_tests/queue_stack_map.c line 5

Quoted 9 lines
tools/testing/selftests/bpf/prog_tests/queue_stack_map.c +1 -0
index 41441325e179..a01a0bcbdee7 100644
@@ -2,6 +2,8 @@
 #include <test_progs.h>
 #include <network_helpers.h>
 
+#define U32_MAX ((u32)UINT_MAX)

This isn't a bug, but would using UINT_MAX directly at the single call site read more simply than adding a U32_MAX alias, or is the alias worth keeping for symmetry with reg_bounds.c?

The macro appears in prog_tests/reg_bounds.c where it's part of a family of short number-type aliases used by that file's range-printing tables. Here it has exactly one use as the max_entries argument to a bpf_map_create() call that takes a __u32, so plain UINT_MAX would work directly.

Quoted 7 lines
tools/testing/selftests/bpf/prog_tests/queue_stack_map.c +1 -0
+
 enum {
 	QUEUE,
 	STACK,
@@ -101,8 +103,35 @@ static void test_queue_stack_map_by_type(int type)
 	bpf_object__close(obj);
 }

[ ... ]

Quoted 22 lines
tools/testing/selftests/bpf/prog_tests/queue_stack_map.c +22 -0
+static void test_queue_stack_map_alloc_check(void)
+{
+	int fd;
+
+	fd = bpf_map_create(BPF_MAP_TYPE_QUEUE, NULL, 0, 1000000, 8192, NULL);
+	ASSERT_EQ(fd, -E2BIG, "queue_oversize");
+	if (fd >= 0)
+		close(fd);
+
+	fd = bpf_map_create(BPF_MAP_TYPE_QUEUE, NULL, 0, 1, U32_MAX, NULL);
+	ASSERT_EQ(fd, -E2BIG, "queue_u32max");
+	if (fd >= 0)
+		close(fd);
+
+	fd = bpf_map_create(BPF_MAP_TYPE_STACK, NULL, 0, 1000000, 8192, NULL);
+	ASSERT_EQ(fd, -E2BIG, "stack_oversize");
+	if (fd >= 0)
+		close(fd);
+
+	/* A normal-sized map must still be created successfully. */
+	fd = bpf_map_create(BPF_MAP_TYPE_QUEUE, NULL, 0, 64, 100, NULL);
+	ASSERT_GE(fd, 0, "queue_normal");

tools/testing/selftests/bpf/prog_tests/queue_stack_map.c static void test_queue_stack_map_by_type(int type) · line 137

Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/queue_stack_map.c +5 -0
+	if (fd >= 0)
+		close(fd);
+}
+
 void test_queue_stack_map(void)
 {
 	test_queue_stack_map_by_type(QUEUE);
 	test_queue_stack_map_by_type(STACK);
+	test_queue_stack_map_alloc_check();
 }

---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/33365692838

#14 lore raw
In reply to [email protected]
This series was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:

Hello:

This series was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:

Quoted 11 lines · On Mon, 31 Aug 2026 14:32:24 +0800 you wrote:

From: Yuan Chen <[email protected]>

This series fixes an integer overflow in BPF queue/stack maps. The u32 head/tail index is multiplied by value_size to address elements[], but the storage itself is allocated with 64-bit arithmetic. When max_entries * value_size reaches or exceeds U32_MAX, the index multiplication wraps and push/peek/pop operate on the wrong element, corrupting map data and leaking stale values to user space. max_entries == U32_MAX would also wrap the u32 capacity counter qs->size (max_entries + 1) to 0 and permanently break the map.

Quoted 1 line

[...]

Here is the summary with links:
- [bpf,v5,1/2] bpf: Fix queue/stack map u32 index overflow

    https://git.kernel.org/bpf/bpf-next/c/802a30c5db72
  - [bpf,v5,2/2] selftests/bpf: Add regression test for queue/stack map size limit
    https://git.kernel.org/bpf/bpf-next/c/33576bfee5b7

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
#15 lore raw

PATCH v4 2/2 selftests/bpf: Add regression test for queue/stack map size limit

In reply to [email protected]

From: Yuan Chen <[email protected]>

Verify that queue/stack maps whose element storage would overflow the u32 head/tail index multiplication are rejected at creation time, and that max_entries == U32_MAX (which would wrap the u32 capacity counter to 0) is rejected as well.

---
v4: check the bpf_map_create() return value directly instead of errno
as suggested by Andrii Nakryiko

 .../selftests/bpf/prog_tests/queue_stack_map.c     | 37 ++++++++++++++++++++++
 1 file changed, 37 insertions(+)
tools/testing/selftests/bpf/prog_tests/queue_stack_map.c +37 -0
index 41441325e179..efe808eedd9a 100644
@@ -2,6 +2,8 @@
 #include <test_progs.h>
 #include <network_helpers.h>
 
+#define U32_MAX ((u32)UINT_MAX)
+
 enum {
 	QUEUE,
 	STACK,
@@ -101,8 +103,43 @@ static void test_queue_stack_map_by_type(int type)
 	bpf_object__close(obj);
 }
 
+static void test_queue_stack_map_alloc_check(void)
+{
+	LIBBPF_OPTS(bpf_map_create_opts, opts);
+	const __u32 big_value = 1 << 20; /* 1MB */
+	int fd;
+
+	/*
+	 * Regression test for the u32 index overflow in queue/stack maps:
+	 * a map whose element storage (max_entries * value_size) exceeds
+	 * U32_MAX bytes must be rejected at creation time, otherwise the
+	 * u32 head/tail index multiplication wraps and push/peek/pop
+	 * address the wrong element. 8192 * 1MB = 8GB > U32_MAX.
+	 */
+	fd = bpf_map_create(BPF_MAP_TYPE_QUEUE, NULL, 0, big_value, 8192, &opts);
+	ASSERT_EQ(fd, -E2BIG, "queue_oversize");
+
+	/*
+	 * max_entries == U32_MAX would make the u32 capacity counter
+	 * qs->size (max_entries + 1) wrap to 0, permanently breaking the
+	 * map, so it must be rejected as well.
+	 */
+	fd = bpf_map_create(BPF_MAP_TYPE_QUEUE, NULL, 0, 1, U32_MAX, &opts);
+	ASSERT_EQ(fd, -E2BIG, "queue_u32max");
+
+	fd = bpf_map_create(BPF_MAP_TYPE_STACK, NULL, 0, big_value, 8192, &opts);
+	ASSERT_EQ(fd, -E2BIG, "stack_oversize");
+
+	/* A normal-sized map must still be created successfully. */
+	fd = bpf_map_create(BPF_MAP_TYPE_QUEUE, NULL, 0, 64, 100, &opts);
+	ASSERT_GE(fd, 0, "queue_normal");
+	if (fd >= 0)
+		close(fd);
+}
+
 void test_queue_stack_map(void)
 {
 	test_queue_stack_map_by_type(QUEUE);
 	test_queue_stack_map_by_type(STACK);
+	test_queue_stack_map_alloc_check();
 }
Signature · 1 line
2.43.0
#16 lore raw

Re: [PATCH bpf v4 2/2] selftests/bpf: Add regression test for queue/stack map size limit

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Massive memory leak and file descriptor leak in the test runner on unpatched kernels. --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Massive memory leak and file descriptor leak in the test runner on unpatched kernels. --

--- Patch [2]: [PATCH bpf v4 2/2] selftests/bpf: Add regression test for queue/stack map size limit --- commit b01042556c787abab943d9e6059710f436274dbe
Author: Yuan Chen <[email protected]>

selftests/bpf: Add regression test for queue/stack map size limit

This commit adds a regression test to verify that queue/stack maps whose element storage overflows the u32 head/tail index multiplication are rejected at creation time. It also checks that max_entries == U32_MAX is rejected.

Quoted 4 lines
tools/testing/selftests/bpf/prog_tests/queue_stack_map.c +0 -0
index 41441325e1794..efe808eedd9a8 100644

[ ... ]

Quoted 16 lines
tools/testing/selftests/bpf/prog_tests/queue_stack_map.c +12 -0
@@ -101,8 +103,43 @@ static void test_queue_stack_map_by_type(int type)
 	bpf_object__close(obj);
 }
 
+static void test_queue_stack_map_alloc_check(void)
+{
+	LIBBPF_OPTS(bpf_map_create_opts, opts);
+	const __u32 big_value = 1 << 20; /* 1MB */
+	int fd;
+
+	/*
+	 * Regression test for the u32 index overflow in queue/stack maps:
+	 * a map whose element storage (max_entries * value_size) exceeds
+	 * U32_MAX bytes must be rejected at creation time, otherwise the
+	 * u32 head/tail index multiplication wraps and push/peek/pop
+	 * address the wrong element. 8192 * 1MB = 8GB > U32_MAX.

tools/testing/selftests/bpf/prog_tests/queue_stack_map.c static void test_queue_stack_map_by_type(int type) · line 127

Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/queue_stack_map.c +10 -0
+	 */
+	fd = bpf_map_create(BPF_MAP_TYPE_QUEUE, NULL, 0, big_value, 8192, &opts);
+	ASSERT_EQ(fd, -E2BIG, "queue_oversize");
+
+	/*
+	 * max_entries == U32_MAX would make the u32 capacity counter
+	 * qs->size (max_entries + 1) wrap to 0, permanently breaking the
+	 * map, so it must be rejected as well.
+	 */
+	fd = bpf_map_create(BPF_MAP_TYPE_QUEUE, NULL, 0, 1, U32_MAX, &opts);

[Severity: Medium]
If this test runs on an unpatched kernel, the previous bpf_map_create() call might unexpectedly succeed and return a valid file descriptor.

Because ASSERT_EQ() doesn't abort the test upon failure, won't this next bpf_map_create() call overwrite the 'fd' variable without closing the previous one?

This could leak the map file descriptor and the large amount of memory (up to 8GB) allocated by the map, potentially triggering the OOM killer and crashing the test environment.

Should we check if 'fd >= 0' and close it after the ASSERT_EQ() for each of these expected-to-fail allocations?

Quoted 11 lines
tools/testing/selftests/bpf/prog_tests/queue_stack_map.c +11 -0
+	ASSERT_EQ(fd, -E2BIG, "queue_u32max");
+
+	fd = bpf_map_create(BPF_MAP_TYPE_STACK, NULL, 0, big_value, 8192, &opts);
+	ASSERT_EQ(fd, -E2BIG, "stack_oversize");
+
+	/* A normal-sized map must still be created successfully. */
+	fd = bpf_map_create(BPF_MAP_TYPE_QUEUE, NULL, 0, 64, 100, &opts);
+	ASSERT_GE(fd, 0, "queue_normal");
+	if (fd >= 0)
+		close(fd);
+}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#17 lore raw

Re: [PATCH bpf v4 2/2] selftests/bpf: Add regression test for queue/stack map size limit

In reply to [email protected]
Should these three negative test cases close the fd if the map creation unexpectedly succeeds?
Quoted 4 lines
tools/testing/selftests/bpf/prog_tests/queue_stack_map.c +0 -0
index 41441325e179..efe808eedd9a 100644

[ ... ]

Quoted 16 lines
tools/testing/selftests/bpf/prog_tests/queue_stack_map.c +16 -0
+static void test_queue_stack_map_alloc_check(void)
+{
+	LIBBPF_OPTS(bpf_map_create_opts, opts);
+	const __u32 big_value = 1 << 20; /* 1MB */
+	int fd;
+
+	/*
+	 * Regression test for the u32 index overflow in queue/stack maps:
+	 * a map whose element storage (max_entries * value_size) exceeds
+	 * U32_MAX bytes must be rejected at creation time, otherwise the
+	 * u32 head/tail index multiplication wraps and push/peek/pop
+	 * address the wrong element. 8192 * 1MB = 8GB > U32_MAX.
+	 */
+	fd = bpf_map_create(BPF_MAP_TYPE_QUEUE, NULL, 0, big_value, 8192, &opts);
+	ASSERT_EQ(fd, -E2BIG, "queue_oversize");
+

tools/testing/selftests/bpf/prog_tests/queue_stack_map.c static void test_queue_stack_map_by_type(int type) · line 131

Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/queue_stack_map.c +10 -0
+	/*
+	 * max_entries == U32_MAX would make the u32 capacity counter
+	 * qs->size (max_entries + 1) wrap to 0, permanently breaking the
+	 * map, so it must be rejected as well.
+	 */
+	fd = bpf_map_create(BPF_MAP_TYPE_QUEUE, NULL, 0, 1, U32_MAX, &opts);
+	ASSERT_EQ(fd, -E2BIG, "queue_u32max");
+
+	fd = bpf_map_create(BPF_MAP_TYPE_STACK, NULL, 0, big_value, 8192, &opts);
+	ASSERT_EQ(fd, -E2BIG, "stack_oversize");

Should these three negative test cases close the fd if the map creation unexpectedly succeeds?

On a kernel without the fix in patch 1/2, queue_stack_map_alloc_check returns 0 for these attributes. The allocation then attempts an 8.59 GB or 4 GB bpf_map_area_alloc in queue_stack_map_alloc. On a host with enough memory, __vmalloc_node_range can succeed, returning fd >= 0 instead of -E2BIG.

When that happens, the assertion fails correctly, but the fd remains open for the rest of test_progs, pinning roughly 20 GB of kernel memory across all remaining tests. The positive test case below shows the pattern:

tools/testing/selftests/bpf/prog_tests/queue_stack_map.c static void test_queue_stack_map_by_type(int type) · line 138

Quoted 6 lines
tools/testing/selftests/bpf/prog_tests/queue_stack_map.c +6 -0
+	/* A normal-sized map must still be created successfully. */
+	fd = bpf_map_create(BPF_MAP_TYPE_QUEUE, NULL, 0, 64, 100, &opts);
+	ASSERT_GE(fd, 0, "queue_normal");
+	if (fd >= 0)
+		close(fd);
+}

Adding the same guard after each of the three ASSERT_EQ calls would bound the damage to the failing subtest rather than OOMing the rest of the run.

---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/32709296749

#18 lore raw

Re: [PATCH bpf v4 2/2] selftests/bpf: Add regression test for queue/stack map size limit

In reply to [email protected]
Quoted 30 lines · On Mon, Aug 24, 2026 at 1:34 AM <[email protected]> wrote:

From: Yuan Chen <[email protected]>

Verify that queue/stack maps whose element storage would overflow the u32 head/tail index multiplication are rejected at creation time, and that max_entries == U32_MAX (which would wrap the u32 capacity counter to 0) is rejected as well.

---
v4: check the bpf_map_create() return value directly instead of errno
as suggested by Andrii Nakryiko

 .../selftests/bpf/prog_tests/queue_stack_map.c     | 37 ++++++++++++++++++++++
 1 file changed, 37 insertions(+)
tools/testing/selftests/bpf/prog_tests/queue_stack_map.c +2 -0
index 41441325e179..efe808eedd9a 100644
@@ -2,6 +2,8 @@
 #include <test_progs.h>
 #include <network_helpers.h>
 
+#define U32_MAX ((u32)UINT_MAX)
+
 enum {
        QUEUE,
        STACK,

tools/testing/selftests/bpf/prog_tests/queue_stack_map.c static void test_queue_stack_map_by_type(int type) · line 108

Quoted 6 lines
tools/testing/selftests/bpf/prog_tests/queue_stack_map.c +3 -0
@@ -101,8 +103,43 @@ static void test_queue_stack_map_by_type(int type)
        bpf_object__close(obj);
 }
 
+static void test_queue_stack_map_alloc_check(void)
+{
+       LIBBPF_OPTS(bpf_map_create_opts, opts);

this is not used for anything useful, drop it and pass NULL for opts

tools/testing/selftests/bpf/prog_tests/queue_stack_map.c static void test_queue_stack_map_by_type(int type) · line 109

Quoted 1 line
tools/testing/selftests/bpf/prog_tests/queue_stack_map.c +1 -0
+       const __u32 big_value = 1 << 20; /* 1MB */

inline 1000000 in 2 places

tools/testing/selftests/bpf/prog_tests/queue_stack_map.c static void test_queue_stack_map_by_type(int type) · line 118

Quoted 9 lines
tools/testing/selftests/bpf/prog_tests/queue_stack_map.c +9 -0
+       int fd;
+
+       /*
+        * Regression test for the u32 index overflow in queue/stack maps:
+        * a map whose element storage (max_entries * value_size) exceeds
+        * U32_MAX bytes must be rejected at creation time, otherwise the
+        * u32 head/tail index multiplication wraps and push/peek/pop
+        * address the wrong element. 8192 * 1MB = 8GB > U32_MAX.
+        */

drop this verbosity, this doesn't deserve more than one line comment, if at all

tools/testing/selftests/bpf/prog_tests/queue_stack_map.c static void test_queue_stack_map_by_type(int type) · line 120

Quoted 2 lines
tools/testing/selftests/bpf/prog_tests/queue_stack_map.c +2 -0
+       fd = bpf_map_create(BPF_MAP_TYPE_QUEUE, NULL, 0, big_value, 8192, &opts);
+       ASSERT_EQ(fd, -E2BIG, "queue_oversize");

leaking fd, if test fails, not a big deal (as per me), but we'll be pestered by follow up AI-generated fixes, so let's close fd if we got a valid FD

pw-bot: cr

tools/testing/selftests/bpf/prog_tests/queue_stack_map.c static void test_queue_stack_map_by_type(int type) · line 126

Quoted 6 lines
tools/testing/selftests/bpf/prog_tests/queue_stack_map.c +6 -0
+
+       /*
+        * max_entries == U32_MAX would make the u32 capacity counter
+        * qs->size (max_entries + 1) wrap to 0, permanently breaking the
+        * map, so it must be rejected as well.
+        */

same, drop

Quoted 22 lines
tools/testing/selftests/bpf/prog_tests/queue_stack_map.c +14 -1
+       fd = bpf_map_create(BPF_MAP_TYPE_QUEUE, NULL, 0, 1, U32_MAX, &opts);
+       ASSERT_EQ(fd, -E2BIG, "queue_u32max");
+
+       fd = bpf_map_create(BPF_MAP_TYPE_STACK, NULL, 0, big_value, 8192, &opts);
+       ASSERT_EQ(fd, -E2BIG, "stack_oversize");
+
+       /* A normal-sized map must still be created successfully. */
+       fd = bpf_map_create(BPF_MAP_TYPE_QUEUE, NULL, 0, 64, 100, &opts);
+       ASSERT_GE(fd, 0, "queue_normal");
+       if (fd >= 0)
+               close(fd);
+}
+
 void test_queue_stack_map(void)
 {
        test_queue_stack_map_by_type(QUEUE);
        test_queue_stack_map_by_type(STACK);
+       test_queue_stack_map_alloc_check();
 }
--

2.43.0