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: fa20105e09 ("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>
Message-ID: <20260529090625.78761-1-zhaoyz24@mails.tsinghua.edu.cn>
Signed-off-by: Dominique Martinet <asmadeus@codewreck.org>
This commit is contained in:
Yizhou Zhao 2026-05-29 17:06:24 +08:00 committed by Dominique Martinet
parent 5852cdf000
commit 37dce65a0b
2 changed files with 6 additions and 7 deletions

View File

@ -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));

View File

@ -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;