BPF List
 help / color / mirror / Atom feed
* [PATCH v2 0/2] bpf: Fix incorrect handling of user flags by percpu map updates
@ 2026-09-30 13:57 Masoud Aghasi
  2026-09-30 13:57 ` [PATCH v2 1/2] " Masoud Aghasi
  2026-09-30 13:57 ` [PATCH v2 2/2] selftests/bpf: add test for percpu map flags combination Masoud Aghasi
  0 siblings, 2 replies; 10+ messages in thread
From: Masoud Aghasi @ 2026-09-30 13:57 UTC (permalink / raw)
  To: bpf
  Cc: andrii, eddyz87, ast, daniel, memxor, martin.lau, song,
	yonghong.song, jolsa, emil, ihor.solodrai, leon.hwang,
	Masoud Aghasi

For BPF_MAP_TYPE_PERCPU_HASH map, htab_map_check_update_flags() and
check_flags() are not considering the possibility of a combination of
(BPF_NOEXIST, BPF_EXIST) flags with (BPF_F_CPU, BPF_F_ALL_CPUS) flags.
This causes the (BPF_NOEXIST, BPF_EXIST) flags to lose their effect.

For example, when using (BPF_F_CPU | BPF_EXIST) flag combination
with bpf_map_update_elem() on a BPF_MAP_TYPE_PERCPU_HASH map, the
BPF_EXIST flag does not prevent new insertions as expected.

Also for BPF_MAP_TYPE_PERCPU_ARRAY map, using the (BPF_F_ALL_CPUS |
BPF_EXIST) flag combination with bpf_map_update_elem() results in an
incorrect EINVAL error response, even though the flag combination is
valid. 

This series fixes the bug by adding proper flag validations and checks
and adds regression tests.

Changes since v1:
- Fix a BPF_EXIST flag check in __htab_lru_percpu_map_update_elem()
- Add additional test for BPF_MAP_TYPE_LRU_PERCPU_HASH map
- Add check for BPF_EXIST, BPF_NOEXIST combination in percpu array map

Masoud Aghasi (2):
  bpf: Fix incorrect handling of user flags by percpu map updates
  selftests/bpf: add test for percpu map flags combination

 kernel/bpf/arraymap.c                         |  5 +--
 kernel/bpf/hashtab.c                          | 11 ++++---
 .../selftests/bpf/prog_tests/percpu_alloc.c   | 32 +++++++++++++++++++
 3 files changed, 42 insertions(+), 6 deletions(-)

-- 
2.47.3


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

end of thread, other threads:[~2026-10-02  5:45 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-30 13:57 [PATCH v2 0/2] bpf: Fix incorrect handling of user flags by percpu map updates Masoud Aghasi
2026-09-30 13:57 ` [PATCH v2 1/2] " Masoud Aghasi
2026-10-01 15:16   ` Leon Hwang
2026-10-02  5:34     ` Masoud Aghasi
2026-09-30 13:57 ` [PATCH v2 2/2] selftests/bpf: add test for percpu map flags combination Masoud Aghasi
2026-09-30 14:42   ` bot+bpf-ci
2026-10-01 15:17   ` Leon Hwang
2026-10-02  5:36     ` Masoud Aghasi
2026-10-01 15:37   ` Alexei Starovoitov
2026-10-02  5:45     ` Masoud Aghasi

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