From: Tamaki Yanagawa <ty@000ty.net>
To: netfilter-devel@vger.kernel.org
Cc: pablo@netfilter.org, fw@strlen.de, phil@nwl.cc,
coreteam@netfilter.org, linux-kernel@vger.kernel.org,
ty@000ty.net
Subject: [PATCH nf] netfilter: ipset: restore element before rescanning cidrs on seqcount retry
Date: Sun, 18 Oct 2026 03:52:13 +0000 [thread overview]
Message-ID: <20261018035205.1008-1-ty@000ty.net> (raw)
mtype_test_cidrs() masks the element under test in place with
mtype_data_netmask() while walking the cidr array from the most to the
least specific prefix. Since the walk is restarted on concurrent cidr
array updates, the IPSET_NET_COUNT == 1 types (hash:net, hash:net,port,
hash:ip,port,net, hash:net,iface) rescan with an element already masked
to the widest prefix tried, so a lookup can wrongly match a more specific
entry at the network base address (e.g. 10.200.3.4 matching 10.0.0.0/29).
Restore the element before rescanning.
Fixes: e80456d79ec8 ("netfilter: ipset: remove need to allocate memory on delete operations")
Signed-off-by: Tamaki Yanagawa <ty@000ty.net>
Assisted-by: Claude:claude-opus-5-5
---
net/netfilter/ipset/ip_set_hash_gen.h | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/net/netfilter/ipset/ip_set_hash_gen.h b/net/netfilter/ipset/ip_set_hash_gen.h
index 80ca523f30..4f94443dcd 100644
--- a/net/netfilter/ipset/ip_set_hash_gen.h
+++ b/net/netfilter/ipset/ip_set_hash_gen.h
@@ -1307,9 +1307,9 @@ mtype_test_cidrs(struct ip_set *set, struct mtype_elem *d,
struct net_prefixes *nets0;
struct hbucket *n;
struct mtype_elem *data;
+ struct mtype_elem orig = *d;
#if IPSET_NET_COUNT == 2
struct net_prefixes *nets1;
- struct mtype_elem orig = *d;
unsigned int seq1;
int ret, i, j, k;
#else
@@ -1372,13 +1372,17 @@ mtype_test_cidrs(struct ip_set *set, struct mtype_elem *d,
ret = 0;
unlock:
if (read_seqcount_retry(&nets0->seq, seq0))
- goto retry;
+ goto restore;
#if IPSET_NET_COUNT == 2
if (read_seqcount_retry(&nets1->seq, seq1))
- goto retry;
+ goto restore;
#endif
rcu_read_unlock_bh();
return ret;
+restore:
+ /* mtype_data_netmask() masks @d in place, undo it before rescanning */
+ *d = orig;
+ goto retry;
}
#endif
base-commit: ab699d296e066eb64f51d2a8a1d42237a3b186c8
--
2.52.0.windows.1
next reply other threads:[~2026-10-18 3:52 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-18 3:52 Tamaki Yanagawa [this message]
2026-10-18 4:55 ` [PATCH nf] netfilter: ipset: restore element before rescanning cidrs on seqcount retry Florian Westphal
2026-10-18 5:23 ` Tamaki Yanagawa
2026-10-18 11:44 ` Florian Westphal
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=20261018035205.1008-1-ty@000ty.net \
--to=ty@000ty.net \
--cc=coreteam@netfilter.org \
--cc=fw@strlen.de \
--cc=linux-kernel@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
--cc=phil@nwl.cc \
/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.