Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: Stanley Jhu <stanleyjhu@google.com>
To: sashiko-bot@kernel.org
Cc: linux-scsi@vger.kernel.org, sashiko-reviews@lists.linux.dev,
	 "Martin K . Petersen" <mkp@kernel.org>,
	Brian Kao <powenkao@google.com>
Subject: Re: [PATCH v3 2/2] scsi: ufs: rpmb: Decouple device lifecycle from devres to avoid UAF
Date: Thu, 10 Sep 2026 10:13:18 +0800	[thread overview]
Message-ID: <20260910021318.2030765-1-stanleyjhu@google.com> (raw)
In-Reply-To: <20260910020917.C22961F000FF@smtp.kernel.org>

On Thu, 10 Sep 2026, sashiko-bot@kernel.org wrote:
> [Severity: Critical]
> This isn't a bug introduced by this patch, but does this sequence still
> leave a use-after-free window during device removal?
> 
> When rpmb_dev_unregister() is called, it internally calls device_del() on
> the child device, which immediately drops the reference to its parent device
> (ufs_rpmb->dev).
> 
> If a consumer is actively holding a reference to the child device via
> rpmb_dev_get(), the child device itself remains allocated. However, the
> subsequent call to device_unregister() here drops the final reference to
> the parent ufs_rpmb structure, causing it to be freed.
> 
> If the consumer then concurrently executes a request, the framework will
> pass the now-dangling parent pointer to the route_frames callback:
> 
> drivers/ufs/core/ufs-rpmb.c:ufs_rpmb_route_frames() {
>     struct ufs_rpmb_dev *ufs_rpmb = dev_get_drvdata(dev);
>     ...
> }
> 
> Could this dev_get_drvdata(dev) dereference the freed parent memory,
> resulting in a use-after-free despite the new lifecycle management?

This specific teardown race is guarded by the companion patch in the
generic RPMB core:
"[PATCH v3] rpmb: core: Guard frame requests and teardown with mutex"
https://lore.kernel.org/r/20260910015515.1991789-1-stanleyjhu@google.com

In rpmb_dev_unregister(), rdev->lock is acquired to drain in-flight
requests and mark rdev->dead = true before device_del() is invoked.
Any concurrent or subsequent call to rpmb_route_frames() is rejected
with -ENODEV under rdev->lock before dereferencing rdev->dev.parent.

Therefore, the dangling parent pointer is never dereferenced once
rpmb_dev_unregister() returns.

Thanks,
Stanley

  reply	other threads:[~2026-09-10  2:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-10  1:55 [PATCH v3 0/2] scsi: ufs: rpmb: Fix bus registration and device lifecycle Stanley Jhu
2026-09-10  1:55 ` [PATCH v3 1/2] scsi: ufs: rpmb: Register and unregister ufs_rpmb_bus_type Stanley Jhu
2026-09-10  1:55 ` [PATCH v3 2/2] scsi: ufs: rpmb: Decouple device lifecycle from devres to avoid UAF Stanley Jhu
2026-09-10  2:09   ` sashiko-bot
2026-09-10  2:13     ` Stanley Jhu [this message]
2026-09-10  2:06 ` [PATCH v3 0/2] scsi: ufs: rpmb: Fix bus registration and device lifecycle 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=20260910021318.2030765-1-stanleyjhu@google.com \
    --to=stanleyjhu@google.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=mkp@kernel.org \
    --cc=powenkao@google.com \
    --cc=sashiko-bot@kernel.org \
    --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