]>
Commit | Line | Data |
---|---|---|
415bbd25 GKH |
1 | From 349ae63f40638a28c6fce52e8447c2d14b84cc0c Mon Sep 17 00:00:00 2001 |
2 | From: Johannes Thumshirn <jthumshirn@suse.de> | |
3 | Date: Mon, 18 Feb 2019 11:28:37 +0100 | |
4 | Subject: btrfs: ensure that a DUP or RAID1 block group has exactly two stripes | |
5 | ||
6 | From: Johannes Thumshirn <jthumshirn@suse.de> | |
7 | ||
8 | commit 349ae63f40638a28c6fce52e8447c2d14b84cc0c upstream. | |
9 | ||
10 | We recently had a customer issue with a corrupted filesystem. When | |
11 | trying to mount this image btrfs panicked with a division by zero in | |
12 | calc_stripe_length(). | |
13 | ||
14 | The corrupt chunk had a 'num_stripes' value of 1. calc_stripe_length() | |
15 | takes this value and divides it by the number of copies the RAID profile | |
16 | is expected to have to calculate the amount of data stripes. As a DUP | |
17 | profile is expected to have 2 copies this division resulted in 1/2 = 0. | |
18 | Later then the 'data_stripes' variable is used as a divisor in the | |
19 | stripe length calculation which results in a division by 0 and thus a | |
20 | kernel panic. | |
21 | ||
22 | When encountering a filesystem with a DUP block group and a | |
23 | 'num_stripes' value unequal to 2, refuse mounting as the image is | |
24 | corrupted and will lead to unexpected behaviour. | |
25 | ||
26 | Code inspection showed a RAID1 block group has the same issues. | |
27 | ||
28 | Fixes: e06cd3dd7cea ("Btrfs: add validadtion checks for chunk loading") | |
29 | CC: stable@vger.kernel.org # 4.4+ | |
30 | Reviewed-by: Qu Wenruo <wqu@suse.com> | |
31 | Reviewed-by: Nikolay Borisov <nborisov@suse.com> | |
32 | Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de> | |
33 | Reviewed-by: David Sterba <dsterba@suse.com> | |
34 | Signed-off-by: David Sterba <dsterba@suse.com> | |
35 | Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> | |
36 | ||
37 | --- | |
38 | fs/btrfs/volumes.c | 4 ++-- | |
39 | 1 file changed, 2 insertions(+), 2 deletions(-) | |
40 | ||
41 | --- a/fs/btrfs/volumes.c | |
42 | +++ b/fs/btrfs/volumes.c | |
43 | @@ -6782,10 +6782,10 @@ static int btrfs_check_chunk_valid(struc | |
44 | } | |
45 | ||
46 | if ((type & BTRFS_BLOCK_GROUP_RAID10 && sub_stripes != 2) || | |
47 | - (type & BTRFS_BLOCK_GROUP_RAID1 && num_stripes < 1) || | |
48 | + (type & BTRFS_BLOCK_GROUP_RAID1 && num_stripes != 2) || | |
49 | (type & BTRFS_BLOCK_GROUP_RAID5 && num_stripes < 2) || | |
50 | (type & BTRFS_BLOCK_GROUP_RAID6 && num_stripes < 3) || | |
51 | - (type & BTRFS_BLOCK_GROUP_DUP && num_stripes > 2) || | |
52 | + (type & BTRFS_BLOCK_GROUP_DUP && num_stripes != 2) || | |
53 | ((type & BTRFS_BLOCK_GROUP_PROFILE_MASK) == 0 && | |
54 | num_stripes != 1)) { | |
55 | btrfs_err(fs_info, |