Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Bart Van Assche" <bvanassche@acm.org>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v4 4/6] scsi: core: Add lock context annotations
Date: Fri, 31 Jul 2026 22:07:39 +0000	[thread overview]
Message-ID: <20260731220739.97C6E1F00AC4@smtp.kernel.org> (raw)
In-Reply-To: <0a289ca5cf0c22588e4ae193acabd1cdfef672f3.1785534721.git.bvanassche@acm.org>

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

Pre-existing issues:
- [High] An integer overflow in the calculation of the REPORT LUNS response length allows a malicious or malformed device to cause an infinite loop or kernel crash.
--

--- Patch [4]: [PATCH v4 4/6] scsi: core: Add lock context annotations ---
commit 548e6f9dc80e81c45d6f26ae1feeb609869a4064
Author: Bart Van Assche <bvanassche@acm.org>

scsi: core: Add lock context annotations

This commit documents which functions expect that shost->scan_mutex is held.

> diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
> index d7e0e93931947..3b82e80e807a7 100644
> --- a/drivers/scsi/scsi_scan.c
> +++ b/drivers/scsi/scsi_scan.c

[ ... ]

> @@ -1444,6 +1446,7 @@ static void scsi_sequential_lun_scan(struct Scsi_Host *shost,
>  static int scsi_report_lun_scan(struct Scsi_Host *shost,
>  			struct scsi_target *starget, blist_flags_t bflags,
>  			enum scsi_scan_mode rescan)
> +	__must_hold(&shost->scan_mutex)
>  {
>  	unsigned char scsi_cmd[MAX_COMMAND_SIZE];
>  	unsigned int length;

[Severity: High]
This isn't a bug introduced by this patch, but while looking at this function,
I noticed a potential integer overflow when calculating the response length:

drivers/scsi/scsi_scan.c:scsi_report_lun_scan() {
    ...
	if (get_unaligned_be32(lun_data->scsi_lun) +
	    sizeof(struct scsi_lun) > length) {
		length = get_unaligned_be32(lun_data->scsi_lun) +
			 sizeof(struct scsi_lun);
		kfree(lun_data);
		goto retry;
	}
    ...
}

If a malicious or malformed device returns a large value like 0xFFFFFFFF
in the first 4 bytes of its response, can the addition of
sizeof(struct scsi_lun) overflow?

On 64-bit systems, would this addition yield a 64-bit value that bypasses
the greater-than length check, but then truncate when assigned back to the
32-bit unsigned int length variable?  Could this cause an infinite retry
loop or an invalid pointer dereference if it truncates to zero?

On 32-bit systems, could the addition directly overflow to a small value,
fail the greater-than length check, and proceed to parse out-of-bounds luns
from the initially allocated buffer?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/68f3346cab2be570839350831f82b6c9233832ed.1785534721.git.bvanassche@acm.org?part=4

  reply	other threads:[~2026-07-31 22:07 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-31 21:52 [PATCH v4 0/6] Enable lock context analysis in the SCSI core and UFS driver Bart Van Assche
2026-07-31 21:52 ` [PATCH v4 1/6] ufs: core: Set task state before io_schedule_timeout() Bart Van Assche
2026-07-31 21:52   ` [PATCH v4 2/6] ufs: core: Enable lock context analysis Bart Van Assche
2026-07-31 21:52   ` [PATCH v4 3/6] scsi: core: Pass the SCSI host pointer directly Bart Van Assche
2026-07-31 21:52   ` [PATCH v4 4/6] scsi: core: Add lock context annotations Bart Van Assche
2026-07-31 22:07     ` sashiko-bot [this message]
2026-07-31 21:52   ` [PATCH v4 5/6] scsi: core: Protect host state changes with the host lock Bart Van Assche
2026-07-31 22:05     ` sashiko-bot
2026-07-31 21:52   ` [PATCH v4 6/6] scsi: core: Enable lock context analysis Bart Van Assche
2026-07-31 22:05     ` sashiko-bot

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=20260731220739.97C6E1F00AC4@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bvanassche@acm.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