[PATCH] nvme-tcp: use correct network namespace to resolve addresses
sashiko-bot at kernel.org
sashiko-bot at kernel.org
Wed Nov 25 06:29:29 PST 2026
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 at 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
More information about the Linux-nvme
mailing list