Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Brandon Kammerdiener and committed by
Alexei Starovoitov
75673fda f2858f30

+1 -1
+1 -1
kernel/bpf/hashtab.c
··· 2189 2189 b = &htab->buckets[i]; 2190 2190 rcu_read_lock(); 2191 2191 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) { 2193 2193 key = elem->key; 2194 2194 if (is_percpu) { 2195 2195 /* current cpu value for percpu map */