From: Jozsef Kadlecsik <kadlec@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: Pablo Neira Ayuso <pablo@netfilter.org>
Subject: [PATCH v6 8/8] netfilter: ipset: fix order of usage counters
Date: Fri, 8 May 2026 22:59:03 +0200 [thread overview]
Message-ID: <20260508205903.10238-9-kadlec@netfilter.org> (raw)
In-Reply-To: <20260508205903.10238-1-kadlec@netfilter.org>
Eulgyu Kim reported a slab-use-after-free issue when resizing
a set and gc runs in parallel. Resizing may run parallel with
already running gc or gc can start but notice that resizing
started. The operation which finishes last must destroy the
original set. The logic for the testing is: "I was the last
user of the set and it was resized". However setting the
counters in resizing was: "the set will be resized and I'm
going to use the set". That created a small racing window
at the testing phase. Fix the order in the resizing functions.
Reported by: Eulgyu Kim <eulgyukim@snu.ac.kr>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
---
net/netfilter/ipset/ip_set_hash_gen.h | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/net/netfilter/ipset/ip_set_hash_gen.h b/net/netfilter/ipset/ip_set_hash_gen.h
index 71b57c731dcb..023a3d7aeba0 100644
--- a/net/netfilter/ipset/ip_set_hash_gen.h
+++ b/net/netfilter/ipset/ip_set_hash_gen.h
@@ -681,8 +681,9 @@ mtype_resize(struct ip_set *set, bool retried)
* between the original and resized sets.
*/
orig = ipset_dereference_bh_nfnl(h->table);
- atomic_set(&orig->ref, 1);
atomic_inc(&orig->uref);
+ smp_mb__after_atomic();
+ atomic_set(&orig->ref, 1);
pr_debug("attempt to resize set %s from %u to %u, t %p\n",
set->name, orig->htable_bits, htable_bits, orig);
for (r = 0; r < ahash_numof_locks(orig->htable_bits); r++) {
@@ -799,6 +800,7 @@ mtype_resize(struct ip_set *set, bool retried)
cleanup:
rcu_read_unlock_bh();
atomic_set(&orig->ref, 0);
+ smp_mb__before_atomic();
atomic_dec(&orig->uref);
mtype_ahash_destroy(set, t, false);
if (ret == -EAGAIN)
--
2.39.5
next prev parent reply other threads:[~2026-05-08 21:04 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-08 20:58 [PATCH v6 0/8] netfilter: ipset fixes Jozsef Kadlecsik
2026-05-08 20:58 ` [PATCH v6 1/8] netfilter: ipset: fix a potential dump-destroy race Jozsef Kadlecsik
2026-05-08 20:58 ` [PATCH v6 2/8] netfilter: ipset: Fix data race between add and list header in all hash types Jozsef Kadlecsik
2026-05-08 20:58 ` [PATCH v6 3/8] netfilter: ipset: Fix data race between add and dump " Jozsef Kadlecsik
2026-05-08 20:58 ` [PATCH v6 4/8] netfilter: ipset: annotate "pos" for concurrent readers/writers Jozsef Kadlecsik
2026-05-08 20:59 ` [PATCH v6 5/8] netfilter: ipset: Don't use test_bit() in lockless RCU readers Jozsef Kadlecsik
2026-05-08 20:59 ` [PATCH v6 6/8] netfilter: ipset: fix potential torn read in reuse/forceadd cases Jozsef Kadlecsik
2026-05-08 20:59 ` [PATCH v6 7/8] netfilter: ipset: skip gc when resize is in progress Jozsef Kadlecsik
2026-05-08 20:59 ` Jozsef Kadlecsik [this message]
2026-05-09 8:09 ` [PATCH v6 0/8] netfilter: ipset fixes Florian Westphal
2026-05-10 21:43 ` Pablo Neira Ayuso
2026-05-11 7:45 ` Jozsef Kadlecsik
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=20260508205903.10238-9-kadlec@netfilter.org \
--to=kadlec@netfilter.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.