netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] nf-next: x_tables: Replace kmalloc(s*n) with kmalloc_array(n,s)
@ 2016-08-10 14:11 Loganaden Velvindron
  2016-08-11 23:13 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 4+ messages in thread
From: Loganaden Velvindron @ 2016-08-10 14:11 UTC (permalink / raw)
  To: netfilter-devel

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

Signed-off-by: Loganaden Velvindron <logan@hackers.mu>
---
 net/netfilter/x_tables.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/netfilter/x_tables.c b/net/netfilter/x_tables.c
index e0aa7c1..c8f20f2 100644
--- a/net/netfilter/x_tables.c
+++ b/net/netfilter/x_tables.c
@@ -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);
 
-- 
2.9.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] nf-next: x_tables: Replace kmalloc(s*n) with kmalloc_array(n,s)
  2016-08-10 14:11 [PATCH] nf-next: x_tables: Replace kmalloc(s*n) with kmalloc_array(n,s) Loganaden Velvindron
@ 2016-08-11 23:13 ` Pablo Neira Ayuso
  2016-08-12  7:12   ` Loganaden Velvindron
  2016-08-12  7:19   ` Loganaden Velvindron
  0 siblings, 2 replies; 4+ messages in thread
From: Pablo Neira Ayuso @ 2016-08-11 23:13 UTC (permalink / raw)
  To: Loganaden Velvindron; +Cc: netfilter-devel

On Wed, Aug 10, 2016 at 06:11:51PM +0400, Loganaden Velvindron wrote:
> 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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] nf-next: x_tables: Replace kmalloc(s*n) with kmalloc_array(n,s)
  2016-08-11 23:13 ` Pablo Neira Ayuso
@ 2016-08-12  7:12   ` Loganaden Velvindron
  2016-08-12  7:19   ` Loganaden Velvindron
  1 sibling, 0 replies; 4+ messages in thread
From: Loganaden Velvindron @ 2016-08-12  7:12 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter-devel

On Fri, Aug 12, 2016 at 01:13:52AM +0200, Pablo Neira Ayuso wrote:
> On Wed, Aug 10, 2016 at 06:11:51PM +0400, Loganaden Velvindron wrote:
> > 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 !

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] nf-next: x_tables: Replace kmalloc(s*n) with kmalloc_array(n,s)
  2016-08-11 23:13 ` Pablo Neira Ayuso
  2016-08-12  7:12   ` Loganaden Velvindron
@ 2016-08-12  7:19   ` Loganaden Velvindron
  1 sibling, 0 replies; 4+ messages in thread
From: Loganaden Velvindron @ 2016-08-12  7:19 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter-devel

On Fri, Aug 12, 2016 at 01:13:52AM +0200, Pablo Neira Ayuso wrote:
> On Wed, Aug 10, 2016 at 06:11:51PM +0400, Loganaden Velvindron wrote:
> > 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 ?

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-08-12  7:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-10 14:11 [PATCH] nf-next: x_tables: Replace kmalloc(s*n) with kmalloc_array(n,s) Loganaden Velvindron
2016-08-11 23:13 ` Pablo Neira Ayuso
2016-08-12  7:12   ` Loganaden Velvindron
2016-08-12  7:19   ` Loganaden Velvindron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).