From: Alexey Gladkov <legion@kernel.org>
To: Linus Torvalds <torvalds@linux-foundation.org>,
"Eric W . Biederman" <ebiederm@xmission.com>,
Kees Cook <kees@kernel.org>,
Joel Granados <joel.granados@kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>, linux-fsdevel@vger.kernel.org
Subject: [RFC PATCH v1 09/30] sysctl: net: use sysctl_field in xfrm sysctls
Date: Wed, 26 Aug 2026 21:42:13 +0200 [thread overview]
Message-ID: <accaf54c772bc10dc44e2716047ecb74d29ba95d.1787771905.git.legion@kernel.org> (raw)
In-Reply-To: <cover.1787771905.git.legion@kernel.org>
The xfrm sysctl table is cloned for each network namespace only to
replace data pointers with per-net storage. The descriptors are
otherwise static, while unprivileged network namespaces still register
an empty table to preserve the existing visibility rule.
Use sysctl_field accessors to derive the per-net storage from the
registration context instead. This keeps the xfrm descriptors const and
removes the per-net ctl_table allocation and free path without changing
which sysctls are exposed.
Signed-off-by: Alexey Gladkov <legion@kernel.org>
---
net/xfrm/xfrm_sysctl.c | 77 ++++++++++++++++--------------------------
1 file changed, 30 insertions(+), 47 deletions(-)
diff --git a/net/xfrm/xfrm_sysctl.c b/net/xfrm/xfrm_sysctl.c
index ca003e8a0376..1097dd4dc0dc 100644
--- a/net/xfrm/xfrm_sysctl.c
+++ b/net/xfrm/xfrm_sysctl.c
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: GPL-2.0
#include <linux/sysctl.h>
-#include <linux/slab.h>
#include <net/net_namespace.h>
#include <net/xfrm.h>
@@ -13,71 +12,55 @@ static void __net_init __xfrm_sysctl_init(struct net *net)
}
#ifdef CONFIG_SYSCTL
-static struct ctl_table xfrm_table[] = {
- {
- .procname = "xfrm_aevent_etime",
- .maxlen = sizeof(u32),
- .mode = 0644,
- .proc_handler = proc_douintvec
- },
- {
- .procname = "xfrm_aevent_rseqth",
- .maxlen = sizeof(u32),
- .mode = 0644,
- .proc_handler = proc_douintvec
- },
- {
- .procname = "xfrm_larval_drop",
- .maxlen = sizeof(int),
- .mode = 0644,
- .proc_handler = proc_dointvec
- },
- {
- .procname = "xfrm_acq_expires",
- .maxlen = sizeof(int),
- .mode = 0644,
- .proc_handler = proc_dointvec
- },
+#define XFRM_UINT_DATA(name) \
+static unsigned int *xfrm_ ## name ## _data(const struct sysctl_context *ctx) \
+{ \
+ return &ctx->ns.net_ns->xfrm.name; \
+}
+
+#define XFRM_INT_DATA(name) \
+static int *xfrm_ ## name ## _data(const struct sysctl_context *ctx) \
+{ \
+ return &ctx->ns.net_ns->xfrm.name; \
+}
+
+XFRM_UINT_DATA(sysctl_aevent_etime)
+XFRM_UINT_DATA(sysctl_aevent_rseqth)
+XFRM_INT_DATA(sysctl_larval_drop)
+XFRM_INT_DATA(sysctl_acq_expires)
+
+static const struct sysctl_field xfrm_table[] = {
+ SYSCTL_FIELD_UINT("xfrm_aevent_etime", 0644, xfrm_sysctl_aevent_etime_data),
+ SYSCTL_FIELD_UINT("xfrm_aevent_rseqth", 0644, xfrm_sysctl_aevent_rseqth_data),
+ SYSCTL_FIELD_INT("xfrm_larval_drop", 0644, xfrm_sysctl_larval_drop_data),
+ SYSCTL_FIELD_INT("xfrm_acq_expires", 0644, xfrm_sysctl_acq_expires_data),
};
int __net_init xfrm_sysctl_init(struct net *net)
{
- struct ctl_table *table;
+ struct sysctl_context ctx = {
+ .ns.net_ns = net,
+ };
size_t table_size = ARRAY_SIZE(xfrm_table);
__xfrm_sysctl_init(net);
- table = kmemdup(xfrm_table, sizeof(xfrm_table), GFP_KERNEL);
- if (!table)
- goto out_kmemdup;
- table[0].data = &net->xfrm.sysctl_aevent_etime;
- table[1].data = &net->xfrm.sysctl_aevent_rseqth;
- table[2].data = &net->xfrm.sysctl_larval_drop;
- table[3].data = &net->xfrm.sysctl_acq_expires;
-
/* Don't export sysctls to unprivileged users */
if (net->user_ns != &init_user_ns)
table_size = 0;
- net->xfrm.sysctl_hdr = register_net_sysctl_sz(net, "net/core", table,
- table_size);
+ net->xfrm.sysctl_hdr = __register_sysctl_fields(&net->sysctls, "net/core",
+ xfrm_table, table_size,
+ &ctx, sizeof(ctx));
if (!net->xfrm.sysctl_hdr)
- goto out_register;
- return 0;
+ return -ENOMEM;
-out_register:
- kfree(table);
-out_kmemdup:
- return -ENOMEM;
+ return 0;
}
void __net_exit xfrm_sysctl_fini(struct net *net)
{
- const struct ctl_table *table;
-
- table = net->xfrm.sysctl_hdr->ctl_table_arg;
unregister_net_sysctl_table(net->xfrm.sysctl_hdr);
- kfree(table);
}
#else
int __net_init xfrm_sysctl_init(struct net *net)
--
2.55.0
next prev parent reply other threads:[~2026-08-26 19:43 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <cover.1787771905.git.legion@kernel.org>
2026-08-26 19:42 ` [RFC PATCH v1 01/30] proc: sysctl: address table entries by index Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 02/30] sysctl: add unsigned int limit constants Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 03/30] sysctl: add typed field descriptors Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 04/30] sysctl: use sysctl_field in ucounts Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 05/30] sysctl: ipc: use sysctl_field in mq_sysctl Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 06/30] sysctl: ipc: use sysctl_field in ipc_sysctl Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 07/30] sysctl: use sysctl_field in pid sysctls Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 08/30] sysctl: net: use sysctl_field in unix sysctl Alexey Gladkov
2026-08-26 19:42 ` Alexey Gladkov [this message]
2026-08-26 19:42 ` [RFC PATCH v1 10/30] sysctl: net: use sysctl_field for simple IPv4 per-net sysctls Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 11/30] sysctl: net: use sysctl_field in IPv4 sysctls Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 12/30] sysctl: net: use sysctl_field in IPv6 xfrm sysctls Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 13/30] sysctl: net: use sysctl_field in IPv6 fragment sysctls Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 14/30] sysctl: net: use sysctl_field in 6lowpan " Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 15/30] sysctl: net: use sysctl_field in vsock sysctls Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 16/30] sysctl: net: use sysctl_field in MPTCP sysctls Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 17/30] sysctl: net: use sysctl_field in SCTP sysctls Alexey Gladkov
2026-08-26 20:29 ` Linus Torvalds
2026-08-29 16:14 ` Alexey Gladkov
2026-08-29 16:14 ` [RFC PATCH 1/4] sysctl: add typed field descriptors Alexey Gladkov
2026-08-29 16:14 ` [RFC PATCH 2/4] sysctl: ipc: use typed fields for IPC namespace sysctls Alexey Gladkov
2026-08-29 16:14 ` [RFC PATCH 3/4] sctp: use typed fields for per-net sysctls Alexey Gladkov
2026-08-29 16:14 ` [RFC PATCH 4/4] mpls: use typed fields for per-device sysctls Alexey Gladkov
2026-08-30 15:38 ` [RFC PATCH v1 17/30] sysctl: net: use sysctl_field in SCTP sysctls Linus Torvalds
2026-08-26 19:42 ` [RFC PATCH v1 18/30] sysctl: net: use sysctl_field in core IPv6 sysctls Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 19/30] sysctl: net: use sysctl_field in net core per-net sysctls Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 20/30] sysctl: net: use sysctl_field in SMC sysctls Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 21/30] sysctl: net: use sysctl_field in VRF sysctls Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 22/30] sysctl: net: use sysctl_field in RDS sysctls Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 23/30] sysctl: netfilter: use sysctl_field for per-net sysctls Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 24/30] sysctl: ipvs: " Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 25/30] sysctl: bridge: use sysctl_field for br_netfilter sysctls Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 26/30] sysctl: net: use sysctl_field for MPLS sysctls Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 27/30] sysctl: net: use sysctl_field in IPv4 devconf sysctls Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 28/30] sysctl: net: use sysctl_field in IPv6 " Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 29/30] sysctl: net: use sysctl_field in neighbour sysctls Alexey Gladkov
2026-08-26 19:42 ` [RFC PATCH v1 30/30] sysctl: parport: use sysctl_field for dynamic sysctls Alexey Gladkov
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=accaf54c772bc10dc44e2716047ecb74d29ba95d.1787771905.git.legion@kernel.org \
--to=legion@kernel.org \
--cc=ebiederm@xmission.com \
--cc=joel.granados@kernel.org \
--cc=kees@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
/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®