During hash table resizing, mtype_resize() skips expired elements without freeing their extensions. The old table is then destroyed with ext_destroy=false, so these extensions are never freed. Fix this by calling ip_set_ext_destroy() on expired elements in the resize copy loop. The cleanup is done under the region lock with the bucket re-read into a separate variable to avoid races with mtype_add() concurrently reusing or reallocating the bucket, while preserving the original bucket pointer for subsequent loop iterations. Discovered by Sashiko, not triggered, not runtime tested. Fixes: 80571a9ea4ca ("netfilter: ipset: Fix hash resizing with comments") Signed-off-by: Ă–mer Mete Kaya --- net/netfilter/ipset/ip_set_hash_gen.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/net/netfilter/ipset/ip_set_hash_gen.h b/net/netfilter/ipset/ip_set_hash_gen.h index 80ca523f304b..47aab02c9d23 100644 --- a/net/netfilter/ipset/ip_set_hash_gen.h +++ b/net/netfilter/ipset/ip_set_hash_gen.h @@ -823,8 +823,19 @@ mtype_resize(struct ip_set *set, bool retried) if (!test_bit_acquire(j, n->used)) continue; data = ahash_data(n, j, dsize); - if (SET_ELEM_EXPIRED(set, data)) + if (SET_ELEM_EXPIRED(set, data)) { + struct hbucket *cur; + + spin_lock_bh(&orig->hregion[r].lock); + cur = __ipset_dereference(hbucket(orig, i)); + if (cur && test_bit(j, cur->used)) { + data = ahash_data(cur, j, dsize); + if (SET_ELEM_EXPIRED(set, data)) + ip_set_ext_destroy(set, data); + } + spin_unlock_bh(&orig->hregion[r].lock); continue; + } #ifdef IP_SET_HASH_WITH_NETS /* We have readers running parallel with us, * so the live data cannot be modified. -- 2.56.0