History

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.

Brandon Kammerdiener committed 1 year ago

Commit 75673fd1 parent f2858f31 file · +1 −1Browse files

Unified · Split

kernel/bpf/hashtab.c+1−1
@@ -2189,7 +2189,7 @@ static long bpf_for_each_hash_elem(struct bpf_map *map, bpf_callback_t callback_ · 2188 unmodified lines
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 */