Skip to contentSkip to conversation

scsi: fix off-by-one error in sd_read_block_characteristics()

PATCH Applied Martin Wilck 2 participants 2 messages Sep 12, 2024 – Sep 13, 2024 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: fix off-by-one error in sd_read_block_characteristics()

if the device returns page 0xb1 with length 8 (happens with qemu v2.x, for example), sd_read_block_characteristics() may attempt an out-of-bounds memory access when accessing the zoned field at offset 8.

Fixes 7fb019c46eee ("scsi: sd: Switch to using scsi_device VPD pages")
---
 drivers/scsi/sd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/sd.c +1 -1
index 9db86943d04c..9513406ad640 100644
@@ -3404,7 +3404,7 @@ static void sd_read_block_characteristics(struct scsi_disk *sdkp,
 	rcu_read_lock();
 	vpd = rcu_dereference(sdkp->device->vpd_pgb1);
 
-	if (!vpd || vpd->len < 8) {
+	if (!vpd || vpd->len <= 8) {
 		rcu_read_unlock();
 	        return;
 	}
Signature · 1 line
2.46.0
#1 lore raw

Martin,

Quoted 4 lines

if the device returns page 0xb1 with length 8 (happens with qemu v2.x, for example), sd_read_block_characteristics() may attempt an out-of-bounds memory access when accessing the zoned field at offset 8.

Applied to 6.12/scsi-staging, thanks!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering