Skip to content

Commit 349ae63

Browse files
Johannes Thumshirnkdave
authored andcommitted
btrfs: ensure that a DUP or RAID1 block group has exactly two stripes
We recently had a customer issue with a corrupted filesystem. When trying to mount this image btrfs panicked with a division by zero in calc_stripe_length(). The corrupt chunk had a 'num_stripes' value of 1. calc_stripe_length() takes this value and divides it by the number of copies the RAID profile is expected to have to calculate the amount of data stripes. As a DUP profile is expected to have 2 copies this division resulted in 1/2 = 0. Later then the 'data_stripes' variable is used as a divisor in the stripe length calculation which results in a division by 0 and thus a kernel panic. When encountering a filesystem with a DUP block group and a 'num_stripes' value unequal to 2, refuse mounting as the image is corrupted and will lead to unexpected behaviour. Code inspection showed a RAID1 block group has the same issues. Fixes: e06cd3d ("Btrfs: add validadtion checks for chunk loading") CC: stable@vger.kernel.org # 4.4+ Reviewed-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent e49be14 commit 349ae63

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

fs/btrfs/volumes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6791,10 +6791,10 @@ static int btrfs_check_chunk_valid(struct btrfs_fs_info *fs_info,
67916791
}
67926792

67936793
if ((type & BTRFS_BLOCK_GROUP_RAID10 && sub_stripes != 2) ||
6794-
(type & BTRFS_BLOCK_GROUP_RAID1 && num_stripes < 1) ||
6794+
(type & BTRFS_BLOCK_GROUP_RAID1 && num_stripes != 2) ||
67956795
(type & BTRFS_BLOCK_GROUP_RAID5 && num_stripes < 2) ||
67966796
(type & BTRFS_BLOCK_GROUP_RAID6 && num_stripes < 3) ||
6797-
(type & BTRFS_BLOCK_GROUP_DUP && num_stripes > 2) ||
6797+
(type & BTRFS_BLOCK_GROUP_DUP && num_stripes != 2) ||
67986798
((type & BTRFS_BLOCK_GROUP_PROFILE_MASK) == 0 &&
67996799
num_stripes != 1)) {
68006800
btrfs_err(fs_info,

0 commit comments

Comments
 (0)