From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796384687; b=ceSiF8UMNlWBrXvR7YGHASk96Im/j21Z5YAulnQms3rwELD66KZc4H4Q0JMvmWJDqyb3 Shvk6uELERiff9ouKsl1/hO5SyKvLbm8EO5IBxW7Aoz/pWwo2I1hXpfVsP8i0hkpFCb/Q z+lqDSeiCW5WIIrrX1tqyuaqlUI4Vk4Z+j/dLOrmCKjWP85+aWigRkFI7hwOg5phYyBYl bS2WxuZhN3d+DcxH0y0afau2VOfEPQqkbofSo/GlUb2qWqrmfRzLOGP4BJbgBcD95rOuv M97DU9JAQkGzQu3QzXAa/RRrI3bdoLRtoawnA3AehaRuhPzIT0jmJnMZ59ZLUsgtWPw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384687; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=905r5BobOxE73rKYgJQ8KlTRhcrQfc3epyngKU8aFgo=; b=wHyvwyPiMsM1/BEe1WLvVCQaL09u7afkwuweap1KXdh1lqFLVuXDO1LCX0JNuC0neyCH E/RXgKJ12wr7XSy5YSu6MFAtWIoQNMkPJ5tm+8rBUb4uOynjiWcYXkY+LnEu4i1hJIwI2 VGFnpBT0CX6e0HK+/4TYseCxPjtupU1mGs4+VpNYNl2gH5YCwppXTbTBopezYITCMm06s JSodQutA18PM6REXyi3f7mld30EWW0lktwgw5Kr6Q2zk6zK16uZ49dElixfIzf0bdKRMR ejUbFEh3yOyYOIAtaq2sJIOQQ4vkeUXTjQUd3hQX49AwPB8oXg8/WLXtEXW/ptJ0zYA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=PGhoam1r; arc=none smtp.remote-ip=100.103.45.18 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 36834606A322; Fri, 4 Dec 2026 11:44:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=PGhoam1r Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4670E1F000C2; Fri, 4 Dec 2026 11:44:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384686; bh=905r5BobOxE73rKYgJQ8KlTRhcrQfc3epyngKU8aFgo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=PGhoam1rOr/B79Tcx4FlEtgTqLKjo5LablC/87is1GWTvuVshtZtdLL2dH12WJ26G 8Dhash7w8bRqOcL6D5pu3L8U51lu4nnKeZDbEn3swF6PSnvpKkKkZ3ezCmjG84gqQ2 SpCSt192nR9pO46sHNFx0SqNPLchkJ7/iWBqdfgM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Chris Mason , Kuniyuki Iwashima , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.6 0251/1167] tcp: Drop any segments if DEFER_CONNECT is set. Date: Fri, 4 Dec 2026 18:54:38 +0900 Message-ID: <20261204100708.602470364@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chris Mason [ Upstream commit 44809e49177992b15708a150437d9aebc5beea9c ] TCP Fast Open lets a client send data in its SYN. With TCP_FASTOPEN_CONNECT and a cached Fast Open cookie, which the server sent in the SYN-ACK of an earlier connection, the connection is set up in two steps: - connect() sends nothing, so that the SYN can carry the data of the first write(). It only sets DEFER_CONNECT and inserts the socket into the hash table in SYN_SENT. - The first write() calls tcp_connect(), which runs tcp_connect_init() and sends the SYN. A socket must not accept any segment before it has sent its SYN. But nothing on the receive path checks DEFER_CONNECT. So until the write(), the half-initialised socket processes segments like any socket in SYN_SENT, and a forged SYN is accepted. Similarly, ICMP with seq matching ISN is accepted in the state. Before commit 57889a8f6d49 ("tcp: initialize send sequence numbers before deferring TFO"), even seq 0 message was accepted. Drop any segments if DEFER_CONNECT is set. Fixes: 19f6d3f3c842 ("net/tcp-fastopen: Add new API support") Signed-off-by: Chris Mason [kuniyu: revised DEFER_CONNECT tests and the commit message] Signed-off-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20261107235720.3129212-3-kuniyu@google.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/ipv4/tcp_input.c | 9 +++++++++ net/ipv4/tcp_ipv4.c | 2 +- net/ipv6/tcp_ipv6.c | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 4c4fd70f5e742..2efd492f40001 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -6711,6 +6711,15 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb) goto discard; case TCP_SYN_SENT: + /* We sent nothing yet, so no segment belongs to this connection. + * Send no RST: it would be built from this socket, whose TCP-AO + * keys are not set up either. + */ + if (unlikely(inet_test_bit(DEFER_CONNECT, sk))) { + SKB_DR_SET(reason, NOT_SPECIFIED); + goto discard; + } + tp->rx_opt.saw_tstamp = 0; tcp_mstamp_refresh(tp); queued = tcp_rcv_synsent_state_process(sk, skb, th); diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index a31c9e228cdc9..6eb0270275343 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -527,7 +527,7 @@ int tcp_v4_err(struct sk_buff *skb, u32 info) if (!(type == ICMP_DEST_UNREACH && code == ICMP_FRAG_NEEDED)) __NET_INC_STATS(net, LINUX_MIB_LOCKDROPPEDICMPS); } - if (sk->sk_state == TCP_CLOSE) + if (sk->sk_state == TCP_CLOSE || inet_test_bit(DEFER_CONNECT, sk)) goto out; if (static_branch_unlikely(&ip4_min_ttl)) { diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index 6c5d0d8c65f9e..5c7a992f291c1 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -413,7 +413,7 @@ static int tcp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt, if (sock_owned_by_user(sk) && type != ICMPV6_PKT_TOOBIG) __NET_INC_STATS(net, LINUX_MIB_LOCKDROPPEDICMPS); - if (sk->sk_state == TCP_CLOSE) + if (sk->sk_state == TCP_CLOSE || inet_test_bit(DEFER_CONNECT, sk)) goto out; if (static_branch_unlikely(&ip6_min_hopcount)) { -- 2.53.0