diff mbox series

[-next,4/5] netfilter: iptables: Use kmemdup_array() instead of kmemdup() for multiple allocation

Message ID 20240828071004.1245213-5-ruanjinjie@huawei.com (mailing list archive)
State Awaiting Upstream
Delegated to: Netdev Maintainers
Headers show
Series net: Use kmemdup_array() instead of kmemdup() for multiple allocation | expand

Checks

Context Check Description
netdev/series_format warning Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 16 this patch: 16
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 9 of 9 maintainers
netdev/build_clang success Errors and warnings before: 16 this patch: 16
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 23 this patch: 23
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest fail net-next-2024-08-28--12-00 (tests: 712)

Commit Message

Jinjie Ruan Aug. 28, 2024, 7:10 a.m. UTC
Let the kmemdup_array() take care about multiplication and possible
overflows.

Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
 net/ipv4/netfilter/ip_tables.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Pablo Neira Ayuso Aug. 28, 2024, 8:42 a.m. UTC | #1
On Wed, Aug 28, 2024 at 03:10:03PM +0800, Jinjie Ruan wrote:
> Let the kmemdup_array() take care about multiplication and possible
> overflows.

No patch for net/ipv6/netfilter/ip6_tables.c?

We have yet another code copy & paste there.

BTW, could you collapse all these patches for netfilter in one single
patch?

Thanks.

> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
> ---
>  net/ipv4/netfilter/ip_tables.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
> index fe89a056eb06..096bfef472b1 100644
> --- a/net/ipv4/netfilter/ip_tables.c
> +++ b/net/ipv4/netfilter/ip_tables.c
> @@ -1767,7 +1767,7 @@ int ipt_register_table(struct net *net, const struct xt_table *table,
>  		goto out_free;
>  	}
>  
> -	ops = kmemdup(template_ops, sizeof(*ops) * num_ops, GFP_KERNEL);
> +	ops = kmemdup_array(template_ops, num_ops, sizeof(*ops), GFP_KERNEL);
>  	if (!ops) {
>  		ret = -ENOMEM;
>  		goto out_free;
> -- 
> 2.34.1
> 
>
Pablo Neira Ayuso Aug. 28, 2024, 2:51 p.m. UTC | #2
On Wed, Aug 28, 2024 at 10:42:12AM +0200, Pablo Neira Ayuso wrote:
> On Wed, Aug 28, 2024 at 03:10:03PM +0800, Jinjie Ruan wrote:
> > Let the kmemdup_array() take care about multiplication and possible
> > overflows.
> 
> No patch for net/ipv6/netfilter/ip6_tables.c?
> 
> We have yet another code copy & paste there.
> 
> BTW, could you collapse all these patches for netfilter in one single
> patch?

BTW, someone else seems to have made the same patch:

https://patchwork.ozlabs.org/project/netfilter-devel/patch/20240826034136.1791485-1-yanzhen@vivo.com/

it is already sitting in the queue.
diff mbox series

Patch

diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
index fe89a056eb06..096bfef472b1 100644
--- a/net/ipv4/netfilter/ip_tables.c
+++ b/net/ipv4/netfilter/ip_tables.c
@@ -1767,7 +1767,7 @@  int ipt_register_table(struct net *net, const struct xt_table *table,
 		goto out_free;
 	}
 
-	ops = kmemdup(template_ops, sizeof(*ops) * num_ops, GFP_KERNEL);
+	ops = kmemdup_array(template_ops, num_ops, sizeof(*ops), GFP_KERNEL);
 	if (!ops) {
 		ret = -ENOMEM;
 		goto out_free;