Article View: linux.kernel.netdev
Article #3840[PATCH net] net/sched: cls_flow: avoid integer overflow in perturb_period
From: Wei Tao
Date: Fri, 16 Oct 2026 04:03
Date: Fri, 16 Oct 2026 04:03
75 lines
8100 bytes
8100 bytes
flow_change() calculates perturb_period by directly multiplying
nla_get_u32(tb[TCA_FLOW_PERTURB]) by HZ, without any overflow
protection. Since perturb_period is a u32, the multiplication
overflows when the value from netlink exceeds UINT_MAX / HZ.
The result can be an unexpectedly short period or even zero.
# tc qdisc add dev lo clsact
# tc filter add dev lo ingress protocol ip pref 1 handle 1 flow \
hash keys src perturb 42949673 baseclass 1:10
With HZ=100, 42949673*100=4294967300, but UINT_MAX is 4294967295,
so the product wraps to 4 jiffies.
Both the filter-modify and filter-create paths in flow_change()
are affected.
Since perturb_period is ultimately fed to mod_timer(), and
calc_wheel_index() internally casts delta to signed long for
comparison, reject values greater than INT_MAX / HZ. Besides
preventing the u32 multiplication from wrapping, this also
keeps the relative timeout within the signed-long range on
32-bit systems.
Fixes: 72d9794f4447 ("net-sched: cls_flow: add perturbation support")
Cc: stable@vger.kernel.org
Signed-off-by: Wei Tao <taowei@kylinos.cn>
---
net/sched/cls_flow.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/net/sched/cls_flow.c b/net/sched/cls_flow.c
index a9ac3acf6eda..29d1042a1988 100644
--- a/net/sched/cls_flow.c
+++ b/net/sched/cls_flow.c
@@ -408,6 +408,7 @@ static int flow_change(struct net *net, struct sk_buff *in_skb,
u32 keymask = 0;
u32 mode;
int err;
+ u32 val;
if (opt == NULL)
return -EINVAL;
@@ -486,7 +487,13 @@ static int flow_change(struct net *net, struct sk_buff *in_skb,
if (tb[TCA_FLOW_PERTURB]) {
if (mode != FLOW_MODE_HASH)
goto err2;
- perturb_period = nla_get_u32(tb[TCA_FLOW_PERTURB]) * HZ;
+ val = nla_get_u32(tb[TCA_FLOW_PERTURB]);
+ if (val > INT_MAX / HZ) {
+ NL_SET_ERR_MSG_MOD(extack, "invalid perturb period");
+ err = -EINVAL;
+ goto err2;
+ }
+ perturb_period = val * HZ;
}
} else {
err = -EINVAL;
@@ -504,7 +511,13 @@ static int flow_change(struct net *net, struct sk_buff *in_skb,
if (tb[TCA_FLOW_PERTURB]) {
if (mode != FLOW_MODE_HASH)
goto err2;
- perturb_period = nla_get_u32(tb[TCA_FLOW_PERTURB]) * HZ;
+ val = nla_get_u32(tb[TCA_FLOW_PERTURB]);
+ if (val > INT_MAX / HZ) {
+ NL_SET_ERR_MSG_MOD(extack, "invalid perturb period");
+ err = -EINVAL;
+ goto err2;
+ }
+ perturb_period = val * HZ;
}
if (TC_H_MAJ(baseclass) == 0) {
--
2.25.1
Technical Details
Message-ID:
<20261016040330.59041-1-taowei@kylinos.cn>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-347102-linux-kernel-netdev=dewy.ruShow 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-347102-linux-kernel-netdev=dewy.ru From: taowei@kylinos.cn (Wei Tao) Newsgroups: linux.kernel.netdev Subject: [PATCH net] net/sched: cls_flow: avoid integer overflow in perturb_period Date: Fri, 16 Oct 2026 12:03:30 +0800 Organization: Usenet Network Sender: cs_taowei@163.com Message-ID: <20261016040330.59041-1-taowei@kylinos.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2681779"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:Kj05OtQOuvwyj6cq8uN5G/An7wY= sha256:8RCWq7hA5htKJq+SLlKls9xl/KGZZVU3p/UNvIV0fz4= sha1:UpWEf3+/0OHieCsIDp5Rq8EeTwk= sha256:mUU7AemVKl5b8MhFqpZh4DD5cQui4bccrsDPb/TaYuw= 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 7BB84110451; Fri, 16 Oct 2026 07:05:54 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -0.649 X-Spam-Status: No, score=-0.649 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.25, MAILING_LIST_MULTI=-1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key) header.d=163.com 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 5kMMgN33KDkn; Fri, 16 Oct 2026 07:05:46 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-347102-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=kylinos.cn X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id 8069810D723; Fri, 16 Oct 2026 07:05:36 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1]) by tor.lore.kernel.org (Postfix) with ESMTP id 3F5223D6AF; Fri, 16 Oct 2026 04:04:50 +0000 (UTC) X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5178C3009F2; Fri, 16 Oct 2026 04:04:47 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="DJ0fKwU5" X-Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF8E22AE78; Fri, 16 Oct 2026 04:04:41 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.3 X-ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792123487; cv=none; b=M2colbPlAReXR73QLS2WmpSpDWSk58tPSJSzrQqOLUpIe5GqbVnX+HG7X2By1NYLxyT6tApdMbz4BZ1Gq5335TSAPRmk5DgjjKAUtY85T2GXkPpyTsVgIgsSnwsFlTMkXK+TmGY+k7YBu2anfSUe9lgUKOvXY0Q4tL8LVdarxVs= X-ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792123487; c=relaxed/simple; bh=dBccgCuaVzH+N1Rz9JtQ4trlumXJHxiMaEFh5SW0AVE=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=cZ8F1fDCqSuQyaovFQfkGy54+VJIcJcgFGTo9OZe1PDSKXSLaLGkqlyMXeA1lrPftOwKPQ+aoQpzpTfkQFULqy6U8T4JvvNT/zNR5uIpfscBYLmwTGPpakbO0phiO3klReRCEBx10FUMlo60A0CqorMaKgxeZE2CdyrWTuhwziM= X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=DJ0fKwU5; arc=none smtp.client-ip=117.135.210.3 X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=4b e52hP6zWTa7KhzJ+Re6k7CxAgZ28hbTTZrb39cHuQ=; b=DJ0fKwU5o3ImQNDeeT WDSGSmMdy7SiT7PGFC05iOutxAHlgN4QAJGjby2sksLWDyxlmiwyogbAmBopu1XU qkJZpcl6qfWknwpPEwUisofajMjIURRaP+acp5r0MO40TMUBTkWBOwB/09XPMSIM f8YixgMtZMYWbM6d/xxixriPU= X-Received: from localhost.localdomain (unknown []) by gzga-smtp-mtada-g0-4 (Coremail) with SMTP id _____wD3_5MzotFqa0TGAQ--.25685S2; Fri, 16 Oct 2026 12:04:04 +0800 (CST) X-Cc: horms@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Wei Tao <taowei@kylinos.cn>, stable@vger.kernel.org X-Mailer: git-send-email 2.25.1 X-Precedence: bulk X-Mailing-List: netdev@vger.kernel.org X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-CM-TRANSID: _____wD3_5MzotFqa0TGAQ--.25685S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7AF1Utw13Gw4DZFW8Zr1xuFg_yoW5JrWrpF 9rJw1rJw4kZry7G3s7Ar1kZ3Zxuw4IkFy8CF4Ikw45JwnrGF1vkw10g34SgFsrCFWrAayr JFy5KrW2yr1qyrJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jCJP_UUUUU= X-CM-SenderInfo: xfvb3tprzhxqqrwthudrp/xtbC-RTEBmrRojQvrAAA3F