🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #18676

Re: [PATCH net v2 4/5] tcp: clamp the samples in tcp_rcv_rtt_update()

#18676
From: netdev-bot+sashiko
Date: Wed, 18 Nov 2026 18:23
106 lines
11789 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] The fix is incomplete.
- [Low] The comment on TCP_RTT_MAX_US in include/net/tcp.h (lines
  167-172) still says it is the 'Max RTT sample for tcp_rtt_estimator()'…

--

tcp: clamp the samples in tcp_rcv_rtt_update()

This patch clamps the sample passed to tcp_rcv_rtt_update() to
TCP_RTT_MAX_US before the shift left by 3. The goal is that a
receive-window fill time of 536.9 s or more no longer wraps in u32
arithmetic. The commit message says this covers both callers of
tcp_rcv_rtt_update().

> diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
> index 69e038b9389ae..d9a66a1342efd 100644
> --- a/net/ipv4/tcp_input.c
> +++ b/net/ipv4/tcp_input.c
> @@ -857,7 +857,11 @@ void tcp_initialize_rcv_mss(struct sock *sk)
>  static void tcp_rcv_rtt_update(struct tcp_sock *tp, u32 sample, int win_dep)
>  {
>  	u32 new_sample, old_sample = tp->rcv_rtt_est.rtt_us;
> -	long m = sample << 3;
> +	long m;
> +
> +	/* Keep sample << 3 and the smoothed estimate within u32. */
> +	sample = min(sample, TCP_RTT_MAX_US);
> +	m = sample << 3;

[Severity: High]
Can a long window-fill time still wrap before it gets to this clamp?

In tcp_rcv_rtt_measure(), the sample comes from tcp_stamp_us_delta():

net/ipv4/tcp_input.c:tcp_rcv_rtt_measure() {
    ...
	delta_us = tcp_stamp_us_delta(tp->tcp_mstamp, tp->rcv_rtt_est.time);
	if (!delta_us)
		delta_us = 1;
	tcp_rcv_rtt_update(tp, delta_us, 1);
    ...
}

That helper narrows the s64 difference to u32:

include/net/tcp.h:
static inline u32 tcp_stamp_us_delta(u64 t1, u64 t0)
{
	return max_t(s64, t1 - t0, 0);
}

So by the time min() sees an interval of 2^32 us (about 4295 s) or more,
it has already been reduced modulo 2^32.

For example, a 4300 s window-fill time arrives here as 5,032,704 us
(about 5.03 s). That passes the 120 s clamp unchanged. With win_dep=1 it
is stored when old_sample == 0 or when m < old_sample.

The only writer of rcv_rtt_est.time is the new_measure label in
tcp_rcv_rtt_measure(), and nothing resets a pending measurement when the
connection goes idle. The window-completing segment could arrive after
more than about 72 minutes of idle time or a slow sender. Would that
still hit the case the commit message describes, where "the wrapped
value is kept whenever it is below the current estimate", only with a
higher threshold?

Without timestamps the win_dep path only lowers the estimate. A bogus
small value would stay for the life of the connection.

Would it be better to clamp the 64-bit delta in tcp_rcv_rtt_measure()
before it is narrowed to u32?

[Severity: Low]
This isn't a bug, but the comment on TCP_RTT_MAX_US in include/net/tcp.h
still describes the constant only in terms of tcp_rtt_estimator() and the
RTO:

/* Max RTT sample for tcp_rtt_estimator(). srtt_us holds 8 times the RTT, and
 * mdev_us and rttvar_us up to 4 times its deviation, all in u32, like the sum
 * in __tcp_set_rto(). A larger sample could not raise the RTO, which
 * TCP_RTO_MAX bounds.
 */
#define TCP_RTT_MAX_US	(TCP_RTO_MAX_SEC * USEC_PER_SEC)

After this patch, tcp_rcv_rtt_update() also relies on 8 * TCP_RTT_MAX_US
fitting in u32 for rcv_rtt_est.rtt_us, which is not an input to
__tcp_set_rto(). tcp_rtt_tsopt_us() also uses the constant.

Could the header comment be extended to cover the receive-side users?
Alternatively, a static_assert could check that TCP_RTT_MAX_US << 3 fits
in a u32.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118155144.18393-1-mason%40kernel.org
Technical Details
Message-ID: <179502618349.3136.1063676165373741119@kernel.org>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-366334-linux-kernel-netdev=dewy.ru
References: <20261118155144.18393-5-mason@kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-366334-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v2 4/5] tcp: clamp the samples in tcp_rcv_rtt_update()
Date: Wed, 18 Nov 2026 18:23:03 +0000
Organization: Usenet Network
Message-ID: <179502618349.3136.1063676165373741119@kernel.org>
References: <20261118155144.18393-5-mason@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2663222"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:LfZ5hx2LSp+eE8b/6DaektmuNro= sha256:MwHCmqsNcCQfknvRsysvl9vhRWHGRDXrBGJhJKyP3Qk=
	sha1:GwfFl+CbK3gxilbxjZcjcswQ5v8= sha256:h4EKvxdAIWgQNVjlmTsjkynQhoTJ3aoZx51Sz4Z8YgA=
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 0BBE6115363; Wed, 18 Nov 2026 21:24:24 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	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 (2048-bit key)
	header.d=kernel.org
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 Fu0D6kNvmif7;
	Wed, 18 Nov 2026 21:24:20 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-366334-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 1E5E3114CB4; Wed, 18 Nov 2026 21:24:12 +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 14C33C68DD; Wed, 18 Nov 2026 18:23:30 +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=1795026185;
	b=5fdHUjR46ciZkSd2u3IWTgh1FiccX7odZxqkayI8AWLK/pL5GeGJ1mBjUaqS1sEUQBxv
	 BaMHwzf6zgAOFBe2hHCAGCpNfI0CQ9yPVrlJz0Xwemyz4MPwuGW4DmFFhe9yOeciKs5vs
	 cHI5JIK8MKxOl6QP1FST9uBoHVd8C131SFhOF695m2MLV8/c6idcmOGAfXACRsBruc7sX
	 PaNystTtrhlQwodCf/3RfMPqdV1j0MpklfbHEH2ZJ6v21aVAEZPm3iI812aioyhGQosXx
	 vmB/pfUKbt6aFTlkEZu6ovSCLgbmRqQO8j1Lt2EGDH7UWwTu5hvxGqaMEREvhnG2kBA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795026185;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=1BLuMdvTJ1JeEYJY7PkA8OaRV4HThP5dbZvdIrOXxco=;
	b=mDwuYu+hqB7GLnI7zDBfBhH7Rha4SgX/rOueSptWF+28MNl1uQ9SY9Q3I4JggWbIBAzl
	 DoVWiIBxASdzC4MgQICqlqHA/CHxlHqP6C2p7s4fXy4+IPyyHorxWsi7Rcl0XCpDsQHVu
	 eN3VeHH4RzmOni8cZ9HQ0CflpSZE2WDNCgC70otr67Keb6OjHOhep7rjSjuHQIf/iIi2p
	 KrJYROnY2sjNqA+TbSTYV+qlcrEHOUiKWYCsnJa32PSzGu+QSgYy5qChlLL95stUbsz8L
	 DZ72BLkhDUhLt8pQLqAlEevPuqDbC48c4VoX3QOA8imMsIrp/7+2Vzjem6ZyOSptEHw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Fg8QpE8D;
	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 9CD9C60A383E;
	Wed, 18 Nov 2026 18:23:05 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Fg8QpE8D
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795026184;
	b=LyzhBGz0S/40KjLCw+BKySn2DnhdrkjONUQ4+bSfhKVc0SYeNdC7fGIjG4b0gfi1fN6B
	 R0VeEQy5uAdy9nLvr3tMy1cdHelDTh7DmAvnCkAr6noTvLZe8ZX5PbnKlw2gisCdP+GgL
	 CmLf+2fg++A6V+e0LrSRUGCMC6YEtd2DJmDOwVZgVh7R3ppm4OAeMXCsbKu+t5DOVpawR
	 V5Y8lw+vvxZhZfE3+mZPtY2pvgQmU21Vvt9VfAWQbxEJD55GH5owteiqEgG4EasTwIVMm
	 NeBnHrF1v+n5Qqml5oBUJJsnEBBwKsmDxqw2LH1K/wqLuSGSaI5c3j94EoKs3vQDD0A==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795026184;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=1BLuMdvTJ1JeEYJY7PkA8OaRV4HThP5dbZvdIrOXxco=;
	b=Uo4RHoC0hgJvmCj+UEgQp+ejwvsVKHAg2sZ/3tsOFlPHS3WJVVjw5CLLOzH0dfYdkLH/
	 K3Ml1BZQCZzKrX/hH6gXn2NpGZQag1TjJu4eEN04r8TI9M+ideAhjGOO5ui825jIqgZu5
	 pO1cGOFbo94L4tdTGcKRkFWfDZw0hNiVw8xlhVy2q+FVHCRKIY2zduCsBQZc35i1+gDIg
	 04mOZd/68X6C7umJQpFGDJ92s4zmgK+b/H+iDrbJIKzhwJ+z1lOAfyH0dcMsov1+vA7hi
	 183Jsm0QDaswL0SGGU9Lh27rez66Id14u5//SSpyQZc4bogtFVVnGXRJkCjfotwafjA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Fg8QpE8D;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE58760A260C
	for <netdev@vger.kernel.org>; Wed, 18 Nov 2026 18:23:04 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id E0F151F000CA;
	Wed, 18 Nov 2026 18:23:03 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795026184;
	bh=1BLuMdvTJ1JeEYJY7PkA8OaRV4HThP5dbZvdIrOXxco=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=Fg8QpE8DIiQzDSw7eGq0ChdNF/BTPr5uKYZ6yfoxkKRkPG+HHpiqLMtxOqLM8VTkJ
	 KZq529Fa+EH2m2yj03DhIl0NBrUjo/ZNEtaanJaWt3sd17nqyEeHZzHLZGIFNuJrg/
	 UNhgqPYWtUl8xKJFyjFZ46Mp9c26rTulQEsFZMevYrCQKAkoqpqIkliN6FihY4GPaB
	 WLhbMw8A/heeVGc8agblO8i+Np1/RFqUxkw5WlBLWH7OZiUco0qEl2meWYmAEdJFu4
	 9HX7rViP9zskpkhdKEtuOJF419wAd7vJBR3/rGdeCShWqxPXm6rvhOgbMb410Z3ZRW
	 6eCbbV5rfqfiQ==
X-Cc: edumazet@kernel.org, ncardwell@google.com, kuniyu@google.com,
 davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org,
 willemb@google.com, josef@toxicpanda.com, netdev@vger.kernel.org
X-In-Reply-To: <20261118155144.18393-5-mason@kernel.org>
X-sashiko-severity: High
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