The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH v2] 9p: use fc->net_ns for network namespace in RDMA and socket transports
@ 2026-05-29  9:06 Yizhou Zhao
  2026-06-15 13:15 ` Dominique Martinet
  0 siblings, 1 reply; 2+ messages in thread
From: Yizhou Zhao @ 2026-05-29  9:06 UTC (permalink / raw)
  To: v9fs
  Cc: Yizhou Zhao, Eric Van Hensbergen, Latchesar Ionkov,
	Dominique Martinet, Christian Schoenebeck, linux-kernel,
	Yuxiang Yang, Ao Wang, Xuewei Feng, Qi Li, Ke Xu

The 9p RDMA transport currently passes &init_net to rdma_create_id().
As a result, RDMA address resolution and connection setup are performed
in the initial network namespace, even when the mount is initiated from
a non-initial network namespace.

This differs from the socket-based 9p transports, which create sockets
in current->nsproxy->net_ns.  Use fc->net_ns for both the RDMA and
socket transports instead, so that transport setup follows the VFS
mount namespace context rather than depending on the calling process's
current namespace.

This avoids surprising behaviour where a 9p RDMA mount from a container
or other non-initial network namespace may use the host namespace for
RDMA CM operations.

Fixes: fa20105e09e9 ("IB/cma: Add support for network namespaces")
Reported-by: Yizhou Zhao <zhaoyz24@mails.tsinghua.edu.cn>
Reported-by: Yuxiang Yang <yangyx22@mails.tsinghua.edu.cn>
Reported-by: Ao Wang <wangao@seu.edu.cn>
Reported-by: Xuewei Feng <fengxw06@126.com>
Reported-by: Qi Li <qli01@tsinghua.edu.cn>
Reported-by: Ke Xu <xuke@tsinghua.edu.cn>
Suggested-by: Dominique Martinet <asmadeus@codewreck.org>
Assisted-by: GLM:GLM-5.1
Signed-off-by: Yizhou Zhao <zhaoyz24@mails.tsinghua.edu.cn>
---
Changes in v2:
- Use fc->net_ns instead of current->nsproxy->net_ns in trans_rdma.c
(per Dominique Martinet's suggestion: fc->net_ns is the VFS mount
namespace, more correct than current->nsproxy->net_ns)
- Also fix trans_fd.c which has the same issue: 3 occurrences of
current->nsproxy->net_ns replaced with fc->net_ns
- Link to v1: https://lore.kernel.org/v9fs/20260529070817.76798-1-zhaoyz24@mails.tsinghua.edu.cn/
---
 net/9p/trans_fd.c   | 6 +++---
 net/9p/trans_rdma.c | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
index dbad3213b..868882258 100644
--- a/net/9p/trans_fd.c
+++ b/net/9p/trans_fd.c
@@ -887,7 +887,7 @@ p9_fd_create_tcp(struct p9_client *client, struct fs_context *fc)
 		return -EINVAL;

 	sprintf(port_str, "%u", opts.port);
-	err = inet_pton_with_scope(current->nsproxy->net_ns, AF_UNSPEC, addr,
+	err = inet_pton_with_scope(fc->net_ns, AF_UNSPEC, addr,
 				   port_str, &stor);
 	if (err < 0)
 		return err;
@@ -896,7 +896,7 @@ p9_fd_create_tcp(struct p9_client *client, struct fs_context *fc)

 	client->trans_opts.tcp.port = opts.port;
 	client->trans_opts.tcp.privport = opts.privport;
-	err = __sock_create(current->nsproxy->net_ns, stor.ss_family,
+	err = __sock_create(fc->net_ns, stor.ss_family,
 			    SOCK_STREAM, IPPROTO_TCP, &csocket, 1);
 	if (err) {
 		pr_err("%s (%d): problem creating socket\n",
@@ -948,7 +948,7 @@ p9_fd_create_unix(struct p9_client *client, struct fs_context *fc)

 	sun_server.sun_family = PF_UNIX;
 	strcpy(sun_server.sun_path, addr);
-	err = __sock_create(current->nsproxy->net_ns, PF_UNIX,
+	err = __sock_create(fc->net_ns, PF_UNIX,
 			    SOCK_STREAM, 0, &csocket, 1);
 	if (err < 0) {
 		pr_err("%s (%d): problem creating socket\n",
diff --git a/net/9p/trans_rdma.c b/net/9p/trans_rdma.c
index aa5bd74d3..b3d6c27d7 100644
--- a/net/9p/trans_rdma.c
+++ b/net/9p/trans_rdma.c
@@ -541,7 +541,7 @@ rdma_create_trans(struct p9_client *client, struct fs_context *fc)
 		return -ENOMEM;

 	/* Create the RDMA CM ID */
-	rdma->cm_id = rdma_create_id(&init_net, p9_cm_event_handler, client,
+	rdma->cm_id = rdma_create_id(fc->net_ns, p9_cm_event_handler, client,
 				     RDMA_PS_TCP, IB_QPT_RC);
 	if (IS_ERR(rdma->cm_id))
 		goto error;
--
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] 9p: use fc->net_ns for network namespace in RDMA and socket transports
  2026-05-29  9:06 [PATCH v2] 9p: use fc->net_ns for network namespace in RDMA and socket transports Yizhou Zhao
@ 2026-06-15 13:15 ` Dominique Martinet
  0 siblings, 0 replies; 2+ messages in thread
From: Dominique Martinet @ 2026-06-15 13:15 UTC (permalink / raw)
  To: Yizhou Zhao
  Cc: v9fs, Eric Van Hensbergen, Latchesar Ionkov,
	Christian Schoenebeck, linux-kernel, Yuxiang Yang, Ao Wang,
	Xuewei Feng, Qi Li, Ke Xu

Yizhou Zhao wrote on Fri, May 29, 2026 at 05:06:24PM +0800:
> The 9p RDMA transport currently passes &init_net to rdma_create_id().
> As a result, RDMA address resolution and connection setup are performed
> in the initial network namespace, even when the mount is initiated from
> a non-initial network namespace.
> 
> This differs from the socket-based 9p transports, which create sockets
> in current->nsproxy->net_ns.  Use fc->net_ns for both the RDMA and
> socket transports instead, so that transport setup follows the VFS
> mount namespace context rather than depending on the calling process's
> current namespace.
> 
> This avoids surprising behaviour where a 9p RDMA mount from a container
> or other non-initial network namespace may use the host namespace for
> RDMA CM operations.
> 
> Fixes: fa20105e09e9 ("IB/cma: Add support for network namespaces")
> Reported-by: Yizhou Zhao <zhaoyz24@mails.tsinghua.edu.cn>
> Reported-by: Yuxiang Yang <yangyx22@mails.tsinghua.edu.cn>
> Reported-by: Ao Wang <wangao@seu.edu.cn>
> Reported-by: Xuewei Feng <fengxw06@126.com>
> Reported-by: Qi Li <qli01@tsinghua.edu.cn>
> Reported-by: Ke Xu <xuke@tsinghua.edu.cn>
> Suggested-by: Dominique Martinet <asmadeus@codewreck.org>
> Assisted-by: GLM:GLM-5.1
> Signed-off-by: Yizhou Zhao <zhaoyz24@mails.tsinghua.edu.cn>

Thanks, picked up
-- 
Dominique

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-06-15 13:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-29  9:06 [PATCH v2] 9p: use fc->net_ns for network namespace in RDMA and socket transports Yizhou Zhao
2026-06-15 13:15 ` Dominique Martinet

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox