Linux SCSI subsystem development
 help / color / mirror / Atom feed
* [PATCH] scsi: hpsa: clamp physical LUN count in fallback report
@ 2026-07-01  5:36 Pengpeng Hou
  2026-07-01  5:47 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Pengpeng Hou @ 2026-07-01  5:36 UTC (permalink / raw)
  To: Don Brace, James E.J. Bottomley, Martin K. Petersen
  Cc: Pengpeng Hou, storagedev, linux-scsi, linux-kernel

When REPORT PHYS EXTENDED is not supported,
hpsa_scsi_do_report_phys_luns() falls back to REPORT LUNS and converts
each 8-byte LUN entry into the extended report buffer. The number of
entries comes from the device-provided LUNListLength field, but the loop
did not clamp it to either the source ReportLUNdata array or the
destination ReportExtendedLUNdata array.

Clamp the converted count to both arrays and update the output
LUNListLength to match the entries that were actually copied.

Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>
---
 drivers/scsi/hpsa.c |    4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
index a1b116cd..a7115efd 100644
--- a/drivers/scsi/hpsa.c
+++ b/drivers/scsi/hpsa.c
@@ -3797,6 +3797,10 @@ static inline int hpsa_scsi_do_report_phys_luns(struct ctlr_info *h,
 		/* Copy ReportLUNdata header */
 		memcpy(buf, lbuf, 8);
 		nphys = be32_to_cpu(*((__be32 *)lbuf->LUNListLength)) / 8;
+		nphys = min_t(u32, nphys, ARRAY_SIZE(lbuf->LUN));
+		nphys = min_t(u32, nphys, ARRAY_SIZE(buf->LUN));
+		put_unaligned_be32(nphys * sizeof(buf->LUN[0]),
+				   buf->LUNListLength);
 		for (i = 0; i < nphys; i++)
 			memcpy(buf->LUN[i].lunid, lbuf->LUN[i], 8);
 	}


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

end of thread, other threads:[~2026-07-01  5:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-01  5:36 [PATCH] scsi: hpsa: clamp physical LUN count in fallback report Pengpeng Hou
2026-07-01  5:47 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox