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=1796385871; b=Q2ETXnYcEv4pcK4N4udUypagdVCjpj4qm8KCp+vkpVFnvZWCC03Rjlv9Rcf4OaUgCDTm QLVGxVfcx9xOFItzEaC1sixP/G4+YoV3f1oqneyQKZAvYom0GexrAxvh5q9VNfC7jVsMD xfZc/ik2UaSRwudy8OHNapH6pLlc0DpPad6VO6uXnKbgT/Kv+qF2pXWegw/H6BZUsrUtG MnlqwaNMNgH90XR5z0jJ8fS7BOGs/F5k4jvBSOLsFmX5AFdy+457rIVXkCZjoJQlseJ1O H9Wm9FzJJ6fqjF3keEvMGM388wkTzMnLr897efxkXsWQeP103d6ZNXFybCkkCJBCiPA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385871; 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=E85CAzywZtnSn0RQG34V3K7RUICwsiVrQX16SQqgZe4=; b=CgPEx+OYvVRbtU1UI7khHjlSi4I3hAG1GxJMly9EKX/PlLDnYzg7G+eZSGfxy337Osmn p98s98vGOLX3o/2OBDz6DLeg5gzGYVhL4xEMiAuzVYZBFv5rnwrcgh0TPrjBp4icGsDpW rGfDb+P/UHoZuEAS2dP8SLtm7bu53y4a3pzen3j3Yn5JpeMw6RY+ig182oe5T/cHT1DNl o0OfSvt9WHoic84tdkE1rrz2Sr/PkDhXiE3P1pfiavdT9igx9XqVd4In5iqpdueZGbWvn QZDdz01S52d6UlrFO3tzOd6tkkmMrxillWlBOe+VC8mQoMvrPUJGCNnJmZDxwnivhWA== 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=d20Al5PK; 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 F1592606A32F; Fri, 4 Dec 2026 12:04:30 +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=d20Al5PK Received: by smtp.kernel.org (Postfix) with ESMTPSA id 753191F000CE; Fri, 4 Dec 2026 12:04:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796385870; bh=E85CAzywZtnSn0RQG34V3K7RUICwsiVrQX16SQqgZe4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=d20Al5PKeuTokUm3g7qbU3VLlnOLtepL2W21Fxbvj32QMpubnheiPMlW6F7KF998c HsmjBeNwVv7ccQWj9EORN/sqRqf9Hn+tKbpdUU7AzwfkhPPHDzmgCMvJVScCbyckje 4DQBwoesXKbcqd93l68iv4VeHxKf8lt4p0zBS9N4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Kyle Zeng , Michal Luczaj , Hyunwoo Kim , Kuniyuki Iwashima , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.6 0728/1167] tcp: Do not allow buggy transitions between ehash and lhash2. Date: Fri, 4 Dec 2026 19:02:35 +0900 Message-ID: <20261204100721.036845374@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: Kuniyuki Iwashima [ Upstream commit 8cc3aef0cb198049805ecc061a2cc7b79b0ae43e ] The following state transitions have long been a playground for syzbot, and recently AI joined in, reporting a lot more bugs. * listen() + shutdown() + connect() * connect() + connect(AF_UNSPEC) + listen() All the fix attempts would add more code to the fast path, which is not worth it. Instead of playing whack-a-mole with these edge-case bugs, let's disallow these transitions. Note that unhashed_state is placed in the 4-byte hole after icsk_pmtu_cookie. $ pahole -C inet_connection_sock vmlinux struct inet_connection_sock { ... __u32 icsk_pmtu_cookie; /* 1208 4 */ unsigned char unhashed_state; /* 1212 1 */ /* XXX 3 bytes hole, try to pack */ Reported-by: Kyle Zeng Closes: https://lore.kernel.org/netdev/20260731140512.566464-1-david.lee@trailofbits.com/ Reported-by: Michal Luczaj Closes: https://lore.kernel.org/netdev/20260803-sockmap-lookup-tcp-leak-v2-0-306e025bfe66@rbox.co/ Reported-by: Hyunwoo Kim Closes: https://lore.kernel.org/netdev/20260824033331.1084971-1-imv4bel@gmail.com/ Signed-off-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20260904033543.2635540-2-kuniyu@google.com Signed-off-by: Jakub Kicinski [ Hyunwoo Kim: Check __inet_hash() for IPv4 and IPv6 on 6.6.y; record the state after each locked unhashed check. ] Signed-off-by: Hyunwoo Kim Signed-off-by: Sasha Levin --- include/net/inet_connection_sock.h | 1 + net/ipv4/inet_connection_sock.c | 1 + net/ipv4/inet_hashtables.c | 11 +++++++++++ 3 files changed, 13 insertions(+) diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h index 0a33e7cdcc8ba..96e29df15fe0c 100644 --- a/include/net/inet_connection_sock.h +++ b/include/net/inet_connection_sock.h @@ -102,6 +102,7 @@ struct inet_connection_sock { __u32 icsk_rto_min; __u32 icsk_delack_max; __u32 icsk_pmtu_cookie; + unsigned char unhashed_state; const struct tcp_congestion_ops *icsk_ca_ops; const struct inet_connection_sock_af_ops *icsk_af_ops; const struct tcp_ulp_ops *icsk_ulp_ops; diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c index eb4dddccf17e2..3959237da96b0 100644 --- a/net/ipv4/inet_connection_sock.c +++ b/net/ipv4/inet_connection_sock.c @@ -1198,6 +1198,7 @@ struct sock *inet_csk_clone_lock(const struct sock *sk, if (newsk) { struct inet_connection_sock *newicsk = inet_csk(newsk); + newicsk->unhashed_state = 0; inet_sk_set_state(newsk, TCP_SYN_RECV); newicsk->icsk_bind_hash = NULL; newicsk->icsk_bind2_hash = NULL; diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c index f3430f96db0c3..1ca4a6cb27d61 100644 --- a/net/ipv4/inet_hashtables.c +++ b/net/ipv4/inet_hashtables.c @@ -748,6 +748,11 @@ int __inet_hash(struct sock *sk, struct sock *osk) return 0; } WARN_ON(!sk_unhashed(sk)); + + if (unlikely(inet_csk(sk)->unhashed_state && + inet_csk(sk)->unhashed_state != TCP_LISTEN)) + return -EINVAL; + ilb2 = inet_lhash2_bucket_sk(hashinfo, sk); spin_lock(&ilb2->lock); @@ -801,6 +806,8 @@ void inet_unhash(struct sock *sk) return; } + inet_csk(sk)->unhashed_state = sk->sk_state; + if (rcu_access_pointer(sk->sk_reuseport_cb)) reuseport_stop_listen_sock(sk); @@ -815,6 +822,7 @@ void inet_unhash(struct sock *sk) spin_unlock_bh(lock); return; } + inet_csk(sk)->unhashed_state = sk->sk_state; __sk_nulls_del_node_init_rcu(sk); sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1); spin_unlock_bh(lock); @@ -1021,6 +1029,9 @@ int __inet_hash_connect(struct inet_timewait_death_row *death_row, int l3mdev; u32 index; + if (unlikely(inet_csk(sk)->unhashed_state == TCP_LISTEN)) + return -EINVAL; + if (port) { local_bh_disable(); ret = check_established(death_row, sk, port, NULL); -- 2.53.0