nvme-rdma: use current network namespace
PATCH 1/1 nvme-rdma: use current network namespace
Creating the connection manager in the initial network namespace will result in expected issues when running with network namespaces. So capture the current network namespace when setting up the connection manager to ensure we're accessing the right information.
--- drivers/nvme/host/rdma.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/nvme/host/rdma.c +8 -4
@@ -133,6 +133,7 @@ struct nvme_rdma_ctrl {u32 max_fr_pages; +struct net *net;struct sockaddr_storage addr;struct sockaddr_storage src_addr;
@@ -595,8 +596,8 @@ static int nvme_rdma_alloc_queue(struct nvme_rdma_queue *queue)else queue->cmnd_capsule_len =sizeof (struct nvme_command ); - queue->cm_id =rdma_create_id (&init_net, nvme_rdma_cm_handler, queue, -RDMA_PS_TCP ,IB_QPT_RC ); + queue->cm_id =rdma_create_id (ctrl->net, nvme_rdma_cm_handler, + queue,RDMA_PS_TCP ,IB_QPT_RC );if (IS_ERR (queue->cm_id)) {dev_info (ctrl->ctrl.device,"failed to create CM ID: %ld\n" ,PTR_ERR (queue->cm_id));
@@ -2288,6 +2289,8 @@ static struct nvme_rdma_ctrl *nvme_rdma_alloc_ctrl(struct device *dev,if (!ctrl)return ERR_PTR (-ENOMEM ); ctrl->ctrl.opts = opts; + ctrl->net =get_net (current->nsproxy->net_ns); +/* * Safe to init list while allocating ctrl object. */
@@ -2303,7 +2306,7 @@ static struct nvme_rdma_ctrl *nvme_rdma_alloc_ctrl(struct device *dev, opts->mask |=NVMF_OPT_TRSVCID ; } - ret =inet_pton_with_scope (&init_net,AF_UNSPEC , + ret =inet_pton_with_scope (ctrl->net,AF_UNSPEC , opts->traddr, opts->trsvcid, &ctrl->addr);if (ret) { pr_err("malformed address passed: %s:%s\n",
@@ -2312,7 +2315,7 @@ static struct nvme_rdma_ctrl *nvme_rdma_alloc_ctrl(struct device *dev, }if (opts->mask &NVMF_OPT_HOST_TRADDR ) { - ret =inet_pton_with_scope (&init_net,AF_UNSPEC , + ret =inet_pton_with_scope (ctrl->net,AF_UNSPEC , opts->host_traddr,NULL , &ctrl->src_addr);if (ret) { pr_err("malformed src address passed: %s\n",
@@ -2354,6 +2357,7 @@ static struct nvme_rdma_ctrl *nvme_rdma_alloc_ctrl(struct device *dev, out_kfree_queues:kfree (ctrl->queues); out_free_ctrl: +put_net (ctrl->net);kfree (ctrl);return ERR_PTR (ret); }
Signature · 1 line
2.51.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] nvme-rdma: netns reference leak in nvme_rdma_free_ctrl() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] nvme-rdma: netns reference leak in nvme_rdma_free_ctrl() --
commit ea2302951454868193e26cecb0bf291eea317e73
Author: Hannes Reinecke <[email protected]>
nvme-rdma: use current network namespace
This commit records the caller's network namespace in struct nvme_rdma_ctrl and passes it to inet_pton_with_scope() and rdma_create_id() instead of init_net.
Quoted 4 lines
drivers/nvme/host/rdma.c +0
-0
[ ... ]
Quoted 9 lines
drivers/nvme/host/rdma.c +2
-0@@ -2288,6 +2289,8 @@ static struct nvme_rdma_ctrl *nvme_rdma_alloc_ctrl(struct device *dev,if (!ctrl)return ERR_PTR (-ENOMEM ); ctrl->ctrl.opts = opts; + ctrl->net =get_net (current->nsproxy->net_ns); +/* * Safe to init list while allocating ctrl object. */
[ ... ]
drivers/nvme/host/rdma.c static struct nvme_rdma_ctrl *nvme_rdma_alloc_ctrl(struct device *dev, · line 2363
Quoted 8 lines
drivers/nvme/host/rdma.c +1
-0@@ -2354,6 +2357,7 @@ static struct nvme_rdma_ctrl *nvme_rdma_alloc_ctrl(struct device *dev, out_kfree_queues:kfree (ctrl->queues); out_free_ctrl: +put_net (ctrl->net);kfree (ctrl);return ERR_PTR (ret); }
[Severity: High]
Does this leak ctrl->net when a controller is freed after nvme_rdma_alloc_ctrl() succeeds? Once nvme_init_ctrl() succeeds, controller teardown goes through nvme_put_ctrl() -> nvme_rdma_free_ctrl(), which frees ctrl without calling put_net(ctrl->net), preventing the network namespace from ever being destroyed.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1