Linux SCSI subsystem development
 help / color / mirror / Atom feed
* [PATCH] scsi: scsi_dh_alua: validate RTPG descriptors
@ 2026-07-06  9:14 Pengpeng Hou
  2026-07-06  9:26 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Pengpeng Hou @ 2026-07-06  9:14 UTC (permalink / raw)
  To: James E.J. Bottomley
  Cc: Pengpeng, Martin K. Petersen, Brian Bunker, Riya Savla,
	Krishna Kant, Marco Crivellari, Hannes Reinecke, Kees Cook,
	linux-scsi, linux-kernel

From: Pengpeng <pengpeng@iscas.ac.cn>

alua_rtpg() walks REPORT TARGET PORT GROUPS descriptors using the
response length, but the loop reads descriptor bytes 2 and 7 before
proving that the current descriptor has the fixed eight-byte header.

Stop parsing a truncated trailing descriptor before reading its group id,
state fields or relative target port count.

Signed-off-by: Pengpeng <pengpeng@iscas.ac.cn>
---
 drivers/scsi/device_handler/scsi_dh_alua.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/device_handler/scsi_dh_alua.c b/drivers/scsi/device_handler/scsi_dh_alua.c
index 80ab0ff921d4..f63f32bad12a 100644
--- a/drivers/scsi/device_handler/scsi_dh_alua.c
+++ b/drivers/scsi/device_handler/scsi_dh_alua.c
@@ -681,7 +681,12 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg)
 	for (k = tpg_desc_tbl_off, desc = buff + tpg_desc_tbl_off;
 	     k < len;
 	     k += off, desc += off) {
-		u16 group_id = get_unaligned_be16(&desc[2]);
+		u16 group_id;
+
+		if (len - k < 8)
+			break;
+
+		group_id = get_unaligned_be16(&desc[2]);
 
 		spin_lock_irqsave(&port_group_lock, flags);
 		tmp_pg = alua_find_get_pg(pg->device_id_str, pg->device_id_len,
-- 
2.43.0


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

end of thread, other threads:[~2026-07-06  9:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-06  9:14 [PATCH] scsi: scsi_dh_alua: validate RTPG descriptors Pengpeng Hou
2026-07-06  9:26 ` sashiko-bot

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