[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230726140635.2059334-15-j.granados@samsung.com>
Date: Wed, 26 Jul 2023 16:06:34 +0200
From: Joel Granados <j.granados@...sung.com>
To: mcgrof@...nel.org, Kees Cook <keescook@...omium.org>,
Iurii Zaikin <yzaikin@...gle.com>
Cc: willy@...radead.org, josh@...htriplett.org,
Joel Granados <j.granados@...sung.com>,
linux-kernel@...r.kernel.org, linux-fsdevel@...r.kernel.org
Subject: [PATCH 14/14] sysctl: Use size as stopping criteria for list macro
Add header->ctl_table_size as an additional stopping criteria for the
list_for_each_table_entry macro. In this way it will execute until it
finds an "empty" ->procname or until the size runs out. Therefore if a
ctl_table array with a sentinel is passed its size will be too big (by
one element) but it will stop on the sentinel. On the other hand, if the
ctl_table array without a sentinel is passed its size will be just write
and there will be no need for a sentinel.
Signed-off-by: Joel Granados <j.granados@...sung.com>
---
fs/proc/proc_sysctl.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
index 6c0721cd35f3..3eea34d98d54 100644
--- a/fs/proc/proc_sysctl.c
+++ b/fs/proc/proc_sysctl.c
@@ -19,8 +19,9 @@
#include <linux/kmemleak.h>
#include "internal.h"
-#define list_for_each_table_entry(entry, header) \
- for ((entry) = (header->ctl_table); (entry)->procname; (entry)++)
+#define list_for_each_table_entry(entry, header) \
+ entry = header->ctl_table; \
+ for (size_t i = 0 ; i < header->ctl_table_size && entry->procname; ++i, entry++)
static const struct dentry_operations proc_sys_dentry_operations;
static const struct file_operations proc_sys_file_operations;
--
2.30.2
Powered by blists - more mailing lists