From bae1f0f0ee01b6a39efa136652eec09faf19d8ad Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Thu, 19 Apr 2018 19:02:11 +0800 Subject: btrfs: Add csum type check for btrfs_check_super_valid() Just like incompat flags check, although we have already done super csum type check before calling btrfs_check_super_valid(), we can still add such check for later write time check. Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- fs/btrfs/disk-io.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'fs/btrfs') diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 6531f07d6ca7..e9c84c5800ed 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -3984,6 +3984,16 @@ static int btrfs_check_super_valid(struct btrfs_fs_info *fs_info) btrfs_err(fs_info, "no valid FS found"); ret = -EINVAL; } + + /* + * For write time check, as for mount time we have checked csum before + * calling btrfs_check_super_valid(), so it must be a corruption + */ + if (btrfs_super_csum_type(sb) >= ARRAY_SIZE(btrfs_csum_sizes)) { + btrfs_err(fs_info, "corrupted csum type %u", + btrfs_super_csum_type(sb)); + ret = -EINVAL; + } if (btrfs_super_flags(sb) & ~BTRFS_SUPER_FLAG_SUPP) { btrfs_err(fs_info, "unrecognized or unsupported super flag: %llu", btrfs_super_flags(sb) & ~BTRFS_SUPER_FLAG_SUPP); -- cgit v1.2.1