All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joel Granados <j.granados@samsung.com>
To: <mcgrof@kernel.org>, Kees Cook <keescook@chromium.org>,
	Iurii Zaikin <yzaikin@google.com>
Cc: Joel Granados <j.granados@samsung.com>,
	<linux-kernel@vger.kernel.org>, <linux-fsdevel@vger.kernel.org>
Subject: [PATCH 01/11] sysctl: Prefer ctl_table_header in proc_sysctl
Date: Wed, 21 Jun 2023 11:09:50 +0200	[thread overview]
Message-ID: <20230621091000.424843-2-j.granados@samsung.com> (raw)
In-Reply-To: <20230621091000.424843-1-j.granados@samsung.com>

This is a preparation commit to use ctl_table_header instead of
ctl_table as the pointer that is passed around in proc_sysctl.c. This is
necessary as the size of the ctl_table array moved from the ctl_table
pointer to the ctl_table_header. The functions changed are
sysctl_check_table, get_links and new_links.

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

diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
index c4ea804d862b..1d9f42840518 100644
--- a/fs/proc/proc_sysctl.c
+++ b/fs/proc/proc_sysctl.c
@@ -1125,11 +1125,11 @@ static int sysctl_check_table_array(const char *path, struct ctl_table *table)
 	return err;
 }
 
-static int sysctl_check_table(const char *path, struct ctl_table *table)
+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, table) {
+	list_for_each_table_entry(entry, header->ctl_table) {
 		if ((entry->proc_handler == proc_dostring) ||
 		    (entry->proc_handler == proc_dobool) ||
 		    (entry->proc_handler == proc_dointvec) ||
@@ -1159,8 +1159,7 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
 	return err;
 }
 
-static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
-	struct ctl_table_root *link_root)
+static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table_header *head)
 {
 	struct ctl_table *link_table, *entry, *link;
 	struct ctl_table_header *links;
@@ -1170,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, table) {
+	list_for_each_table_entry(entry, head->ctl_table) {
 		nr_entries++;
 		name_bytes += strlen(entry->procname) + 1;
 	}
@@ -1189,12 +1188,12 @@ 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, table) {
+	list_for_each_table_entry(entry, head->ctl_table) {
 		int len = strlen(entry->procname) + 1;
 		memcpy(link_name, entry->procname, len);
 		link->procname = link_name;
 		link->mode = S_IFLNK|S_IRWXUGO;
-		link->data = link_root;
+		link->data = head->root;
 		link_name += len;
 		link++;
 	}
@@ -1205,15 +1204,16 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
 }
 
 static bool get_links(struct ctl_dir *dir,
-	struct ctl_table *table, struct ctl_table_root *link_root)
+		      struct ctl_table_header *header,
+		      struct ctl_table_root *link_root)
 {
-	struct ctl_table_header *head;
+	struct ctl_table_header *tmp_head;
 	struct ctl_table *entry, *link;
 
 	/* Are there links available for every entry in table? */
-	list_for_each_table_entry(entry, table) {
+	list_for_each_table_entry(entry, header->ctl_table) {
 		const char *procname = entry->procname;
-		link = find_entry(&head, dir, procname, strlen(procname));
+		link = find_entry(&tmp_head, dir, procname, strlen(procname));
 		if (!link)
 			return false;
 		if (S_ISDIR(link->mode) && S_ISDIR(entry->mode))
@@ -1224,10 +1224,10 @@ static bool get_links(struct ctl_dir *dir,
 	}
 
 	/* The checks passed.  Increase the registration count on the links */
-	list_for_each_table_entry(entry, table) {
+	list_for_each_table_entry(entry, header->ctl_table) {
 		const char *procname = entry->procname;
-		link = find_entry(&head, dir, procname, strlen(procname));
-		head->nreg++;
+		link = find_entry(&tmp_head, dir, procname, strlen(procname));
+		tmp_head->nreg++;
 	}
 	return true;
 }
@@ -1246,13 +1246,13 @@ static int insert_links(struct ctl_table_header *head)
 	if (IS_ERR(core_parent))
 		return 0;
 
-	if (get_links(core_parent, head->ctl_table, head->root))
+	if (get_links(core_parent, head, head->root))
 		return 0;
 
 	core_parent->header.nreg++;
 	spin_unlock(&sysctl_lock);
 
-	links = new_links(core_parent, head->ctl_table, head->root);
+	links = new_links(core_parent, head);
 
 	spin_lock(&sysctl_lock);
 	err = -ENOMEM;
@@ -1260,7 +1260,7 @@ static int insert_links(struct ctl_table_header *head)
 		goto out;
 
 	err = 0;
-	if (get_links(core_parent, head->ctl_table, head->root)) {
+	if (get_links(core_parent, head, head->root)) {
 		kfree(links);
 		goto out;
 	}
@@ -1371,7 +1371,7 @@ struct ctl_table_header *__register_sysctl_table(
 
 	node = (struct ctl_node *)(header + 1);
 	init_header(header, root, set, node, table);
-	if (sysctl_check_table(path, table))
+	if (sysctl_check_table(path, header))
 		goto fail;
 
 	spin_lock(&sysctl_lock);
-- 
2.30.2


  parent reply	other threads:[~2023-06-21  9:10 UTC|newest]

Thread overview: 113+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20230621091002eucas1p28cbe3260b7d4c2a086f0b5ac79a7f038@eucas1p2.samsung.com>
2023-06-21  9:09 ` [PATCH 00/11] Remove the end element in sysctl table arrays Joel Granados
     [not found]   ` <CGME20230621091004eucas1p2e53ad3001cdaef7b3c44555653bbec37@eucas1p2.samsung.com>
2023-06-21  9:09     ` Joel Granados [this message]
     [not found]   ` <CGME20230621091007eucas1p2271595a5889075994e8dceb0c06ae7cc@eucas1p2.samsung.com>
2023-06-21  9:09     ` [PATCH 02/11] sysctl: Use the ctl header in list ctl_table macro Joel Granados
     [not found]   ` <CGME20230621091009eucas1p1e4fa56beb44e49e4d1160bfac6eb59ec@eucas1p1.samsung.com>
2023-06-21  9:09     ` [PATCH 03/11] sysctl: Add ctl_table_size to ctl_table_header Joel Granados
     [not found]   ` <CGME20230621091011eucas1p2116c1fb8f406bec7ca9a831f66955724@eucas1p2.samsung.com>
2023-06-21  9:09     ` [PATCH 04/11] sysctl: Add size argument to init_header Joel Granados
     [not found]   ` <CGME20230621091014eucas1p1a30430568d0f7fec5ccbed31cab73aa0@eucas1p1.samsung.com>
2023-06-21  9:09     ` [PATCH 05/11] sysctl: Add a size arg to __register_sysctl_table Joel Granados
2023-06-21 20:53       ` Jakub Kicinski
2023-06-22 14:09         ` Joel Granados
     [not found]   ` <CGME20230621091022eucas1p1c097da50842b23e902e1a674e117e1aa@eucas1p1.samsung.com>
2023-06-21  9:09     ` [PATCH 06/11] sysctl: Add size to register_net_sysctl function Joel Granados
2023-06-21  9:09       ` [Bridge] " Joel Granados
2023-06-21  9:09       ` Joel Granados
2023-06-21  9:09       ` Joel Granados
2023-06-21  9:47       ` Dan Carpenter
2023-06-21  9:47         ` [Bridge] " Dan Carpenter
2023-06-21  9:47         ` Dan Carpenter
2023-06-21  9:47         ` Dan Carpenter
2023-06-21 10:23         ` Dan Carpenter
2023-06-21 10:23           ` [Bridge] " Dan Carpenter
2023-06-21 10:23           ` Dan Carpenter
2023-06-21 10:23           ` Dan Carpenter
2023-06-21 12:03           ` Joel Granados
2023-06-21 12:03             ` [Bridge] " Joel Granados
2023-06-21 12:03             ` Joel Granados
2023-06-21 12:03             ` Joel Granados
2023-06-23 14:21           ` Joel Granados
2023-06-23 14:21             ` [Bridge] " Joel Granados
2023-06-23 14:21             ` Joel Granados
2023-06-23 14:21             ` Joel Granados
2023-06-21 10:49         ` Dan Carpenter
2023-06-21 10:49           ` [Bridge] " Dan Carpenter
2023-06-21 10:49           ` Dan Carpenter
2023-06-21 10:49           ` Dan Carpenter
2023-06-21 11:49           ` Joel Granados
2023-06-21 11:49             ` [Bridge] " Joel Granados
2023-06-21 11:49             ` Joel Granados
2023-06-21 11:49             ` Joel Granados
2023-06-21 11:36         ` Joel Granados
2023-06-21 11:36           ` [Bridge] " Joel Granados
2023-06-21 11:36           ` Joel Granados
2023-06-21 11:36           ` Joel Granados
     [not found]   ` <CGME20230621091029eucas1p2f9fd694dae3dfbdfffd25dccf4fcb568@eucas1p2.samsung.com>
2023-06-21  9:09     ` [PATCH 07/11] sysctl: Add size to register_sysctl Joel Granados
2023-06-21  9:09       ` [Intel-gfx] " Joel Granados
2023-06-21  9:09       ` Joel Granados
2023-06-21  9:09       ` Joel Granados
2023-06-21  9:09       ` [Ocfs2-devel] " Joel Granados via Ocfs2-devel
     [not found]   ` <CGME20230621091037eucas1p188e11d8064526a5a0549217d5a419647@eucas1p1.samsung.com>
2023-06-21  9:09     ` [PATCH 08/11] sysctl: Add size to register_sysctl_init Joel Granados
2023-06-21  9:09       ` Joel Granados
2023-06-21  9:56       ` Jiri Slaby
2023-06-21  9:56         ` Jiri Slaby
2023-06-21 13:11         ` Joel Granados
2023-06-21 13:11           ` Joel Granados
2023-06-22  4:25           ` Jiri Slaby
2023-06-22  4:25             ` Jiri Slaby
2023-06-22 13:59             ` Joel Granados
2023-06-22 13:59               ` Joel Granados
2023-06-21 10:47       ` Greg Kroah-Hartman
2023-06-21 10:47         ` Greg Kroah-Hartman
2023-06-21 13:15         ` Joel Granados
2023-06-21 13:15           ` Joel Granados
2023-06-22  4:21           ` Jiri Slaby
2023-06-22  4:21             ` Jiri Slaby
2023-06-22 14:00             ` Joel Granados
2023-06-22 14:00               ` Joel Granados
2023-06-23 15:20               ` Petr Mladek
2023-06-23 15:20                 ` Petr Mladek
2023-06-21 11:36       ` Petr Mladek
2023-06-21 11:36         ` Petr Mladek
2023-06-21 15:30         ` Joel Granados
2023-06-21 15:30           ` Joel Granados
     [not found]   ` <CGME20230621094824eucas1p154c97eead5f2de6bceca6359304b775c@eucas1p1.samsung.com>
2023-06-21  9:48     ` [PATCH 09/11] sysctl: Remove the end element in sysctl table arrays Joel Granados
2023-06-21  9:48       ` [Bridge] " Joel Granados
2023-06-21  9:48       ` Joel Granados
2023-06-21  9:48       ` Joel Granados
2023-06-21  9:48       ` [Intel-gfx] " Joel Granados
2023-06-21  9:48       ` Joel Granados
2023-06-21  9:48       ` Joel Granados
2023-06-21  9:48       ` [Ocfs2-devel] " Joel Granados via Ocfs2-devel
2023-06-21  9:48       ` Joel Granados
     [not found]       ` <CGME20230621094825eucas1p2d37372e5bd2377bfe953e6e4f7ff0363@eucas1p2.samsung.com>
2023-06-21  9:48         ` [PATCH 10/11] sysctl: Remove nr_entries from new_links Joel Granados
     [not found]       ` <CGME20230621094828eucas1p22b0b45adc25f881fe00a20d96d495d95@eucas1p2.samsung.com>
2023-06-21  9:48         ` [PATCH 11/11] sysctl: rm "child" from __register_sysctl_table doc Joel Granados
2023-06-21 11:16       ` [PATCH 09/11] sysctl: Remove the end element in sysctl table arrays Jani Nikula
2023-06-21 11:16         ` [Bridge] " Jani Nikula
2023-06-21 11:16         ` Jani Nikula
2023-06-21 11:16         ` Jani Nikula
2023-06-21 11:16         ` [Intel-gfx] " Jani Nikula
2023-06-21 11:16         ` Jani Nikula
2023-06-21 11:16         ` Jani Nikula
2023-06-21 11:16         ` [Ocfs2-devel] " Jani Nikula via Ocfs2-devel
2023-06-21 13:06         ` Joel Granados
2023-06-21 13:06           ` [Bridge] " Joel Granados
2023-06-21 13:06           ` Joel Granados
2023-06-21 13:06           ` [Intel-gfx] " Joel Granados
2023-06-21 13:06           ` Joel Granados
2023-06-21 13:06           ` Joel Granados
2023-06-21 13:06           ` [Ocfs2-devel] " Joel Granados via Ocfs2-devel
2023-06-21 13:15           ` Jani Nikula
2023-06-21 13:15             ` [Bridge] " Jani Nikula
2023-06-21 13:15             ` Jani Nikula
2023-06-21 13:15             ` [Intel-gfx] " Jani Nikula
2023-06-21 13:15             ` Jani Nikula
2023-06-21 13:15             ` Jani Nikula
2023-06-21 13:15             ` [Ocfs2-devel] " Jani Nikula via Ocfs2-devel
2023-06-21 13:43             ` Joel Granados
2023-06-21 13:43               ` [Bridge] " Joel Granados
2023-06-21 13:43               ` Joel Granados
2023-06-21 13:43               ` [Intel-gfx] " Joel Granados
2023-06-21 13:43               ` Joel Granados
2023-06-21 13:43               ` Joel Granados
2023-06-21 13:43               ` [Ocfs2-devel] " Joel Granados via Ocfs2-devel
2023-06-21 10:46   ` [PATCH 00/11] " Greg KH
2023-06-21 12:38     ` Joel Granados
2023-06-21 13:10       ` Greg KH
2023-06-21 14:13         ` Joel Granados

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230621091000.424843-2-j.granados@samsung.com \
    --to=j.granados@samsung.com \
    --cc=keescook@chromium.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=yzaikin@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.