The commit is pushed to "branch-rh7-3.10.0-1160.119.1.vz7.224.x-ovz" and will appear at g...@bitbucket.org:openvz/vzkernel.git after rh7-3.10.0-1160.119.1.vz7.224.3 ------> commit 916bbfebb3fc1b677dbc1529716b00c7b3af3635 Author: Alexander Maltsev <keltar...@gmail.com> Date: Wed Sep 25 17:35:43 2024 +0800
ms/netfilter: ipset: Add list flush to cancel_gc Flushing list in cancel_gc drops references to other lists right away, without waiting for RCU to destroy list. Fixes race when referenced ipsets can't be destroyed while referring list is scheduled for destroy. Fixes: 97f7cf1cd80e ("netfilter: ipset: fix performance regression in swap operation") Signed-off-by: Alexander Maltsev <keltar...@gmail.com> Acked-by: Jozsef Kadlecsik <kad...@netfilter.org> Signed-off-by: Pablo Neira Ayuso <pa...@netfilter.org> https://virtuozzo.atlassian.net/browse/PSBM-155867 (cherry picked from commit c1193d9bbbd379defe9be3c6de566de684de8a6f) Signed-off-by: Pavel Tikhomirov <ptikhomi...@virtuozzo.com> ================= Patchset description: netfilter: ipset: Fix possible cause of memory corruption Patch [1] fixes possible race between swap/destroy and add/del/test. Here is is possible order of events when this race can lead to double free with kfree_rcu on already freed hash bucket: # Thread 1 +-> ip_set_add +-> set = ip_set_rcu_get(xt_net(par), index) < pause > # Thread 2 ipset swap ipset destroy +-> mtype_destroy +-> mtype_ahash_destroy +-> n = __ipset_dereference(hbucket(t, i)) +-> kfree(n) # Thread 1 < unpause > +-> ip_set_lock(set) +-> hash_net4_kadt +-> mtype_variant->adt[adt] +-> net4_kadt_add (mtype_add) +-> n = rcu_dereference_bh(hbucket(t, key)) +-> if (n->pos >= n->size) +-> old = n +-> if (old != ERR_PTR(-ENOENT)) +-> kfree_rcu(old, rcu) That can in it's turn lead to possible rcu free list corruption if this double fried memory is reused just after rcu_free and before actual rcu callback. note1: The patch [1] has a reproducer but, sadly, I was unable to reproduce the situation, even adding mdelay(100) to ip_set_add/del/test. note2: All other patches are fixups to the original fixing patch. note3: We don't have proof that this a fix to original issue, we only know that ipset hash buckets were several times seen double freed just before crash, which might indirectly indicate that the original problem is related to ipset hash buckets. Signed-off-by: Pavel Tikhomirov <ptikhomi...@virtuozzo.com> https://virtuozzo.atlassian.net/browse/PSBM-155867 Alexander Maltsev (1): netfilter: ipset: Add list flush to cancel_gc Eric Dumazet (1): netns: add pre_exit method to struct pernet_operations Jozsef Kadlecsik (5): netfilter: ipset: fix race condition between swap/destroy and kernel side add/del/test [1] netfilter: ipset: fix performance regression in swap operation netfilter: ipset: Missing gc cancellations fixed netfilter: ipset: Fix race between namespace cleanup and gc in the list:set type netfilter: ipset: Fix suspicious rcu_dereference_protected() --- net/netfilter/ipset/ip_set_list_set.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/netfilter/ipset/ip_set_list_set.c b/net/netfilter/ipset/ip_set_list_set.c index b9dc3063e0d4..dd0fa9ada492 100644 --- a/net/netfilter/ipset/ip_set_list_set.c +++ b/net/netfilter/ipset/ip_set_list_set.c @@ -553,6 +553,9 @@ list_set_cancel_gc(struct ip_set *set) if (SET_WITH_TIMEOUT(set)) del_timer_sync(&map->gc); + + /* Flush list to drop references to other ipsets */ + list_set_flush(set); } static const struct ip_set_type_variant set_variant = { _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel