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

Showing the changes to kernel (1 of 1 file). Show all

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