Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Li Qiang" <liqiang01@kylinos.cn>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v2 4/6] scsi: ufs: rpmb: Validate request frame length before parsing
Date: Fri, 17 Jul 2026 16:32:16 +0000	[thread overview]
Message-ID: <20260717163216.F16661F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260717153914.26321-5-liqiang01@kylinos.cn>

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

Pre-existing issues:
- [High] Missing IS_ERR() check for tee_shm_get_va() return values in OP-TEE RPMB RPC handler.
- [High] Circular refcount and incorrect use of devm_kzalloc() for a dynamically registered struct device lead to a memory leak and severe Use-After-Free when UFS is unbound.
--

--- Patch [4]: [PATCH v2 4/6] scsi: ufs: rpmb: Validate request frame length before parsing ---
commit 1f68e5566b9d9ef98707ec46f344522aaa25cb6b
Author: Li Qiang <liqiang01@kylinos.cn>

scsi: ufs: rpmb: Validate request frame length before parsing

The RPMB core only verifies that request and response buffers are nonempty.
This commit adds a check to ensure a complete RPMB request frame is provided
before reading req_resp at the end of the frame.

> diff --git a/drivers/ufs/core/ufs-rpmb.c b/drivers/ufs/core/ufs-rpmb.c
> index ffad049872b9a..431f85b368760 100644
> --- a/drivers/ufs/core/ufs-rpmb.c
> +++ b/drivers/ufs/core/ufs-rpmb.c
> @@ -69,6 +69,10 @@ static int ufs_rpmb_route_frames(struct device *dev, u8 *req, unsigned int req_l
>  
>  	hba = ufs_rpmb->hba;

[Severity: High]
This is a pre-existing issue, but does this lead to a use-after-free when the
UFS host is unbound?

Because ufs_rpmb was allocated with devm_kzalloc(), it is automatically freed
on unbind. However, ufs_rpmb_remove() unregisters ufs_rpmb->dev but fails to
unregister the child rdev. Since rdev->dev implicitly holds a parent reference
to ufs_rpmb->dev, ufs_rpmb->dev's refcount never drops to zero, and
ufs_rpmb_device_release() is never invoked to call rpmb_dev_unregister().

If a subsequent RPMB request routes a frame, will it extract and dereference
the freed ufs_rpmb object here?

> +	/* req_resp is at the end of an RPMB frame. */
> +	if (req_len < sizeof(*frm_out))
> +		return -EINVAL;
> +
>  	req_type = be16_to_cpu(frm_out->req_resp);

[Severity: High]
This isn't a bug introduced by this patch, but can we dereference an error
pointer here?

If drivers/tee/optee/rpc.c:handle_rpc_func_rpmb_frames() receives an
out-of-bounds offset from the Secure World, tee_shm_get_va() returns
ERR_PTR(-EINVAL). Because there is no IS_ERR() check, this error pointer is
passed as 'req' to rpmb_route_frames() and eventually reaches here as frm_out.

Will accessing frm_out->req_resp cause a panic if the Secure World sends an
invalid offset?

>  
>  	switch (req_type) {

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260717153914.26321-1-liqiang01@kylinos.cn?part=4

  reply	other threads:[~2026-07-17 16:32 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-16  6:19 [PATCH 0/5] scsi: ufs: Fix descriptor parsing and invalid input handling liqiang
2026-07-16  6:19 ` [PATCH 1/5] scsi: ufs: core: Validate string descriptors liqiang
2026-07-16 17:47   ` Bart Van Assche
2026-07-17 15:35     ` Li Qiang
2026-07-16  6:19 ` [PATCH 2/5] scsi: ufs: Fix NULL dereferences after tag lookup liqiang
2026-07-16  6:43   ` sashiko-bot
2026-07-16 17:52   ` Bart Van Assche
2026-07-16  6:19 ` [PATCH 3/5] scsi: ufs: core: Validate connected lane counts liqiang
2026-07-16  6:19 ` [PATCH 4/5] scsi: ufs: rpmb: Validate frame before parsing liqiang
2026-07-16  6:28   ` sashiko-bot
2026-07-16 17:58   ` Bart Van Assche
2026-07-16  6:19 ` [PATCH 5/5] scsi: ufs: debugfs: Reserve space for a string terminator liqiang
2026-07-16 17:56   ` Bart Van Assche
2026-07-16 17:42 ` [PATCH 0/5] scsi: ufs: Fix descriptor parsing and invalid input handling Bart Van Assche
2026-07-17 15:16   ` Li Qiang
2026-07-17 15:39 ` [PATCH v2 0/6] " Li Qiang
2026-07-17 15:39   ` [PATCH v2 1/6] scsi: ufs: core: Validate string descriptors Li Qiang
2026-07-17 15:39   ` [PATCH v2 2/6] scsi: ufs: Avoid NULL CQE dereference when reporting invalid tags Li Qiang
2026-07-17 15:39   ` [PATCH v2 3/6] scsi: ufs: core: Validate connected lane counts Li Qiang
2026-07-17 16:21     ` sashiko-bot
2026-07-17 15:39   ` [PATCH v2 4/6] scsi: ufs: rpmb: Validate request frame length before parsing Li Qiang
2026-07-17 16:32     ` sashiko-bot [this message]
2026-07-17 15:39   ` [PATCH v2 5/6] scsi: ufs: rpmb: Use unaligned accessors for RPMB frames Li Qiang
2026-07-17 16:54     ` sashiko-bot
2026-07-17 15:39   ` [PATCH v2 6/6] scsi: ufs: debugfs: Reserve space for a string terminator Li Qiang

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=20260717163216.F16661F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=liqiang01@kylinos.cn \
    --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