From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.68 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793205470; b=tqmjK50gMHYDtWpx7XNdX6rqIHVcz23EhkXBaJnJDeAGFuxdJYHDU7L838trOJNCFNBK mNp21RcqZFJgzLMOC+kf8oQn5YtINkq8QYZafYssmtEgKuIn/FlUDnasmHjLQARywgCS7 EVJFFkkkm5DtAidjHnCdQPdRW0QLnQCs+9mbwgcSoLQp/+BRqQtm+tmXtXIU44BQkq2Mg tmR5GduOOwQTGeq6f17CboDwm5uiNTAWXElKwUbQogIji/mjzK8J8XN1jTF+W25ji4e4q ppVS4nvFypFbtspCvxXEK7dnutvvd3qh86gI4uKMZqZYv1ZRN/+7SJEMeGCkaTPw7VA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793205470; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:Subject:Date:Message-Id: X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=SmZHdJwA0nTVD4grXEA4LqGJNLaI+aWn1kdnnfhjo+Y=; b=BdxQolDy++T+lnlZTTwLCeLEuJweQiHCazYNbEbAFLPe7KPIMg149gptmIWIzmcBDOhg 4o0OJUgSyOZbGLibBDiU1DAPHcknRJgtjhE3yUzKmjitcZhQF63nWmomFqVpYGFy86svT f3cBOwnu7y9ua1uNTCNDe1e+HuIugSFWt8/9Vl7NORbObgmv0Exd1mnxUEQbkXnLvEoeC g8LTYlp9XeVz11YybQp28xfBPW7aZ80yDA90C5VxDX8QmPA+i+sBHRtAOBtB2YrpJ7K98 iqaKiyDARGANzGpZ5i9FgW5mDU79428vCbOZIOrfX8pZ373iAKyChdx+ccCh7DSHmmQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=I23JiWKT; arc=none smtp.remote-ip=95.215.58.68 Received: from mta1.migadu.com (out-68.mta1.migadu.com [95.215.58.68]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5F4A960A380E for ; Wed, 28 Oct 2026 16:37:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5F4A960A380E Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=I23JiWKT X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=rcJjShQ6Rwi265pTCdrAfCG+yQUnwPiDdCgX68/XHjY=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1793205467; v=1; x=1793810267; b=I23JiWKTEUWf1+6SqtW0zqXhbhGyKWFMG13NrPD/3Xn05KVBz2fe36TxBfugO06lXicQoRho PEFAn9nHUNyY42KWekPoGgcLbLZrQgaZx5Jc+LzeBtweoxyb5RiPA4RLJr13hL4Ew2CeF2Yf4e8 cwX4dtJo/aZ94nxAtrG7wQhY= X-Envelope-To: linux-kernel@vger.kernel.org Received: by mta11.migadu.com with ESMTPS id 9c7125b63677d464; Wed, 28 Oct 2026 16:37:47 +0000 X-Mizu-Trace-ID: 9c7125b63677d464 X-Migadu-Flow: FLOW_OUT From: wen.yang@linux.dev To: Joel Granados Cc: Wen Yang , 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 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Wen Yang Refresh core network limits before validating sysctl writes. Suggested-by: Joel Granados Signed-off-by: Wen Yang --- 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