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 v9 05/11] scsi: scsi_debug: Report the residual of a write
Date: Sun, 27 Sep 2026 05:40:39 +0000	[thread overview]
Message-ID: <20260927054039.E7B7D1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260927052650.567035-18-cassel@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] scsi: scsi_debug: incorrect residual for WRITE SCATTERED due to 32-bit overflow
--

commit 8bc6d8e408815c5b6d6afe8b3e8dbdaabb79d3d5
Author: Niklas Cassel <cassel@kernel.org>
scsi: scsi_debug: Report the residual of a write

This commit adds residual reporting for writes in scsi_debug, ensuring
that writes with data buffers larger than their transfer length report
the residual correctly, similar to reads. It updates resp_write_dt0(),
resp_write_scat(), and resp_atomic_write() to calculate and set the
residual based on what the command consumed.

> diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
> index b64ae3ad300d8..0c66a3118ee89 100644
> --- a/drivers/scsi/scsi_debug.c
> +++ b/drivers/scsi/scsi_debug.c

[ ... ]

> @@ -5352,6 +5358,13 @@ static int resp_write_scat(struct scsi_cmnd *scp,
>  	}
>  	ret = 0;
>  err_out_unlock:
> +	/*
> +	 * sg_off counts what the command asked for, which can exceed the
> +	 * buffer: lbdof is not validated against it, and a range is counted
> +	 * in full even if do_device_access() copied less.
> +	 */
> +	if (scsi_bufflen(scp) > sg_off)
> +		scsi_set_resid(scp, scsi_bufflen(scp) - sg_off);

[Severity: Medium]
Will this calculation produce an incorrect residual if the command includes
a very large LBA range?

In resp_write_scat(), the variables num_by, num, and lb_size are all 32-bit
integers, and num_by is calculated as:

    num_by = num * lb_size;

If num is sufficiently large (e.g., > 8.38M blocks), does this 32-bit
multiplication overflow and wrap around to a small value?

If num_by wraps, it appears the sg_off accumulator will also wrap below the
actual buffer length, causing this new guard if (scsi_bufflen(scp) > sg_off)
to erroneously evaluate to true. Could this result in a bogus residual being
set for a write that actually fully consumed the buffer, potentially
confusing the initiator or midlayer into failing or retrying completed I/Os?

>  	sdeb_meta_write_unlock(sip);
>  err_out:
>  	kfree(lrdp);

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

  reply	other threads:[~2026-09-27  5:40 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-27  5:26 [PATCH v9 00/11] scsi: scsi_debug: fix zoned write validation Niklas Cassel
2026-09-27  5:26 ` [PATCH v9 01/11] scsi: scsi_debug: Refuse a zoned device with a non-zero lowest aligned LBA Niklas Cassel
2026-09-27  5:26 ` [PATCH v9 02/11] scsi: scsi_debug: Make atomic writes and ZBC emulation mutually exclusive Niklas Cassel
2026-09-27  5:26 ` [PATCH v9 03/11] scsi: scsi_debug: Take the zone metadata lock before the data lock Niklas Cassel
2026-09-27  5:26 ` [PATCH v9 04/11] scsi: scsi_debug: Evaluate scsi_debug_lbp() only once Niklas Cassel
2026-09-27  5:26 ` [PATCH v9 05/11] scsi: scsi_debug: Report the residual of a write Niklas Cassel
2026-09-27  5:40   ` sashiko-bot [this message]
2026-09-27  7:01     ` Niklas Cassel
2026-09-28  6:45   ` Damien Le Moal
2026-09-28  7:15     ` Niklas Cassel
2026-09-28  7:51       ` Damien Le Moal
2026-09-28  8:15         ` Damien Le Moal
2026-09-27  5:26 ` [PATCH v9 06/11] scsi: scsi_debug: Enforce physical block alignment of zoned writes Niklas Cassel
2026-09-27  5:26 ` [PATCH v9 07/11] scsi: scsi_debug: Do not write a partial physical block to a zoned device Niklas Cassel
2026-09-27  5:26 ` [PATCH v9 08/11] scsi: scsi_debug: Advance the write pointer over the data written Niklas Cassel
2026-09-27  5:27 ` [PATCH v9 09/11] scsi: scsi_debug: Refuse a short WRITE ATOMIC (16) before writing it Niklas Cassel
2026-09-27  5:27 ` [PATCH v9 10/11] scsi: scsi_debug: Map the region written by WRITE ATOMIC (16) Niklas Cassel
2026-09-27  5:27 ` [PATCH v9 11/11] 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=20260927054039.E7B7D1F000FF@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