public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: Casey Chen <cachen@purestorage.com>
To: linux-nvme@lists.infradead.org, linux-block@vger.kernel.org
Cc: yzhong@purestorage.com, sconnor@purestorage.com, axboe@kernel.dk,
	mkhalfella@purestorage.com, Casey Chen <cachen@purestorage.com>
Subject: [PATCH 1/1] nvme: fix use-after-free of admin queue via stale pointer
Date: Wed, 29 Oct 2025 15:08:53 -0600	[thread overview]
Message-ID: <20251029210853.20768-2-cachen@purestorage.com> (raw)
In-Reply-To: <20251029210853.20768-1-cachen@purestorage.com>

From: Yuanyuan Zhong <yzhong@purestorage.com>

When a controller is deleted (e.g., via sysfs delete_controller), the
admin queue is freed while userspace may still have open fd to the
namespace block device. Userspace can issue IOCTLs on the open fd
that access the freed admin queue through the stale ns->ctrl->admin_q
pointer, causing a use-after-free.

Fix this by taking an additional reference on the admin queue during
namespace allocation and releasing it during namespace cleanup.

Signed-off-by: Casey Chen <cachen@purestorage.com>
Signed-off-by: Seamus Connor <sconnor@purestorage.com>
---
 drivers/nvme/host/core.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 8d8af58e79d1..184a6096a2be 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -687,6 +687,7 @@ static void nvme_free_ns(struct kref *kref)
 {
 	struct nvme_ns *ns = container_of(kref, struct nvme_ns, kref);
 
+	blk_put_queue(ns->ctrl->admin_q);
 	put_disk(ns->disk);
 	nvme_put_ns_head(ns->head);
 	nvme_put_ctrl(ns->ctrl);
@@ -3903,9 +3904,14 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, struct nvme_ns_info *info)
 	struct gendisk *disk;
 	int node = ctrl->numa_node;
 
+	if (!blk_get_queue(ctrl->admin_q)) {
+		dev_err(ctrl->device, "failed to get admin_q %p\n", ctrl->admin_q);
+		return;
+	}
+
 	ns = kzalloc_node(sizeof(*ns), GFP_KERNEL, node);
 	if (!ns)
-		return;
+		goto out_put_admin_q;
 
 	if (ctrl->opts && ctrl->opts->data_digest)
 		lim.features |= BLK_FEAT_STABLE_WRITES;
@@ -4002,6 +4008,8 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, struct nvme_ns_info *info)
 	put_disk(disk);
  out_free_ns:
 	kfree(ns);
+ out_put_admin_q:
+	blk_put_queue(ctrl->admin_q);
 }
 
 static void nvme_ns_remove(struct nvme_ns *ns)
-- 
2.49.0


  reply	other threads:[~2025-10-29 21:09 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-29 21:08 [PATCH 0/1] cover letter Casey Chen
2025-10-29 21:08 ` Casey Chen [this message]
2025-10-29 23:00   ` [PATCH 1/1] nvme: fix use-after-free of admin queue via stale pointer Chaitanya Kulkarni
2025-10-29 23:33     ` Ming Lei
2025-10-30  0:39   ` Keith Busch
2025-10-30  8:12     ` Chaitanya Kulkarni
2025-10-31  2:54       ` Keith Busch
2025-10-31  8:16         ` Chaitanya Kulkarni
2025-10-31 19:19       ` Casey Chen
2025-10-31 19:31         ` Chaitanya Kulkarni
2025-11-04 22:39           ` Casey Chen
2025-11-04 23:00             ` Keith Busch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251029210853.20768-2-cachen@purestorage.com \
    --to=cachen@purestorage.com \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=mkhalfella@purestorage.com \
    --cc=sconnor@purestorage.com \
    --cc=yzhong@purestorage.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox