]> git.hungrycats.org Git - linux/commitdiff
btrfs: add checks for sys_chunk_array sizes
authorDavid Sterba <dsterba@suse.cz>
Fri, 31 Oct 2014 17:42:05 +0000 (18:42 +0100)
committerZygo Blaxell <zblaxell@waya.furryterror.org>
Fri, 27 Mar 2015 03:27:46 +0000 (23:27 -0400)
Verify that possible minimum and maximum size is set, validity of
contents is checked in btrfs_read_sys_array.

Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
(cherry picked from commit ce7fca5f57ed0fcd7e7b3d7b1a3e1791f8e56fa3)

fs/btrfs/disk-io.c

index 40ffec17b4d92de08336705a22b927c7b130f88c..38a862abdedb769bc4167249f32f7f009dc958e2 100644 (file)
@@ -3911,6 +3911,25 @@ static int btrfs_check_super_valid(struct btrfs_fs_info *fs_info,
                ret = -EINVAL;
        }
 
+       /*
+        * Obvious sys_chunk_array corruptions, it must hold at least one key
+        * and one chunk
+        */
+       if (btrfs_super_sys_array_size(sb) > BTRFS_SYSTEM_CHUNK_ARRAY_SIZE) {
+               printk(KERN_ERR "BTRFS: system chunk array too big %u > %u\n",
+                               btrfs_super_sys_array_size(sb),
+                               BTRFS_SYSTEM_CHUNK_ARRAY_SIZE);
+               ret = -EINVAL;
+       }
+       if (btrfs_super_sys_array_size(sb) < sizeof(struct btrfs_disk_key)
+                       + sizeof(struct btrfs_chunk)) {
+               printk(KERN_ERR "BTRFS: system chunk array too small %u < %lu\n",
+                               btrfs_super_sys_array_size(sb),
+                               sizeof(struct btrfs_disk_key)
+                               + sizeof(struct btrfs_chunk));
+               ret = -EINVAL;
+       }
+
        /*
         * The generation is a global counter, we'll trust it more than the others
         * but it's still possible that it's the one that's wrong.