summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorAlexei Starovoitov <ast@kernel.org>2025-04-25 08:36:59 -0700
committerAlexei Starovoitov <ast@kernel.org>2025-04-25 08:37:21 -0700
commit6ae003adc029c74e7f97cc65dc1e79109a1f2d67 (patch)
tree4c40aabec804482096aa1993ebb93a92ebc74d64 /kernel
parentf2858f308131a09e33afb766cd70119b5b900569 (diff)
parent3d9c463f959f41cd6616ebf8a5d15e9d3ef04f16 (diff)
Merge branch 'bpf-fix-softlock-condition-in-bpf-hashmap-interation'
Brandon Kammerdiener says: ==================== This patchset fixes an endless loop condition that can occur in bpf_for_each_hash_elem, causing the core to softlock. My understanding is that a combination of RCU list deletion and insertion introduces the new element after the iteration cursor and that there is a chance that an RCU reader may in fact use this new element in iteration. The patch uses a _safe variant of the macro which gets the next element to iterate before executing the loop body for the current element. I have also added a subtest in the for_each selftest that can trigger this condition without the fix. Changes since v2: - Renaming and additional checks in selftests/bpf/prog_tests/for_each.c Changes since v1: - Added missing Signed-off-by lines to both patches ==================== Acked-by: Hou Tao <houtao1@huawei.com> Link: https://patch.msgid.link/20250424153246.141677-1-brandon.kammerdiener@intel.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/bpf/hashtab.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c
index 5a5adc66b8e2..92b606d60020 100644
--- a/kernel/bpf/hashtab.c
+++ b/kernel/bpf/hashtab.c
@@ -2189,7 +2189,7 @@ static long bpf_for_each_hash_elem(struct bpf_map *map, bpf_callback_t callback_
b = &htab->buckets[i];
rcu_read_lock();
head = &b->head;
- hlist_nulls_for_each_entry_rcu(elem, n, head, hash_node) {
+ hlist_nulls_for_each_entry_safe(elem, n, head, hash_node) {
key = elem->key;
if (is_percpu) {
/* current cpu value for percpu map */