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-next>] [day] [month] [year] [list]
Message-ID: <20210106204014.34730-1-alobakin@pm.me>
Date:   Wed, 06 Jan 2021 20:40:28 +0000
From:   Alexander Lobakin <alobakin@...me>
To:     "David S. Miller" <davem@...emloft.net>,
        Jakub Kicinski <kuba@...nel.org>
Cc:     Alexander Lobakin <alobakin@...me>, netdev@...r.kernel.org,
        linux-kernel@...r.kernel.org
Subject: [PATCH net-next] net: sysctl: cleanup net_sysctl_init()

'net_header' is not used outside of this function, so can be moved
from BSS onto the stack.
Declarations of one-element arrays are discouraged, and there's no
need to store 'empty' in BSS. Simply allocate it from heap at init.

Signed-off-by: Alexander Lobakin <alobakin@...me>
---
 net/sysctl_net.c | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/net/sysctl_net.c b/net/sysctl_net.c
index d14dab8b6774..4cf81800a907 100644
--- a/net/sysctl_net.c
+++ b/net/sysctl_net.c
@@ -92,27 +92,34 @@ static struct pernet_operations sysctl_pernet_ops = {
 	.exit = sysctl_net_exit,
 };
 
-static struct ctl_table_header *net_header;
 __init int net_sysctl_init(void)
 {
-	static struct ctl_table empty[1];
+	struct ctl_table_header *net_header;
+	struct ctl_table *empty;
 	int ret = -ENOMEM;
+
 	/* Avoid limitations in the sysctl implementation by
 	 * registering "/proc/sys/net" as an empty directory not in a
 	 * network namespace.
 	 */
+
+	empty = kzalloc(sizeof(*empty), GFP_KERNEL);
+	if (!empty)
+		return ret;
+
 	net_header = register_sysctl("net", empty);
 	if (!net_header)
-		goto out;
+		goto err_free;
+
 	ret = register_pernet_subsys(&sysctl_pernet_ops);
-	if (ret)
-		goto out1;
-out:
-	return ret;
-out1:
+	if (!ret)
+		return 0;
+
 	unregister_sysctl_table(net_header);
-	net_header = NULL;
-	goto out;
+err_free:
+	kfree(empty);
+
+	return ret;
 }
 
 struct ctl_table_header *register_net_sysctl(struct net *net,
-- 
2.30.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ