Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Niklas Cassel" <cassel@kernel.org>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v10 05/12] scsi: scsi_debug: Avoid 32-bit overflow in WRITE SCATTERED offsets
Date: Mon, 28 Sep 2026 07:39:49 +0000	[thread overview]
Message-ID: <20260928073950.4BF0D1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260928072102.725566-19-cassel@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] scsi: scsi_debug: out-of-bounds read in sg_copy_buffer via off_t underflow
--

commit 84b5a3ba9d6d206750a298cdc52cd60cfbdeb0a6
Author: Niklas Cassel <cassel@kernel.org>

scsi: scsi_debug: Avoid 32-bit overflow in WRITE SCATTERED offsets

This commit changes num_by and sg_off to 64-bit to avoid 32-bit overflow
issues in resp_write_scat() when handling large LBA ranges. When calling
do_device_access(), it caps sg_off at U32_MAX.

> diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
> index b64ae3ad300d8..8f9d54269dcec 100644
> --- a/drivers/scsi/scsi_debug.c
> +++ b/drivers/scsi/scsi_debug.c
[ ... ]
> @@ -5311,7 +5312,8 @@ static int resp_write_scat(struct scsi_cmnd *scp,
>  		 * Write ranges atomically to keep as close to pre-atomic
>  		 * writes behaviour as possible.
>  		 */
> -		ret = do_device_access(sip, scp, sg_off, lba, num, group, true, true);
> +		ret = do_device_access(sip, scp, min_t(u64, sg_off, U32_MAX), lba,
> +				       num, group, true, true);

[Severity: High]
Does capping the offset to U32_MAX here lead to an out-of-bounds memory read
on 32-bit systems when processing descriptors beyond 4 GiB?

do_device_access() takes the capped value as a u32 (sg_skip), and then
passes it down to sg_copy_buffer() which expects an off_t:

lib/scatterlist.c:sg_copy_buffer() {
    size_t sg_copy_buffer(struct scatterlist *sgl, unsigned int nents,
                          void *buf, size_t buflen, off_t skip,
                          bool to_buffer)
}

On 32-bit platforms, off_t is a signed 32-bit integer, so the unsigned
U32_MAX (0xFFFFFFFF) is implicitly converted into -1.

When sg_copy_buffer() calls sg_miter_skip(), it uses this negative skip
value:

lib/scatterlist.c:sg_miter_skip() {
    ...
    consumed = min_t(off_t, offset, miter->__remaining);
    ...
}

Because offset is -1 and off_t is signed, min_t() selects -1 as the
consumed amount. This bypasses the skip loop and offsets the iterator
backwards, setting its internal byte offset to 0xFFFFFFFF.

Could this cause subsequent pointer arithmetic to point one byte before the
mapped page, resulting in an out-of-bounds memory copy?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260928072102.725566-14-cassel@kernel.org?part=5

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

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-28  7:21 [PATCH v10 00/12] scsi: scsi_debug: fix zoned write validation Niklas Cassel
2026-09-28  7:21 ` [PATCH v10 01/12] scsi: scsi_debug: Refuse a zoned device with a non-zero lowest aligned LBA Niklas Cassel
2026-09-28  7:21 ` [PATCH v10 02/12] scsi: scsi_debug: Make atomic writes and ZBC emulation mutually exclusive Niklas Cassel
2026-09-28  7:21 ` [PATCH v10 03/12] scsi: scsi_debug: Take the zone metadata lock before the data lock Niklas Cassel
2026-09-28  7:21 ` [PATCH v10 04/12] scsi: scsi_debug: Evaluate scsi_debug_lbp() only once Niklas Cassel
2026-09-28  7:21 ` [PATCH v10 05/12] scsi: scsi_debug: Avoid 32-bit overflow in WRITE SCATTERED offsets Niklas Cassel
2026-09-28  7:39   ` sashiko-bot [this message]
2026-09-28  7:21 ` [PATCH v10 06/12] scsi: scsi_debug: Report the residual of a write Niklas Cassel
2026-09-28  8:18   ` Damien Le Moal
2026-09-28  7:21 ` [PATCH v10 07/12] scsi: scsi_debug: Enforce physical block alignment of zoned writes Niklas Cassel
2026-09-28  7:21 ` [PATCH v10 08/12] scsi: scsi_debug: Do not write a partial physical block to a zoned device Niklas Cassel
2026-09-28  7:21 ` [PATCH v10 09/12] scsi: scsi_debug: Advance the write pointer over the data written Niklas Cassel
2026-09-28  7:21 ` [PATCH v10 10/12] scsi: scsi_debug: Refuse a short WRITE ATOMIC (16) before writing it Niklas Cassel
2026-09-28  7:21 ` [PATCH v10 11/12] scsi: scsi_debug: Map the region written by WRITE ATOMIC (16) Niklas Cassel
2026-09-28  7:21 ` [PATCH v10 12/12] scsi: scsi_debug: Validate the access parameters of " Niklas Cassel

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=20260928073950.4BF0D1F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=cassel@kernel.org \
    --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