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=1796388605; b=QxsGV1DKOEier4g3gF6tTbjUz21wGH0sciNgVU7/ZQLjcBMWZwxsJwGGjDRHNKAfjpb2 qLRC8RLIq8+O8ILS4oeTLnvLrEj4F1TTotrQ7IyihfPL9cZ+WLnahJEHoVzEIFtZhPtjS oR2Kog9giihzSm+qeU6Ic2A7zCMm9cpliUbUAeqtqjQw3Mu5TV//Uc1rct0YwjlmmZrPQ CJ8f/l+MXBBqoN/ngoKuxJS6hr1QGL0O+BlbIzxmHMypv7qMX/VwBEtm/0ztfRCkBY6ir EADud9DalglsX4DR6ufnEM+0MNLZg7cP5g/ODwzjWrA9+qDKaXfCcC4L+mVaoA8BDyQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796388605; 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=R7irRdpTLGlTbwqx2ei1hT08YmHefQuKd8XD2SlOtnU=; b=t4odf6rVjUkBL5vGJGTwhH6DX+nEviYx8tiTeG4Op/V3Y0PUIpOzJs15Xkjaj+QtPkOp YdNmvSGeOJaWqk0X95JSgUJ85UDLDtHcSmg3yZ4fsCNuNT2Ru16vsnS83mySZsqvnaD4u Gz4MctxW7l3hzsgVAt9Cts2yO1BueEMy0bxdx5z5DAkWuaLRdU6sTEOV1rmsYee5lsXzv wZOLsoCF4i6AGwjV3yUFDMFTPVUxgDsUKpd41YbQEHsKdirYpqyyh3nMH9j+SPVrheSNB wf6MIe9A+g752k8krrRBR8+7SYySTDleZaWoXJB1SUozf5u2ptrAr56M3/2/J5x6yAg== 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=C0kSPyCS; 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 E0418606A322; Fri, 4 Dec 2026 12:50:04 +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=C0kSPyCS Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5DF3B1F000C2; Fri, 4 Dec 2026 12:50:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796388604; bh=R7irRdpTLGlTbwqx2ei1hT08YmHefQuKd8XD2SlOtnU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=C0kSPyCSXrhzakRnnr2Vl8iFT9ROb2ivp8zrqsDP6hPbPyD88Gt+P66VjA1VwwknP j/7ZftYa2oDOJx2Tf8newER/ZwTj/vV0yWzumpsvKJn41XUiFJ0f91nFqoO7S4y8VX 94C89hKf8r7GfSO7hqNWTXro/uN8L8ONSQ9yThwk= 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.1 0685/1059] tcp: Do not allow buggy transitions between ehash and lhash2. Date: Fri, 4 Dec 2026 19:03:36 +0900 Message-ID: <20261204100701.744533333@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@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.1-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.1.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 51be99667a23c..76ec18fdc5bbb 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 00102d364a42d..b188cfa0c04db 100644 --- a/net/ipv4/inet_connection_sock.c +++ b/net/ipv4/inet_connection_sock.c @@ -1196,6 +1196,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 d4fc6ad1e2d58..7510330e2dc1c 100644 --- a/net/ipv4/inet_hashtables.c +++ b/net/ipv4/inet_hashtables.c @@ -735,6 +735,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); @@ -788,6 +793,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); @@ -802,6 +809,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); @@ -1008,6 +1016,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