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=1796382623; b=fSCM37n1IM7y4obU105GqW8uujCmET5VTGJAhazfJ5ZKnWZJmmn9oMBOJ+h9wS5ytnGG 1ZxpFcjJTTKAxHfM/FX74OBy4HBIqfgk16hSDw+MLSwXZtmvCSKP6F0pF5zV3Tup5gezO CNVFpxkF3Alg6yPfQrx9E62dIjaz115DqD2ikgFiUQb9uWUDaStWrsQjhJ27tjAlXVwHm C2Inc/93Ge2MV4J7UsEIXUiOuseiDBSF3PllvhfbR2cMTMW76BAWG5NLKoUqV1wW3bM6H tt8UsWCQQ8JDdg8FK0HkAhsFIgrCyLFliFHCEdxgp4Bs0pOf1Ir+QLWOIjZSd8Gjfwg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382623; 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=x8rUjKB/haxYF5M0nRW507fLRkgxdNYKP42V6buGTsk=; b=fLE5btQer3vIlj4sFf5zGKewhanM7rIFWo8tP2vrPrOS+at5zgpGDzTnvCWbA4fJu9+n cdKeYE3KqSkWLE+aqmLr+SWUN8ezmPZDrMDWnNFn2RomY7+N+3xLJA0pAkAQ9klHUqYdR BpjHKNeDWXRsM4Xt3GusMAix4y6mCsKUEOD2qB5+rCi2xeqc2m4lEG1Eh3fDcDbmCEoVO 4peqKKIbHjDxOpQ7S6ultAfoMnmu9zfckeizE78NKwx8N83oUzof+cptqay8XMY/w1CVl lYws4jGmDLggC6Nk7zZZydMfbN5jTVU2zHj66GW3Mz0ETYqtmNC/injhrAJwyrE2jtg== 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=UR7KY0gg; 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 13E86606A322; Fri, 4 Dec 2026 11:10:23 +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=UR7KY0gg Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7CB0E1F000C2; Fri, 4 Dec 2026 11:10:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382622; bh=x8rUjKB/haxYF5M0nRW507fLRkgxdNYKP42V6buGTsk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=UR7KY0ggnTKQnvq3cmqvNwEJGf4kWO574DTdAlfexAbZS0809PmgNQTrpSubcEbIS G1cAtDo5m/rAvoWBwMVZ+yGehaoeJwdo0v9QA64uhzl7rDcQLnxGyCkLc3dr0QJv21 GOdpYsfMi4VGhPESkYnXLh87Di5TE472C27SQHXA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Juan Agustin Niccolini , Kuniyuki Iwashima , Eric Dumazet , Jakub Kicinski Subject: [PATCH 6.18 532/703] tcp: Fix the SO_REUSEPORT bind cache admitting a conflicting socket Date: Fri, 4 Dec 2026 19:07:11 +0900 Message-ID: <20261204100641.943824893@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Juan Agustin Niccolini commit f675070191f202010b010160b509a543dd232ae6 upstream. When the port is in the FASTREUSEPORT_STRICT state, inet_csk_get_port() skips the bind conflict check if sk_reuseport_match() finds the new socket's address covered by the socket cached in tb->fast_*. This is only safe if both sockets match on everything inet_bind_conflict() reads. The cache misses some of it: - It does not record sk_bound_dev_if or sk_reuse. - It records the family and IPV6_V6ONLY but never compares them with the new socket, so a cached v6only [::] (or 0.0.0.0) socket covers a dual-stack [::] socket. As a result, an unprivileged user can bind and listen on a port that another user is listening on, for example a dual-stack [::] socket on top of a 0.0.0.0 listener: victim: bind(0.0.0.0:P), listen() attacker: SO_REUSEPORT + IPV6_V6ONLY, bind([::]:P) /* fills cache */ attacker: SO_REUSEPORT, bind([::]:P), listen() /* should fail */ Only take the fast path when the new socket matches the cached one in family, IPV6_V6ONLY, bound device and SO_REUSEADDR. Identical SO_REUSEPORT listeners, the workload this cache was added for, still skip the scan (binding 16384 of them: 9.80 ms before, 9.86 ms after, 5874 ms with the full check every time). Fixes: 637bc8bbe6c0 ("inet: reset tb->fastreuseport when adding a reuseport sk") Cc: stable@vger.kernel.org Signed-off-by: Juan Agustin Niccolini Reviewed-by: Kuniyuki Iwashima Reviewed-by: Eric Dumazet Link: https://patch.msgid.link/20261111174704.24312-2-juanagusnicco@gmail.com Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- include/net/inet_hashtables.h | 2 ++ net/ipv4/inet_connection_sock.c | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) --- a/include/net/inet_hashtables.h +++ b/include/net/inet_hashtables.h @@ -87,6 +87,8 @@ struct inet_bind_bucket { __be32 fast_rcv_saddr; unsigned short fast_sk_family; bool fast_ipv6_only; + unsigned char fast_sk_reuse; + int fast_bound_dev_if; struct hlist_node node; struct hlist_head bhash2; struct rcu_head rcu; --- a/net/ipv4/inet_connection_sock.c +++ b/net/ipv4/inet_connection_sock.c @@ -421,13 +421,18 @@ static inline int sk_reuseport_match(str return 0; if (!uid_eq(tb->fastuid, sk_uid(sk))) return 0; - /* We only need to check the rcv_saddr if this tb was once marked + /* We only need to check the fast_* fields if this tb was once marked * without fastreuseport and then was reset, as we can only know that - * the fast_*rcv_saddr doesn't have any conflicts with the socks on the - * owners list. + * the socket they describe doesn't have any conflicts with the socks + * on the owners list. */ if (tb->fastreuseport == FASTREUSEPORT_ANY) return 1; + if (tb->fast_sk_family != sk->sk_family || + tb->fast_ipv6_only != ipv6_only_sock(sk) || + tb->fast_bound_dev_if != sk->sk_bound_dev_if || + tb->fast_sk_reuse != sk->sk_reuse) + return 0; #if IS_ENABLED(CONFIG_IPV6) if (tb->fast_sk_family == AF_INET6) return ipv6_rcv_saddr_equal(&tb->fast_v6_rcv_saddr, @@ -456,6 +461,8 @@ void inet_csk_update_fastreuse(const str tb->fast_rcv_saddr = sk->sk_rcv_saddr; tb->fast_ipv6_only = ipv6_only_sock(sk); tb->fast_sk_family = sk->sk_family; + tb->fast_sk_reuse = sk->sk_reuse; + tb->fast_bound_dev_if = sk->sk_bound_dev_if; #if IS_ENABLED(CONFIG_IPV6) tb->fast_v6_rcv_saddr = sk->sk_v6_rcv_saddr; #endif @@ -483,6 +490,8 @@ void inet_csk_update_fastreuse(const str tb->fast_rcv_saddr = sk->sk_rcv_saddr; tb->fast_ipv6_only = ipv6_only_sock(sk); tb->fast_sk_family = sk->sk_family; + tb->fast_sk_reuse = sk->sk_reuse; + tb->fast_bound_dev_if = sk->sk_bound_dev_if; #if IS_ENABLED(CONFIG_IPV6) tb->fast_v6_rcv_saddr = sk->sk_v6_rcv_saddr; #endif