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=1796389431; b=IYz0T167+elUPpigAYr4d9JMBOYwNviMDxbmUrajO3C5mlxFUNe8X7R3PWet9e5J1L/x I3AdT9/N9jkfSOseTcCdwTg0QnW37JqEVoSl01OvbL4V5kJRsdmnZjbLLdogSFm1eNQv2 jeUTOxt4sEEwYoUJazuWjR47vfJx+Il8wLSYmrQKNxJZ9hHVM/F8muXhgEnvp06S4t4Bo PW2SP9X0TrnafMevY7n/OC7queXNBfi44NHO/mMHj+72TrC1qDtEDx6EMldIDZF7EX4gL gvS6MN93zKJnreiBdUSB7M15mhkBv42x/52rh50ZUM4ujIIGNysRts2AVfxumxiNXNg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796389431; 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=aBGwQAlrd4779ypJlq5SZ63mO1/AEMwMeX6igOaqLNE=; b=JyNWyE6kk/V5BvvaF7NFh1ntxBFzhQVYXCQYrrYhq1IB9Ia4fnczFeG6NR+eiVPxVtw6 JHAPXFzgQ2EkyER+ypEwdij8cKhIlfbzpLmKsPiGSh/Zw/sxpI3ghQKWe4ITo77dhaZGa TtCjudcfzhfV7XhXnkRBYSme1FB5wMczRQyIq3dgnB4a7CkXmBvTRfSuVBHS6eQBxySPj V+Q+GglQhBmzguqJUjCzDZYFtm4+ynnoSb265jpggI3jJh+rFA8TcYmNknL7QBSr7+lnB umZSVAIvadGW7U5u1UZNWhDME+J6gQ7uJ9HLiVhKci+27aYaEPKoc4TQ+kSbvJ4gt4g== 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=06VuiKPm; 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 D590E606A322; Fri, 4 Dec 2026 13:03:51 +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=06VuiKPm Received: by smtp.kernel.org (Postfix) with ESMTPSA id D1BF51F0093B; Fri, 4 Dec 2026 13:03:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796389431; bh=aBGwQAlrd4779ypJlq5SZ63mO1/AEMwMeX6igOaqLNE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=06VuiKPmoul//NdayKGDNP9ghlBYB4L+uF546NaPv0qaIlSjXqA1IDv+62uarzmkU JGInC5ujMwOCogWUpVgoV4JcpvmYM6bxcJI/sANgVKUbCfMQo31Ve91tM/Of6rVgO4 C8I4GAyP0aSdlCBL7yAHPQ9Gagul8UMNdP7Kn868= 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.1 0990/1059] tcp: Fix the SO_REUSEPORT bind cache admitting a conflicting socket Date: Fri, 4 Dec 2026 19:08:41 +0900 Message-ID: <20261204100709.643974766@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: 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.1-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 owners; }; --- a/net/ipv4/inet_connection_sock.c +++ b/net/ipv4/inet_connection_sock.c @@ -425,13 +425,18 @@ static inline int sk_reuseport_match(str return 0; if (!uid_eq(tb->fastuid, uid)) 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, @@ -459,6 +464,8 @@ void inet_csk_update_fastreuse(struct in 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 @@ -486,6 +493,8 @@ void inet_csk_update_fastreuse(struct in 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