Skip to content

Commit f0aa59a

Browse files
Damien Le Moalmartinkpetersen
authored andcommitted
scsi: core: Improve scsi_vpd_inquiry() checks
Some USB-SATA adapters have broken behavior when an unsupported VPD page is probed: Depending on the VPD page number, a 4-byte header with a valid VPD page number but with a 0 length is returned. Currently, scsi_vpd_inquiry() only checks that the page number is valid to determine if the page is valid, which results in receiving only the 4-byte header for the non-existent page. This error manifests itself very often with page 0xb9 for the Concurrent Positioning Ranges detection done by sd_read_cpr(), resulting in the following error message: sd 0:0:0:0: [sda] Invalid Concurrent Positioning Ranges VPD page Prevent such misleading error message by adding a check in scsi_vpd_inquiry() to verify that the page length is not 0. Signed-off-by: Damien Le Moal <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Benjamin Block <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 2309df2 commit f0aa59a

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

drivers/scsi/scsi.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,18 @@ static int scsi_vpd_inquiry(struct scsi_device *sdev, unsigned char *buffer,
314314
if (result)
315315
return -EIO;
316316

317-
/* Sanity check that we got the page back that we asked for */
317+
/*
318+
* Sanity check that we got the page back that we asked for and that
319+
* the page size is not 0.
320+
*/
318321
if (buffer[1] != page)
319322
return -EIO;
320323

321-
return get_unaligned_be16(&buffer[2]) + 4;
324+
result = get_unaligned_be16(&buffer[2]);
325+
if (!result)
326+
return -EIO;
327+
328+
return result + 4;
322329
}
323330

324331
static int scsi_get_vpd_size(struct scsi_device *sdev, u8 page)

0 commit comments

Comments
 (0)