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=1795042377; b=sQiN6ojZS9MEqi4SCWH3QG7nN75M0LMg7hRXdODbHZS2XsjXB5oZ40efymqtQVyFGayA 5CXKLHTHbVz3rLDbYOrsyhz65JCpbZEmjYhqB9MsTr+IGLET+XfJuqUQnb0mZaBeUq/BW Oi6RQ/JgC07k6gNPp5Aw8ZG59shpXP2JfbZhd5JmGUuTi5WnYFzFRXD82sGDzQD1jme5f rHXERZgVXlk43lO8vpQSXX/F5S1KNJdTfDA42jI1iJHbQ6p3vzEZX50LyXkbiebRXuJln +hSDSBFfxmrPbzN28G3ppFNjL2DNR9c5sYOKwY9LMWgiOqxXLYjwApHI+nrhF0M8cSA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795042377; 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=GYxzc/1GrHmTyTlNAIzntfB7YHdYIQyaFTPhlSsFFa4=; b=qwM4AoY5lhz7uo+p7XxBKVB8BW5xtpg9Rb839uJJYe9xTHtMHPGLxZLW9aEhalV+I52b 7hOD7EI39XGcjJF/NjVBmj2QhbZOymTJ1tWq+94SYvo/EqboaD7//vW6hZvxSUwCT6uUA S6erBhqDvkCeHwGMKMQ51U1+Rw5uxxVowyuGi9TaBBxYjlzkUJI3Opa/ypoVABdRm/N/V yJyhGGJAlseL7S04z0BYS8rNYl2X0WSXTOvR/yAKxru+YJ76AcE536ldgm4xCHg7z/44x 3KZXyXRiu+tJfjV8hhSQKP++ZD7pyRWMUMB0S+SDgzm0Lyjjb5sFqQyFFMQFP4fSH9A== 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=P+ZO6OZ6; 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 48D98606A325; Wed, 18 Nov 2026 22:52:57 +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=P+ZO6OZ6 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9B9B91F000C4; Wed, 18 Nov 2026 22:52:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795042377; bh=GYxzc/1GrHmTyTlNAIzntfB7YHdYIQyaFTPhlSsFFa4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=P+ZO6OZ6dwHWNiVllZozR5yFZax/9ND3ayyCvd53hhchOfRHjt9TTc9fsWmvu69fM Fxm4z0NVLLoC6bpoSo8UgJMjwBcCemmOCUuZnkciI0xRWvof4FOB+mT6FLD8f31mZE VSv7dEzC3+TOUw4Cg02V/cWptwHntzJHvYYfuWQk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Allison Henderson , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.6 3148/3318] net/rds: keep the connected peers scope id apart from the bound one Date: Wed, 18 Nov 2026 16:02:50 +0100 Message-ID: <20261118150454.307756721@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150313.527275416@linuxfoundation.org> References: <20261118150313.527275416@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.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Allison Henderson [ Upstream commit 3fe64a5f670dbd6c7c84c2345b0b9726b3b79b31 ] rds_connect() has nowhere to keep the scope of a link-local peer, so it stores it in rs_bound_scope_id, the scope of the socket's own bound address, for rds_bind() to check a later link-local bind against. That field is then also what a send without a destination uses as the request's scope, what getpeername() and recvmsg() report as the peer's scope, and what a later bind() overwrites: rds_add_bound() stores the bound address's scope unconditionally, which for a non-link-local address is 0. So after connect(fe80::x%ifA) followed by bind(global), a send() with no destination asks for fe80::x with scope 0. rds_conn_lookup() keys on the interface, so that finds or creates a connection with c_dev_if 0, which the TCP transport then tries to connect through sin6_scope_id 0 and tcp_v6_connect() rejects for a link-local peer: the connected socket's data is queued on a connection that can never come up. In the other order, bind(global) then connect(fe80::x%ifB), the connect leaves a global-bound socket with rs_bound_scope_id ifB, so sends to other link-local peers are refused as off-link and sends to global peers inherit a meaningless interface. Give the connected peer its own rs_conn_scope_id. rds_connect() records it there and leaves the bound scope alone, rds_bind()'s connected-socket check compares against it, and the destination-less send takes its scope from it - falling back to the bound scope for a non-link-local peer, so that send() and sendto() to the connected peer compute the same scope, and so the same connection. getpeername() reports the connected peer with its own scope. recvmsg() used to report every sender with the socket's bound scope; a connected socket receives from any peer, so neither the bound scope nor the connected peer's scope is right for an arbitrary sender. It now reports a link-local sender with the interface recorded on its connection, c_dev_if: the TCP accept path takes it from the incoming socket, and the IB passive side resolves it from the local address, the closest the CM gets to the arrival interface. Any other sender is reported with scope 0, the inet6 convention. Either way, a reply to the address an application was given reaches the same connection. Found by inspection while reworking the sendmsg connection cache; not observed in the field. Fixes: 1e2b44e78eea ("rds: Enable RDS IPv6 support") Signed-off-by: Allison Henderson Link: https://patch.msgid.link/20261020002816.3087414-3-achender@kernel.org Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/rds/af_rds.c | 15 +++++++++------ net/rds/bind.c | 4 ++-- net/rds/rds.h | 2 ++ net/rds/recv.c | 11 ++++++++++- net/rds/send.c | 6 +++++- 5 files changed, 28 insertions(+), 10 deletions(-) diff --git a/net/rds/af_rds.c b/net/rds/af_rds.c index 85f6471ee6543..63b6d6e6b035d 100644 --- a/net/rds/af_rds.c +++ b/net/rds/af_rds.c @@ -135,8 +135,7 @@ static int rds_getname(struct socket *sock, struct sockaddr *uaddr, sin6->sin6_port = rs->rs_conn_port; sin6->sin6_addr = rs->rs_conn_addr; sin6->sin6_flowinfo = 0; - /* scope_id is the same as in the bound address. */ - sin6->sin6_scope_id = rs->rs_bound_scope_id; + sin6->sin6_scope_id = rs->rs_conn_scope_id; uaddr_len = sizeof(*sin6); } } else { @@ -568,6 +567,7 @@ static int rds_connect(struct socket *sock, struct sockaddr *uaddr, } ipv6_addr_set_v4mapped(sin->sin_addr.s_addr, &rs->rs_conn_addr); rs->rs_conn_port = sin->sin_port; + rs->rs_conn_scope_id = 0; break; #if IS_ENABLED(CONFIG_IPV6) @@ -612,11 +612,14 @@ static int rds_connect(struct socket *sock, struct sockaddr *uaddr, ret = -EINVAL; break; } - /* Remember the connected address scope ID. It will - * be checked against the binding local address when - * the socket is bound. + /* Remember the connected address scope ID. It is + * checked against the binding local address when + * the socket is bound, and gives a send without a + * destination its scope. */ - rs->rs_bound_scope_id = sin6->sin6_scope_id; + rs->rs_conn_scope_id = sin6->sin6_scope_id; + } else { + rs->rs_conn_scope_id = 0; } rs->rs_conn_addr = sin6->sin6_addr; rs->rs_conn_port = sin6->sin6_port; diff --git a/net/rds/bind.c b/net/rds/bind.c index 97a29172a8eec..70237a3243f02 100644 --- a/net/rds/bind.c +++ b/net/rds/bind.c @@ -233,8 +233,8 @@ int rds_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) * non-link local address (scope_id is 0). */ if (!ipv6_addr_any(&rs->rs_conn_addr) && scope_id && - rs->rs_bound_scope_id && - scope_id != rs->rs_bound_scope_id) { + rs->rs_conn_scope_id && + scope_id != rs->rs_conn_scope_id) { ret = -EINVAL; goto out; } diff --git a/net/rds/rds.h b/net/rds/rds.h index a1dd83c2f9a29..5a1789ace8fbf 100644 --- a/net/rds/rds.h +++ b/net/rds/rds.h @@ -613,6 +613,8 @@ struct rds_sock { struct in6_addr rs_conn_addr; #define rs_conn_addr_v4 rs_conn_addr.s6_addr32[3] __be16 rs_conn_port; + /* scope of rs_conn_addr when it is link-local, 0 otherwise */ + __u32 rs_conn_scope_id; struct rds_transport *rs_transport; /* diff --git a/net/rds/recv.c b/net/rds/recv.c index 110fb22c3e2e4..b205943803570 100644 --- a/net/rds/recv.c +++ b/net/rds/recv.c @@ -755,7 +755,16 @@ int rds_recvmsg(struct socket *sock, struct msghdr *msg, size_t size, sin6->sin6_port = inc->i_hdr.h_sport; sin6->sin6_addr = inc->i_saddr; sin6->sin6_flowinfo = 0; - sin6->sin6_scope_id = rs->rs_bound_scope_id; + /* A link-local sender is reported with the + * interface recorded on its connection (the + * accepting socket's device for TCP, the one + * resolved for the local address on IB); any + * other sender has no scope. + */ + sin6->sin6_scope_id = + (ipv6_addr_type(&inc->i_saddr) & + IPV6_ADDR_LINKLOCAL) ? + inc->i_conn->c_dev_if : 0; msg->msg_namelen = sizeof(*sin6); } } diff --git a/net/rds/send.c b/net/rds/send.c index d38964cbf3aa1..f9f6482ffb79f 100644 --- a/net/rds/send.c +++ b/net/rds/send.c @@ -1222,7 +1222,11 @@ int rds_sendmsg(struct socket *sock, struct msghdr *msg, size_t payload_len) lock_sock(sk); daddr = rs->rs_conn_addr; dport = rs->rs_conn_port; - scope_id = rs->rs_bound_scope_id; + /* The connected peer's scope for a link-local peer, else + * the bound scope, as an explicit send to that peer would + * compute below. + */ + scope_id = rs->rs_conn_scope_id ?: rs->rs_bound_scope_id; release_sock(sk); } -- 2.53.0