btrfs: check for supported superblock checksum type before checksum validation
authorJohannes Thumshirn <jthumshirn@suse.de>
Mon, 3 Jun 2019 14:58:54 +0000 (16:58 +0200)
committerDavid Sterba <dsterba@suse.com>
Mon, 1 Jul 2019 11:35:01 +0000 (13:35 +0200)
Now that we have factorerd out the superblock checksum type validation,
we can check for supported superblock checksum types before doing the
actual validation of the superblock read from disk.

This leads the path to further simplifications of
btrfs_check_super_csum() later on.

Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
Reviewed-by: David Sterba <dsterba@suse.com>
[ add comment ]
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/disk-io.c

index 3f3bb70ca437aef354de6b6af39e585ccc326dd3..ce6dc95effaec471fa90147063fc46ed7a01abf2 100644 (file)
@@ -2816,6 +2816,20 @@ int open_ctree(struct super_block *sb,
                goto fail_alloc;
        }
 
+       /*
+        * Verify the type first, if that or the the checksum value are
+        * corrupted, we'll find out
+        */
+       if (!btrfs_supported_super_csum(btrfs_super_csum_type(
+                                (struct btrfs_super_block *) bh->b_data))) {
+               btrfs_err(fs_info, "unsupported checksum algorithm: %u",
+                         btrfs_super_csum_type((struct btrfs_super_block *)
+                                               bh->b_data));
+               err = -EINVAL;
+               brelse(bh);
+               goto fail_alloc;
+       }
+
        /*
         * We want to check superblock checksum, the type is stored inside.
         * Pass the whole disk block of size BTRFS_SUPER_INFO_SIZE (4k).