From: Jun Yang When the xtables SET target adds an element to a full hash region, mtype_add() runs garbage collection on that region. If mtype_resize() has already copied a live element, both tables point to the same comment. If the element then expires, inline GC can free the comment in the old table. Destroying the set frees it again in the new table. Take h->gc.lock and check t->resizing before running inline GC, as the periodic GC worker does. Resize sets the flag under the same lock before it starts copying elements. Fixes: cffcf57bf03c ("netfilter: ipset: exclude gc when resize is in progress") Cc: stable@kernel.org Reported-by: TencentOS Corvus AI Signed-off-by: Jun Yang --- A KASAN reproducer for this issue is available if requested. net/netfilter/ipset/ip_set_hash_gen.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/net/netfilter/ipset/ip_set_hash_gen.h b/net/netfilter/ipset/ip_set_hash_gen.h index 80ca523f304bb..70f768ba7b443 100644 --- a/net/netfilter/ipset/ip_set_hash_gen.h +++ b/net/netfilter/ipset/ip_set_hash_gen.h @@ -1009,8 +1009,12 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext, maxelem = t->maxelem; if (elements >= maxelem) { u32 e; - if (SET_WITH_TIMEOUT(set)) - mtype_gc_do(set, h, t, r); + if (SET_WITH_TIMEOUT(set)) { + spin_lock_bh(&h->gc.lock); + if (!t->resizing) + mtype_gc_do(set, h, t, r); + spin_unlock_bh(&h->gc.lock); + } maxelem = h->maxelem; elements = 0; for (e = 0; e < ahash_numof_locks(t->htable_bits); e++) -- 2.54.0 (Apple Git-157)