fscache: fix OOB Read in __fscache_acquire_volume
[sfrench/cifs-2.6.git] / fs / fscache / volume.c
index a058e0136bfebfc8fb5771f3826c91a5cbe5e5cc..ab8ceddf9efad9d16ed5ecfaa54606fea53412b5 100644 (file)
@@ -203,7 +203,11 @@ static struct fscache_volume *fscache_alloc_volume(const char *volume_key,
        struct fscache_volume *volume;
        struct fscache_cache *cache;
        size_t klen, hlen;
-       char *key;
+       u8 *key;
+
+       klen = strlen(volume_key);
+       if (klen > NAME_MAX)
+               return NULL;
 
        if (!coherency_data)
                coherency_len = 0;
@@ -229,7 +233,6 @@ static struct fscache_volume *fscache_alloc_volume(const char *volume_key,
        /* Stick the length on the front of the key and pad it out to make
         * hashing easier.
         */
-       klen = strlen(volume_key);
        hlen = round_up(1 + klen + 1, sizeof(__le32));
        key = kzalloc(hlen, GFP_KERNEL);
        if (!key)