Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Mohamed Khalfella" <mkhalfella@purestorage.com>
Cc: linux-nvme@lists.infradead.org
Subject: Re: [PATCH v7 09/17] nvme: Implement cross-controller reset completion
Date: Sat, 14 Nov 2026 03:29:37 +0000	[thread overview]
Message-ID: <sashiko-outbox-214111@kernel.org> (raw)
In-Reply-To: <20261114030454.2836543-10-mkhalfella@purestorage.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] nvme: UAF and deadlock in nvme_ccr_work() when controller is
  not LIVE
--

commit ccb451fbdaf89eaa6e4be835d2b43da8b0854559
Author: Mohamed Khalfella <mkhalfella@purestorage.com>

nvme: Implement cross-controller reset completion

This commit adds ctrl->ccr_work and handles NVME_AER_NOTICE_CCR_COMPLETED
events by reading the NVME_LOG_CCR log page and completing matching entries on
ctrl->ccr_list.

> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index 27c33dc49175e..54b83092a9e8f 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
[ ... ]
> @@ -5060,6 +5061,48 @@ static void nvme_get_fw_slot_info(struct nvme_ctrl *ctrl)
>  	kfree(log);
>  }
>  
> +static void nvme_ccr_work(struct work_struct *work)
> +{
> +	struct nvme_ctrl *ctrl = container_of(work, struct nvme_ctrl, ccr_work);
> +	struct nvme_ccr_entry *ccr;
> +	struct nvme_ccr_log_entry *entry;
> +	struct nvme_ccr_log *log;
> +	int num_entries, ret, i;
> +	unsigned long flags;
> +
> +	log = kmalloc_obj(*log);
> +	if (!log)
> +		return;
> +
> +	ret = nvme_get_log(ctrl, 0, NVME_LOG_CCR, 0x01,
> +			   0x00, log, sizeof(*log), 0);

[Severity: High]
Can nvme_ccr_work() submit a Get Log Page command to a destroyed or quiesced
ctrl->admin_q when the controller is no longer live?

During controller deletion, nvme_do_delete_ctrl() calls nvme_stop_ctrl()
before ctrl->ops->delete_ctrl() stops the admin queue, and
nvme_uninit_ctrl() runs only after nvme_remove_admin_tag_set() has already
destroyed ctrl->admin_q and freed ctrl->admin_tagset.  If an in-flight AEN
completes with NVME_AER_NOTICE_CCR_COMPLETED after nvme_stop_ctrl() cancels
ctrl->ccr_work, nvme_ccr_work() is re-queued and can access ctrl->admin_q
while or after it is destroyed:

CPU0                                  CPU1
nvme_do_delete_ctrl()
  nvme_stop_ctrl()
    cancel_work_sync(&ctrl->ccr_work)
                                      nvme_complete_async_event()
                                        nvme_handle_aen_notice()
                                          queue_work(nvme_wq, &ctrl->ccr_work)
  ctrl->ops->delete_ctrl()
    ...
    nvme_remove_admin_tag_set()
      blk_mq_destroy_queue(ctrl->admin_q)
      blk_mq_free_tag_set(ctrl->admin_tagset)
                                      nvme_ccr_work()
                                        nvme_get_log(ctrl, ...)
                                          <-- use-after-free on admin_q
  nvme_uninit_ctrl()
    cancel_work_sync(&ctrl->ccr_work)

Because nvme_ccr_work() does not check nvme_ctrl_state(ctrl) ==
NVME_CTRL_LIVE, it can also run while ctrl->admin_q is quiesced during reset
or transport error recovery; nvme_get_log() then blocks in blk_execute_rq()
waiting for the queue to be unquiesced, and the next nvme_stop_ctrl() ->
cancel_work_sync(&ctrl->ccr_work) deadlocks before teardown can unquiesce
ctrl->admin_q.

Checking nvme_ctrl_state(ctrl) != NVME_CTRL_LIVE at the start of
nvme_ccr_work() (like nvme_ana_work() and nvme_scan_work()) and cancelling
ctrl->ccr_work in nvme_remove_admin_tag_set() before destroying
ctrl->admin_q would avoid both issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261114030454.2836543-1-mkhalfella@purestorage.com?part=9


  reply	other threads:[~2026-11-14  3:29 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-14  3:04 [PATCH v7 00/17] TP8028 Rapid Path Failure Recovery Mohamed Khalfella
2026-11-14  3:04 ` [PATCH v7 01/17] nvmet: Rapid Path Failure Recovery set controller identify fields Mohamed Khalfella
2026-11-14  3:17   ` sashiko-bot
2026-11-14  3:04 ` [PATCH v7 02/17] nvmet/debugfs: Export controller CIU and CIRN via debugfs Mohamed Khalfella
2026-11-14  3:12   ` sashiko-bot
2026-11-14  3:04 ` [PATCH v7 03/17] nvmet: Implement CCR nvme command Mohamed Khalfella
2026-11-14  3:30   ` sashiko-bot
2026-11-14  3:04 ` [PATCH v7 04/17] nvmet: Implement CCR logpage Mohamed Khalfella
2026-11-14  3:20   ` sashiko-bot
2026-11-14  3:04 ` [PATCH v7 05/17] nvmet: Send an AEN on CCR completion Mohamed Khalfella
2026-11-14  3:04 ` [PATCH v7 06/17] nvme: Rapid Path Failure Recovery read controller identify fields Mohamed Khalfella
2026-11-14  3:04 ` [PATCH v7 07/17] nvme: Introduce FENCING and FENCED controller states Mohamed Khalfella
2026-11-14  3:29   ` sashiko-bot
2026-11-14  3:04 ` [PATCH v7 08/17] nvme: Implement cross-controller reset recovery Mohamed Khalfella
2026-11-14  3:26   ` sashiko-bot
2026-11-14  3:04 ` [PATCH v7 09/17] nvme: Implement cross-controller reset completion Mohamed Khalfella
2026-11-14  3:29   ` sashiko-bot [this message]
2026-11-14  3:04 ` [PATCH v7 10/17] nvme-tcp: Use CCR to recover controller that hits an error Mohamed Khalfella
2026-11-14  3:38   ` sashiko-bot
2026-11-14  3:04 ` [PATCH v7 11/17] nvme-rdma: " Mohamed Khalfella
2026-11-14  3:04 ` [PATCH v7 12/17] nvme-fc: start error recovery instead of aborting timed out IOs Mohamed Khalfella
2026-11-14  3:46   ` sashiko-bot
2026-11-14  3:04 ` [PATCH v7 13/17] nvme-fc: perform error recovery directly from ioerr_work Mohamed Khalfella
2026-11-14  3:31   ` sashiko-bot
2026-11-14  3:04 ` [PATCH v7 14/17] nvme-fc: Use CCR to recover controller that hits an error Mohamed Khalfella
2026-11-14  3:38   ` sashiko-bot
2026-11-14  3:04 ` [PATCH v7 15/17] nvme-fc: Hold inflight requests while in FENCING state Mohamed Khalfella
2026-11-14  4:06   ` sashiko-bot
2026-11-14  3:04 ` [PATCH v7 16/17] nvmet: Add support for CQT to nvme target Mohamed Khalfella
2026-11-14  3:04 ` [PATCH v7 17/17] nvme: Add support for CQT to nvme host Mohamed Khalfella

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=sashiko-outbox-214111@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=mkhalfella@purestorage.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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