From: sashiko-bot@kernel.org
To: "Hyeoncheol Jeong" <hyenc.jeong@samsung.com>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v3 2/2] scsi: ufs: Add support for the aggregated read query opcode
Date: Fri, 24 Jul 2026 03:27:54 +0000 [thread overview]
Message-ID: <20260724032754.E5D281F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260724031215epcms2p4d3f734cacf21104ef1396e893edd141d@epcms2p4>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The patch introduces a dedicated DMA allocation for the device management command descriptor (`devman_ucd_base_addr`) and restricts its Physical Region Descriptor Table (PRDT) size to only 2 entries (`UFSHCD_DEVMAN_SG_ENTRIES`). However, Advanced RPMB requests originating from userspace via the block layer's BSG interface are mapped into scatter-gather lists without enforcing this 2-entry limit. Because userspace can submit highly fragmented I/O vectors (or even a contiguous 4KB buffer that spans across three memory pages), the block layer can generate an `sg_cnt` greater than 2. The driver blindly passes this `sg_cnt` to `ufshcd_sgl_to_prdt()`, which iterates over the scatterlist and writes beyond the bounds of the 2-entry `prd_table`. This results in a silent out-of-bounds write that corrupts adjacent DMA-coherent memory.
--
--- Patch [2]: [PATCH v3 2/2] scsi: ufs: Add support for the aggregated read query opcode ---
commit e3d69e949ea76c3908ee9edb0203a7ddef6ca03f
Author: Hyeoncheol Jeong <hyenc.jeong@samsung.com>
scsi: ufs: Add support for the aggregated read query opcode
UFS 5.0 / JEDEC 220H introduces the AGGREGATED READ query opcode (0x9),
which retrieves an aggregated data packet in a single query request. This
patch adds a dedicated utp_devman_cmd_desc with a 4 KiB response area,
allocated once for the reserved (device management) tag that aggregated
read uses.
> diff --git a/include/ufs/ufshcd.h b/include/ufs/ufshcd.h
> index 1c732601afcea..d59e701851683 100644
> --- a/include/ufs/ufshcd.h
> +++ b/include/ufs/ufshcd.h
[ ... ]
> @@ -1359,6 +1367,18 @@ static inline size_t ufshcd_get_ucd_size(const struct ufs_hba *hba)
> return sizeof(struct utp_transfer_cmd_desc) + SG_ALL * ufshcd_sg_entry_size(hba);
> }
>
> +/*
> + * Two entries should be enough for the largest devman PRDT transfer (4 KiB),
> + * like advanced RPMB.
> + */
> +#define UFSHCD_DEVMAN_SG_ENTRIES 2
> +
> +static inline size_t ufshcd_get_devman_ucd_size(const struct ufs_hba *hba)
> +{
> + return sizeof(struct utp_devman_cmd_desc) +
> + UFSHCD_DEVMAN_SG_ENTRIES * ufshcd_sg_entry_size(hba);
> +}
[Severity: High]
Does this 2-entry limit expose us to an out-of-bounds write when handling
Advanced RPMB BSG requests?
Advanced RPMB requests coming from userspace (via the BSG interface) can
supply highly fragmented scatter-gather lists. For example, a contiguous 4KB
user buffer could cross page boundaries and span 3 memory pages, producing an
sg_cnt greater than 2.
When ufs_bsg_request() dispatches to ufshcd_advanced_rpmb_req_handler(),
the unvalidated sg_cnt is passed directly to ufshcd_sgl_to_prdt():
ufshcd_advanced_rpmb_req_handler() {
...
if (dir != DMA_NONE && sg_list)
ufshcd_sgl_to_prdt(hba, lrbp, sg_cnt, sg_list);
...
}
ufshcd_sgl_to_prdt() will then iterate over the scatterlist up to sg_cnt:
ufshcd_sgl_to_prdt() {
...
for_each_sg(sg, sg, sg_segments, i) {
prd_table[i].addr = cpu_to_le64(sg_dma_address(sg));
prd_table[i].size = cpu_to_le32(sg_dma_len(sg) - 1);
...
}
Could this write past the end of the newly introduced 2-entry prd_table array
and corrupt adjacent DMA-coherent memory if a privileged user submits a
request with sg_cnt greater than 2?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260724030812epcms2p4eb2c77cb4dcd5fd51ca9c3eaa5ea4bfa@epcms2p4?part=2
prev parent reply other threads:[~2026-07-24 3:27 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20260724030812epcms2p4eb2c77cb4dcd5fd51ca9c3eaa5ea4bfa@epcms2p4>
2026-07-24 3:08 ` [PATCH v3 0/2] scsi: ufs: Add support for the aggregated read query opcode Hyeoncheol Jeong
2026-07-24 3:10 ` [PATCH v3 1/2] scsi: ufs: Use unsigned types for the BSG query Hyeoncheol Jeong
2026-07-24 3:12 ` [PATCH v3 2/2] scsi: ufs: Add support for the aggregated read query opcode Hyeoncheol Jeong
2026-07-24 3:27 ` 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=20260724032754.E5D281F000E9@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.