Skip to content

Commit 75673fd

Browse files
bkammerdAlexei Starovoitov
authored andcommitted
bpf: fix possible endless loop in BPF map iteration
The _safe variant used here gets the next element before running the callback, avoiding the endless loop condition. Signed-off-by: Brandon Kammerdiener <brandon.kammerdiener@intel.com> Link: https://lore.kernel.org/r/20250424153246.141677-2-brandon.kammerdiener@intel.com Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Hou Tao <houtao1@huawei.com>
1 parent f2858f3 commit 75673fd

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

kernel/bpf/hashtab.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2189,7 +2189,7 @@ static long bpf_for_each_hash_elem(struct bpf_map *map, bpf_callback_t callback_
21892189
b = &htab->buckets[i];
21902190
rcu_read_lock();
21912191
head = &b->head;
2192-
hlist_nulls_for_each_entry_rcu(elem, n, head, hash_node) {
2192+
hlist_nulls_for_each_entry_safe(elem, n, head, hash_node) {
21932193
key = elem->key;
21942194
if (is_percpu) {
21952195
/* current cpu value for percpu map */

0 commit comments

Comments
 (0)