Skip to contentSkip to conversation

netfilter: ipset: drop logically empty buckets in mtype_del

PATCH RESEND In review Yuan Tan 2 participants 2 messages Mar 27 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Yuan Tan

author
#1 lore raw

PATCH RESEND 1/1 netfilter: ipset: drop logically empty buckets in mtype_del

From: Yifan Wu <[email protected]>

mtype_del() counts empty slots below n->pos in k, but it only drops the bucket when both n->pos and k are zero. This misses buckets whose live entries have all been removed while n->pos still points past deleted slots.

Treat a bucket as empty when all positions below n->pos are unused and release it directly instead of shrinking it further.

Fixes 8af1c6fbd923 ("netfilter: ipset: Fix forceadd evaluation path")
---
 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 181daa9c2019..b79e5dd2af03 100644
@@ -1098,7 +1098,7 @@ mtype_del(struct ip_set *set, void *value, const struct ip_set_ext *ext,
 			if (!test_bit(i, n->used))
 				k++;
 		}
-		if (n->pos == 0 && k == 0) {
+		if (k == n->pos) {
 			t->hregion[r].ext_size -= ext_size(n->size, dsize);
 			rcu_assign_pointer(hbucket(t, key), NULL);
 			kfree_rcu(n, rcu);
Signature · 1 line
2.43.0
reviewer Reviewed-by on v1 1/1
#2 lore raw
Quoted 9 lines · Yuan Tan

From: Yifan Wu <[email protected]>

mtype_del() counts empty slots below n->pos in k, but it only drops the bucket when both n->pos and k are zero. This misses buckets whose live entries have all been removed while n->pos still points past deleted slots.

Treat a bucket as empty when all positions below n->pos are unused and release it directly instead of shrinking it further.

Quoted 7 lines
Fixes 8af1c6fbd923 ("netfilter: ipset: Fix forceadd evaluation path")