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=1796381197; b=rI5Lk+3DOdRnbLZQF8y+WdwcN4kWTB8Lib610ptjhTAP1qHDMcCN31eMlHOte8G2qk5F l6QUJCV6Jm94DSJx9GyQM8octw+CBVilB57vTizT+lChxXhtAQSHOb2nH0N8ttme7Bv68 JRemmRnQN1Lp0LsmmP8EO0tdyGbjbLIuL98DheY89L1hHbwt7nSHEDViNr5WLjFAD1b78 pb44ZsbCXMRevbj6AaWtVE4VnjsCT399WoD5UOSC789/Vi7YVxKwgd0NJaJwQUeNQLsvl CKjPJ922uYIQ8r6er6qqk1qM82jjyKy4PXGvW9pHQNOj568yV6omQdm8ot85nim5yrQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381197; 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=eIQQrMnBU3Rd39JrJnkx2R7W5WcDjFKMqP4hhI53zxE=; b=VFjspwxl84WrqeWG0L9qEqMLFe1jbaA53lHW0Ua1gTS8AZbqIs3715CeiUHUQDGSf6KC WmcYhzff2+z9KZxAwuepJgCA7T7Kxl6YfI5evVZzhwg6khlwgyFQ1fT32i61FWGWO+QPN PwafEKYe1zhMQC7xzVAgHWmt8aNt8GEyy/Ekf9Ht7ky3pz99m95+K3ukycpdmrwjG24uP 0dtNZcqm479uBbm6uZR1tXTzHLRClkGNEX+edPQj8ynww3lbB+CPOGSj6OZylTBZbrRMn /8wWru1lqzK8Ubfob6WVhlUsTBQH2lxN8S7YTUjNvY9VM8FPBwotFylRIXFMUo2t4IQ== 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=CmjmZssi; 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 85F46606A322; Fri, 4 Dec 2026 10:46:37 +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=CmjmZssi Received: by smtp.kernel.org (Postfix) with ESMTPSA id 003C51F000C2; Fri, 4 Dec 2026 10:46:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381197; bh=eIQQrMnBU3Rd39JrJnkx2R7W5WcDjFKMqP4hhI53zxE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=CmjmZssiRxgjn3/ezNQrzfu1IvZxQChL3jYbm8OBP1pXfmuc534yLi4QT26ostY+7 K1KMsQz/hsSdf7RIQLWpydatfX12qtBTJp+Kjovylo+a73NbWFFO9JBUiiVwKQxg5N aTCM/WbND87uWMtEWjMw4C+xbPxFzJbzccipSJO4= 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 7.3 600/742] tcp: Fix the SO_REUSEPORT bind cache admitting a conflicting socket Date: Fri, 4 Dec 2026 19:07:44 +0900 Message-ID: <20261204100651.057341230@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@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 7.3-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 @@ -420,13 +420,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, @@ -455,6 +460,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 @@ -482,6 +489,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