bba2ca1
From 03fdcf282c8fe212efae0d1229fb8594ffe60b17 Mon Sep 17 00:00:00 2001
bba2ca1
From: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
bba2ca1
Date: Sat, 7 Nov 2015 11:24:51 +0100
bba2ca1
Subject: [PATCH 3/3] netfilter: ipset: Fix hash type expire: release empty
bba2ca1
 hash bucket block
bba2ca1
bba2ca1
When all entries are expired/all slots are empty, release the bucket.
bba2ca1
bba2ca1
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
bba2ca1
---
bba2ca1
 net/netfilter/ipset/ip_set_hash_gen.h | 13 +++++++++----
bba2ca1
 1 file changed, 9 insertions(+), 4 deletions(-)
bba2ca1
bba2ca1
diff --git a/net/netfilter/ipset/ip_set_hash_gen.h b/net/netfilter/ipset/ip_set_hash_gen.h
bba2ca1
index fa4f6374bb73..e5336ab36d67 100644
bba2ca1
--- a/net/netfilter/ipset/ip_set_hash_gen.h
bba2ca1
+++ b/net/netfilter/ipset/ip_set_hash_gen.h
bba2ca1
@@ -476,7 +476,7 @@ static void
bba2ca1
 mtype_expire(struct ip_set *set, struct htype *h, u8 nets_length, size_t dsize)
bba2ca1
 {
bba2ca1
 	struct htable *t;
bba2ca1
-	struct hbucket *n;
bba2ca1
+	struct hbucket *n, *tmp;
bba2ca1
 	struct mtype_elem *data;
bba2ca1
 	u32 i, j, d;
bba2ca1
 #ifdef IP_SET_HASH_WITH_NETS
bba2ca1
@@ -511,9 +511,14 @@ mtype_expire(struct ip_set *set, struct htype *h, u8 nets_length, size_t dsize)
bba2ca1
 			}
bba2ca1
 		}
bba2ca1
 		if (d >= AHASH_INIT_SIZE) {
bba2ca1
-			struct hbucket *tmp = kzalloc(sizeof(*tmp) +
bba2ca1
-					(n->size - AHASH_INIT_SIZE) * dsize,
bba2ca1
-					GFP_ATOMIC);
bba2ca1
+			if (d >= n->size) {
bba2ca1
+				rcu_assign_pointer(hbucket(t, i), NULL);
bba2ca1
+				kfree_rcu(n, rcu);
bba2ca1
+				continue;
bba2ca1
+			}
bba2ca1
+			tmp = kzalloc(sizeof(*tmp) +
bba2ca1
+				      (n->size - AHASH_INIT_SIZE) * dsize,
bba2ca1
+				      GFP_ATOMIC);
bba2ca1
 			if (!tmp)
bba2ca1
 				/* Still try to delete expired elements */
bba2ca1
 				continue;
bba2ca1
-- 
bba2ca1
2.4.3
bba2ca1