public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf v2 0/2] bpf: fix end-of-list detection in cgroup_storage_get_next_key()
@ 2026-04-03 13:29 Weiming Shi
  2026-04-03 13:29 ` [PATCH bpf v2 1/2] " Weiming Shi
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Weiming Shi @ 2026-04-03 13:29 UTC (permalink / raw)
  To: Martin KaFai Lau, Alexei Starovoitov, Daniel Borkmann,
	Andrii Nakryiko, Eduard Zingerman, Kumar Kartikeya Dwivedi
  Cc: Song Liu, Yonghong Song, Jiri Olsa, Roman Gushchin, bpf,
	Xiang Mei, Weiming Shi

list_next_entry() never returns NULL, so the NULL check in
cgroup_storage_get_next_key() is dead code. When iterating past the last
element, the function reads storage->key from a bogus pointer that aliases
internal map fields and copies the result to userspace.

Patch 1 replaces the NULL check with list_entry_is_head() so the function
correctly returns -ENOENT when there are no more entries.

Patch 2 adds a selftest to cover this corner case, as suggested by Sun Jian
and Paul Chaignon.

v2:
  - Added selftest (Paul Chaignon)
  - Collected Reviewed-by and Acked-by tags

Weiming Shi (2):
  bpf: fix end-of-list detection in cgroup_storage_get_next_key()
  selftests/bpf: add get_next_key boundary test for cgroup_storage

 kernel/bpf/local_storage.c                              | 2 +-
 tools/testing/selftests/bpf/prog_tests/cgroup_storage.c | 5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)

-- 
2.43.0


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

end of thread, other threads:[~2026-04-06  1:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-03 13:29 [PATCH bpf v2 0/2] bpf: fix end-of-list detection in cgroup_storage_get_next_key() Weiming Shi
2026-04-03 13:29 ` [PATCH bpf v2 1/2] " Weiming Shi
2026-04-03 13:29 ` [PATCH bpf v2 2/2] selftests/bpf: add get_next_key boundary test for cgroup_storage Weiming Shi
2026-04-03 14:16   ` Paul Chaignon
2026-04-06  1:50 ` [PATCH bpf v2 0/2] bpf: fix end-of-list detection in cgroup_storage_get_next_key() patchwork-bot+netdevbpf

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