Skip to content

bpf: fix end-of-list detection in cgroup_storage_get_next_key()

Weiming Shi bpf 2 versions – Applied

Status from this message: This series was applied to bpf/bpf-next.git (master)

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest2 patches 1 replyApplied 2/2
  2. v11 patch 3 repliesSuperseded

Changes in v2 from the cover letter

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

Patches in v2 All 2 applied

#Subject and filesSizeRepliesApplied
1/2bpf: fix end-of-list detection in cgroup_storage_get_next_key()kernel/bpf/local_storage.c+1 -10 repliesApplied
2/2selftests/bpf: add get_next_key boundary test for cgroup_storagetools/testing/selftests/bpf/prog_tests/cgroup_storage.c+5 -01 replyApplied

Reviews trailers per patch

All 2 patches have a Reviewed-by or Acked-by.

PatchSun JianPaul Chaignon
1/2R-b A-b
2/2A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH bpf v2 0/2] bpf: fix end-of-list detection in cgroup_storage_get_next_key()

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(-)
Signature · 1 line
2.43.0