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 v4 2/3] scsi: ufs: rpmb: Decouple device lifecycle from devres to avoid UAF
Date: Sun, 13 Sep 2026 03:47:25 +0000	[thread overview]
Message-ID: <20260913034726.28F751F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260913033633.3159296-3-stanleyjhu@google.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Module Reference Leak / Unload Deadlock
--

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

scsi: ufs: rpmb: Decouple device lifecycle from devres to avoid UAF

This commit addresses a use-after-free issue by tying the ufs_rpmb_dev
memory to its reference count instead of devres. It pins the SCSI WLUN
during probe, cleans up properly during release to break the lifecycle
cycle, and rejects requests once the WLUN is offline.

> diff --git a/drivers/ufs/core/ufs-rpmb.c b/drivers/ufs/core/ufs-rpmb.c
> index 783ecfc7581d7..373b60aba9166 100644
> --- a/drivers/ufs/core/ufs-rpmb.c
> +++ b/drivers/ufs/core/ufs-rpmb.c
[ ... ]
> @@ -177,25 +186,28 @@ int ufs_rpmb_probe(struct ufs_hba *hba)
[ ... ]
>  		ufs_rpmb = kzalloc_obj(*ufs_rpmb);
>  		if (!ufs_rpmb) {
>  			ret = -ENOMEM;
>  			goto err_out;
>  		}
>  
> -		ufs_rpmb->hba = hba;
> -		ufs_rpmb->dev.parent = &hba->ufs_rpmb_wlun->sdev_gendev;
> +		INIT_LIST_HEAD(&ufs_rpmb->node);
> +
> +		ret = scsi_device_get(sdev);

[Severity: Medium]
Does this code introduce a module reference leak that prevents driver unloading?

When ufs_rpmb_probe() calls scsi_device_get(), the following call chain occurs:

ufs_rpmb_probe()
  scsi_device_get(sdev)
    try_module_get(sdev->host->hostt->module)

Since this is called during the driver's probe sequence, and the SCSI host
template module is likely this exact same module (ufshcd-core), it ends up
taking a reference on itself. 

Because the reference won't be dropped until the device is released, and the
device won't be released while the module is held active, doesn't this create
a lifecycle deadlock where rmmod will permanently fail with -EBUSY?

> +		if (ret) {
> +			kfree(ufs_rpmb);
> +			goto err_out;
> +		}
> +
> +		ufs_rpmb->sdev = sdev;
> +		ufs_rpmb->region_id = region;

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

  reply	other threads:[~2026-09-13  3:47 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-13  3:36 [PATCH v4 0/3] rpmb: Fix request serialisation and teardown races Stanley Jhu
2026-09-13  3:36 ` [PATCH v4 1/3] rpmb: core: Guard frame requests and teardown with mutex Stanley Jhu
2026-09-13 17:43   ` Bean Huo
2026-09-13  3:36 ` [PATCH v4 2/3] scsi: ufs: rpmb: Decouple device lifecycle from devres to avoid UAF Stanley Jhu
2026-09-13  3:47   ` sashiko-bot [this message]
2026-09-13  5:07     ` Stanley Jhu
2026-09-13  3:36 ` [PATCH v4 3/3] scsi: ufs: rpmb: Drop the unregistered ufs_rpmb bus Stanley Jhu

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=20260913034726.28F751F000FF@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