From: Alan Stern Date: Fri, 6 Sep 2013 15:49:51 +0000 (-0400) Subject: SCSI: sd: Fix potential out-of-bounds access X-Git-Tag: v3.10.13~108 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=13915e203f991e77eb5a52bcd4c61e5f155e3bbc;p=platform%2Fkernel%2Flinux-3.10.git 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 Reported-by: Dmitry Vyukov Signed-off-by: James Bottomley Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 610417e..c398634 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -2409,14 +2409,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);