From: Joel Granados <joel.granados@kernel.org>
To: Kees Cook <kees@kernel.org>, Alexey Gladkov <legion@kernel.org>,
David Laight <david.laight.linux@gmail.com>,
Wen Yang <wen.yang@linux.dev>
Cc: Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
Linus Torvalds <torvalds@linux-foundation.org>,
linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
netdev@vger.kernel.org, Joel Granados <joel.granados@kernel.org>
Subject: [PATCH RFC 5/9] net: sysctl: Add sysctl registration to networking
Date: Thu, 26 Nov 2026 12:47:45 +0100 [thread overview]
Message-ID: <20261126-lklm-sysctl-ctx-flatarray-v1-5-d7fc9cc9b03e@kernel.org> (raw)
In-Reply-To: <20261126-lklm-sysctl-ctx-flatarray-v1-0-d7fc9cc9b03e@kernel.org>
Add the per-netns entry point for template registration. It takes the
shared template and the caller's overlay and registers in the
namespace's set through __register_sysctl_table_tmpl(). Run
ensure_safe_net_sysctl() on the overlay for namespaces other than
init_net.
Signed-off-by: Joel Granados <joel.granados@kernel.org>
---
include/net/net_namespace.h | 14 ++++++++++++++
net/sysctl_net.c | 25 +++++++++++++++++++++++++
2 files changed, 39 insertions(+)
diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
index c29a22ca178fa678c0468247b9f85f53eec86184..ecec120de3081d7e8f5c13b72ca98dc647704139 100644
--- a/include/net/net_namespace.h
+++ b/include/net/net_namespace.h
@@ -527,11 +527,19 @@ struct ctl_table;
#define register_net_sysctl(net, path, table) \
register_net_sysctl_sz(net, path, table, ARRAY_SIZE(table))
+#define register_net_sysctl_tmpl(net, path, tmpl, overlay) \
+ register_net_sysctl_tmpl_sz(net, path, CTL_TABLE_TMPL(tmpl), \
+ overlay, ARRAY_SIZE(tmpl))
#ifdef CONFIG_SYSCTL
int net_sysctl_init(void);
struct ctl_table_header *register_net_sysctl_sz(struct net *net, const char *path,
const struct ctl_table *table,
size_t table_size);
+struct ctl_table_header *register_net_sysctl_tmpl_sz(struct net *net,
+ const char *path,
+ const struct ctl_table_tmpl *tmpl,
+ const struct ctl_table *overlay,
+ size_t table_size);
void unregister_net_sysctl_table(struct ctl_table_header *header);
#else
static inline int net_sysctl_init(void) { return 0; }
@@ -540,6 +548,12 @@ static inline struct ctl_table_header *register_net_sysctl_sz(struct net *net,
{
return NULL;
}
+static inline struct ctl_table_header *register_net_sysctl_tmpl_sz(
+ struct net *net, const char *path, const struct ctl_table_tmpl *tmpl,
+ const struct ctl_table *overlay, size_t table_size)
+{
+ return NULL;
+}
static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
{
}
diff --git a/net/sysctl_net.c b/net/sysctl_net.c
index e190a639eef2f6929c4aed85ad625aaf8a6ebd6a..c6eae05dedaecc3bdce402741140d8690d3c15ea 100644
--- a/net/sysctl_net.c
+++ b/net/sysctl_net.c
@@ -173,6 +173,31 @@ struct ctl_table_header *register_net_sysctl_sz(struct net *net,
}
EXPORT_SYMBOL_GPL(register_net_sysctl_sz);
+/**
+ * register_net_sysctl_tmpl_sz - register a shared template for one netns
+ * @net: the network namespace
+ * @path: path of the directory under /proc/sys
+ * @tmpl: the template every namespace shares, see register_sysctl_tmpl_sz()
+ * @overlay: copy of @tmpl holding values for @net; this ptr is not kept!
+ * @table_size: number of entries in @tmpl and @overlay
+ *
+ * The safety check runs on @overlay, since that is what @net will see
+ */
+struct ctl_table_header *register_net_sysctl_tmpl_sz(struct net *net,
+ const char *path,
+ const struct ctl_table_tmpl *tmpl,
+ const struct ctl_table *overlay,
+ size_t table_size)
+{
+ if (!net_eq(net, &init_net))
+ if (ensure_safe_net_sysctl(net, path, overlay, table_size))
+ return NULL;
+
+ return __register_sysctl_table_tmpl(&net->sysctls, path, tmpl, overlay,
+ table_size);
+}
+EXPORT_SYMBOL_GPL(register_net_sysctl_tmpl_sz);
+
void unregister_net_sysctl_table(struct ctl_table_header *header)
{
unregister_sysctl_table(header);
--
2.50.1
next prev parent reply other threads:[~2026-11-26 11:48 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 11:47 [PATCH RFC 0/9] sysctl: Replace ARRAY kmemdup with overlay mechanism for NS registration Joel Granados
2026-11-26 11:47 ` [PATCH RFC 1/9] sysctl: Add struct ctl_table_tmpl as a distinct template type Joel Granados
2026-11-26 11:47 ` [PATCH RFC 2/9] sysctl: Add flags to struct ctl_table Joel Granados
2026-11-26 11:47 ` [PATCH RFC 3/9] sysctl: Add overlay mechanism for flagged ctl_table members Joel Granados
2026-11-26 11:47 ` [PATCH RFC 4/9] sysctl: Add sysctl template registration Joel Granados
2026-11-26 11:47 ` Joel Granados [this message]
2026-11-26 11:47 ` [PATCH RFC 6/9] ipv4: Register ipv4_net_table as a template Joel Granados
2026-11-26 11:47 ` [PATCH RFC 7/9] ipc: Register ipc_sysctls " Joel Granados
2026-11-26 11:47 ` [PATCH RFC 8/9] ipc: Register mq_sysctls " Joel Granados
2026-11-26 11:47 ` [PATCH RFC 9/9] ucount: Register user_table " 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=20261126-lklm-sysctl-ctx-flatarray-v1-5-d7fc9cc9b03e@kernel.org \
--to=joel.granados@kernel.org \
--cc=david.laight.linux@gmail.com \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=kees@kernel.org \
--cc=kuba@kernel.org \
--cc=legion@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=torvalds@linux-foundation.org \
--cc=wen.yang@linux.dev \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®