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

From: Yuan Chen <chenyuan@kylinos.cn>

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: stable@vger.kernel.org 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(+)

-- 
2.54.0


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

end of thread, other threads:[~2026-08-24  9:25 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-10 13:59 [PATCH bpf v3 0/2] bpf: Fix queue/stack map u32 index overflow chenyuan_fl
2026-08-10 13:59 ` [PATCH bpf v3 1/2] " chenyuan_fl
2026-08-10 13:59 ` [PATCH bpf v3 2/2] selftests/bpf: Add regression test for queue/stack map size limit chenyuan_fl
2026-08-10 14:49   ` bot+bpf-ci
2026-08-13 22:19   ` Andrii Nakryiko
2026-08-24  8:33     ` [PATCH bpf v4 0/2] bpf: Fix queue/stack map u32 index overflow chenyuan_fl
2026-08-24  8:33       ` [PATCH bpf v4 1/2] " chenyuan_fl
2026-08-24  8:47         ` sashiko-bot
2026-08-24  8:33       ` [PATCH bpf v4 2/2] selftests/bpf: Add regression test for queue/stack map size limit chenyuan_fl
2026-08-24  8:43         ` sashiko-bot
2026-08-24  9:25         ` bot+bpf-ci

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