> diff --git a/tools/testing/selftests/bpf/prog_tests/queue_stack_map.c b/tools/testing/selftests/bpf/prog_tests/queue_stack_map.c
> index 41441325e179..efe808eedd9a 100644
> --- a/tools/testing/selftests/bpf/prog_tests/queue_stack_map.c
> +++ b/tools/testing/selftests/bpf/prog_tests/queue_stack_map.c
[ ... ]
> +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");
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:
> + /* 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.