From 37dce65a0b4356d7ec289a5d09cece5db241c302 Mon Sep 17 00:00:00 2001 From: Yizhou Zhao Date: Fri, 29 May 2026 17:06:24 +0800 Subject: [PATCH] 9p: use fc->net_ns for network namespace in RDMA and socket transports 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 Reported-by: Yuxiang Yang Reported-by: Ao Wang Reported-by: Xuewei Feng Reported-by: Qi Li Reported-by: Ke Xu Suggested-by: Dominique Martinet Assisted-by: GLM:GLM-5.1 Signed-off-by: Yizhou Zhao Message-ID: <20260529090625.78761-1-zhaoyz24@mails.tsinghua.edu.cn> Signed-off-by: Dominique Martinet --- net/9p/trans_fd.c | 11 +++++------ net/9p/trans_rdma.c | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c index eb685b52aeb2..dce963332a04 100644 --- a/net/9p/trans_fd.c +++ b/net/9p/trans_fd.c @@ -887,8 +887,8 @@ 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, - port_str, &stor); + err = inet_pton_with_scope(fc->net_ns, AF_UNSPEC, addr, port_str, + &stor); if (err < 0) return err; @@ -896,8 +896,8 @@ 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, - SOCK_STREAM, IPPROTO_TCP, &csocket, 1); + 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", __func__, task_pid_nr(current)); @@ -946,8 +946,7 @@ p9_fd_create_unix(struct p9_client *client, struct fs_context *fc) __func__, task_pid_nr(current), addr); return -ENAMETOOLONG; } - err = __sock_create(current->nsproxy->net_ns, PF_UNIX, - SOCK_STREAM, 0, &csocket, 1); + err = __sock_create(fc->net_ns, PF_UNIX, SOCK_STREAM, 0, &csocket, 1); if (err < 0) { pr_err("%s (%d): problem creating socket\n", __func__, task_pid_nr(current)); diff --git a/net/9p/trans_rdma.c b/net/9p/trans_rdma.c index b4274f10fa44..f4450e779a79 100644 --- a/net/9p/trans_rdma.c +++ b/net/9p/trans_rdma.c @@ -556,7 +556,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;