Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] nvme-tcp: use correct network namespace to resolve addresses
@ 2026-11-25 14:20 Hannes Reinecke
  2026-11-25 14:29 ` sashiko-bot
  2026-11-26  8:56 ` Christoph Hellwig
  0 siblings, 2 replies; 3+ messages in thread
From: Hannes Reinecke @ 2026-11-25 14:20 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Keith Busch, Sagi Grimberg, 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.

Fixes: 87a1ac965502 ("nvme-tcp: store and use the caller's network namespace")

Signed-off-by: Hannes Reinecke <hare@kernel.org>
---
 drivers/nvme/host/tcp.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c
index c3149a9151f5..a4ecd0aa6783 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,7 +3344,7 @@ 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,
+		if (!__dev_get_by_name(ctrl->net,
 				       opts->host_iface)) {
 			pr_err("invalid interface passed: %s\n",
 			       opts->host_iface);
@@ -3367,16 +3368,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] 3+ messages in thread

* Re: [PATCH] nvme-tcp: use correct network namespace to resolve addresses
  2026-11-25 14:20 [PATCH] nvme-tcp: use correct network namespace to resolve addresses Hannes Reinecke
@ 2026-11-25 14:29 ` sashiko-bot
  2026-11-26  8:56 ` Christoph Hellwig
  1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-25 14:29 UTC (permalink / raw)
  To: Hannes Reinecke; +Cc: linux-nvme

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] nvme-tcp: use-after-free in nvme_tcp_alloc_ctrl() [1]
--

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

nvme-tcp: use correct network namespace to resolve addresses

This commit initializes ctrl->net earlier in nvme_tcp_alloc_ctrl() and
uses it instead of init_net when resolving traddr, host_traddr, and
host_iface.

> diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c
> index 62a594b8ab9bf..bcc092cdf42b0 100644
> --- a/drivers/nvme/host/tcp.c
> +++ b/drivers/nvme/host/tcp.c
> @@ -3309,6 +3309,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);
> @@ -3325,7 +3326,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",
> @@ -3334,7 +3335,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",
> @@ -3344,7 +3345,7 @@ 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,
> +		if (!__dev_get_by_name(ctrl->net,
>  				       opts->host_iface)) {

[Severity: Critical]
This problem wasn't introduced by this patch, but can calling
__dev_get_by_name() without holding rtnl_lock or rcu_read_lock() cause a
use-after-free [1]?

__dev_get_by_name() traverses the net->dev_name_head hash list without
taking any locks.  Concurrent network device registration or
unregistration can modify or free list entries during the traversal,
leading to a use-after-free or an infinite loop.

[1] https://sashiko.dev/#/bug/linux-8edcdd49-7446-4c9f-86a0-f1b1561c3867

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


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

* Re: [PATCH] nvme-tcp: use correct network namespace to resolve addresses
  2026-11-25 14:20 [PATCH] nvme-tcp: use correct network namespace to resolve addresses Hannes Reinecke
  2026-11-25 14:29 ` sashiko-bot
@ 2026-11-26  8:56 ` Christoph Hellwig
  1 sibling, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2026-11-26  8:56 UTC (permalink / raw)
  To: Hannes Reinecke; +Cc: Christoph Hellwig, Keith Busch, Sagi Grimberg, linux-nvme

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

Can you also look into the Sashiko complaint about __dev_get_by_name?



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

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

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 14:20 [PATCH] nvme-tcp: use correct network namespace to resolve addresses Hannes Reinecke
2026-11-25 14:29 ` sashiko-bot
2026-11-26  8:56 ` Christoph Hellwig

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