🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #12997

[PATCH nf-next v3 2/2] netfilter: h323: avoid secs-to-jiffies overflow in RAS timeout

#12997
From: luoqing
Date: Mon, 09 Nov 2026 05:53
87 lines
12436 bytes
From: Qing Luo <luoqing@kylinos.cn>

process_rcf() converts info->timeout with "* HZ" twice, once for the
conntrack refresh and once for the Q.931 expectation, both in 32-bit
arithmetic.  info->timeout is a u32 decoded from the ASN.1 timeToLive
field and only checked for being non-zero, so it is remote-controlled
by both the endpoint (RegistrationRequest) and the gatekeeper
(RegistrationConfirm).

With the signed expiry test "(__s32)(ct->timeout - nfct_time_stamp)
<= 0", a wrapped product can only cut the lifetime short, never
extend it: at HZ=1000 a timeToLive of 2147484 seconds (24.9 days)
crosses 2^31, so the entry is born expired and the RAS connection
drops mid-call, while 4294968 seconds wraps to 704 jiffies and the
Q.931 expectation is reaped almost immediately.  A peer that wants a
long Q.931 expectation can already get one by sending a non-wrapping
timeToLive, so the overflow is not what extends it.

Reuse nf_ct_secs_to_jiffies() for both conversions and compute the
value once.  The helper multiplies in u64 and saturates at INT_MAX,
so an oversized timeToLive now saturates to the INT_MAX jiffies
ceiling - about 24.8 days at HZ=1000 and 248 days at HZ=100 - which
is the same maximum the peer could already request with the largest
non-wrapping timeToLive (2147483 seconds at HZ=1000).  The longest
lifetime a remote peer can force on the RAS conntrack and the Q.931
expectation is therefore unchanged by this patch.

Sweeping all 2^32-1 inputs at HZ=1000, the helper never wraps, never
yields a value that reads as expired, and matches the old expression
up to INT_MAX / HZ; objdump shows the two 32-bit "imul $0x3e8" in
ras_help() replaced by a 64-bit multiply plus cmp/cmova saturation.

nf_ct_secs_to_jiffies() is added by the SIP helper patch earlier in
this series ("netfilter: conntrack: avoid secs-to-jiffies overflow in
SIP helper"), which carries a different Fixes: tag.  Backporting this
patch alone would not build; both patches are tagged for stable and
should be picked up together.

Fixes: f587de0e2feb ("[NETFILTER]: nf_conntrack/nf_nat: add H.323 helper port")
Cc: stable@vger.kernel.org
Signed-off-by: Qing Luo <luoqing@kylinos.cn>
---
v3:
- Retargeted to nf-next.git as suggested by Pablo.
- Rebased onto nf-next/master.

v2:
- Removed the inaccurate "pinned for days" symptom from the commit message,
  as the 32-bit wrap can only shorten the lifetime, never extend it.
- Clarified that oversized TTLs now saturate to INT_MAX jiffies instead.
- Noted the build dependency on the SIP patch (1/2) for stable backports.

v1: https://lore.kernel.org/all/20261104085925.773471-2-l1138897701@163.com/
---
 net/netfilter/nf_conntrack_h323_main.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/net/netfilter/nf_conntrack_h323_main.c b/net/netfilter/nf_conntrack_h323_main.c
index 4cb1665bba02..5e900037fa6f 100644
--- a/net/netfilter/nf_conntrack_h323_main.c
+++ b/net/netfilter/nf_conntrack_h323_main.c
@@ -1375,9 +1375,11 @@ static int process_rcf(struct sk_buff *skb, struct nf_conn *ct,
 	}
 
 	if (info->timeout > 0) {
+		u32 timeout = nf_ct_secs_to_jiffies(info->timeout);
+
 		pr_debug("nf_ct_ras: set RAS connection timeout to "
 			 "%u seconds\n", info->timeout);
-		nf_ct_refresh(ct, info->timeout * HZ);
+		nf_ct_refresh(ct, timeout);
 
 		/* Set expect timeout */
 		spin_lock_bh(&nf_conntrack_expect_lock);
@@ -1388,8 +1390,7 @@ static int process_rcf(struct sk_buff *skb, struct nf_conn *ct,
 				 "timeout to %u seconds for",
 				 info->timeout);
 			nf_ct_dump_tuple(&exp->tuple);
-			WRITE_ONCE(exp->timeout,
-				   nfct_time_stamp + (info->timeout * HZ));
+			WRITE_ONCE(exp->timeout, nfct_time_stamp + timeout);
 		}
 		spin_unlock_bh(&nf_conntrack_expect_lock);
 	}
-- 
2.25.1
Technical Details
Message-ID: <20261109055309.512876-2-l1138897701@163.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-359038-linux-kernel-netdev=dewy.ru
References: <20261109055309.512876-1-l1138897701@163.com>

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-359038-linux-kernel-netdev=dewy.ru
From: l1138897701@163.com (luoqing)
Newsgroups: linux.kernel.netdev
Subject: [PATCH nf-next v3 2/2] netfilter: h323: avoid secs-to-jiffies overflow in RAS timeout
Date: Mon,  9 Nov 2026 13:53:09 +0800
Organization: Usenet Network
Message-ID: <20261109055309.512876-2-l1138897701@163.com>
References: <20261109055309.512876-1-l1138897701@163.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="283847"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:c4yioSDsCmJfUEyrTvhspSw9J2w= sha256:aVGkizThWSaHuHlj9cvlAOEb9XkPioJ8xcJ3Oprkm+o=
	sha1:g7IqYgi/stFhJbZJffvJOxsiZqI= sha256:oKXwCKF3mOedJrPCbXadkHenFduHRVFXkl+19I+RfDg=
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 9CC7D1136E2; Mon,  9 Nov 2026 08:56:00 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.048
X-Spam-Status: No, score=-3.048 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, FREEMAIL_FORGED_FROMDOMAIN=0.001,
	FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, 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 c0giwH-DU59b;
	Mon,  9 Nov 2026 08:55:54 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-359038-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=163.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 1EC0E1136D9; Mon,  9 Nov 2026 08:55:45 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id DCDDD68E5F; Mon,  9 Nov 2026 05:54:54 +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=1794203694;
	b=gD/L5rU4pWqMcRcPzyyBxgfF4dNuPcsqTTMPZfAV5TiSm2DvBSE5yQwtb/nWNw6fEX/2
	 2d/mnYzmxq9wz5hbBHqCEdgri5Cx5C4pB1Yoj7STuAR2bplrsax4eMke9VzE1T5cTfIia
	 U5EGkFXYq1vYfOpW+akz6OyyYSDEkSzeWznfYHGqXxyinS1/Y/MoqnfRBYqcH1uVa8Ob7
	 oc60U2VIMkCElBkhLO7TrvjToycFHoDduGuKVEvtmoisReqDmRPfa9fGlYnOdSKTmnN8f
	 p5x/U9kAr6NgF2I4n/4iGMeWdTFZQxMZE5JLQEHmD+JlU0Apv5VegiZ7IW28WqJYsKA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794203694;
	h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:Received: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:X-CM-TRANSID:X-Coremail-Antispam:
	 X-CM-SenderInfo;
	bh=5+odt879/va85pZrodnnc/2GCO8t5B5tuWVaCuFrTbg=;
	b=LKdzvndKQNOyXS3x49XsjZwPiXIG9YT30Zlba4+zqF2kbjVfV4wbwP8GFGTbE/lPUbz9
	 ar3/6JvW9DDFFHUkfFEtcHN4I2d55Q5LSvKwflVL/4VYeC2fe0fZkY+C/HWoqyZ5cOpxC
	 RB9ixXvK664p1KZTw41rdLZ84qt5kUGRLMw0FD4DGC6Z349mSreSw9CJY6aruL2i2JGCo
	 HecipV5BcZRnqqXcdVZ0T5nc+O8DDvucN97AFxuX2J+7hF4PuXQvuVaPZbo9VgjQWQmaD
	 jQL2ARGJn2EbHfjgcmGfpuxJfTRXn2Six5SXo+I60G8VBn+mStInurHu1BSO3B0f7kg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=CUyxPMPk;
	dmarc=pass header.from=163.com;
	spf=pass smtp.mailfrom=163.com;
	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 B6A32606A333;
	Mon,  9 Nov 2026 05:54:54 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=CUyxPMPk
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=117.135.210.5
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1794203678;
	b=c/VxAYttGX9g5ZeFdb/JCnLFSlcxcj77tOaNMPJ1XUW8Gsvg1BtSMzI6oRKZCbhpN6Nr
	 yY7Y/QvwVo6/h1biS/da5aKoGfqUWhKsX5UIqp09XeXpKGSLulrSWk+EeHg4sMPInrn9L
	 cxBo/D9GUVqQq2o05FFxUdhO0teDmRz57MSxtbOll2xHktkTvXJzNdej54/fEVg8qVP3V
	 NXDlqqEGKKA5fK7SIqJ1PY47JQbQe2Ds9Nnv0QrPCWaHe2usRvAYX5G3hNPHHzq358bya
	 ukC5s0TMQ6JwxYA749YMLYcZT7Aet+0Y7xKuN/3iT7odI8CmI3znTIZ3jPfK/ezopLw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794203678;
	h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date:
	 Message-Id:X-Mailer:In-Reply-To:References:MIME-Version:
	 Content-Transfer-Encoding:X-CM-TRANSID:X-Coremail-Antispam:
	 X-CM-SenderInfo;
	bh=5+odt879/va85pZrodnnc/2GCO8t5B5tuWVaCuFrTbg=;
	b=AnfO8Z2ln4PMC02rBFJw3l8qWt9MsN0Kbp63FcR0lLK6jY4o8fVV/GCiz+d0GH5uTBrf
	 V1uaEqHtu/wCmyBEfMLOOUO9+hYSiGD9QFLXpfUJ7Iz9x94qkDAbLzPGA7+B1Zu2UMzqt
	 z9dUx4OLT5JmcW8qAuCLeFmQKYSBvyxZZT+5g8877fhaRhOpJvE0fQD2QBDdj7bcov4E5
	 M6lmeypDsyQCJ8FGxcSk/JKo7710IqEGCY+gELYiQMrzLfnpRtBzRDzhkqCTqrP6ObkaX
	 2DIHYyRrVhVWUpqtI1WGPdykUlWpwdC8n0QhpaEC0jyCsGsWZHFlQ1ihyrMU8Nox61w==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=163.com;
	spf=pass smtp.mailfrom=163.com;
	dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=CUyxPMPk;
	arc=none smtp.remote-ip=117.135.210.5
X-Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.5])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 942AE606A321;
	Mon,  9 Nov 2026 05:54:34 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 942AE606A321
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com
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=5+
	odt879/va85pZrodnnc/2GCO8t5B5tuWVaCuFrTbg=; b=CUyxPMPkyQFm4aovwP
	QcizX/Eka5iPuA+guUfKBixGWjqRyAJTszsd9HodnqMg8DE+6ZSy9in96dtz1w1E
	WWCJ6HgO1unXMg5KtE7VyvSPpfpz72/sTNjNc2aELEdFpN5yDh0yEd1XiHzPTCts
	2vwVCPpAkWyIxTY2P/h1Xi/Y8=
X-Received: from localhost.localdomain (unknown [])
	by gzsmtp5 (Coremail) with SMTP id QCgvCgCnH57FX_FqLONMEw--.40637S3;
	Mon, 09 Nov 2026 13:53:11 +0800 (CST)
X-Cc: Phil Sutter <phil@nwl.cc>,
	"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>,
	Patrick McHardy <kaber@trash.net>,
	netfilter-devel@vger.kernel.org,
	coreteam@netfilter.org,
	netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
X-Mailer: git-send-email 2.25.1
X-In-Reply-To: <20261109055309.512876-1-l1138897701@163.com>
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
X-CM-TRANSID: QCgvCgCnH57FX_FqLONMEw--.40637S3
X-Coremail-Antispam: 1Uf129KBjvJXoWxGFyDGF4kXw4UKr47GF45KFg_yoWrGw1DpF
	W8K3srKw4kJr4Yk3W093WkCFWDZws5Gay5Crn8G3yrCwnxJrsayFWfKF9F9a4UJrs7Wr4j
	qF4jqw17C3W0yFJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2
	9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jbdbbUUUUU=
X-CM-SenderInfo: jorrjmiyzxliqr6rljoofrz/xtbC3QcgZGrxX8e4-wAA3a