aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Stern <stern@rowland.harvard.edu>2013-09-06 11:49:51 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-09-26 17:15:29 -0700
commit8283dfa4d7864d1a1cbafbe0b89d83fdbf6204ae (patch)
tree8c00d35874bbb37ae0f56a0c961696ddb9bd9605
parentd10b95b412369a7f1d437304db7d02d41fe33e22 (diff)
SCSI: sd: Fix potential out-of-bounds access
commit 984f1733fcee3fbc78d47e26c5096921c5d9946a upstream. This patch fixes an out-of-bounds error in sd_read_cache_type(), found by Google's AddressSanitizer tool. When the loop ends, we know that "offset" lies beyond the end of the data in the buffer, so no Caching mode page was found. In theory it may be present, but the buffer size is limited to 512 bytes. Signed-off-by: Alan Stern <stern@rowland.harvard.edu> Reported-by: Dmitry Vyukov <dvyukov@google.com> Signed-off-by: James Bottomley <JBottomley@Parallels.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/scsi/sd.c11
1 files changed, 3 insertions, 8 deletions
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 105fff2ecd5..05973a49131 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -2225,14 +2225,9 @@ sd_read_cache_type(struct scsi_disk *sdkp, unsigned char *buffer)
}
}
- if (modepage == 0x3F) {
- sd_printk(KERN_ERR, sdkp, "No Caching mode page "
- "present\n");
- goto defaults;
- } else if ((buffer[offset] & 0x3f) != modepage) {
- sd_printk(KERN_ERR, sdkp, "Got wrong page\n");
- goto defaults;
- }
+ sd_printk(KERN_ERR, sdkp, "No Caching mode page found\n");
+ goto defaults;
+
Page_found:
if (modepage == 8) {
sdkp->WCE = ((buffer[offset + 2] & 0x04) != 0);