Article View: linux.kernel.netdev
Article #18584Re: [PATCH net v3 1/2] tcp: fix shift-out-of-bounds in SYN-ACK retransmit timers
From: Eric Dumazet
Date: Wed, 18 Nov 2026 15:05
Date: Wed, 18 Nov 2026 15:05
75 lines
12253 bytes
12253 bytes
Le mer. 18 nov. 2026 ร 15:43, Jiayuan Chen <jiayuan.chen@linux.dev> a รฉcrit :
>
> req->num_timeout counts the SYN-ACK timeouts of a request and is used as
> a shift amount:
>
> /* tcp_reqsk_timeout() */
> u64 timeout = (u64)req->timeout << req->num_timeout;
> /* tcp_fastopen_synack_timer() */
> req->timeout << req->num_timeout
>
> Once it climbs past the width of the shifted type the shift is UB. Seen
> with tcp_synack_retries=255 and a peer that never completes the
> handshake:
>
> The sysctl is not needed: TCP_SYNCNT=127 on the listener gets there
> too, and the TFO shift is 32-bit, so it is UB from num_timeout 32.
>
> The value can also wrap to 0 before the shift count is out of range,
> which arms a zero-length timer. E.g. with HZ=1000 and req->timeout ==
> 1000, (u64)1000 << 61 and (u32)1000 << 29 are both 0.
>
> num_timeout is a 7-bit field. Once a retransmit limit is above 127 the
> "num_timeout >= limit" check can never be true, the request is never
> expired by that limit, and after the field wraps to 0
> reqsk_timer_handler() decrements queue->young again on the next expiry.
>
> - split tcp_reqsk_timeout() into tcp_reqsk_timeout_sk() and cap the
> shift at 32 there, same as inet_csk_rto_backoff() in the next patch.
> req->timeout << 32 is already above tcp_rto_max(), so the clamped
> result does not change.
> - cap max_retries / max_syn_ack_retries at MAX_TCP_SYNCNT (127), the
> largest value the field can hold. The sysctl range is left alone:
> narrowing it would make setups that write 128..255 fail with
> -EINVAL, and the caps are needed anyway for TCP_DEFER_ACCEPT and the
> TFO "+ 1". 128..255 now act as 127.
> - cap the TCP_DEFER_ACCEPT conversion in secs_to_retrans() at 127 too;
> larger values kept an acked request from ever expiring. getsockopt()
> now reports at most 14527 instead of 29887 seconds.
> - route the TFO path through the same helper.
> - document that tcp_synack_retries values above 127 act as 127.
>
> Found by checking sysctl ranges against their users. Reproduced in a VM
> with UBSAN: tcp_synack_retries=255 and tcp_rto_max_ms=1000 on the
> server, and an iptables rule dropping the final ACK of the handshake.
> The splat shows up after about 64 seconds, and is gone with this patch.
>
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Fixes: e6c022a4fa2d ("tcp: better retrans tracking for defer-accept")
> Cc: stable@vger.kernel.org
> Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
> ---
> v2 -> v3:
> - drop READ_ONCE(req->timeout), cap the shift at 32, reuse
> MAX_TCP_SYNCNT, simplify the doc text (Neal)
> - changelog: mention TCP_SYNCNT, the wrap to 0, why the sysctl range
> is not narrowed, how it was found and tested (Neal)
> - add Fixes: 1da177e4c3f4, the shift was already there
> v1 -> v2: reworded the commit message, no code change.
> v2: https://lore.kernel.org/netdev/20261026123244.239766-1-jiayuan.chen@linux.dev/
> v1: https://lore.kernel.org/netdev/20261023064915.401112-1-jiayuan.chen@linux.dev/
> ---
Note this might conflict with Chris series, which changes __tcp_set_rto():
https://lore.kernel.org/netdev/20261118005048.53393-2-mason@kernel.org/
No big deal, just FYI.
Reviewed-by: Eric Dumazet <edumazet@kernel.org>
Technical Details
Message-ID:
<CAL4Wiiqo2f7WxE0uccUOvGyLMhu66cwYWSFS1ZCQU=Lkaxp1Bg@mail.gmail.com>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-366214-linux-kernel-netdev=dewy.ruReferences:
<20261118144249.358481-1-jiayuan.chen@linux.dev>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-366214-linux-kernel-netdev=dewy.ru
From: edumazet@kernel.org (Eric Dumazet)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v3 1/2] tcp: fix shift-out-of-bounds in SYN-ACK
retransmit timers
Date: Wed, 18 Nov 2026 16:05:03 +0100
Organization: Usenet Network
Message-ID: <CAL4Wiiqo2f7WxE0uccUOvGyLMhu66cwYWSFS1ZCQU=Lkaxp1Bg@mail.gmail.com>
References: <20261118144249.358481-1-jiayuan.chen@linux.dev>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
logging-data="2624299"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:syakqjOWuvC3821RRg8X3Sy0/ec= sha256:sY2/wGszMaVTq7r2jSwD25hXkS1os+gil97kN0Ae4h4=
sha1:l0hmgzHkhhp3JYZ+fhgJeDUl6FA= sha256:UPRaeOjC5NKkqwAlLqibYDSG9Y3LzVxJ54GQ9274pyk=
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 EB4741152EB; Wed, 18 Nov 2026 18:06:10 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 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] 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 oZF7Es5W_HAD;
Wed, 18 Nov 2026 18:06:06 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-366214-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 D33301152D9; Wed, 18 Nov 2026 18:05:57 +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 CEE2238154; Wed, 18 Nov 2026 15:05:22 +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=1795014322;
b=V+04pi9YKQc9gq2E91x/U00mi+4fP0goQt/smFs2MiFHqlKTMsEJLcSTA3pv46It2P6g
Pk2xV+eDcGw+Pgs6OT5YKkfiFlrBx7TTeMYH+FyO+Tjl4lzDT3sKJqcR4jzagnqTBXJAG
+8DwiqXzD+4pB5hVt3dc3FAjnNZtTuDBayyx0hzrCDcNX1VAK8CTUtpgjGMF9mC8eKyLB
/fdHtFXdZzpvN+jEFAzqS1HK8Rh7eOYuDm7Ct75Qrr7R42eRZp5GDkvymdqmvGtWHTsQJ
GIiOa+0XBEev0rvtYq4mvatgKeWf6DgznZh0SdaBD1+0sQDoZDevCPD7z6E+RPgq2aw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1795014322;
h=X-Original-To:Received:Received:DKIM-Signature:Received:
X-Gm-Message-State:X-Received:X-Mailing-List:List-Id:List-Post:
List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence:
MIME-Version:References:In-Reply-To:From:Date:
X-Gmail-Original-Message-ID:X-Gm-Features:Message-ID:Subject:To:Cc:
Content-Type:Content-Transfer-Encoding;
bh=Lz1QdUMe27LCdf6G1Y1DFNn2GN9+azDTK9VSxTlk49k=;
b=FO83CKqEec35cCfp8KZ2SSZ8fT2v1tsGaU59CD2DrNzrTZd2knTy3Yzx6KVgK2GTNGW8
/k+Ajv05jC5npyS9Ia+cniPU5nHgtPaYYPX85qdEhqKLi83WCauzNjM/Rs8oLvlS+BRD1
V1avH8EQJ15UmlO1emgG50VTfdHtKPckzomVWAq/gKooiMPK/A+pLzT9ypuwxGvIw4ATV
vDAkpXiwHKknVvxvUP+bb2SykK+ApkDAqlkABKScvMyU27uMHTI8r5+08TBKslHtk9LGH
fBQOxq3EJUTRur0sUxa14LAgf2PC6ja/MQa7l57dnj2tHa7+UbLroPGs+q2xFpFKqjg==
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="JG/Pgo8g";
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 E48C760A2603;
Wed, 18 Nov 2026 15:05:21 +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=JG/Pgo8g
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=1795014316;
b=n8et8ni/r6lvzrYzsLxSWBZAZceRMVH7bvFqmVEFGNlNUhNVQUeg9aG95TY6OXjGAKoB
3ka4hf/2IK6UAfTMTvTmHbLWREm731kOqffFGFG2fyWLXouUAWTrv1s+dcoENGomEj2pp
2mRMY94omRTYXnjDKtcTvzlMsZTi6/x7AR8Yi0PZppbkb+0JOO8pNj/0vfmVZzueVlrXt
Ipj4CE4Shu4TcAZ0uxTTaprYGqejJHfWTAkMnfLEmSb0q0cUY8zOGoIpNXAUdzLAOPUnx
Lu/O/EtyBxkY1FbPsYzP5CqcRJOIjIbAwWimBvhPrTy0MNkn1DLhSbJWYm8kKa9ekoQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1795014316;
h=Received:DKIM-Signature:Received:X-Gm-Message-State:X-Received:
MIME-Version:References:In-Reply-To:From:Date:
X-Gmail-Original-Message-ID:X-Gm-Features:Message-ID:Subject:To:Cc:
Content-Type:Content-Transfer-Encoding;
bh=Lz1QdUMe27LCdf6G1Y1DFNn2GN9+azDTK9VSxTlk49k=;
b=rVatHFMmgHWgokODV1zeMnlQiYAMT+zSfdWwjrR6pnt9ngQe4HrmrH/BJ+ekI1jZxZZo
ykXbdSWYMmMQftc3JQIh2IQGrEBEOdEZ/AogKN4vs62eX9U57r2frOOG//AWtivsob2Qz
Cww+8XJ0eGoZVRplUD43Y03CznlgMkD7HpLQhkhESgsmVISMJXJv0jlIrbBjf+g1T0HrB
69NP30UAoqI598tswbXHM+YAzn3yx3aRSp27Wke4bVNEiP3ZzlEHq3L6H46aWDnipCu6D
4yp5eau3lKeeK7Jcp3/DKiovl7O/l7+CftEuTU2wVNBQ66F7TilFEnE2HvLxzavvTtw==
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="JG/Pgo8g";
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 0C962606A333
for <netdev@vger.kernel.org>; Wed, 18 Nov 2026 15:05:16 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id D841D1F000C8
for <netdev@vger.kernel.org>; Wed, 18 Nov 2026 15:05:15 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
s=k20260515; t=1795014315;
bh=Lz1QdUMe27LCdf6G1Y1DFNn2GN9+azDTK9VSxTlk49k=;
h=References:In-Reply-To:From:Date:Subject:To:Cc;
b=JG/Pgo8gq5RRuSQIIC/oWtlyuaLjVTXUMApB/FzwjyuvGbjJ5wBxWtqTaD1s8LXYM
DaE7qoKV2BpLPGJjGusUhCLmcvgDyoUv92i3ZAfk3NbOE+TaII+s8jR+qF2JjUfeD+
SXsjgAHOb4e90orULfw4au9xxURZzyWuHIsQAYMPjf/sdL1vDGsW4maYFzaEXEwslZ
b9kIqgXfcoRZH43QOcECH1OBRK6d3ybxEhdIsU2AFSfanldRpJmKJ6EToi2cAT+zUn
gvjnaLE4wcVQRzOAN07fTxCsLqoUoZceIezuoMglooKc2Xgw9+9gwBkXbKFjPBzxjY
AkfJkTINQyoag==
X-Received: by mail-oo1-f41.google.com with SMTP id 006d021491bc7-716b58a4365so623963eaf.3
for <netdev@vger.kernel.org>; Wed, 18 Nov 2026 07:05:15 -0800 (PST)
X-Gm-Message-State: APuU4Z8b84qaxap9dg/w4el2LHSva6ov9BB6mwXJmNy+Yh9NaOp+Ldct
dioPvgN4iKE6V3XCi4aml5601pXbDZc0YmVL+WTT0XcJ9a9T6SViuMgas3E4QjEs3pNWMxCXuGj
3Kck7MVsZVrUVY+jpxpCLj1DfHkaMn2I=
X-Received: by 2002:a05:6820:c3c8:b0:717:da:ba3e with SMTP id
006d021491bc7-71b1843987dmr1511462eaf.19.1795014315202; Wed, 18 Nov 2026
07:05:15 -0800 (PST)
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-In-Reply-To: <20261118144249.358481-1-jiayuan.chen@linux.dev>
X-Gmail-Original-Message-ID: <CAL4Wiiqo2f7WxE0uccUOvGyLMhu66cwYWSFS1ZCQU=Lkaxp1Bg@mail.gmail.com>
X-Gm-Features: Aa3M54piHjPwp_y_R61vPpndNd95o_tqH2TJpVGd8jo1PrAJ9sbocGNqFSQPXG4
X-Cc: netdev@vger.kernel.org, stable@vger.kernel.org,
"David S. Miller" <davem@davemloft.net>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>, Jonathan Corbet <corbet@lwn.net>,
Shuah Khan <skhan@linuxfoundation.org>, Randy Dunlap <rdunlap@infradead.org>,
Neal Cardwell <ncardwell@google.com>, Kuniyuki Iwashima <kuniyu@google.com>, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org