Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Stanley Jhu" <stanleyjhu@google.com>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v3] scsi: ufs: core: Keep internal commands dispatchable during error handling
Date: Sat, 12 Sep 2026 13:37:39 +0000	[thread overview]
Message-ID: <20260912133739.826361F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260912131625.2301486-1-stanleyjhu@google.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Concurrent use-after-free of `pseudo_sdev` and its `request_queue` during driver removal.
--

commit 8a56a1b6be4e0430f65c83bfe4de68c1b55a6211
Author: Stanley Jhu <stanleyjhu@google.com>

scsi: ufs: core: Keep internal commands dispatchable during error handling

This commit unquiesces the pseudo SCSI device's request queue during error
handling so internal commands can be dispatched while logical units remain
quiesced. It balances this by re-quiescing the pseudo device queue in the
unprepare phase.

Link: https://lore.kernel.org/all/6f78c4bd-a70b-402d-abfd-599091b67674@acm.org/

> diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
> index 234e18b5078f2..eb86db492f225 100644
> --- a/drivers/ufs/core/ufshcd.c
> +++ b/drivers/ufs/core/ufshcd.c
> @@ -6841,11 +6841,17 @@ static void ufshcd_err_handling_prepare(struct ufs_hba *hba)
>  	}
>  	/* Wait for ongoing ufshcd_queuecommand() calls to finish. */
>  	blk_mq_quiesce_tagset(&hba->host->tag_set);
> +	/*
> +	 * Internal commands are submitted on the pseudo SCSI device. Let them
> +	 * through so that the error handler can recover the link.
> +	 */
> +	blk_mq_unquiesce_queue(hba->host->pseudo_sdev->request_queue);

[Severity: High]
Is it possible for hba->host->pseudo_sdev and its request_queue to be freed
before we access it here?

When the driver is unbound, ufshcd_remove() calls scsi_remove_host() before
the error handler workqueue is drained and destroyed in ufshcd_hba_exit():

drivers/ufs/core/ufshcd.c:ufshcd_remove() {
        ...
        if (hba->scsi_host_added)
                scsi_remove_host(hba->host);
        ...
}

Calling scsi_remove_host() removes all attached SCSI devices, including the
pseudo_sdev, which drops its final reference and frees it.

If ufshcd_err_handler() executes concurrently, it checks
ufshcd_err_handling_should_stop() and drops the host_lock:

drivers/ufs/core/ufshcd.c:ufshcd_err_handler() {
        ...
        if (ufshcd_err_handling_should_stop(hba)) {
                // ...
        }
        spin_unlock_irqrestore(&hba->host->host_lock, flags);

        ufshcd_err_handling_prepare(hba);
        ...
}

Since ufshcd_err_handling_should_stop() might return false before teardown
flags like is_powered are set, could this race lead to a use-after-free
when we dereference hba->host->pseudo_sdev->request_queue?

>  	cancel_work_sync(&hba->eeh_work);
>  }
>  
>  static void ufshcd_err_handling_unprepare(struct ufs_hba *hba)
>  {
> +	blk_mq_quiesce_queue_nowait(hba->host->pseudo_sdev->request_queue);

[Severity: High]
Would the same use-after-free race occur here during the unprepare phase?

>  	blk_mq_unquiesce_tagset(&hba->host->tag_set);
>  	ufshcd_release(hba);
>  	if (ufshcd_is_clkscaling_supported(hba))

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260912131625.2301486-1-stanleyjhu@google.com?part=1

  reply	other threads:[~2026-09-12 13:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-12 13:16 [PATCH v3] scsi: ufs: core: Keep internal commands dispatchable during error handling Stanley Jhu
2026-09-12 13:37 ` sashiko-bot [this message]
2026-09-12 13:53   ` Stanley Jhu
2026-09-14 20:34 ` Bart Van Assche
2026-09-17  2:28 ` Martin K. Petersen (Oracle)

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=20260912133739.826361F00893@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=stanleyjhu@google.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