lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <9c2f78e4-6bf3-9eb1-9dc2-67371a6d68e1@gmail.com>
Date:   Fri, 8 Jul 2022 18:10:57 +0200
From:   Eric Dumazet <eric.dumazet@...il.com>
To:     Kuniyuki Iwashima <kuniyu@...zon.com>,
        "David S. Miller" <davem@...emloft.net>,
        Eric Dumazet <edumazet@...gle.com>,
        Jakub Kicinski <kuba@...nel.org>,
        Paolo Abeni <pabeni@...hat.com>
Cc:     "Eric W. Biederman" <ebiederm@...ssion.com>,
        Pavel Emelyanov <xemul@...nvz.org>,
        Herbert Xu <herbert@...dor.apana.org.au>,
        Kuniyuki Iwashima <kuni1840@...il.com>, netdev@...r.kernel.org
Subject: Re: [PATCH v3 net] af_unix: Do not call kmemdup() for init_net's
 sysctl table.


On 6/28/22 01:36, Kuniyuki Iwashima wrote:
> While setting up init_net's sysctl table, we need not duplicate the
> global table and can use it directly as ipv4_sysctl_init_net() does.
>
> Unlike IPv4, AF_UNIX does not have a huge sysctl table for now, so it
> cannot be a problem, but this patch makes code consistent.
>
> Fixes: 1597fbc0faf8 ("[UNIX]: Make the unix sysctl tables per-namespace")
> Acked-by: Eric W. Biederman <ebiederm@...ssion.com>
> Signed-off-by: Kuniyuki Iwashima <kuniyu@...zon.com>
> ---
> v3:
>    * Update changelog
>    * Fix a bug when we unload unix.ko
>
> v2: https://lore.kernel.org/all/20220626082331.36119-1-kuniyu@amazon.com/
>    * Fix NULL comparison style by checkpatch.pl
>
> v1: https://lore.kernel.org/all/20220626074454.28944-1-kuniyu@amazon.com/
> ---
>   net/unix/sysctl_net_unix.c | 19 +++++++++++++------
>   1 file changed, 13 insertions(+), 6 deletions(-)
>
> diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
> index 01d44e2598e2..3f1fdffd6092 100644
> --- a/net/unix/sysctl_net_unix.c
> +++ b/net/unix/sysctl_net_unix.c
> @@ -26,11 +26,16 @@ int __net_init unix_sysctl_register(struct net *net)
>   {
>   	struct ctl_table *table;
>   
> -	table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
> -	if (table == NULL)
> -		goto err_alloc;
> +	if (net_eq(net, &init_net)) {
> +		table = unix_table;
> +	} else {
> +		table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
> +		if (!table)
> +			goto err_alloc;
> +
> +		table[0].data = &net->unx.sysctl_max_dgram_qlen;
> +	}
>   
> -	table[0].data = &net->unx.sysctl_max_dgram_qlen;
>   	net->unx.ctl = register_net_sysctl(net, "net/unix", table);
>   	if (net->unx.ctl == NULL)
>   		goto err_reg;
> @@ -38,7 +43,8 @@ int __net_init unix_sysctl_register(struct net *net)
>   	return 0;
>   
>   err_reg:
> -	kfree(table);
> +	if (net_eq(net, &init_net))
> +		kfree(table);

Inverted test, I guess :/

I will send a fix.


>   err_alloc:
>   	return -ENOMEM;
>   }
> @@ -49,5 +55,6 @@ void unix_sysctl_unregister(struct net *net)
>   
>   	table = net->unx.ctl->ctl_table_arg;
>   	unregister_net_sysctl_table(net->unx.ctl);
> -	kfree(table);
> +	if (!net_eq(net, &init_net))
> +		kfree(table);
>   }

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ