]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/5.0.4/btrfs-ensure-that-a-dup-or-raid1-block-group-has-exactly-two-stripes.patch
Linux 5.0.4
[thirdparty/kernel/stable-queue.git] / releases / 5.0.4 / btrfs-ensure-that-a-dup-or-raid1-block-group-has-exactly-two-stripes.patch
CommitLineData
415bbd25
GKH
1From 349ae63f40638a28c6fce52e8447c2d14b84cc0c Mon Sep 17 00:00:00 2001
2From: Johannes Thumshirn <jthumshirn@suse.de>
3Date: Mon, 18 Feb 2019 11:28:37 +0100
4Subject: btrfs: ensure that a DUP or RAID1 block group has exactly two stripes
5
6From: Johannes Thumshirn <jthumshirn@suse.de>
7
8commit 349ae63f40638a28c6fce52e8447c2d14b84cc0c upstream.
9
10We recently had a customer issue with a corrupted filesystem. When
11trying to mount this image btrfs panicked with a division by zero in
12calc_stripe_length().
13
14The corrupt chunk had a 'num_stripes' value of 1. calc_stripe_length()
15takes this value and divides it by the number of copies the RAID profile
16is expected to have to calculate the amount of data stripes. As a DUP
17profile is expected to have 2 copies this division resulted in 1/2 = 0.
18Later then the 'data_stripes' variable is used as a divisor in the
19stripe length calculation which results in a division by 0 and thus a
20kernel panic.
21
22When encountering a filesystem with a DUP block group and a
23'num_stripes' value unequal to 2, refuse mounting as the image is
24corrupted and will lead to unexpected behaviour.
25
26Code inspection showed a RAID1 block group has the same issues.
27
28Fixes: e06cd3dd7cea ("Btrfs: add validadtion checks for chunk loading")
29CC: stable@vger.kernel.org # 4.4+
30Reviewed-by: Qu Wenruo <wqu@suse.com>
31Reviewed-by: Nikolay Borisov <nborisov@suse.com>
32Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
33Reviewed-by: David Sterba <dsterba@suse.com>
34Signed-off-by: David Sterba <dsterba@suse.com>
35Signed-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,