From: Jun Yang <juny24602@gmail.com>
To: pablo@netfilter.org, fw@strlen.de
Cc: phil@nwl.cc, davem@davemloft.net, edumazet@kernel.org,
kuba@kernel.org, pabeni@redhat.com, horms@kernel.org,
kadlec@netfilter.org, echaudro@redhat.com, aconole@redhat.com,
david.lee@trailofbits.com, manizada@pm.me, yifanwucs@gmail.com,
netfilter-devel@vger.kernel.org, coreteam@netfilter.org,
netdev@vger.kernel.org, junvyyang@tencent.com,
corvus@tencent.com, stable@kernel.org
Subject: [PATCH net] netfilter: ipset: skip inline gc during hash resize
Date: Tue, 17 Nov 2026 19:06:11 +0800 [thread overview]
Message-ID: <20261117110619.46590-1-juny24602@gmail.com> (raw)
From: Jun Yang <junvyyang@tencent.com>
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 <corvus@tencent.com>
Signed-off-by: Jun Yang <junvyyang@tencent.com>
---
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)
reply other threads:[~2026-11-17 11:06 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261117110619.46590-1-juny24602@gmail.com \
--to=juny24602@gmail.com \
--cc=aconole@redhat.com \
--cc=coreteam@netfilter.org \
--cc=corvus@tencent.com \
--cc=davem@davemloft.net \
--cc=david.lee@trailofbits.com \
--cc=echaudro@redhat.com \
--cc=edumazet@kernel.org \
--cc=fw@strlen.de \
--cc=horms@kernel.org \
--cc=junvyyang@tencent.com \
--cc=kadlec@netfilter.org \
--cc=kuba@kernel.org \
--cc=manizada@pm.me \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pablo@netfilter.org \
--cc=phil@nwl.cc \
--cc=stable@kernel.org \
--cc=yifanwucs@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox