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=1796384010; b=OsllGUc4lgU+qrv2Q9GdJFV6eXVcsqjLbyTdQzexv+/K51ltCnbSegZ8Q+1EtR5iD3dQ f8cqUoyqgQOe8BXBzEf7ibB2+eegk+kV7uG/bHW14QNYjfBjFIZCZhdE4HgibNvfvduxk zYEeSkZ+Tpx1D5WRu9lLZOuS7mdVHe1lQbggQPz0fVaEOSyY+rsa7pd7VzMP5Nj0+6M4D jbxihiNeK23W6O4LkRATdwofNZO4tafaGZYDcRXRk12Xl/V0UTFFFQmXSoBoA5O44r7co XtgSOE+ISLXQ+GIUWPlUfFndQ5pPca0x5yCHiGkV9cNyDQeh6FfUipYcQjIBVs2IyVw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384010; 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=U1haomP16c0a/39S3JS0u3wUJE401NSUnnNbTYBJWbs=; b=5FzvYxv9HyLNUq8wfpJ1UrYUrfLK72vLU8WO59K9FVnYOV9cIcOOHCPYY8VeOS0CfJR9 0US5mlOk0AZz95FzPYKV5YHnEXiLpyF60795k4qgV1hRs4Q6vjt2ZwW2loJuFIzGmJY8V rrLsgG8W7TumYMtMEhPsIS0qQGCcEg9Vk/rxeatLls6cef7OpklR/MOnplcVi3GjlQAX8 GJaktUAbAogh1oYcGrQq9RG2hjhtGE2qWMgJHvG8K64jBhofVa9OW8EItKsqWBvXRAqUd SejBS7E2Zr9U0L1e8Z2XH2y8cvULEun8Sn9+9N3fmW0ddtj5WmnKRXTwGeNron89u/Q== 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=GgYxI5MX; 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 22227606A322; Fri, 4 Dec 2026 11:33: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=GgYxI5MX Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F7771F00897; Fri, 4 Dec 2026 11:33:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384009; bh=U1haomP16c0a/39S3JS0u3wUJE401NSUnnNbTYBJWbs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=GgYxI5MXFC2sTIKdhO+1M/DfS/asQhZB78URhK3YMW10wIju0b4BeFF4pFsZybn1M TG+NEO6r12cgZTQusZE5QzlLElxxoznQQcBSwkS1IuXxeNzRR+exhXfiQXXWnppS5u k4oCm6q7o+A6tbhzm3DAH1UzRfIhjNU8Ppc9nq04= 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.12 455/555] tcp: Fix the SO_REUSEPORT bind cache admitting a conflicting socket Date: Fri, 4 Dec 2026 19:08:18 +0900 Message-ID: <20261204100626.734021250@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@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.12-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; }; --- a/net/ipv4/inet_connection_sock.c +++ b/net/ipv4/inet_connection_sock.c @@ -422,13 +422,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, @@ -458,6 +463,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 @@ -485,6 +492,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