Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCHv2] nvme-tcp: use correct network namespace to resolve addresses
@ 2026-11-26 11:51 Hannes Reinecke
  2026-11-26 11:58 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Hannes Reinecke @ 2026-11-26 11:51 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Sagi Grimberg, Keith Busch, linux-nvme, Hannes Reinecke

Resolving network addresses should use the current network namespace;
the passed-in addresses might not exist in the default network namespace.
And while at use dev_get_by_name_rcu() with proper rcu locks to avoid
a possible crash on network namespace changes.
 
Signed-off-by: Hannes Reinecke <hare@kernel.org>
---
 drivers/nvme/host/tcp.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c
index c3149a9151f5..34a8bc2c5af0 100644
--- a/drivers/nvme/host/tcp.c
+++ b/drivers/nvme/host/tcp.c
@@ -3308,6 +3308,7 @@ static struct nvme_tcp_ctrl *nvme_tcp_alloc_ctrl(struct device *dev,
 	ctrl->ctrl.queue_count = NVME_TCP_OPT_NR_QUEUES(opts);
 	ctrl->ctrl.sqsize = opts->queue_size - 1;
 	ctrl->ctrl.kato = opts->kato;
+	ctrl->net = get_net(current->nsproxy->net_ns);
 
 	INIT_DELAYED_WORK(&ctrl->connect_work,
 			nvme_tcp_reconnect_ctrl_work);
@@ -3324,7 +3325,7 @@ static struct nvme_tcp_ctrl *nvme_tcp_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",
@@ -3333,7 +3334,7 @@ static struct nvme_tcp_ctrl *nvme_tcp_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",
@@ -3343,8 +3344,13 @@ static struct nvme_tcp_ctrl *nvme_tcp_alloc_ctrl(struct device *dev,
 	}
 
 	if (opts->mask & NVMF_OPT_HOST_IFACE) {
-		if (!__dev_get_by_name(current->nsproxy->net_ns,
-				       opts->host_iface)) {
+		struct net_device *found;
+
+		rcu_read_lock();
+		found = dev_get_by_name_rcu(ctrl->net,
+					    opts->host_iface);
+		rcu_read_unlock();
+		if (!found) {
 			pr_err("invalid interface passed: %s\n",
 			       opts->host_iface);
 			ret = -ENODEV;
@@ -3367,16 +3373,15 @@ static struct nvme_tcp_ctrl *nvme_tcp_alloc_ctrl(struct device *dev,
 	for (i = 0; i < ctrl->nr_allocated_queues; i++)
 		nvme_tcp_init_queue(ctrl, i);
 
-	ctrl->net = get_net(current->nsproxy->net_ns);
 	ret = nvme_init_ctrl(&ctrl->ctrl, dev, &nvme_tcp_ctrl_ops, 0);
 	if (ret)
 		goto out_kfree_queues;
 
 	return ctrl;
 out_kfree_queues:
-	put_net(ctrl->net);
 	kfree(ctrl->queues);
 out_free_ctrl:
+	put_net(ctrl->net);
 	kfree(ctrl);
 	return ERR_PTR(ret);
 }
-- 
2.51.0



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

* Re: [PATCHv2] nvme-tcp: use correct network namespace to resolve addresses
  2026-11-26 11:51 [PATCHv2] nvme-tcp: use correct network namespace to resolve addresses Hannes Reinecke
@ 2026-11-26 11:58 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-26 11:58 UTC (permalink / raw)
  To: Hannes Reinecke; +Cc: linux-nvme

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] nvme-tcp: missing Fixes trailer for nvme_tcp_alloc_ctrl() netns
  and RCU fixes
--

commit a9e44348b8fe94c523f1cf508bd4bb1ce6079725
Author: Hannes Reinecke <hare@kernel.org>

> nvme-tcp: use correct network namespace to resolve addresses
>
> Resolving network addresses should use the current network namespace;
> the passed-in addresses might not exist in the default network namespace.
> And while at use dev_get_by_name_rcu() with proper rcu locks to avoid
> a possible crash on network namespace changes.
>
> Signed-off-by: Hannes Reinecke <hare@kernel.org>

[Severity: Low]
Resolving opts->traddr and opts->host_traddr against init_net dates back
to 3f2304f8c6d6 ("nvme-tcp: add NVMe over TCP host driver"), and the
unlocked __dev_get_by_name() call was introduced in 8b43ced64d2b
("nvme-tcp: use __dev_get_by_name instead dev_get_by_name for
OPT_HOST_IFACE").  Should this include:

  Fixes: 3f2304f8c6d6 ("nvme-tcp: add NVMe over TCP host driver")
  Fixes: 8b43ced64d2b ("nvme-tcp: use __dev_get_by_name instead dev_get_by_name for OPT_HOST_IFACE")

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261126115121.6032-1-hare@kernel.org?part=1


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

end of thread, other threads:[~2026-11-26 11:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 11:51 [PATCHv2] nvme-tcp: use correct network namespace to resolve addresses Hannes Reinecke
2026-11-26 11:58 ` sashiko-bot

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