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 3/6] scsi: ufs: core: Validate connected lane counts
Date: Fri, 17 Jul 2026 16:21:37 +0000	[thread overview]
Message-ID: <20260717162137.ACF8C1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260717153914.26321-4-liqiang01@kylinos.cn>

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

Pre-existing issues:
- [High] Missing bounds check on untrusted `tx_lanes` value read from the device in `ufshcd_disable_tx_lcc` could lead to an excessive loop and kernel hang.
--

--- Patch [3]: [PATCH v2 3/6] scsi: ufs: core: Validate connected lane counts ---
commit a03fd44c15e264d545e15508efe3bce7ec4082a8
Author: Li Qiang <liqiang01@kylinos.cn>

scsi: ufs: core: Validate connected lane counts

This commit updates ufshcd_get_max_pwr_mode() to validate that RX and TX
lane counts read from the device do not exceed UFS_MAX_LANES. It ensures
these counts are bounded before they are propagated.

> diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
> index d1b989abc9e2d..bbadddcd661a0 100644
> --- a/drivers/ufs/core/ufshcd.c
> +++ b/drivers/ufs/core/ufshcd.c
> @@ -4729,7 +4729,9 @@ static int ufshcd_get_max_pwr_mode(struct ufs_hba *hba)
>  	ufshcd_dme_get(hba, UIC_ARG_MIB(PA_CONNECTEDTXDATALANES),
>  			&pwr_info->lane_tx);
>  
> -	if (!pwr_info->lane_rx || !pwr_info->lane_tx) {
> +	if (!pwr_info->lane_rx || !pwr_info->lane_tx ||
> +	    pwr_info->lane_rx > UFS_MAX_LANES ||
> +	    pwr_info->lane_tx > UFS_MAX_LANES) {
>  		dev_err(hba->dev, "%s: invalid connected lanes value. rx=%d, tx=%d\n",
>  				__func__,
>  				pwr_info->lane_rx,

[Severity: High]
This isn't a bug introduced by this patch, but since we are adding bounds
checking for PA_CONNECTEDTXDATALANES here, is it possible we need similar
validation in ufshcd_disable_tx_lcc()?

When ufshcd_disable_tx_lcc() reads the connected TX lane count, it uses the
value directly as a loop boundary:

drivers/ufs/core/ufshcd.c:ufshcd_disable_tx_lcc() {
	...
	if (!peer)
		ufshcd_dme_get(hba, UIC_ARG_MIB(PA_CONNECTEDTXDATALANES),
			       &tx_lanes);
	else
		ufshcd_dme_peer_get(hba, UIC_ARG_MIB(PA_CONNECTEDTXDATALANES),
				    &tx_lanes);
	for (i = 0; i < tx_lanes; i++) {
	...
}

If a malicious endpoint or UniPro link error causes the read to return an
abnormally large integer, the code could enter an unvalidated loop.

If the endpoint continuously returns success to the synchronous
ufshcd_dme_peer_set() commands inside the loop, could this force the kernel
to execute an excessive number of slow hardware commands?

This might potentially block the probe or error handler thread and result
in a kernel hang.

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

  reply	other threads:[~2026-07-17 16:21 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 [this message]
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
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=20260717162137.ACF8C1F000E9@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