BPF List
 help / color / mirror / Atom feed
* [PATCH bpf 0/2] bpf: Fix queue/stack map u32 index overflow
@ 2026-08-07  2:05 chenyuan_fl
  2026-08-07  2:05 ` [PATCH 1/2] " chenyuan_fl
  2026-08-07  2:05 ` [PATCH 2/2] selftests/bpf: Add regression test for queue/stack map size limit chenyuan_fl
  0 siblings, 2 replies; 5+ messages in thread
From: chenyuan_fl @ 2026-08-07  2:05 UTC (permalink / raw)
  To: bpf
  Cc: linux-kernel, Alexei Starovoitov, Daniel Borkmann,
	Andrii Nakryiko, Yuan Chen

From: Yuan Chen <chenyuan@kylinos.cn>

queue/stack maps address their element storage with a u32 head/tail
index multiplied by value_size. The storage itself is allocated using
64-bit arithmetic, so a map with max_entries * value_size exceeding
U32_MAX can be created, and the u32 multiplication then wraps, making
push/peek/pop operate on the wrong element: map data gets corrupted and
stale values can leak to user space through peek.

The bound check that used to prevent this was removed by c85d69135a91
("bpf: move memory size checks to bpf_map_charge_init()"), which
migrated only the bytes-to-pages conversion and dropped the overflow
guard, so oversized queue/stack maps can be created again.

Patch 1 restores the bound at map creation time: a map whose element
storage would exceed U32_MAX bytes is rejected with -E2BIG, keeping the
u32 index multiplication overflow-free.
Patch 2 adds a regression test covering both map types and a
normal-sized control case.

Verification: built and run in QEMU - oversized queue/stack maps are
rejected with -E2BIG, normal-sized maps still work, and the
queue_stack_map selftest passes.

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                 |  7 ++++
 .../bpf/prog_tests/queue_stack_map.c          | 34 +++++++++++++++++++
 2 files changed, 41 insertions(+)

-- 
2.54.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-08-07  2:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox