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 24/39] net: refresh core sysctl limits without bound pointers
Date: Thu, 29 Oct 2026 00:35:03 +0800 [thread overview]
Message-ID: <c8afbf52fbf9467eb2110a88d8c917ff30422be8.1793204511.git.wen.yang@linux.dev> (raw)
In-Reply-To: <cover.1793204511.git.wen.yang@linux.dev>
From: Wen Yang <wen.yang@linux.dev>
Refresh core network limits before validating sysctl writes.
Suggested-by: Joel Granados <joel.granados@kernel.org>
Signed-off-by: Wen Yang <wen.yang@linux.dev>
---
net/core/sysctl_net_core.c | 118 ++++++++++++++++++++-----------------
1 file changed, 65 insertions(+), 53 deletions(-)
diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
index 473c162736d6..1721e63240c9 100644
--- a/net/core/sysctl_net_core.c
+++ b/net/core/sysctl_net_core.c
@@ -32,12 +32,6 @@
#include "dev.h"
#include "net-sysfs.h"
-static int int_3600 = 3600;
-static int min_sndbuf = SOCK_MIN_SNDBUF;
-static int min_rcvbuf = SOCK_MIN_RCVBUF;
-static int max_skb_frags = MAX_SKB_FRAGS;
-static int min_mem_pcpu_rsv = SK_MEMORY_PCPU_RESERVE;
-static int netdev_budget_usecs_min = 2 * USEC_PER_SEC / HZ;
static int net_msg_warn; /* Unused, but still a sysctl */
@@ -146,7 +140,7 @@ static int rps_sock_flow_sysctl(const struct ctl_table *table, int write,
struct ctl_table tmp = {
.data = &size,
.maxlen = sizeof(size),
- .mode = table->mode
+ .mode = table->mode,
};
void *tofree = NULL;
int ret, i;
@@ -384,8 +378,8 @@ static int proc_dointvec_minmax_bpf_enable(const struct ctl_table *table, int wr
loff_t *ppos)
{
int ret, jit_enable = *(int *)table->data;
- int min = *(int *)table->extra1;
- int max = *(int *)table->extra2;
+ int min = (int)table->min;
+ int max = (int)table->max;
struct ctl_table tmp = *table;
if (write && !capable(CAP_SYS_ADMIN))
@@ -426,10 +420,13 @@ static int
proc_dolongvec_minmax_bpf_restricted(const struct ctl_table *table, int write,
void *buffer, size_t *lenp, loff_t *ppos)
{
+ struct ctl_table tmp = *table;
+
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
- return proc_doulongvec_minmax(table, write, buffer, lenp, ppos);
+ tmp.max = (unsigned long)READ_ONCE(bpf_jit_limit_max);
+ return proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
}
#endif
@@ -440,7 +437,8 @@ static struct ctl_table net_core_table[] = {
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = proc_dointvec_minmax,
- .extra1 = &min_mem_pcpu_rsv,
+ .min = SK_MEMORY_PCPU_RESERVE,
+ .max = INT_MAX,
},
{
.procname = "dev_weight",
@@ -448,7 +446,8 @@ static struct ctl_table net_core_table[] = {
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = proc_do_dev_weight,
- .extra1 = SYSCTL_ONE,
+ .min = 1,
+ .max = INT_MAX,
},
{
.procname = "dev_weight_rx_bias",
@@ -456,7 +455,8 @@ static struct ctl_table net_core_table[] = {
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = proc_do_dev_weight,
- .extra1 = SYSCTL_ONE,
+ .min = 1,
+ .max = INT_MAX,
},
{
.procname = "dev_weight_tx_bias",
@@ -464,7 +464,8 @@ static struct ctl_table net_core_table[] = {
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = proc_do_dev_weight,
- .extra1 = SYSCTL_ONE,
+ .min = 1,
+ .max = INT_MAX,
},
{
.procname = "netdev_max_backlog",
@@ -495,11 +496,11 @@ static struct ctl_table net_core_table[] = {
.mode = 0644,
.proc_handler = proc_dointvec_minmax_bpf_enable,
# ifdef CONFIG_BPF_JIT_ALWAYS_ON
- .extra1 = SYSCTL_ONE,
- .extra2 = SYSCTL_ONE,
+ .min = 1,
+ .max = 1,
# else
- .extra1 = SYSCTL_ZERO,
- .extra2 = SYSCTL_TWO,
+ .min = 0,
+ .max = 2,
# endif
},
# ifdef CONFIG_HAVE_EBPF_JIT
@@ -509,8 +510,8 @@ static struct ctl_table net_core_table[] = {
.maxlen = sizeof(int),
.mode = 0600,
.proc_handler = proc_dointvec_minmax_bpf_restricted,
- .extra1 = SYSCTL_ZERO,
- .extra2 = SYSCTL_TWO,
+ .min = 0,
+ .max = 2,
},
{
.procname = "bpf_jit_kallsyms",
@@ -518,8 +519,8 @@ static struct ctl_table net_core_table[] = {
.maxlen = sizeof(int),
.mode = 0600,
.proc_handler = proc_dointvec_minmax_bpf_restricted,
- .extra1 = SYSCTL_ZERO,
- .extra2 = SYSCTL_ONE,
+ .min = 0,
+ .max = 1,
},
# endif
{
@@ -528,8 +529,8 @@ static struct ctl_table net_core_table[] = {
.maxlen = sizeof(long),
.mode = 0600,
.proc_handler = proc_dolongvec_minmax_bpf_restricted,
- .extra1 = SYSCTL_LONG_ONE,
- .extra2 = &bpf_jit_limit_max,
+ .min = 1,
+ .max = ULONG_MAX,
},
#endif
{
@@ -582,7 +583,8 @@ static struct ctl_table net_core_table[] = {
.maxlen = sizeof(unsigned int),
.mode = 0644,
.proc_handler = proc_dointvec_minmax,
- .extra1 = SYSCTL_ZERO,
+ .min = 0,
+ .max = INT_MAX,
},
{
.procname = "busy_read",
@@ -590,7 +592,8 @@ static struct ctl_table net_core_table[] = {
.maxlen = sizeof(unsigned int),
.mode = 0644,
.proc_handler = proc_dointvec_minmax,
- .extra1 = SYSCTL_ZERO,
+ .min = 0,
+ .max = INT_MAX,
},
#endif
#ifdef CONFIG_NET_SCHED
@@ -621,8 +624,8 @@ static struct ctl_table net_core_table[] = {
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = proc_dointvec_minmax,
- .extra1 = SYSCTL_ONE,
- .extra2 = &max_skb_frags,
+ .min = 1,
+ .max = MAX_SKB_FRAGS,
},
{
.procname = "netdev_budget_usecs",
@@ -630,7 +633,8 @@ static struct ctl_table net_core_table[] = {
.maxlen = sizeof(unsigned int),
.mode = 0644,
.proc_handler = proc_dointvec_minmax,
- .extra1 = &netdev_budget_usecs_min,
+ .min = 2 * USEC_PER_SEC / HZ,
+ .max = INT_MAX,
},
{
.procname = "fb_tunnels_only_for_init_net",
@@ -638,8 +642,8 @@ static struct ctl_table net_core_table[] = {
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = proc_dointvec_minmax,
- .extra1 = SYSCTL_ZERO,
- .extra2 = SYSCTL_TWO,
+ .min = 0,
+ .max = 2,
},
{
.procname = "devconf_inherit_init_net",
@@ -647,8 +651,8 @@ static struct ctl_table net_core_table[] = {
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = proc_dointvec_minmax,
- .extra1 = SYSCTL_ZERO,
- .extra2 = SYSCTL_THREE,
+ .min = 0,
+ .max = 3,
},
{
.procname = "high_order_alloc_disable",
@@ -663,7 +667,8 @@ static struct ctl_table net_core_table[] = {
.maxlen = sizeof(unsigned int),
.mode = 0644,
.proc_handler = proc_dointvec_minmax,
- .extra1 = SYSCTL_ONE,
+ .min = 1,
+ .max = INT_MAX,
},
{
.procname = "netdev_unregister_timeout_secs",
@@ -671,8 +676,8 @@ static struct ctl_table net_core_table[] = {
.maxlen = sizeof(unsigned int),
.mode = 0644,
.proc_handler = proc_dointvec_minmax,
- .extra1 = SYSCTL_ONE,
- .extra2 = &int_3600,
+ .min = 1,
+ .max = 3600,
},
{
.procname = "skb_defer_max",
@@ -680,7 +685,8 @@ static struct ctl_table net_core_table[] = {
.maxlen = sizeof(unsigned int),
.mode = 0644,
.proc_handler = proc_do_skb_defer_max,
- .extra1 = SYSCTL_ZERO,
+ .min = 0,
+ .max = INT_MAX,
},
{
.procname = "neigh_inherit_init_net",
@@ -688,8 +694,8 @@ static struct ctl_table net_core_table[] = {
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = proc_dointvec_minmax,
- .extra1 = SYSCTL_ZERO,
- .extra2 = SYSCTL_ONE,
+ .min = 0,
+ .max = 1,
},
};
@@ -707,24 +713,26 @@ static const struct ctl_table netns_core_table[] = {
.data = &init_net.core.sysctl_somaxconn,
.maxlen = sizeof(int),
.mode = 0644,
- .extra1 = SYSCTL_ZERO,
- .proc_handler = proc_dointvec_minmax
+ .min = 0,
+ .proc_handler = proc_dointvec_minmax,
+ .max = INT_MAX,
},
{
.procname = "optmem_max",
.data = &init_net.core.sysctl_optmem_max,
.maxlen = sizeof(int),
.mode = 0644,
- .extra1 = SYSCTL_ZERO,
- .proc_handler = proc_dointvec_minmax
+ .min = 0,
+ .proc_handler = proc_dointvec_minmax,
+ .max = INT_MAX,
},
{
.procname = "txrehash",
.data = &init_net.core.sysctl_txrehash,
.maxlen = sizeof(u8),
.mode = 0644,
- .extra1 = SYSCTL_ZERO,
- .extra2 = SYSCTL_ONE,
+ .min = 0,
+ .max = 1,
.proc_handler = proc_dou8vec_minmax,
},
{
@@ -740,8 +748,8 @@ static const struct ctl_table netns_core_table[] = {
.maxlen = sizeof(u8),
.mode = 0644,
.proc_handler = proc_dou8vec_minmax,
- .extra1 = SYSCTL_ZERO,
- .extra2 = SYSCTL_ONE
+ .min = 0,
+ .max = 1
},
{
.procname = "bypass_prot_mem",
@@ -749,8 +757,8 @@ static const struct ctl_table netns_core_table[] = {
.maxlen = sizeof(u8),
.mode = 0644,
.proc_handler = proc_dou8vec_minmax,
- .extra1 = SYSCTL_ZERO,
- .extra2 = SYSCTL_ONE
+ .min = 0,
+ .max = 1
},
/* sysctl_core_net_init() will set the values after this
* to readonly in network namespaces
@@ -761,7 +769,8 @@ static const struct ctl_table netns_core_table[] = {
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = proc_dointvec_minmax,
- .extra1 = &min_sndbuf,
+ .min = SOCK_MIN_SNDBUF,
+ .max = INT_MAX,
},
{
.procname = "rmem_max",
@@ -769,7 +778,8 @@ static const struct ctl_table netns_core_table[] = {
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = proc_dointvec_minmax,
- .extra1 = &min_rcvbuf,
+ .min = SOCK_MIN_RCVBUF,
+ .max = INT_MAX,
},
{
.procname = "wmem_default",
@@ -777,7 +787,8 @@ static const struct ctl_table netns_core_table[] = {
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = proc_dointvec_minmax,
- .extra1 = &min_sndbuf,
+ .min = SOCK_MIN_SNDBUF,
+ .max = INT_MAX,
},
{
.procname = "rmem_default",
@@ -785,7 +796,8 @@ static const struct ctl_table netns_core_table[] = {
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = proc_dointvec_minmax,
- .extra1 = &min_rcvbuf,
+ .min = SOCK_MIN_RCVBUF,
+ .max = INT_MAX,
},
};
--
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 ` wen.yang [this message]
2026-10-28 16:35 ` [RFC PATCH 25/39] sctp: resolve numeric ranges from the current namespace wen.yang
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=c8afbf52fbf9467eb2110a88d8c917ff30422be8.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®