Skip to contentSkip to conversation

nf-next: x_tables: Replace kmalloc(s*n) with kmalloc_array(n,s)

PATCH In review Loganaden Velvindron 2 participants 4 messages Aug 10, 2016 – Aug 12, 2016

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

PATCH 1/1 nf-next: x_tables: Replace kmalloc(s*n) with kmalloc_array(n,s)

It is easier to check that the calculation doesn't wrap or return a smaller allocation.

---
 net/netfilter/x_tables.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/x_tables.c +1 -1
index e0aa7c1..c8f20f2 100644
@@ -1513,7 +1513,7 @@ xt_hook_ops_alloc(const struct xt_table *table, nf_hookfn *fn)
 	if (!num_hooks)
 		return ERR_PTR(-EINVAL);
 
-	ops = kmalloc(sizeof(*ops) * num_hooks, GFP_KERNEL);
+	ops = kmalloc_array(num_hooks, sizeof(*ops), GFP_KERNEL);
 	if (ops == NULL)
 		return ERR_PTR(-ENOMEM);
 
Signature · 1 line
2.9.2
#1 lore raw
Quoted 2 lines · Loganaden Velvindron

It is easier to check that the calculation doesn't wrap or return a smaller allocation.

Could you review the netfilter tree in search for similar kmalloc() invocation that can be replaced? I could at least find one more at quick glace.

Thanks.

#2 lore raw
Quoted 9 lines · Pablo Neira Ayuso
Quoted 2 lines · Loganaden Velvindron

It is easier to check that the calculation doesn't wrap or return a smaller allocation.

Could you review the netfilter tree in search for similar kmalloc() invocation that can be replaced? I could at least find one more at quick glace.

Thanks.

Yes. I am currently working on that !

Quoted 4 lines

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw
In reply to Pablo Neira Ayuso
Quoted 9 lines · Pablo Neira Ayuso
Quoted 2 lines · Loganaden Velvindron

It is easier to check that the calculation doesn't wrap or return a smaller allocation.

Could you review the netfilter tree in search for similar kmalloc() invocation that can be replaced? I could at least find one more at quick glace.

Thanks.

I saw quite a few, but many have constants. OK with replacing the ones with constants too ?

Quoted 4 lines

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html