Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Hyeoncheol Jeong" <hyenc.jeong@samsung.com>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v2 2/2] scsi: ufs: Serve the device init reads from one aggregated read
Date: Wed, 30 Sep 2026 07:28:05 +0000	[thread overview]
Message-ID: <20260930072805.DBE281F00898@smtp.kernel.org> (raw)
In-Reply-To: <1653986196.21790747102619.JavaMail.epsvc@epcpadp1new>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] ufs: unaligned memory access in ufshcd_agg_group() crashes on bad device input
--

commit 8bc3a3d567bfb8009dd9c20e3fdb96ed162e1ae5
Author: Hyeoncheol Jeong <hyenc.jeong@samsung.com>

scsi: ufs: Serve the device init reads from one aggregated read

This commit introduces an aggregated read mechanism for UFS 5.0 devices to
fetch attributes, flags, and ID-strings in a single query during device
initialization.

> diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
> index c18b4784a3595..028f0179ee8be 100644
> --- a/drivers/ufs/core/ufshcd.c
> +++ b/drivers/ufs/core/ufshcd.c

[ ... ]

> +static const u8 *ufshcd_agg_group(const struct ufs_hba *hba, u8 type,
> +				  u16 *group_len)
> +{
> +	const u8 *packet = hba->agg_packet;
> +	u16 packet_len = hba->agg_packet_len;
> +	u16 group_off = 0;
> +
> +	while (packet && group_off + QUERY_AGG_GROUP_HDR_SIZE <= packet_len) {
> +		const struct utp_agg_group_header *hdr =
> +			(const void *)(packet + group_off);
> +		u16 next_group_off = be16_to_cpu(hdr->next_group_offset);

[Severity: High]
Does this code safely handle unaligned memory accesses?

If a malformed or untrusted UFS device returns an odd next_group_offset, the
loop adds this odd offset to the base pointer, and the next iteration will
attempt to read the 16-bit hdr->next_group_offset from an unaligned address.

This will cause a kernel panic on architectures without unaligned access
support. Should get_unaligned_be16() be used here, or should the
utp_agg_group_header struct be marked as __packed?

> +		u16 payload_off = group_off + QUERY_AGG_GROUP_HDR_SIZE;
> +
> +		if (next_group_off && (next_group_off < payload_off ||
> +				       next_group_off + QUERY_AGG_GROUP_HDR_SIZE > packet_len))
> +			return NULL;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/1860250540.01790752381858.JavaMail.epsvc@epcpadp2new?part=2

  reply	other threads:[~2026-09-30  7:28 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20260930050201epcms2p13ab67182445b0555acc8d27b927cda86@epcms2p7>
     [not found] ` <20260930050201epcms2p13ab67182445b0555acc8d27b927cda86@epcms2p1>
2026-09-30  5:15   ` [PATCH v2 1/2] scsi: ufs: Add the aggregated read query opcode and its reply format Hyeoncheol Jeong
2026-09-30  7:54     ` Peter Wang
2026-09-30  5:18   ` [PATCH v2 2/2] scsi: ufs: Serve the device init reads from one aggregated read Hyeoncheol Jeong
2026-09-30  7:28     ` sashiko-bot [this message]
2026-09-30  7:55     ` Peter Wang
2026-10-01  5:53     ` Stanley Jhu
2026-10-02  5:11       ` Hyeoncheol Jeong
2026-10-02 15:50     ` Bean Huo
2026-10-06  8:01       ` Hyeoncheol Jeong
     [not found] <CGME20260930050201epcms2p13ab67182445b0555acc8d27b927cda86@epcms2p1>
2026-09-30  5:02 ` [PATCH v2 0/2] scsi: ufs: batch device-init reads with UFS 5.0 " Hyeoncheol Jeong
2026-10-02  9:24   ` Bean Huo
2026-10-06  7:17     ` Hyeoncheol Jeong

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=20260930072805.DBE281F00898@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=hyenc.jeong@samsung.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