Skip to contentSkip to conversation

netfilter: ipset: let destroy callbacks adjust ext mem size

PATCH In review Florian Westphal 2 participants 3 messages Aug 6 – Aug 9

Subsystems (2)
lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/1 netfilter: ipset: let destroy callbacks adjust ext mem size

For bitmap this change makes no difference, because destructors are called synchronously.

List type however calls them via call_rcu() so accounting decrement can happen after list_set_flush() set ext_size to 0.

'set->elements = 0' can be removed for the same reason in the list type case, it calls 'set->elements--' for each element.

Fixes 9e41f26a505c ("netfilter: ipset: Count non-static extension memory for userspace")

---
sashiko: list_set_uadd() may call list_set_replace() and then erronously increments set->elements, causing a counter drift. This bug will be resolved in a different patch.

 net/netfilter/ipset/ip_set_bitmap_gen.h | 2 +-
 net/netfilter/ipset/ip_set_list_set.c   | 3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)
net/netfilter/ipset/ip_set_bitmap_gen.h +1 -1
index 226fdf17b683..d6a7e6604542 100644
@@ -77,7 +77,7 @@ mtype_flush(struct ip_set *set)
 		mtype_ext_cleanup(set);
 	bitmap_zero(map->members, map->elements);
 	set->elements = 0;
-	atomic64_set(&set->ext_size, 0);
+	DEBUG_NET_WARN_ON_ONCE(atomic64_read(&set->ext_size) > 0);
 }
 
 /* Calculate the actual memory size of the set data */
net/netfilter/ipset/ip_set_list_set.c +1 -2
index 56626f4943a9..b4967a9d82b0 100644
@@ -423,8 +423,7 @@ list_set_flush(struct ip_set *set)
 
 	list_for_each_entry_safe(e, n, &map->members, list)
 		list_set_del(set, e);
-	set->elements = 0;
-	atomic64_set(&set->ext_size, 0);
+	DEBUG_NET_WARN_ON_ONCE(set->elements > 0);
 }
 
 static void
Signature · 1 line
2.54.0
author maintainer
#1 lore raw
Quoted 8 lines · Florian Westphal

For bitmap this change makes no difference, because destructors are called synchronously.
List type however calls them via call_rcu() so accounting decrement can happen after list_set_flush() set ext_size to 0.

'set->elements = 0' can be removed for the same reason in the list type case, it calls 'set->elements--' for each element.

Quoted 7 lines
Fixes 9e41f26a505c ("netfilter: ipset: Count non-static extension memory for userspace")

---
sashiko: list_set_uadd() may call list_set_replace() and then erronously increments set->elements, causing a counter drift. This bug will be resolved in a different patch.

Seems sashiko ignored this and reported this bug again. The report can thus be discarded.

Acked-by on v1 1/1
#2 lore raw
In reply to Florian Westphal
Quoted 6 lines · Florian Westphal

For bitmap this change makes no difference, because destructors are called synchronously.

List type however calls them via call_rcu() so accounting decrement can happen after list_set_flush() set ext_size to 0.

Quoted 6 lines

'set->elements = 0' can be removed for the same reason in the list type case, it calls 'set->elements--' for each element.

Fixes 9e41f26a505c ("netfilter: ipset: Count non-static extension memory for userspace")

Best regards,
Jozsef

Quoted 40 lines

---
sashiko: list_set_uadd() may call list_set_replace() and then erronously increments set->elements, causing a counter drift. This bug will be resolved in a different patch.

 net/netfilter/ipset/ip_set_bitmap_gen.h | 2 +-
 net/netfilter/ipset/ip_set_list_set.c   | 3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)
net/netfilter/ipset/ip_set_bitmap_gen.h +1 -1
index 226fdf17b683..d6a7e6604542 100644
@@ -77,7 +77,7 @@ mtype_flush(struct ip_set *set)
 		mtype_ext_cleanup(set);
 	bitmap_zero(map->members, map->elements);
 	set->elements = 0;
-	atomic64_set(&set->ext_size, 0);
+	DEBUG_NET_WARN_ON_ONCE(atomic64_read(&set->ext_size) > 0);
 }
 
 /* Calculate the actual memory size of the set data */
net/netfilter/ipset/ip_set_list_set.c +1 -2
index 56626f4943a9..b4967a9d82b0 100644
@@ -423,8 +423,7 @@ list_set_flush(struct ip_set *set)
 
 	list_for_each_entry_safe(e, n, &map->members, list)
 		list_set_del(set, e);
-	set->elements = 0;
-	atomic64_set(&set->ext_size, 0);
+	DEBUG_NET_WARN_ON_ONCE(set->elements > 0);
 }
 
 static void
Signature · 1 line
2.54.0
Signature · 3 lines
E-mail : [email protected], [email protected], [email protected]
Address: Wigner Research Centre for Physics
         H-1525 Budapest 114, POB. 49, Hungary