From: wen.yang@linux.dev
To: Joel Granados <joel.granados@kernel.org>
Cc: Wen Yang <wen.yang@linux.dev>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [RFC PATCH 25/39] sctp: resolve numeric ranges from the current namespace
Date: Thu, 29 Oct 2026 00:35:04 +0800 [thread overview]
Message-ID: <c65dd020fae1cf48364130682a94a74ba4ed5740.1793204511.git.wen.yang@linux.dev> (raw)
In-Reply-To: <cover.1793204511.git.wen.yang@linux.dev>
From: Wen Yang <wen.yang@linux.dev>
Read sibling SCTP limits from the current namespace on each call.
Suggested-by: Joel Granados <joel.granados@kernel.org>
Signed-off-by: Wen Yang <wen.yang@linux.dev>
---
net/sctp/sysctl.c | 147 +++++++++++++++++++++++-----------------------
1 file changed, 72 insertions(+), 75 deletions(-)
diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
index 59c6f22337ea..ed296f568887 100644
--- a/net/sctp/sysctl.c
+++ b/net/sctp/sysctl.c
@@ -24,25 +24,6 @@
#include <net/sctp/structs.h>
#include <net/sctp/sctp.h>
#include <linux/sysctl.h>
-#include <linux/limits.h>
-
-static int timer_max = 86400000; /* ms in one day */
-static int sack_timer_min = 1;
-static int sack_timer_max = 500;
-static int addr_scope_max = SCTP_SCOPE_POLICY_MAX;
-static int rwnd_scale_max = 16;
-static int rto_alpha_min = 0;
-static int rto_beta_min = 0;
-static int rto_alpha_max = 1000;
-static int rto_beta_max = 1000;
-static int pf_expose_max = SCTP_PF_EXPOSE_MAX;
-static int ps_retrans_max = SCTP_PS_RETRANS_MAX;
-static int udp_port_max = 65535;
-
-static unsigned long max_autoclose_min = 0;
-static unsigned long max_autoclose_max =
- (MAX_SCHEDULE_TIMEOUT / HZ > UINT_MAX)
- ? UINT_MAX : MAX_SCHEDULE_TIMEOUT / HZ;
static int proc_sctp_do_hmac_alg(const struct ctl_table *ctl, int write,
void *buffer, size_t *lenp, loff_t *ppos);
@@ -50,6 +31,26 @@ static int proc_sctp_do_rto_min(const struct ctl_table *ctl, int write,
void *buffer, size_t *lenp, loff_t *ppos);
static int proc_sctp_do_rto_max(const struct ctl_table *ctl, int write, void *buffer,
size_t *lenp, loff_t *ppos);
+static int proc_sctp_do_pf_retrans(const struct ctl_table *ctl, int write,
+ void *buffer, size_t *lenp, loff_t *ppos)
+{
+ struct net *net = container_of(ctl->data, struct net, sctp.pf_retrans);
+ struct ctl_table tmp = *ctl;
+
+ tmp.max = (unsigned long)READ_ONCE(net->sctp.ps_retrans);
+ return proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
+}
+
+static int proc_sctp_do_ps_retrans(const struct ctl_table *ctl, int write,
+ void *buffer, size_t *lenp, loff_t *ppos)
+{
+ struct net *net = container_of(ctl->data, struct net, sctp.ps_retrans);
+ struct ctl_table tmp = *ctl;
+
+ tmp.min = (unsigned long)READ_ONCE(net->sctp.pf_retrans);
+ return proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
+}
+
static int proc_sctp_do_udp_port(const struct ctl_table *ctl, int write, void *buffer,
size_t *lenp, loff_t *ppos);
static int proc_sctp_do_alpha_beta(const struct ctl_table *ctl, int write,
@@ -65,7 +66,7 @@ static struct ctl_table sctp_table[] = {
.data = &sysctl_sctp_mem,
.maxlen = sizeof(sysctl_sctp_mem),
.mode = 0644,
- .proc_handler = proc_doulongvec_minmax
+ .proc_handler = proc_doulongvec_minmax,
.min = 0,
.max = ULONG_MAX,
},
@@ -102,8 +103,8 @@ static const struct ctl_table sctp_net_table[] = {
.maxlen = sizeof(unsigned int),
.mode = 0644,
.proc_handler = proc_sctp_do_rto_min,
- .extra1 = SYSCTL_ONE,
- .extra2 = &init_net.sctp.rto_max
+ .min = 1,
+ .max = UINT_MAX,
},
[SCTP_RTO_MAX_IDX] = {
.procname = "rto_max",
@@ -111,26 +112,26 @@ static const struct ctl_table sctp_net_table[] = {
.maxlen = sizeof(unsigned int),
.mode = 0644,
.proc_handler = proc_sctp_do_rto_max,
- .extra1 = &init_net.sctp.rto_min,
- .extra2 = &timer_max
+ .min = 0,
+ .max = 86400000,
},
[SCTP_PF_RETRANS_IDX] = {
.procname = "pf_retrans",
.data = &init_net.sctp.pf_retrans,
.maxlen = sizeof(int),
.mode = 0644,
- .proc_handler = proc_dointvec_minmax,
- .extra1 = SYSCTL_ZERO,
- .extra2 = &init_net.sctp.ps_retrans,
+ .proc_handler = proc_sctp_do_pf_retrans,
+ .min = 0,
+ .max = INT_MAX,
},
[SCTP_PS_RETRANS_IDX] = {
.procname = "ps_retrans",
.data = &init_net.sctp.ps_retrans,
.maxlen = sizeof(int),
.mode = 0644,
- .proc_handler = proc_dointvec_minmax,
- .extra1 = &init_net.sctp.pf_retrans,
- .extra2 = &ps_retrans_max,
+ .proc_handler = proc_sctp_do_ps_retrans,
+ .min = (unsigned long)INT_MIN,
+ .max = SCTP_PS_RETRANS_MAX,
},
{
.procname = "rto_initial",
@@ -138,8 +139,8 @@ static const struct ctl_table sctp_net_table[] = {
.maxlen = sizeof(unsigned int),
.mode = 0644,
.proc_handler = proc_dointvec_minmax,
- .extra1 = SYSCTL_ONE,
- .extra2 = &timer_max
+ .min = 1,
+ .max = 86400000
},
{
.procname = "rto_alpha_exp_divisor",
@@ -147,8 +148,8 @@ static const struct ctl_table sctp_net_table[] = {
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = proc_sctp_do_alpha_beta,
- .extra1 = &rto_alpha_min,
- .extra2 = &rto_alpha_max,
+ .min = 0,
+ .max = 1000,
},
{
.procname = "rto_beta_exp_divisor",
@@ -156,8 +157,8 @@ static const struct ctl_table sctp_net_table[] = {
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = proc_sctp_do_alpha_beta,
- .extra1 = &rto_beta_min,
- .extra2 = &rto_beta_max,
+ .min = 0,
+ .max = 1000,
},
{
.procname = "max_burst",
@@ -165,8 +166,8 @@ static const struct ctl_table sctp_net_table[] = {
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = proc_dointvec_minmax,
- .extra1 = SYSCTL_ZERO,
- .extra2 = SYSCTL_INT_MAX,
+ .min = 0,
+ .max = INT_MAX,
},
{
.procname = "cookie_preserve_enable",
@@ -188,8 +189,8 @@ static const struct ctl_table sctp_net_table[] = {
.maxlen = sizeof(unsigned int),
.mode = 0644,
.proc_handler = proc_dointvec_minmax,
- .extra1 = SYSCTL_ONE,
- .extra2 = &timer_max
+ .min = 1,
+ .max = 86400000
},
{
.procname = "sack_timeout",
@@ -197,8 +198,8 @@ static const struct ctl_table sctp_net_table[] = {
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = proc_dointvec_minmax,
- .extra1 = &sack_timer_min,
- .extra2 = &sack_timer_max,
+ .min = 1,
+ .max = 500,
},
{
.procname = "hb_interval",
@@ -206,8 +207,8 @@ static const struct ctl_table sctp_net_table[] = {
.maxlen = sizeof(unsigned int),
.mode = 0644,
.proc_handler = proc_dointvec_minmax,
- .extra1 = SYSCTL_ONE,
- .extra2 = &timer_max
+ .min = 1,
+ .max = 86400000
},
{
.procname = "association_max_retrans",
@@ -215,8 +216,8 @@ static const struct ctl_table sctp_net_table[] = {
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = proc_dointvec_minmax,
- .extra1 = SYSCTL_ONE,
- .extra2 = SYSCTL_INT_MAX,
+ .min = 1,
+ .max = INT_MAX,
},
{
.procname = "path_max_retrans",
@@ -224,8 +225,8 @@ static const struct ctl_table sctp_net_table[] = {
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = proc_dointvec_minmax,
- .extra1 = SYSCTL_ONE,
- .extra2 = SYSCTL_INT_MAX,
+ .min = 1,
+ .max = INT_MAX,
},
{
.procname = "max_init_retransmits",
@@ -233,8 +234,8 @@ static const struct ctl_table sctp_net_table[] = {
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = proc_dointvec_minmax,
- .extra1 = SYSCTL_ONE,
- .extra2 = SYSCTL_INT_MAX,
+ .min = 1,
+ .max = INT_MAX,
},
{
.procname = "sndbuf_policy",
@@ -319,8 +320,8 @@ static const struct ctl_table sctp_net_table[] = {
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = proc_sctp_do_udp_port,
- .extra1 = SYSCTL_ZERO,
- .extra2 = &udp_port_max,
+ .min = 0,
+ .max = 65535,
},
{
.procname = "encap_port",
@@ -328,8 +329,8 @@ static const struct ctl_table sctp_net_table[] = {
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = proc_dointvec_minmax,
- .extra1 = SYSCTL_ZERO,
- .extra2 = &udp_port_max,
+ .min = 0,
+ .max = 65535,
},
{
.procname = "addr_scope_policy",
@@ -337,8 +338,8 @@ static const struct ctl_table sctp_net_table[] = {
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = proc_dointvec_minmax,
- .extra1 = SYSCTL_ZERO,
- .extra2 = &addr_scope_max,
+ .min = 0,
+ .max = SCTP_SCOPE_POLICY_MAX,
},
{
.procname = "rwnd_update_shift",
@@ -346,8 +347,8 @@ static const struct ctl_table sctp_net_table[] = {
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = &proc_dointvec_minmax,
- .extra1 = SYSCTL_ONE,
- .extra2 = &rwnd_scale_max,
+ .min = 1,
+ .max = 16,
},
{
.procname = "max_autoclose",
@@ -355,8 +356,9 @@ static const struct ctl_table sctp_net_table[] = {
.maxlen = sizeof(unsigned long),
.mode = 0644,
.proc_handler = &proc_doulongvec_minmax,
- .extra1 = &max_autoclose_min,
- .extra2 = &max_autoclose_max,
+ .min = 0,
+ .max = (MAX_SCHEDULE_TIMEOUT / HZ > UINT_MAX)
+ ? UINT_MAX : MAX_SCHEDULE_TIMEOUT / HZ,
},
#ifdef CONFIG_NET_L3_MASTER_DEV
{
@@ -365,8 +367,8 @@ static const struct ctl_table sctp_net_table[] = {
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = proc_dointvec_minmax,
- .extra1 = SYSCTL_ZERO,
- .extra2 = SYSCTL_ONE,
+ .min = 0,
+ .max = 1,
},
#endif
{
@@ -382,8 +384,8 @@ static const struct ctl_table sctp_net_table[] = {
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = proc_dointvec_minmax,
- .extra1 = SYSCTL_ZERO,
- .extra2 = &pf_expose_max,
+ .min = 0,
+ .max = SCTP_PF_EXPOSE_MAX,
},
};
@@ -426,8 +428,8 @@ static int proc_sctp_do_rto_min(const struct ctl_table *ctl, int write,
void *buffer, size_t *lenp, loff_t *ppos)
{
struct net *net = container_of(ctl->data, struct net, sctp.rto_min);
- unsigned int min = *(unsigned int *) ctl->extra1;
- unsigned int max = *(unsigned int *) ctl->extra2;
+ unsigned int min = ctl->min;
+ unsigned int max = READ_ONCE(net->sctp.rto_max);
struct ctl_table tbl;
int ret, new_value;
@@ -454,8 +456,8 @@ static int proc_sctp_do_rto_max(const struct ctl_table *ctl, int write,
void *buffer, size_t *lenp, loff_t *ppos)
{
struct net *net = container_of(ctl->data, struct net, sctp.rto_max);
- unsigned int min = *(unsigned int *) ctl->extra1;
- unsigned int max = *(unsigned int *) ctl->extra2;
+ unsigned int min = READ_ONCE(net->sctp.rto_min);
+ unsigned int max = ctl->max;
struct ctl_table tbl;
int ret, new_value;
@@ -523,8 +525,8 @@ static int proc_sctp_do_udp_port(const struct ctl_table *ctl, int write,
void *buffer, size_t *lenp, loff_t *ppos)
{
struct net *net = container_of(ctl->data, struct net, sctp.udp_port);
- unsigned int min = *(unsigned int *)ctl->extra1;
- unsigned int max = *(unsigned int *)ctl->extra2;
+ unsigned int min = ctl->min;
+ unsigned int max = ctl->max;
struct ctl_table tbl;
int ret, new_value;
@@ -602,11 +604,6 @@ int sctp_sysctl_net_register(struct net *net)
for (i = 0; i < table_size; i++)
table[i].data += (char *)(&net->sctp) - (char *)&init_net.sctp;
- table[SCTP_RTO_MIN_IDX].extra2 = &net->sctp.rto_max;
- table[SCTP_RTO_MAX_IDX].extra1 = &net->sctp.rto_min;
- table[SCTP_PF_RETRANS_IDX].extra2 = &net->sctp.ps_retrans;
- table[SCTP_PS_RETRANS_IDX].extra1 = &net->sctp.pf_retrans;
-
net->sctp.sysctl_header = register_net_sysctl_sz(net, "net/sctp",
table, table_size);
if (net->sctp.sysctl_header == NULL) {
--
2.25.1
next prev parent reply other threads:[~2026-10-28 16:37 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-28 16:34 [RFC PATCH 00/39] sysctl: replace overloaded extra pointers with typed bounds and context wen.yang
2026-10-28 16:34 ` [RFC PATCH 01/39] " wen.yang
2026-10-28 21:09 ` David Laight
2026-10-28 16:34 ` [RFC PATCH 02/39] test_sysctl: convert bounds to numeric values wen.yang
2026-10-28 16:34 ` [RFC PATCH 03/39] sysctl: add KUnit coverage for numeric bounds and handlers wen.yang
2026-10-28 16:34 ` [RFC PATCH 04/39] sysctl: cover runtime ranges and context lifecycles in KUnit wen.yang
2026-10-28 16:34 ` [RFC PATCH 05/39] sysctl: cover priv in KUnit and the debug test module wen.yang
2026-10-28 16:34 ` [RFC PATCH 06/39] sysctl: convert core table bounds to numeric values wen.yang
2026-10-28 16:34 ` [RFC PATCH 07/39] sysctl: store architecture sysctl bounds by value wen.yang
2026-10-28 16:34 ` [RFC PATCH 08/39] sysctl: store crypto " wen.yang
2026-10-28 16:34 ` [RFC PATCH 09/39] sysctl: store device " wen.yang
2026-10-28 16:34 ` [RFC PATCH 10/39] sysctl: store filesystem " wen.yang
2026-10-28 16:34 ` [RFC PATCH 11/39] sysctl: store message-queue " wen.yang
2026-10-28 16:34 ` [RFC PATCH 12/39] sysctl: store kernel " wen.yang
2026-10-28 16:34 ` [RFC PATCH 13/39] sysctl: store memory-management " wen.yang
2026-10-28 16:34 ` [RFC PATCH 14/39] sysctl: store IPv6 scalar " wen.yang
2026-10-28 16:34 ` [RFC PATCH 15/39] sysctl: store netfilter " wen.yang
2026-10-28 16:34 ` [RFC PATCH 16/39] sysctl: store RPC " wen.yang
2026-10-28 16:34 ` [RFC PATCH 17/39] sysctl: store remaining network " wen.yang
2026-10-28 16:34 ` [RFC PATCH 18/39] sysctl: store security " wen.yang
2026-10-28 16:34 ` [RFC PATCH 19/39] io_uring: store its " wen.yang
2026-10-28 16:34 ` [RFC PATCH 20/39] sysctl: refresh dynamic scheduler and PID bounds per call wen.yang
2026-10-28 16:35 ` [RFC PATCH 21/39] sysctl: refresh device-dependent " wen.yang
2026-10-28 16:35 ` [RFC PATCH 22/39] sysctl: refresh namespace IPC " wen.yang
2026-10-28 16:35 ` [RFC PATCH 23/39] yama: preserve scope locking with numeric sysctl bounds wen.yang
2026-10-28 16:35 ` [RFC PATCH 24/39] net: refresh core sysctl limits without bound pointers wen.yang
2026-10-28 16:35 ` wen.yang [this message]
2026-10-28 16:35 ` [RFC PATCH 26/39] rds: preserve live reconnect limits with numeric bounds wen.yang
2026-10-28 16:35 ` [RFC PATCH 27/39] ipv4: preserve live and vector bounds with numeric sysctls wen.yang
2026-10-28 16:35 ` [RFC PATCH 28/39] net: refresh fragment and remaining dynamic sysctl bounds wen.yang
2026-10-28 16:35 ` [RFC PATCH 29/39] neighbour: derive sysctl ownership independently of bounds wen.yang
2026-10-28 16:35 ` [RFC PATCH 30/39] net: resolve sysctl owners from their backing data wen.yang
2026-10-28 16:35 ` [RFC PATCH 31/39] ipvs: derive sysctl ownership from numeric storage wen.yang
2026-10-28 16:35 ` [RFC PATCH 32/39] sysctl: remove obsolete nr_open bound variables wen.yang
2026-10-28 16:35 ` [RFC PATCH 33/39] ipv6: move address sysctl context to priv wen.yang
2026-10-28 16:35 ` [RFC PATCH 34/39] ipv4: move device " wen.yang
2026-10-28 16:35 ` [RFC PATCH 35/39] netfilter: move logger " wen.yang
2026-10-28 16:35 ` [RFC PATCH 36/39] parport: move device " wen.yang
2026-10-28 16:35 ` [RFC PATCH 37/39] net: move namespace " wen.yang
2026-10-28 16:35 ` [RFC PATCH 38/39] arm64: move vector-length " wen.yang
2026-10-28 16:35 ` [RFC PATCH 39/39] sysctl: remove the extra pointers and the compatibility bounds read wen.yang
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=c65dd020fae1cf48364130682a94a74ba4ed5740.1793204511.git.wen.yang@linux.dev \
--to=wen.yang@linux.dev \
--cc=joel.granados@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.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®