All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Naomi Chu" <naomi.chu@mediatek.com>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v1] scsi: ufs: core: Hold a clock reference across the probe
Date: Wed, 09 Sep 2026 09:25:36 +0000	[thread overview]
Message-ID: <20260909092536.B78571F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260909091045.1134956-1-naomi.chu@mediatek.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [Critical] Missing scsi_remove_host() on the ufshcd_init() error path leaves dangling sysfs references leading to use-after-free.
--

commit a971113b5d6d58a777d3955df4f8947756e7eb86
Author: Naomi Chu <naomi.chu@mediatek.com>

scsi: ufs: core: Hold a clock reference across the probe

This patch modifies the UFS core to take a clock reference as soon as clock
gating is initialized and holds it until the probe finishes or fails. This
ensures register accesses during the probe do not depend on the host state
and prevents them from occurring without a held clock reference.

> diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
> index ee21388e74f5f..7d63287b5ca94 100644
> --- a/drivers/ufs/core/ufshcd.c
> +++ b/drivers/ufs/core/ufshcd.c

[ ... ]

> @@ -11322,7 +11326,7 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
>  
>  	err = ufshcd_add_scsi_host(hba);
>  	if (err)
> -		goto out_disable;
> +		goto out_release;
>  
>  	/* Hold auto suspend until async scan completes */
>  	pm_runtime_get_sync(dev);

[ ... ]

> @@ -11386,6 +11390,8 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
>  	ufshcd_pm_qos_init(hba);
>  	return 0;
>  
> +out_release:
> +	ufshcd_release(hba);
>  out_disable:
>  	hba->is_irq_enabled = false;
>  	ufshcd_hba_exit(hba);

[Severity: Critical]
This is a pre-existing issue, but does this error path leave the SCSI host
registered in sysfs if a failure occurs later in the initialization?

If ufshcd_init() fails after successfully calling ufshcd_add_scsi_host()
(for example, if ufshcd_link_startup() or ufshcd_verify_dev_init() fails
and jumps to out_release), the function returns an error without calling
scsi_remove_host().

Since the driver probe fails, devres will free managed resources such as
the MMIO region mappings and IRQs. However, the SCSI host would remain
registered in sysfs.

Could a subsequent interaction with these orphaned sysfs nodes invoke SCSI
callbacks that attempt to access the unmapped MMIO base and freed memory,
potentially leading to a use-after-free and system crash?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260909091045.1134956-1-naomi.chu@mediatek.com?part=1

      reply	other threads:[~2026-09-09  9:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-09  9:10 [PATCH v1] scsi: ufs: core: Hold a clock reference across the probe Naomi Chu
2026-09-09  9:25 ` sashiko-bot [this message]

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=20260909092536.B78571F00A3D@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=naomi.chu@mediatek.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.