mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH nf] netfilter: ipset: restore element before rescanning cidrs on seqcount retry
@ 2026-10-18  3:52 Tamaki Yanagawa
  2026-10-18  4:55 ` Florian Westphal
  0 siblings, 1 reply; 4+ messages in thread
From: Tamaki Yanagawa @ 2026-10-18  3:52 UTC (permalink / raw)
  To: netfilter-devel; +Cc: pablo, fw, phil, coreteam, linux-kernel, ty

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



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-10-18 11:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-18  3:52 [PATCH nf] netfilter: ipset: restore element before rescanning cidrs on seqcount retry Tamaki Yanagawa
2026-10-18  4:55 ` Florian Westphal
2026-10-18  5:23   ` Tamaki Yanagawa
2026-10-18 11:44     ` Florian Westphal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®