Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jorge Ramirez-Ortiz" <jorge.ramirez@oss.qualcomm.com>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v1 2/2] ufs: rpmb: use a fixed-length RPMB dev_id
Date: Thu, 16 Jul 2026 08:52:09 +0000	[thread overview]
Message-ID: <20260716085210.1DD571F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260716083728.2226422-3-jorge.ramirez@oss.qualcomm.com>

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

Pre-existing issues:
- [High] The `ufs_rpmb->dev` device release function is structurally prevented from running, leaking RPMB child devices and their associated memory.
- [High] The `struct ufs_rpmb_dev` embeds a refcounted `struct device` but is allocated via `devm_kzalloc()`, leading to a use-after-free.
--

--- Patch [2]: [PATCH v1 2/2] ufs: rpmb: use a fixed-length RPMB dev_id ---
commit b0359490487ec8ad9999a553b0e7ff80b787f32c
Author: Jorge Ramirez-Ortiz <jorge.ramirez@oss.qualcomm.com>

ufs: rpmb: use a fixed-length RPMB dev_id

This commit modifies the UFS RPMB driver to generate a fixed 16-byte
device ID by hashing the variable-length UFS device ID and region string
using blake2s. This aligns the UFS device ID length with the eMMC CID
format, allowing OP-TEE's key derivation to work without modification.

> diff --git a/drivers/ufs/core/ufs-rpmb.c b/drivers/ufs/core/ufs-rpmb.c
> index d0c7ea7a36f49..b800871269bb3 100644
> --- a/drivers/ufs/core/ufs-rpmb.c
> +++ b/drivers/ufs/core/ufs-rpmb.c
[ ... ]
> @@ -154,6 +156,7 @@ int ufs_rpmb_probe(struct ufs_hba *hba)
>  {
>  	struct ufs_rpmb_dev *ufs_rpmb, *it, *tmp;

[Severity: High]
This is a pre-existing issue, but does embedding a refcounted struct device
in a devres-managed allocation lead to a use-after-free?

The ufs_rpmb structure is allocated via devm_kzalloc() in the probe loop.
Its lifecycle is tied to the host controller's devres, which frees the
memory when the controller unbinds.

However, the embedded struct device is refcounted independently. If any
references (such as sysfs files) remain when devres frees the structure,
the final reference drop will attempt to access the already-freed struct
device to call ufs_rpmb_device_release(), leading to a use-after-free.

>  	struct rpmb_dev *rdev;
> +	char *dev_id = NULL;
>  	char *cid = NULL;
[ ... ]
> @@ -240,6 +254,7 @@ int ufs_rpmb_probe(struct ufs_hba *hba)
>  	return 0;
>  err_out:
>  	kfree(cid);
> +	kfree(dev_id);
>  	list_for_each_entry_safe(it, tmp, &hba->rpmbs, node) {
>  		list_del(&it->node);
>  		device_unregister(&it->dev);

[Severity: High]
This is a pre-existing issue, but does this error path permanently leak
RPMB child devices and their associated memory?

The rpmb_dev_register() call creates a child device (rdev) with
ufs_rpmb->dev as its parent, which automatically takes a reference on the
parent.

When device_unregister(&it->dev) is called here, the parent's refcount
does not drop to zero because the child still holds a reference. This
prevents ufs_rpmb_device_release() from ever running, meaning
rpmb_dev_unregister() is never called for the child, forming an
unbreakable circular dependency.

>  	}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260716083728.2226422-1-jorge.ramirez@oss.qualcomm.com?part=2

      reply	other threads:[~2026-07-16  8:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-16  8:37 [PATCH v1 0/2] ufs: rpmb: make RPMB usable with OP-TEE key derivation Jorge Ramirez-Ortiz
2026-07-16  8:37 ` [PATCH v1 1/2] ufs: rpmb: retry power-on UNIT ATTENTION on the RPMB WLUN Jorge Ramirez-Ortiz
2026-07-16  8:37 ` [PATCH v1 2/2] ufs: rpmb: use a fixed-length RPMB dev_id Jorge Ramirez-Ortiz
2026-07-16  8:52   ` 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=20260716085210.1DD571F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=jorge.ramirez@oss.qualcomm.com \
    --cc=linux-scsi@vger.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