]> Git Repo - linux.git/commitdiff
[SCSI] sd: Fix potential out-of-bounds access
authorAlan Stern <[email protected]>
Fri, 6 Sep 2013 15:49:51 +0000 (11:49 -0400)
committerJames Bottomley <[email protected]>
Wed, 11 Sep 2013 16:44:00 +0000 (09:44 -0700)
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 <[email protected]>
Reported-by: Dmitry Vyukov <[email protected]>
CC: <[email protected]>
Signed-off-by: James Bottomley <[email protected]>
drivers/scsi/sd.c

index b58e8f815a002548cdea5724be023c55802760f0..e62d17d41d4e7b84ddf7469194aa0c63d541d59d 100644 (file)
@@ -2420,14 +2420,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);
This page took 0.0626 seconds and 4 git commands to generate.