All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scsi: core: reject short REPORT LUNS responses
@ 2026-11-03 10:53 shao.mingyin
  2026-11-03 11:05 ` sashiko-bot
  0 siblings, 1 reply; 3+ messages in thread
From: shao.mingyin @ 2026-11-03 10:53 UTC (permalink / raw)
  To: mkp, James.Bottomley, linux-scsi; +Cc: linux-kernel

scsi_report_lun_scan() allocates the REPORT LUNS buffer with kmalloc()
and does not ask scsi_execute_cmd() for the residual count.  A device that
completes the command successfully after transferring fewer than the eight
bytes of the LUN list header leaves the header uninitialized; the bogus
length read from it can trigger a multi-gigabyte kmalloc() retry or probe
LUNs that do not exist.

Request the residual and abort the scan when the header was not
transferred.

Signed-off-by: Shao Mingyin <shao.mingyin@zte.com.cn>
---
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index 52f3b525d2fd..abbcf529bdc4 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -1475,10 +1475,11 @@ static int scsi_report_lun_scan(struct Scsi_Host *shost,
 		.total_allowed = 3,
 		.failure_definitions = failure_defs,
 	};
+	int ret = 0, resid = 0;
 	const struct scsi_exec_args exec_args = {
+		.resid = &resid,
 		.failures = &failures,
 	};
-	int ret = 0;
 
 	/*
 	 * Only support SCSI-3 and up devices if BLIST_NOREPORTLUN is not set.
@@ -1567,6 +1568,12 @@ static int scsi_report_lun_scan(struct Scsi_Host *shost,
 		goto out_err;
 	}
 
+	if (resid > length - sizeof(struct scsi_lun)) {
+		/* Short transfer: the LUN list header was not filled in. */
+		ret = 1;
+		goto out_err;
+	}
+
 	/*
 	 * Get the length from the first four bytes of lun_data.
 	 */

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-03 11:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-03 10:53 [PATCH] scsi: core: reject short REPORT LUNS responses shao.mingyin
2026-11-03 11:05 ` sashiko-bot
2026-11-03 11:59   ` shao.mingyin

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.