diff mbox series

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

Message ID 20240912134308.282824-1-mwilck@suse.com
State New
Headers show
Series scsi: fix off-by-one error in sd_read_block_characteristics() | expand

Commit Message

Martin Wilck Sept. 12, 2024, 1:43 p.m. UTC
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")
Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 drivers/scsi/sd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 9db86943d04c..9513406ad640 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -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;
 	}