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] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230731071728.3493794-3-j.granados@samsung.com>
Date:   Mon, 31 Jul 2023 09:17:16 +0200
From:   Joel Granados <joel.granados@...il.com>
To:     mcgrof@...nel.org
Cc:     Catalin Marinas <catalin.marinas@....com>,
        Iurii Zaikin <yzaikin@...gle.com>,
        Jozsef Kadlecsik <kadlec@...filter.org>,
        Sven Schnelle <svens@...ux.ibm.com>,
        Marcelo Ricardo Leitner <marcelo.leitner@...il.com>,
        Steffen Klassert <steffen.klassert@...unet.com>,
        Kees Cook <keescook@...omium.org>,
        "D. Wythe" <alibuda@...ux.alibaba.com>, mptcp@...ts.linux.dev,
        Jakub Kicinski <kuba@...nel.org>,
        Vasily Gorbik <gor@...ux.ibm.com>,
        Paolo Abeni <pabeni@...hat.com>, coreteam@...filter.org,
        Jan Karcher <jaka@...ux.ibm.com>,
        Alexander Aring <alex.aring@...il.com>,
        Will Deacon <will@...nel.org>,
        Stefan Schmidt <stefan@...enfreihafen.org>,
        Matthieu Baerts <matthieu.baerts@...sares.net>,
        bridge@...ts.linux-foundation.org,
        linux-arm-kernel@...ts.infradead.org,
        Joerg Reuter <jreuter@...na.de>, Julian Anastasov <ja@....bg>,
        David Ahern <dsahern@...nel.org>,
        netfilter-devel@...r.kernel.org, Wen Gu <guwen@...ux.alibaba.com>,
        linux-kernel@...r.kernel.org,
        Santosh Shilimkar <santosh.shilimkar@...cle.com>,
        linux-wpan@...r.kernel.org, lvs-devel@...r.kernel.org,
        Karsten Graul <kgraul@...ux.ibm.com>,
        Miquel Raynal <miquel.raynal@...tlin.com>,
        Herbert Xu <herbert@...dor.apana.org.au>,
        linux-sctp@...r.kernel.org, Tony Lu <tonylu@...ux.alibaba.com>,
        Pablo Neira Ayuso <pablo@...filter.org>,
        Ralf Baechle <ralf@...ux-mips.org>,
        Florian Westphal <fw@...len.de>, willy@...radead.org,
        Heiko Carstens <hca@...ux.ibm.com>,
        "David S. Miller" <davem@...emloft.net>,
        linux-rdma@...r.kernel.org, Roopa Prabhu <roopa@...dia.com>,
        Alexander Gordeev <agordeev@...ux.ibm.com>,
        Simon Horman <horms@...ge.net.au>,
        Mat Martineau <martineau@...nel.org>, josh@...htriplett.org,
        Christian Borntraeger <borntraeger@...ux.ibm.com>,
        Eric Dumazet <edumazet@...gle.com>, linux-hams@...r.kernel.org,
        Wenjia Zhang <wenjia@...ux.ibm.com>,
        linux-fsdevel@...r.kernel.org, linux-s390@...r.kernel.org,
        Xin Long <lucien.xin@...il.com>,
        Nikolay Aleksandrov <razor@...ckwall.org>,
        netdev@...r.kernel.org, rds-devel@....oracle.com,
        Joel Granados <j.granados@...sung.com>
Subject: [PATCH v2 02/14] sysctl: Use ctl_table_header in list_for_each_table_entry

We replace the ctl_table with the ctl_table_header pointer in
list_for_each_table_entry which is the macro responsible for traversing
the ctl_table arrays. This is a preparation commit that will make it
easier to add the ctl_table array size (that will be added to
ctl_table_header in subsequent commits) to the already existing loop
logic based on empty ctl_table elements (so called sentinels).

Signed-off-by: Joel Granados <j.granados@...sung.com>
---
 fs/proc/proc_sysctl.c | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
index 94d71446da39..884460b0385b 100644
--- a/fs/proc/proc_sysctl.c
+++ b/fs/proc/proc_sysctl.c
@@ -19,8 +19,8 @@
 #include <linux/kmemleak.h>
 #include "internal.h"
 
-#define list_for_each_table_entry(entry, table) \
-	for ((entry) = (table); (entry)->procname; (entry)++)
+#define list_for_each_table_entry(entry, header) \
+	for ((entry) = (header->ctl_table); (entry)->procname; (entry)++)
 
 static const struct dentry_operations proc_sys_dentry_operations;
 static const struct file_operations proc_sys_file_operations;
@@ -204,7 +204,7 @@ static void init_header(struct ctl_table_header *head,
 	if (node) {
 		struct ctl_table *entry;
 
-		list_for_each_table_entry(entry, table) {
+		list_for_each_table_entry(entry, head) {
 			node->header = head;
 			node++;
 		}
@@ -215,7 +215,7 @@ static void erase_header(struct ctl_table_header *head)
 {
 	struct ctl_table *entry;
 
-	list_for_each_table_entry(entry, head->ctl_table)
+	list_for_each_table_entry(entry, head)
 		erase_entry(head, entry);
 }
 
@@ -242,7 +242,7 @@ static int insert_header(struct ctl_dir *dir, struct ctl_table_header *header)
 	err = insert_links(header);
 	if (err)
 		goto fail_links;
-	list_for_each_table_entry(entry, header->ctl_table) {
+	list_for_each_table_entry(entry, header) {
 		err = insert_entry(header, entry);
 		if (err)
 			goto fail;
@@ -1129,7 +1129,7 @@ static int sysctl_check_table(const char *path, struct ctl_table_header *header)
 {
 	struct ctl_table *entry;
 	int err = 0;
-	list_for_each_table_entry(entry, header->ctl_table) {
+	list_for_each_table_entry(entry, header) {
 		if ((entry->proc_handler == proc_dostring) ||
 		    (entry->proc_handler == proc_dobool) ||
 		    (entry->proc_handler == proc_dointvec) ||
@@ -1169,7 +1169,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table_
 
 	name_bytes = 0;
 	nr_entries = 0;
-	list_for_each_table_entry(entry, head->ctl_table) {
+	list_for_each_table_entry(entry, head) {
 		nr_entries++;
 		name_bytes += strlen(entry->procname) + 1;
 	}
@@ -1188,7 +1188,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table_
 	link_name = (char *)&link_table[nr_entries + 1];
 	link = link_table;
 
-	list_for_each_table_entry(entry, head->ctl_table) {
+	list_for_each_table_entry(entry, head) {
 		int len = strlen(entry->procname) + 1;
 		memcpy(link_name, entry->procname, len);
 		link->procname = link_name;
@@ -1211,7 +1211,7 @@ static bool get_links(struct ctl_dir *dir,
 	struct ctl_table *entry, *link;
 
 	/* Are there links available for every entry in table? */
-	list_for_each_table_entry(entry, header->ctl_table) {
+	list_for_each_table_entry(entry, header) {
 		const char *procname = entry->procname;
 		link = find_entry(&tmp_head, dir, procname, strlen(procname));
 		if (!link)
@@ -1224,7 +1224,7 @@ static bool get_links(struct ctl_dir *dir,
 	}
 
 	/* The checks passed.  Increase the registration count on the links */
-	list_for_each_table_entry(entry, header->ctl_table) {
+	list_for_each_table_entry(entry, header) {
 		const char *procname = entry->procname;
 		link = find_entry(&tmp_head, dir, procname, strlen(procname));
 		tmp_head->nreg++;
@@ -1356,12 +1356,14 @@ struct ctl_table_header *__register_sysctl_table(
 {
 	struct ctl_table_root *root = set->dir.header.root;
 	struct ctl_table_header *header;
+	struct ctl_table_header h_tmp;
 	struct ctl_dir *dir;
 	struct ctl_table *entry;
 	struct ctl_node *node;
 	int nr_entries = 0;
 
-	list_for_each_table_entry(entry, table)
+	h_tmp.ctl_table = table;
+	list_for_each_table_entry(entry, (&h_tmp))
 		nr_entries++;
 
 	header = kzalloc(sizeof(struct ctl_table_header) +
@@ -1471,7 +1473,7 @@ static void put_links(struct ctl_table_header *header)
 	if (IS_ERR(core_parent))
 		return;
 
-	list_for_each_table_entry(entry, header->ctl_table) {
+	list_for_each_table_entry(entry, header) {
 		struct ctl_table_header *link_head;
 		struct ctl_table *link;
 		const char *name = entry->procname;
-- 
2.30.2

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ