Skip to contentSkip to conversation

netfilter: ebtables: shashiko nitpicks

PATCH In review Florian Westphal 1 participant 5 messages Jul 4

Subsystems (3)
lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

cover netfilter: ebtables: shashiko nitpicks

Three academic bug fixes for ebtables, based on sashiko drive-by reviews.

All of these "bugs" have existed forever, kets treat this as cleanups.

Florian Westphal (3):
netfilter: ebtables: zero chainstack array
netfilter: ebtables: account compat ebt_table_info to kmemcg
netfilter: ebtables: bound num_counters in do_update_counters()

 net/bridge/netfilter/ebtables.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
Signature · 1 line
2.55.0
author maintainer
#1 lore raw

PATCH 1/3 netfilter: ebtables: zero chainstack array

shashiko reports:
looking at ebtables table
translation, could a sparse cpu_possible_mask lead to an uninitialized pointer free?

If cpu_possible_mask is sparse (for example, CPU 0 and CPU 2 are possible, but CPU 1 is not), the allocation loop skips CPU 1. If vmalloc_node() fails at CPU 2, the cleanup loop will blindly decrement and call vfree() on newinfo->chainstack[1].

Not a real-world bug, such allocation isn't expected to fail in the first place.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 net/bridge/netfilter/ebtables.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/bridge/netfilter/ebtables.c +1 -2
index 042d31278713..66c407cffa16 100644
@@ -923,8 +923,7 @@ static int translate_table(struct net *net, const char *name,
 		 * if an error occurs
 		 */
 		newinfo->chainstack =
-			vmalloc_array(nr_cpu_ids,
-				      sizeof(*(newinfo->chainstack)));
+			vcalloc(nr_cpu_ids, sizeof(*(newinfo->chainstack)));
 		if (!newinfo->chainstack)
 			return -ENOMEM;
 		for_each_possible_cpu(i) {
Signature · 1 line
2.55.0
author maintainer
#2 lore raw

PATCH 2/3 netfilter: ebtables: account compat ebt_table_info to kmemcg

In reply to Florian Westphal

sashiko says:
does compat_do_replace() bypass memory cgroup accounting?

This code is on the chopping block, but lets fix this up for -stable sake.

Fixes e2c8d550a973 ("netfilter: ebtables: account ebt_table_info to kmemcg")
---
 net/bridge/netfilter/ebtables.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/bridge/netfilter/ebtables.c +2 -2
index 66c407cffa16..7238e48d51a1 100644
@@ -2299,7 +2299,7 @@ static int compat_do_replace(struct net *net, sockptr_t arg, unsigned int len)
 	}
 
 	countersize = COUNTER_OFFSET(tmp.nentries) * nr_cpu_ids;
-	newinfo = vmalloc(sizeof(*newinfo) + countersize);
+	newinfo = __vmalloc(sizeof(*newinfo) + countersize, GFP_KERNEL_ACCOUNT);
 	if (!newinfo)
 		return -ENOMEM;
 
@@ -2308,7 +2308,7 @@ static int compat_do_replace(struct net *net, sockptr_t arg, unsigned int len)
 
 	memset(&state, 0, sizeof(state));
 
-	newinfo->entries = vmalloc(tmp.entries_size);
+	newinfo->entries = __vmalloc(tmp.entries_size, GFP_KERNEL_ACCOUNT);
 	if (!newinfo->entries) {
 		ret = -ENOMEM;
 		goto free_newinfo;
Signature · 1 line
2.55.0
author maintainer
#3 lore raw

PATCH 3/3 netfilter: ebtables: bound num_counters in do_update_counters()

In reply to Florian Westphal

sashiko says:
it appears the exact same
pattern remains unfixed in the sibling function do_update_counters().

Fixes 43ae85af154b ("netfilter: ebtables: bound num_counters like nentries in do_replace()")
---
 net/bridge/netfilter/ebtables.c | 3 +++
 1 file changed, 3 insertions(+)
net/bridge/netfilter/ebtables.c +3 -0
index 7238e48d51a1..80008664ebe5 100644
@@ -1390,6 +1390,9 @@ static int do_update_counters(struct net *net, const char *name,
 	if (num_counters == 0)
 		return -EINVAL;
 
+	if (num_counters >= MAX_EBT_ENTRIES)
+		return -ENOMEM;
+
 	tmp = vmalloc_array(num_counters, sizeof(*tmp));
 	if (!tmp)
 		return -ENOMEM;
Signature · 1 line
2.55.0
author maintainer
#4 lore raw
In reply to Florian Westphal
Quoted 10 lines · Florian Westphal

Three academic bug fixes for ebtables, based on sashiko drive-by reviews.

All of these "bugs" have existed forever, kets treat this as cleanups.

Florian Westphal (3):
netfilter: ebtables: zero chainstack array
netfilter: ebtables: account compat ebt_table_info to kmemcg
netfilter: ebtables: bound num_counters in do_update_counters()

Many more drive-bys here. I don't think this is worth our time.

I propose to axe arptables CONFIG_COMPAT in nf-next now.

Then, axe ebtables-compat next querter and finally rest of xt-32bit compat after that.

All the xt COMPAT flavours are already restricted to the initial namespace.