Article View: linux.kernel.netdev
Article #6750[PATCH net 5/5] net: restrict message_cost and message_burst to non-negative values
From: Jiayuan Chen
Date: Fri, 23 Oct 2026 09:13
Date: Fri, 23 Oct 2026 09:13
94 lines
12090 bytes
12090 bytes
net.core.message_cost and net.core.message_burst feed the interval and
burst of net_ratelimit_state, but neither has a lower bound:
message_burst uses plain proc_dointvec, and message_cost uses
proc_dointvec_jiffies, which happily stores -1 second as -HZ jiffies.
Since commit a940d145cc38 ("ratelimit: Warn if ->interval or ->burst are
negative"), ___ratelimit() splats on such values, so the next
net_ratelimit() caller warns, e.g. a martian source log:
Negative interval (-250) or burst (10): Uninitialized ratelimit_state structure?
WARNING: lib/ratelimit.c:43 at ___ratelimit+0x56e/0x960, CPU#1: ping/3218
RIP: 0010:___ratelimit+0x578/0x960
Call Trace:
<IRQ>
net_ratelimit+0x1c/0x30
ip_handle_martian_source+0x1bb/0x340
ip_route_input_slow+0x1057/0x3650
ip_route_input_noref+0x104/0x260
arp_process+0x109b/0x2510
arp_rcv+0x381/0x460
__netif_receive_skb_one_core+0x173/0x1c0
__netif_receive_skb+0x21/0x150
process_backlog+0x37e/0x1200
__napi_poll.constprop.0+0xa5/0x5e0
net_rx_action+0x4c0/0xf70
handle_softirqs+0x204/0x9b0
__do_softirq+0x10/0x18
do_softirq.part.0+0x49/0xd0
</IRQ>
Negative values never meant anything here: ___ratelimit() treats them
like 0, and 0 already expresses both "no limit" (interval) and
"suppress everything" (burst).
Reject them at write time. message_burst can simply use
proc_dointvec_minmax with extra1 = 0. proc_dointvec_jiffies ignores
extra1/extra2, so give message_cost a small handler that parses into a
temporary and only stores the value if it is not negative.
Fixes: a940d145cc38 ("ratelimit: Warn if ->interval or ->burst are negative")
Cc: stable@vger.kernel.org
Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
---
net/core/sysctl_net_core.c | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
index 473c162736d6..8146ed819695 100644
--- a/net/core/sysctl_net_core.c
+++ b/net/core/sysctl_net_core.c
@@ -378,6 +378,22 @@ static int proc_do_skb_defer_max(const struct ctl_table *table, int write,
return ret;
}
+static int proc_do_message_cost(const struct ctl_table *table, int write,
+ void *buffer, size_t *lenp, loff_t *ppos)
+{
+ int ret, interval = READ_ONCE(*(int *)table->data);
+ struct ctl_table tmp = *table;
+
+ tmp.data = &interval;
+ ret = proc_dointvec_jiffies(&tmp, write, buffer, lenp, ppos);
+ if (write && !ret) {
+ if (interval < 0)
+ return -EINVAL;
+ WRITE_ONCE(*(int *)table->data, interval);
+ }
+ return ret;
+}
+
#ifdef CONFIG_BPF_JIT
static int proc_dointvec_minmax_bpf_enable(const struct ctl_table *table, int write,
void *buffer, size_t *lenp,
@@ -544,14 +560,15 @@ static struct ctl_table net_core_table[] = {
.data = &net_ratelimit_state.interval,
.maxlen = sizeof(int),
.mode = 0644,
- .proc_handler = proc_dointvec_jiffies,
+ .proc_handler = proc_do_message_cost,
},
{
.procname = "message_burst",
.data = &net_ratelimit_state.burst,
.maxlen = sizeof(int),
.mode = 0644,
- .proc_handler = proc_dointvec,
+ .proc_handler = proc_dointvec_minmax,
+ .extra1 = SYSCTL_ZERO,
},
#ifdef CONFIG_RPS
{
--
2.43.0
Technical Details
Message-ID:
<20261023091419.167088-6-jiayuan.chen@linux.dev>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-350996-linux-kernel-netdev=dewy.ruReferences:
<20261023091419.167088-1-jiayuan.chen@linux.dev>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-350996-linux-kernel-netdev=dewy.ru From: jiayuan.chen@linux.dev (Jiayuan Chen) Newsgroups: linux.kernel.netdev Subject: [PATCH net 5/5] net: restrict message_cost and message_burst to non-negative values Date: Fri, 23 Oct 2026 17:13:31 +0800 Organization: Usenet Network Message-ID: <20261023091419.167088-6-jiayuan.chen@linux.dev> References: <20261023091419.167088-1-jiayuan.chen@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="460303"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:T6qAnQYb3icHrWX66bQGVaUySu8= sha256:UBOPimFODBMehVjJT7ScH2ksFx9xCQ5FkqY6ptXwhBE= sha1:DF8K1z7v7chDknHaOk3+NGkKISw= sha256:cb9iQ7v2N2jxEOVgDuAe+Zj/1UzW7u3ITepnhEtFSrg= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id F3E48111452; Fri, 23 Oct 2026 12:18:26 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -2.05 X-Spam-Status: No, score=-2.05 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.25, HK_RANDOM_FROM=0.999, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key) header.d=linux.dev X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Wjq5G9m5_AqD; Fri, 23 Oct 2026 12:18:24 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-350996-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linux.dev X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4]) by mail.dewy.ru (Postfix) with ESMTPS id C6335111450; Fri, 23 Oct 2026 12:18:13 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sin.lore.kernel.org (Postfix) with ESMTP id 4F38F28F3B; Fri, 23 Oct 2026 09:17:02 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1792747013; b=Cts4rNpDpwsAnseSP7S3NtK3i+ji8aypwwQVQR9fkmJl4+qRtozolPDCBCXWVS8Gl3Be CnTknecnPd+c1/XyVMQi89j3CHDXSqGqE8P42fNXrogQIzHUQxMQRlVmgGID6tUIknske Y0+E5DjZwanffRfmxDQMVGq/RE3klSdtciLGIOR0kzxJiHihyqzX62XNC5/G6cLo2b0k1 hBcbf8BLXsQpwzoQOFrA/mU4rHWH0L9+dUXva1OGQpkiWEMChMTxAG72NvkClD4dGlPQ9 dPg8ILBHn0waJOV8aXiLxBqgR4yH47bAx6vldVbyXbA/6cKDwmNAFAQXAXDVwqK0lTw== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1792747013; h=X-Original-To:Received: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: X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe: List-Unsubscribe:List-Owner:Precedence:MIME-Version: Content-Transfer-Encoding; bh=q12lwCISyZPjPr61m5RHq2Uo3Q7fFgGiNopmM/Dy4L4=; b=DBMtg7Uph6vEqMsTB7XPHSQHtcrleEE1RSsd/d7k9xvIesUv1mfCRqOuyk1QssKyYK8W ipz2riIE5ncemU9hlVPoRp0BoD+qwaUu/P2hw8yL3SFM5s8MX313xduyEtjFlpqsIUUk5 eHQKHDLt/fh/y5cQo0vOaZbYdKvsIededhwUYYUQv+5WvcR0CsVzwgcNXjVUUb/uKbQSD cKCSneicioqEAjpN6Vfku/AOXE/z2FoMcwd9EWOAR9OLFsXAWipGkTk5FJ+tHsqLXNN7O fSpUvcu9l9EEwdBpaRbNaPKFQ10M2yV34LPinoMLQzYvc8m9xNR8Q3DCmJtj+IjyAyQ== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=DUlE0gg+; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CDAD3606A329; Fri, 23 Oct 2026 09:16:53 +0000 (UTC) X-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=DUlE0gg+ X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.88 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1792747003; b=nEvv9/CsGr9t0jbmIDOHG9/vjfznO5TpO6N9bEX0HjXNmpj2w9Yu1v70b//1bGyVWBa7 NtbGoB9BLFdcJHw8n1cM2VolpMIoHVTJjZSrNAA21Q1NHDp1Zbi+EoQq5NoW4yianjIT7 T21Ek0tl3muX+JrGTp8AB5pu8kncGaPIuFaopUspIl62306wl8Sk7NlxXjJHMagvJaH0o 9kJDY1Kk+Twin6RSlsBFvUr2t3uXiRAnOxT0YhanbpLyrsGvhveZRpouKWAlKoxrTwGxu lpIjLcG4Z+uTkKnzT7qCOdm6lPsVX/SjDBTpuEg9jq2fP8OO1CH+PAKDSnVAjrdHOgA== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1792747003; 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=q12lwCISyZPjPr61m5RHq2Uo3Q7fFgGiNopmM/Dy4L4=; b=QSaFQJ/5zP+z/iVz1rPlKgrp5t5jX2gdgSUjqhVY2e0f2UASWnbOm6hPFbiq5Hbh7l+D KNSmlpnecPFN6TfJY14GmuPRPPMeAQT6uZkfJP26sukwZap9AYvYXGJClTqRPUMEt4m3g T4vErKFNPW2h3aPPMDYV1HqoK7+E7ThTiH+Rcg2Jf6QldiJKBtDQe+xeCrWssJVt5+Ido pBIpDFk6s5a6MrhPnn+XYyRFLaIm5E/4gS9GtcY+MXjoQJCuhfuGKh/wcCjaF+HxkPp0b Si8Bb0w07PwtZYHlV2t5jDjIWTVO6p2qb6OgSxkm98rfsVNLAmguTxKTgSNxNSH2QBQ== X-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=DUlE0gg+; arc=none smtp.remote-ip=95.215.58.88 X-Received: from mta1.migadu.com (out-88.mta1.migadu.com [95.215.58.88]) (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 5522860A260E for <netdev@vger.kernel.org>; Fri, 23 Oct 2026 09:16:41 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5522860A260E X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Envelope-To: netdev@vger.kernel.org X-DKIM-Signature: a=rsa-sha256; bh=1KupEA37m82GidlyX3LbcgZwwrs9UufQXzhoE0mR97Q=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1792747000; v=1; x=1793351800; b=DUlE0gg+48vGYSi77VhILLLl5w916XC2y+cs2xPGiBuofSNgYkeLtsOfYd+gSxFYfkxjeNN+ 2cvFn6Xb/wgnGeD996tFC/dEUvkzKTgcfL+E8IYZ9AjGUUOQzC1s8f3c8kAAfbxPyP+InVPkk2e ET8zT70N/fueCvNJxapYEihU= X-Envelope-To: netdev@vger.kernel.org X-Received: by smtp.migadu.com with ESMTPS id 9ba89e8f548b0aa4; Fri, 23 Oct 2026 09:16:40 +0000 X-Mizu-Trace-ID: 9ba89e8f548b0aa4 X-Migadu-Flow: FLOW_OUT X-Cc: Jiayuan Chen <jiayuan.chen@linux.dev>, stable@vger.kernel.org, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@kernel.org>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>, David Ahern <dsahern@kernel.org>, Ido Schimmel <idosch@nvidia.com>, Kuniyuki Iwashima <kuniyu@google.com>, Joel Granados <joel.granados@kernel.org>, Chia-Yu Chang <chia-yu.chang@nokia-bell-labs.com>, Wyatt Feng <bronzed_45_vested@icloud.com>, Yung Chih Su <yuuchihsu@gmail.com>, Fernando Fernandez Mancera <fmancera@suse.de>, Hannes Frederic Sowa <hannes@stressinduktion.org>, Flavio Leitner <fbl@redhat.com>, Petr Mladek <pmladek@suse.com>, "Paul E. McKenney" <paulmck@kernel.org>, linux-kernel@vger.kernel.org X-Mailer: git-send-email 2.43.0 X-In-Reply-To: <20261023091419.167088-1-jiayuan.chen@linux.dev> X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list