Article View: linux.kernel.netdev
Article #7483[PATCH net v2 2/2] tcp: fix shift-out-of-bounds in inet_csk_rto_backoff()
From: Jiayuan Chen
Date: Mon, 26 Oct 2026 12:32
Date: Mon, 26 Oct 2026 12:32
75 lines
11343 bytes
11343 bytes
icsk_backoff is incremented by tcp_retransmit_timer() on every backed-off
RTO with no cap of its own, and by tcp_send_probe0() up to tcp_retries2.
It is used as a shift amount in inet_csk_rto_backoff():
u64 when = (u64)icsk->icsk_rto << icsk->icsk_backoff;
Once it climbs past 63 the shift is UB. Seen with tcp_retries2=255 and a
silent peer, when an ICMP host unreachable goes through
tcp_ld_RTO_revert():
UBSAN: shift-out-of-bounds in ./include/net/inet_connection_sock.h:258:40
shift exponent 73 is too large for 64-bit type 'long long unsigned int'
Call Trace:
<IRQ>
dump_stack_lvl+0xc1/0xf0
dump_stack+0x10/0x20
__ubsan_handle_shift_out_of_bounds+0x1d1/0x390
tcp_ld_RTO_revert.cold+0x16/0x92
tcp_v4_err+0xdb3/0x13e0
icmp_socket_deliver+0x1a7/0x390
icmp_unreach+0x2dd/0xe50
icmp_rcv+0x93e/0xe30
ip_protocol_deliver_rcu+0x36b/0x3e0
ip_local_deliver_finish+0x37d/0x620
ip_local_deliver+0x165/0x1d0
ip_rcv+0x284/0x320
__netif_receive_skb_one_core+0x16b/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
__irq_exit_rcu+0x13c/0x220
irq_exit_rcu+0xe/0x20
sysvec_apic_timer_interrupt+0x92/0xd0
</IRQ>
The orphan check in tcp_probe_timer() calls the same helper. On x86-64
the oversized shift count is taken modulo 64, so an orphan that should
be dead can be seen as alive, and tcp_ld_RTO_revert() can end up with a
smaller RTO than intended.
Cap the shift at 32: any non-zero icsk_rto << 32 exceeds TCP_RTO_MAX, so
the min_t() result is what the unbounded math would give. The
ilog2(TCP_RTO_MAX / TCP_RTO_MIN) + 1 bound of tcp_probe0_when() does not
fit here, as icsk_rto has no TCP_RTO_MIN floor the way tcp_probe0_base()
has.
Fixes: fcdd1cf4dd63 ("tcp: avoid possible arithmetic overflows")
Cc: stable@vger.kernel.org
Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
---
include/net/inet_connection_sock.h | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
index 903499581db7..562e12033a5d 100644
--- a/include/net/inet_connection_sock.h
+++ b/include/net/inet_connection_sock.h
@@ -255,9 +255,10 @@ static inline unsigned long
inet_csk_rto_backoff(const struct inet_connection_sock *icsk,
unsigned long max_when)
{
- u64 when = (u64)icsk->icsk_rto << icsk->icsk_backoff;
+ u8 backoff = min_t(u8, 32U, icsk->icsk_backoff);
+ u64 when = (u64)icsk->icsk_rto << backoff;
- return (unsigned long)min_t(u64, when, max_when);
+ return (unsigned long)min_t(u64, when, max_when);
}
struct sock *inet_csk_accept(struct sock *sk, struct proto_accept_arg *arg);
--
2.43.0
Technical Details
Message-ID:
<20261026123244.239766-2-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-351894-linux-kernel-netdev=dewy.ruReferences:
<20261026123244.239766-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-351894-linux-kernel-netdev=dewy.ru From: jiayuan.chen@linux.dev (Jiayuan Chen) Newsgroups: linux.kernel.netdev Subject: [PATCH net v2 2/2] tcp: fix shift-out-of-bounds in inet_csk_rto_backoff() Date: Mon, 26 Oct 2026 20:32:39 +0800 Organization: Usenet Network Message-ID: <20261026123244.239766-2-jiayuan.chen@linux.dev> References: <20261026123244.239766-1-jiayuan.chen@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="1304613"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:+VTNI/TzsQXjkbHfPpLCGHtHAfA= sha256:vrmKAY9W4lWZL75dk3bVzRvuV3PnGCJoLkhOe3x5zL4= sha1:OBBcN1RDTxvzTMeOQA34yz6SrTU= sha256:5zII4m1EONk0NS7fJ1+vQgc6HqACmZ/+fb8RkAgyqIA= 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 EC128125BA6; Mon, 26 Oct 2026 15:37:01 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -2.051 X-Spam-Status: No, score=-2.051 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] 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 4LYN_wBcEBDb; Mon, 26 Oct 2026 15:36:58 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-351894-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id 6FB36125BA4; Mon, 26 Oct 2026 15:36:49 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 655B72DC49; Mon, 26 Oct 2026 12:33:09 +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=1793017988; b=gHuR/yz7Khds+owC2BPdCd7KwNFrfrLoOALrk0NEgnb3CIRJapsBHXmbrBlVsyki6mIa 3TIru6X2DJF3g5Qli3pEvOojb3RtzVb8rcUo7A8DbqqpM+hk2V+oN5jmP8Q/pTuRri/Av jw/BVw0i0mKvnDNyXk8QzGVVwHOOIXgoLmNNrS6b/ka9eHozdegSTVaSJDcTdSqPUuXIw nUEYaVRwT4zvWVnnLZ13D8J25cXsWumbmzMJ55PazQ0fXyfGZE3ZRJ/fTLXTeDN/3SuVw FJrAV8qvP3wv0CbwxIyZXcOBJRdDMdkXMsPOayGLyT2N+3V1PI5wxamjlTUJKz5+Sww== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793017988; 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=7mgiolJC8r3eZzy98FWtx4U1AHXNmN+96u0Ij+bgNDQ=; b=mKiJuiSr1Sdk/ExwNPnn1VnmME7bYiN8TZJheK31iSNaKomuQuHh39OqfVWalgNdR+hA +2aBHsTsJp5Mr+zr671e0l9KlPo14Fwavw76QTbgj8e0ex7nc2z1TCz1sJggnp+4Sy8lG aSUSGwi6UFvROClt1DubKV65hNd+Th5Ar55LLp5QC4YtGMYdkQL4uX/iRwjbk7usuBubJ MMxzeYY4zQMRAdryc9lXpvLJVB5ZpCjJ6bfDdRLKde7ziPKDe2n/pLa2BscNGI0atCm5g XqHySFfHsGsvhMNaFZ2B+yd5ekQPCnam41PBYCUXi59PPQwR6yXaBDvApGLh9aptp4Q== 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=LKMYI4Q7; 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 39F6E606A337; Mon, 26 Oct 2026 12:33:08 +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=LKMYI4Q7 X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.203 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793017987; b=HB81VjpiQaXpKfbJsCoWkmQX53EADdN6m93GLvelnIr6fI+RwKJupiWRe7CrPe47zv/y /VvAyeZ0zVXkB4fPJ+M9zmVBzFN1zegJSz6OCEwuuZimUMUb9AmMRgvv85gUrwHYHbEPH UIT6lAyrCw4WYq8UbF62RQgyyTRlUrgDqLW7vBX09qs3yA4WOSvmsQr89jEJeev10SZyX bf9OmBh6zy9DLEiRcreJTs396ogawLi8QFbtTkDn1sgDDiNdey0aWjDnFLE9yV8v/ka4E YV3n/sMwSG7dT1CAKwFvJKJ2t4lDiyYvrzm+OiZhyZE8EV6eTzXT0MkDIpFRoV0K63Q== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793017987; 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=7mgiolJC8r3eZzy98FWtx4U1AHXNmN+96u0Ij+bgNDQ=; b=h98R1PdM0XSHw78YEZsSvuNLCk4I8Ou7z9amoAuJhLB/QU4x6lDHXLIbKCxmsK8HjOUT sf0fMRZgSTggEUSRrRRGiPEuLGEOji5V6UZvvNmKEgUbVYZsrOtfOLmpRQpsRD8isDrW0 AQ/dlxeXm5RWPWbt5ewihDfdfVWRSIuzJ4QQquMQ05UUIyaAlLHj/ZnO96Hfs44hfX/Jc rGt9yjc6igfXnkDh1J7aOa/sCGIIDBajLa6V6Bx+EJQx0K988unt3gz6NrLA+oFy6ZQLx /0kJQMDavgw9UR4EREp00nNCd9nIX4tfKeLrHz8zUiRVFmULyIAmpKdlUM+0sPo1NHw== 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=LKMYI4Q7; arc=none smtp.remote-ip=91.218.175.203 X-Received: from mta0.migadu.com (out-203.mta0.migadu.com [91.218.175.203]) (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 94552606A32A for <netdev@vger.kernel.org>; Mon, 26 Oct 2026 12:33:06 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 94552606A32A 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=9lM8ZmCt5oSDpMBB/mA6pb9f0mkJCYo0DmDEVHVew+A=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1793017984; v=1; x=1793622784; b=LKMYI4Q73DkLwaO5yZpDGyBOgkU0E6i5edhX5Kc5KhSspTNV6Q1Ek9mREno+zN26UB1KtwyC EncgqdceAOagH0G821GpGVsFq5msIy/Ei0opQHiVvRf0zfH2CAD3hbCNZvOVVpIQDJrjuXWn3K9 LmP6BruKJc0XNfqW2Y+A2FF4= X-Envelope-To: netdev@vger.kernel.org X-Received: by smtp.migadu.com with ESMTPS id ba99167e89fbca0f; Mon, 26 Oct 2026 12:33:04 +0000 X-Mizu-Trace-ID: ba99167e89fbca0f 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>, 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 X-Mailer: git-send-email 2.43.0 X-In-Reply-To: <20261026123244.239766-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