* [PATCH] nvmet: use the enabled transport when disabling a port
@ 2026-10-23 19:18 Rongzheng Wang
0 siblings, 0 replies; only message in thread
From: Rongzheng Wang @ 2026-10-23 19:18 UTC (permalink / raw)
To: Christoph Hellwig, Sagi Grimberg
Cc: Chaitanya Kulkarni, linux-nvme, linux-kernel
nvmet_disable_port() looks up the transport from the current
disc_addr.trtype, while nvmet_enable_port() records the transport in
port->tr_ops. If trtype is changed while a port is being enabled, the
port can be removed through a different transport, passing the private
data of the original transport to the wrong ->remove_port().
The same mismatch is reachable with loop and RDMA: loop add_port()
leaves port->priv NULL, and RDMA remove_port() dereferences it.
Use port->tr_ops for removal and serialize trtype changes with
nvmet_config_sem in nvmet_addr_trtype_store(), so the transport that
added the port is also the one that removes it.
Fixes: 8f000cac6e7a ("nvmet-rdma: add a NVMe over Fabrics RDMA target driver")
Reported-by: syzbot+c98b21427617af7f547a@syzkaller.appspotmail.com
Link: https://syzkaller.appspot.com/bug?extid=c98b21427617af7f547a
Link: https://lore.kernel.org/all/6acbc835.a150a118.27e199.003c.GAE@google.com/T/
Signed-off-by: Rongzheng Wang <testwrzwrz@gmail.com>
---
drivers/nvme/target/configfs.c | 16 ++++++++++++----
drivers/nvme/target/core.c | 8 +++++---
2 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/drivers/nvme/target/configfs.c b/drivers/nvme/target/configfs.c
index b03b5d1c2dc3..955f2b127970 100644
--- a/drivers/nvme/target/configfs.c
+++ b/drivers/nvme/target/configfs.c
@@ -387,10 +387,15 @@ static ssize_t nvmet_addr_trtype_store(struct config_item *item,
const char *page, size_t count)
{
struct nvmet_port *port = to_nvmet_port(item);
+ ssize_t ret = count;
int i;
- if (nvmet_is_port_enabled(port, __func__))
- return -EACCES;
+ down_write(&nvmet_config_sem);
+
+ if (nvmet_is_port_enabled(port, __func__)) {
+ ret = -EACCES;
+ goto out;
+ }
for (i = 0; i < ARRAY_SIZE(nvmet_transport); i++) {
if (sysfs_streq(page, nvmet_transport[i].name))
@@ -398,7 +403,8 @@ static ssize_t nvmet_addr_trtype_store(struct config_item *item,
}
pr_err("Invalid value '%s' for trtype\n", page);
- return -EINVAL;
+ ret = -EINVAL;
+ goto out;
found:
memset(&port->disc_addr.tsas, 0, NVMF_TSAS_SIZE);
@@ -407,7 +413,9 @@ static ssize_t nvmet_addr_trtype_store(struct config_item *item,
nvmet_port_init_tsas_rdma(port);
else if (port->disc_addr.trtype == NVMF_TRTYPE_TCP)
nvmet_port_init_tsas_tcp(port, NVMF_TCP_SECTYPE_NONE);
- return count;
+out:
+ up_write(&nvmet_config_sem);
+ return ret;
}
CONFIGFS_ATTR(nvmet_, addr_trtype);
diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index 07a74c2e1f58..5aaeeffc9ba2 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -393,11 +393,13 @@ void nvmet_disable_port(struct nvmet_port *port)
lockdep_assert_held(&nvmet_config_sem);
- port->enabled = false;
- port->tr_ops = NULL;
+ if (!port->enabled)
+ return;
- ops = nvmet_transports[port->disc_addr.trtype];
+ ops = port->tr_ops;
+ port->enabled = false;
ops->remove_port(port);
+ port->tr_ops = NULL;
module_put(ops->owner);
}
base-commit: 864c07de0c7dcbca58b61625dfa2e461ae63b242
--
2.39.5 (Apple Git-154)
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-10-23 19:22 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-23 19:18 [PATCH] nvmet: use the enabled transport when disabling a port Rongzheng Wang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®