From: Martin Wilck Date: Thu, 12 Sep 2024 13:43:08 +0000 (+0200) Subject: scsi: sd: Fix off-by-one error in sd_read_block_characteristics() X-Git-Tag: v6.12-rc1~5^2~2 X-Git-Url: https://gentwo.org/gitweb/?a=commitdiff_plain;h=f81eaf08385ddd474a2f41595a7757502870c0eb;p=linux%2F.git scsi: sd: Fix off-by-one error in sd_read_block_characteristics() Ff 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") Cc: stable@vger.kernel.org Signed-off-by: Martin Wilck Link: https://lore.kernel.org/r/20240912134308.282824-1-mwilck@suse.com Signed-off-by: Martin K. Petersen --- diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 43a723164fc5..64aaf24c6398 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -3402,7 +3402,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; }