Skip to content

Commit b4b5a20

Browse files
winmingregkh
authored andcommitted
bpf: fix end-of-list detection in cgroup_storage_get_next_key()
[ Upstream commit 5828b9e ] list_next_entry() never returns NULL -- when the current element is the last entry it wraps to the list head via container_of(). The subsequent NULL check is therefore dead code and get_next_key() never returns -ENOENT for the last element, instead reading storage->key from a bogus pointer that aliases internal map fields and copying the result to userspace. Replace it with list_entry_is_head() so the function correctly returns -ENOENT when there are no more entries. Fixes: de9cbba ("bpf: introduce cgroup storage maps") Reported-by: Xiang Mei <xmei5@asu.edu> Signed-off-by: Weiming Shi <bestswngs@gmail.com> Reviewed-by: Sun Jian <sun.jian.kdev@gmail.com> Acked-by: Paul Chaignon <paul.chaignon@gmail.com> Link: https://lore.kernel.org/r/20260403132951.43533-2-bestswngs@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 1aa61a6 commit b4b5a20

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

kernel/bpf/local_storage.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ static int cgroup_storage_get_next_key(struct bpf_map *_map, void *key,
259259
goto enoent;
260260

261261
storage = list_next_entry(storage, list_map);
262-
if (!storage)
262+
if (list_entry_is_head(storage, &map->list, list_map))
263263
goto enoent;
264264
} else {
265265
storage = list_first_entry(&map->list,

0 commit comments

Comments
 (0)