🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #5213

[PATCH net-next v6 2/2] net/rds: keep the connected peer's scope id apart from the bound one

#5213
From: Allison Henderson
Date: Tue, 20 Oct 2026 00:28
162 lines
14124 bytes
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")
Assisted-by: Claude-Code:claude-fable-5
Signed-off-by: Allison Henderson <achender@kernel.org>
---
 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 d5defe9172e3..e84d00bbe9a1 100644
--- a/net/rds/af_rds.c
+++ b/net/rds/af_rds.c
@@ -136,8 +136,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 {
@@ -572,6 +571,7 @@ static int rds_connect(struct socket *sock, struct sockaddr_unsized *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)
@@ -616,11 +616,14 @@ static int rds_connect(struct socket *sock, struct sockaddr_unsized *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 f800d920d969..3ac59cd512a2 100644
--- a/net/rds/bind.c
+++ b/net/rds/bind.c
@@ -233,8 +233,8 @@ int rds_bind(struct socket *sock, struct sockaddr_unsized *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 2db49573dacd..9b1ffc49c0a6 100644
--- a/net/rds/rds.h
+++ b/net/rds/rds.h
@@ -646,6 +646,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 6204e577a90a..2458cd4ce73e 100644
--- a/net/rds/recv.c
+++ b/net/rds/recv.c
@@ -789,7 +789,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 38b9cc9e0d20..f38967f65af1 100644
--- a/net/rds/send.c
+++ b/net/rds/send.c
@@ -1256,7 +1256,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.50.1
Technical Details
Message-ID: <20261020002816.3087414-3-achender@kernel.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-348932-linux-kernel-netdev=dewy.ru
References: <20261020002816.3087414-1-achender@kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-348932-linux-kernel-netdev=dewy.ru
From: achender@kernel.org (Allison Henderson)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next v6 2/2] net/rds: keep the connected peer's scope id apart from the bound one
Date: Mon, 19 Oct 2026 17:28:16 -0700
Organization: Usenet Network
Message-ID: <20261020002816.3087414-3-achender@kernel.org>
References: <20261020002816.3087414-1-achender@kernel.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3749849"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:VJ5HfChjy4qiFwSoqVSpLq+yoNE= sha256:4KHGNEi6fJHyCjpgjNSSd8ZqkmUKMM6bzvFpdtHs/Vg=
	sha1:OHXWA9m4Uo1Hz8V/2gil2Ery1x8= sha256:/A705E71on8zu94WG0BAvq3VDET9h7zpQTl2yTmxR4o=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 8CDDA110B92; Tue, 20 Oct 2026 03:34:00 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.729
X-Spam-Status: No, score=-3.729 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.329, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id totPl0A6sGJY;
	Tue, 20 Oct 2026 03:33:53 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-348932-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 4C60B110B7D; Tue, 20 Oct 2026 03:33:45 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id F251240348; Tue, 20 Oct 2026 00:28:19 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1792456099;
	b=Y5T6Rfaa4atZUTJVRWMZ2TpRIYVVPhlIqPoPFUzXrN3QcRrC6Lb2hHdm3U+W+obDeQQn
	 nfXYckLZSRQpM8lawhyxXeSUszmNNQhpD5S9uW2AP81OiiBlg/gTzjL6+0RSlBWYdm2N2
	 ZbMH+I3dwtp0MIm8ww57Xw61+OfeNGVaNy5xVG77U4T9OHoghGenHKQzNdk4EofSGzrfR
	 +2eS/lRkUDVrczpTgrBydqDj2ll4RWQWOJdX8KJ3ba2MJeF3nD6RWF3KN7xF82YiEbO3v
	 S3zkWXKn7ku3wvUM3CizU7bqfRtEjPk5fWCwKNLxYSXLXVWq/zF5Cjza5tWSDca+FdA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792456099;
	h=X-Original-To:Received:Received:DKIM-Signature:From:To:Cc:Subject:
	 Date:Message-ID:X-Mailer:In-Reply-To:References:X-Mailing-List:
	 List-Id:List-Post:List-Help:List-Subscribe:List-Unsubscribe:
	 List-Owner:Precedence:MIME-Version:Content-Transfer-Encoding;
	bh=8uJA/ehV5jojOjVkQUxowY7ETq9rQfYD4jD2peF67N4=;
	b=JKWg12mGypNW9+DGS7Gl3sog2n/tAu31vSxYZU4CQaC7jo6yUpok2OtHQpWMT+WiYHhh
	 roW/fPaNCN4kT28tWnkCyY/vYz3z0Q5wdApEj/FedVMmzzR/w5+NlWK1nh0/otbe4wfEW
	 BpSSbhpw0VLZtUtcsjY8/gLMSRSreveLrL9DdNaaRl1lWibCndZFnAAZP3gjOdgAEMbtO
	 mL5KtHI+U1Mw59aj5DQbiDlmEQvFc286FiKc6GsRuXDe521T0xtstUIoPlaWnBDnACjVt
	 RffjC2O/9DMieb0knVyXeJWkkhH48p4AJhUzWnulMx5Jt5AGucpda68uJOTWC7huBFw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=dWoEQ8r1;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id B8945606A31F;
	Tue, 20 Oct 2026 00:28:19 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=dWoEQ8r1
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1792456098;
	b=L0UOvBOnmQ6gKPSCKEM4b7JufQyddFu0iRyqpCDh1JugZMcdX3fkkZip0hL7FGKlErWB
	 oTx7PERzPS4i/OI4t7Kb9QAh3SRi0o8qZ2+PZhNghj97bn4dX21epmWndi+NqidhEuFxg
	 QiTWzsfqlTEfdgKuuRkrcptXLdsfY2urDRBawa3dDjB/bP5su5qS/PBEeHAhD78O1ThBz
	 7DQZONY5vkMKoLqdLSPDZrCT2hIochJJBCUmQ6/bDMCmqvgi8TIxiv3cDTQafJzMBmTWD
	 q28DyhjBymwxh6szqxzhcteY7e6lAYvePyBB4sAGSOFiVfucIH/ErByynCgwJecaVcA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792456098;
	h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer:
	 In-Reply-To:References:MIME-Version:Content-Transfer-Encoding;
	bh=8uJA/ehV5jojOjVkQUxowY7ETq9rQfYD4jD2peF67N4=;
	b=xZFVQbcLZ4XVdj6nW2GtTQfCi+LdMYWZgmFn/eVKE3+HEbzXw979UhOlqI8XDOG7uhmN
	 6lIeAXIJS2VZq6BAORFWNP6yHq3pWGOvq8CmXagcJPrIPHsgU9/g39PoRPZMX+vGfbLXA
	 d9DoHNDTio/PSTZkPuD80BnYJOl0RO3qiRpM5nhdhPVLvLwIdd3vHbpPcK6hC7NRwSE1j
	 EILLUUUupOCIUNtHCbZGX/Xzxs5GTDFaE0/yt9uDaRDVEJpbrqLqlrEyZ06rI0vKSOIUN
	 s1xtRhEIOYjbBcblZRpZmgAVerJDjx3vJqTtUW1dKKmFdraXwvqz6pUuln04+f3XRcA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=dWoEQ8r1;
	arc=none smtp.remote-ip=100.103.45.18
X-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 9A81B606A323;
	Tue, 20 Oct 2026 00:28:18 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 073D21F000C5;
	Tue, 20 Oct 2026 00:28:17 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1792456098;
	bh=8uJA/ehV5jojOjVkQUxowY7ETq9rQfYD4jD2peF67N4=;
	h=From:To:Cc:Subject:Date:In-Reply-To:References;
	b=dWoEQ8r1bSjfTMWqxFCfUez7dxh6rfCkmQi1q6JZAtnhc4sCaLol7kc++Dk5Ty5vb
	 PgSaqAOhY8TOFAGNh0AMsjswnH1lEN34UABV0WIZ1t6K0xhdGZM7Q6sZK5MUZVRzC1
	 Imnn/PnRnGHTBn81tNWOAnmzZ1b+XOWawHNw9LM4n2/KwxFEVNwLlihepUf66f9e1N
	 tB6rmZ7azTfE/QRuiJwgVmHNwsyOiKBa8WH2kyipBeymjXLRlLOojg/5ID+KyoJVkJ
	 JLTDr1fRi1zTJdYhg1uZt+DRkWrFoODdxwp+mZASB9ZpvjaHzezuGnolUs6WT9MKuF
	 NNm9CRt/z99dw==
X-Cc: achender@kernel.org
X-Mailer: git-send-email 2.50.1
X-In-Reply-To: <20261020002816.3087414-1-achender@kernel.org>
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list