Skip to contentSkip to conversation

ipset patch to fix region locking

PATCH New Jozsef Kadlecsik 1 participant 2 messages May 7, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover ipset patch to fix region locking

Hi Pablo,

Please apply the next patch which fixes the region locking in the hash type of sets.

Region locking was introduced to break up operation on the whole hashes into smaller parts in order to avoid to keep the locking too long continuously. That required three macros: two to calculate the start and end buckets belonging to a region lock and a third one to give back the region lock of a given hash bucket. The third one was incorrect which can lead to a race condition between the internal garbage collector and adding new entries to the hash simultaneously.

The bug affects all hash types, since the region locking was introduced and it was reported by Kota Toda <[email protected]>.

Best regards,
Jozsef

The following changes since commit 3e52667a9c328b3d1a1ddbbb6b8fbf63a217bda3:

Merge branch 'lan78xx-phylink-prep' (2025-05-07 12:57:06 +0100)

are available in the Git repository at:

git://blackhole.kfki.hu/nf-next e2b52b09f1166fce2

for you to fetch changes up to e2b52b09f1166fce29f4888ad9b86a7cfec7ad8a:

netfilter: ipset: fix region locking in hash types (2025-05-07 16:48:30 +0200)

----------------------------------------------------------------
Jozsef Kadlecsik (1):
netfilter: ipset: fix region locking in hash types

 net/netfilter/ipset/ip_set_hash_gen.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
#1 lore raw

PATCH 1/1 netfilter: ipset: fix region locking in hash types

Region locking introduced in v5.6-rc4 contained three macros to handle the region locks: ahash_bucket_start(), ahash_bucket_end() which gave back the start and end hash bucket values belonging to a given region lock and ahash_region() which should give back the region lock belonging to a given hash bucket. The latter was incorrect which can lead to a race condition between the garbage collector and adding new elements when a hash type of set is defined with timeouts.

Fixes f66ee0410b1c ("netfilter: ipset: Fix "INFO: rcu detected stall in hash_xxx" reports")
---
 net/netfilter/ipset/ip_set_hash_gen.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/ipset/ip_set_hash_gen.h +1 -1
index cf3ce72c3de6..5251524b96af 100644
@@ -64,7 +64,7 @@ struct hbucket {
 #define ahash_sizeof_regions(htable_bits)		\
 	(ahash_numof_locks(htable_bits) * sizeof(struct ip_set_region))
 #define ahash_region(n, htable_bits)		\
-	((n) % ahash_numof_locks(htable_bits))
+	((n) / jhash_size(HTABLE_REGION_BITS))
 #define ahash_bucket_start(h,  htable_bits)	\
 	((htable_bits) < HTABLE_REGION_BITS ? 0	\
 		: (h) * jhash_size(HTABLE_REGION_BITS))
Signature · 1 line
2.39.5