Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795033039; b=xbUD94eau5k7Anvoym4zS647r2jIRkvHA/JMMqfxmpc0n5V6oioGIaXNvwFd50d5FJOn O+pkH1xyBots6yNw0TBkdCgrbCQJ0cq2iwWtRItyr3v0m1NQ8apRTtsK6OeaY4uqg5aqa LqbqEWayDjaWsoiXn1VCtIA0oNYBhYCGe7nFfrUTlB3QLdMU/MErHbT5qFE+OXIQix87S YZYhXOwYOv+EcG+t7c9elscGig7JjB5NGc5z4XkIyWCf3f7ZQAGHYJ8g2ORhQJug2mPAK 9oKiJnkZ3Yr5Dr+Jz1jWKPQcf00bPPFOHWmibsEu7SD91OQ3NRIZUSD6hvN80bgFrvg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795033039; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=h2AmZ1p4xPhCU7ySX27x4EfP2WeW/m/p+soGgQs7oKo=; b=1lODXebhhzh/QtvQ0qv+5BnkDZghJ/FJmK5UZd64tzzVYNGqzXULsywnqsdP4R577RWu BvQUheMLrfw2hRHuqiEMFA6OvMWq6eE87ulw11CMqjyO1X/hpPiOVmy8LvY4bQppL5Gs/ 7I5RGM4fN1+o71DydLwi5PuVVjr7Ph9PHLtttWF9R0e+Lm/lS8uxT+C/4+Wm9UwBuE/1u cYey1oX0vvE8vD5bWDZEmYJt+T8cAS8JeYk95fOKTF2TnWgBiiI8tlFpBebKJFt51qLMy a5g3mGnmjiab33eJVU8pW2y3vh4nqWzDvqIp+jnT/Uy/oBhCwmksQVNU1yq8o6bpKYA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=a0zbZenf; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 78B04606A338; Wed, 18 Nov 2026 20:17:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=a0zbZenf Received: by smtp.kernel.org (Postfix) with ESMTPSA id D14AD1F000C7; Wed, 18 Nov 2026 20:17:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795033039; bh=h2AmZ1p4xPhCU7ySX27x4EfP2WeW/m/p+soGgQs7oKo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=a0zbZenfHIbB7qsZJcLQtXCC8y3mHPTk1G833JJOmNWaruoxO7rz+zhvvpibgRgG+ T1Q2MgYpHvYytOyxm2QDeq8RdnngpgqMFDUpreB2TsGNd44QZ068XGqEkNdsy+lt4S duoyzuBvkMPUli1JhhbK0/PSgL4ri9nTTeEz1gUY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, syzbot+c98b21427617af7f547a@syzkaller.appspotmail.com, Rongzheng Wang , Keith Busch , Sasha Levin Subject: [PATCH 6.12 1626/1756] nvmet: use the enabled transport when disabling a port Date: Wed, 18 Nov 2026 16:02:33 +0100 Message-ID: <20261118150114.542160840@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150007.957976754@linuxfoundation.org> References: <20261118150007.957976754@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Rongzheng Wang [ Upstream commit 60385038754ed9fb05dab127b35f88c702252505 ] 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 Signed-off-by: Keith Busch Signed-off-by: Sasha Levin --- 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 7b0c04a3faf62..e6e359ae8b806 100644 --- a/drivers/nvme/target/configfs.c +++ b/drivers/nvme/target/configfs.c @@ -358,10 +358,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)) @@ -369,7 +374,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); @@ -378,7 +384,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 c4a4af8a0547c..6fe67b3d708ec 100644 --- a/drivers/nvme/target/core.c +++ b/drivers/nvme/target/core.c @@ -381,11 +381,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); } -- 2.53.0