[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230731071728.3493794-9-j.granados@samsung.com>
Date: Mon, 31 Jul 2023 09:17:22 +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>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Subject: [PATCH v2 08/14] sysctl: Add size to register_net_sysctl function
This commit adds size to the register_net_sysctl indirection function to
facilitate the removal of the sentinel elements (last empty markers)
from the ctl_table arrays. Though we don't actually remove any sentinels
in this commit, register_net_sysctl* now has the capability of
forwarding table_size for when that happens.
We create a new function register_net_sysctl_sz with an extra size
argument. A macro replaces the existing register_net_sysctl. The size in
the macro is SIZE_MAX instead of ARRAY_SIZE to avoid compilation errors
while we systematically migrate to register_net_sysctl_sz. Will change
to ARRAY_SIZE in subsequent commits.
Care is taken to add table_size to the stopping criteria in such a way
that when we remove the empty sentinel element, it will continue
stopping in the last element of the ctl_table array.
Signed-off-by: Joel Granados <j.granados@...sung.com>
Suggested-by: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
---
include/net/net_namespace.h | 10 ++++++----
net/sysctl_net.c | 22 +++++++++++++---------
2 files changed, 19 insertions(+), 13 deletions(-)
diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
index 78beaa765c73..e4e5fe75a281 100644
--- a/include/net/net_namespace.h
+++ b/include/net/net_namespace.h
@@ -469,15 +469,17 @@ void unregister_pernet_device(struct pernet_operations *);
struct ctl_table;
+#define register_net_sysctl(net, path, table) \
+ register_net_sysctl_sz(net, path, table, SIZE_MAX)
#ifdef CONFIG_SYSCTL
int net_sysctl_init(void);
-struct ctl_table_header *register_net_sysctl(struct net *net, const char *path,
- struct ctl_table *table);
+struct ctl_table_header *register_net_sysctl_sz(struct net *net, const char *path,
+ struct ctl_table *table, size_t table_size);
void unregister_net_sysctl_table(struct ctl_table_header *header);
#else
static inline int net_sysctl_init(void) { return 0; }
-static inline struct ctl_table_header *register_net_sysctl(struct net *net,
- const char *path, struct ctl_table *table)
+static inline struct ctl_table_header *register_net_sysctl_sz(struct net *net,
+ const char *path, struct ctl_table *table, size_t table_size)
{
return NULL;
}
diff --git a/net/sysctl_net.c b/net/sysctl_net.c
index d9cbbb51b143..051ed5f6fc93 100644
--- a/net/sysctl_net.c
+++ b/net/sysctl_net.c
@@ -122,12 +122,13 @@ __init int net_sysctl_init(void)
* allocated.
*/
static void ensure_safe_net_sysctl(struct net *net, const char *path,
- struct ctl_table *table)
+ struct ctl_table *table, size_t table_size)
{
struct ctl_table *ent;
pr_debug("Registering net sysctl (net %p): %s\n", net, path);
- for (ent = table; ent->procname; ent++) {
+ ent = table;
+ for (size_t i = 0; i < table_size && ent->procname; ent++, i++) {
unsigned long addr;
const char *where;
@@ -160,21 +161,24 @@ static void ensure_safe_net_sysctl(struct net *net, const char *path,
}
}
-struct ctl_table_header *register_net_sysctl(struct net *net,
- const char *path, struct ctl_table *table)
+struct ctl_table_header *register_net_sysctl_sz(struct net *net,
+ const char *path,
+ struct ctl_table *table,
+ size_t table_size)
{
- int count = 0;
+ int count;
struct ctl_table *entry;
if (!net_eq(net, &init_net))
- ensure_safe_net_sysctl(net, path, table);
+ ensure_safe_net_sysctl(net, path, table, table_size);
- for (entry = table; entry->procname; entry++)
- count++;
+ entry = table;
+ for (count = 0 ; count < table_size && entry->procname; entry++, count++)
+ ;
return __register_sysctl_table(&net->sysctls, path, table, count);
}
-EXPORT_SYMBOL_GPL(register_net_sysctl);
+EXPORT_SYMBOL_GPL(register_net_sysctl_sz);
void unregister_net_sysctl_table(struct ctl_table_header *header)
{
--
2.30.2
Powered by blists - more mailing lists