Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp621843img; Fri, 22 Mar 2019 05:20:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqwnbpKyMJbNSgJgT/Zyvx+hJMOMM+r2a1pc3xluv8DrII33kpnuZxSqyWsmqXZfFPEl7Zzl X-Received: by 2002:a62:be08:: with SMTP id l8mr8791459pff.162.1553257211035; Fri, 22 Mar 2019 05:20:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553257211; cv=none; d=google.com; s=arc-20160816; b=qCdHUDA6sYSVEXGC55zEJ4KMAUjkcdDEmhsXk/wQumdXgp02quvZbKqGr83KObUJZl AlXb9p6LiF/x1Pbd2XPMYqt3/MF9JQDCnVbnzdObndp/GP8FlCy5Dc82tfohAPM5Xno8 6Rcwv/Q6x5E8Gt5BlgNhs44zqhLoKaEwYmnFMnjJiGr+DIGjSVSbn6EQDqhj8bd1xlZ1 G3PXu+cZ+WWTh89hXkxMa6Hngv8oIbqLcfsTLXh9elEA4N5MrB8tDbEgoZK3sl7b8Bm9 81Qdafarogy02EHkxca/QjawuY8f6/SelCac14rIav5QxWTDb//yqbGa27SRGG8yHq86 hN3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=JEjVYYwndGRBQFcuPAe8DtP7I9SzzT7lXiscagDu9mk=; b=yqYuejAfE7NA3YPzUuIPdNnZMGDdrQqRyVh4CNDJAGxLq0ztX2zHUXGgegdcKAze8p TtVlP1IbFzJ1Xn8RG1FOKIxUs/e4pQzTojOz4YFWNnqYt7Gi5sWVCbIwUOx+YUJmhqjC gOzNGs7fme7p+9PJINOjTla2EAL45wlvr44QeV1H3pOvlQLtauTKsFTmLxnnC2lcVs0g PfH97PtcB4pF8+GmeeY59lqMKnMZfH+hbYgthhOabqprRkRiB1UPj3bwzDAdwZHgdrDU HZsTkYTZD/EA35XqdU4KlLc8qNSNfL6Rej5WTkUe6f1SHTA1td1XLd1ro+hWUu+w9wdn On1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=eOqHbu8k; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e21si6235503pfn.179.2019.03.22.05.19.55; Fri, 22 Mar 2019 05:20:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=eOqHbu8k; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390457AbfCVMSH (ORCPT + 99 others); Fri, 22 Mar 2019 08:18:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:56978 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390028AbfCVMSD (ORCPT ); Fri, 22 Mar 2019 08:18:03 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8F4262082C; Fri, 22 Mar 2019 12:18:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553257083; bh=MpEJFuOS72BMW2v3oTCbRpFnx6PeKlHsyJ/3jQLwGho=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eOqHbu8k9tr4nF1NTACE5HnNrL4W9rJJbJknixcq+GJITgdrKJnlg+oqhevQ5Z5A9 03vuDWSl7IdaueqpSZ9S/FxuwuDPLnrZLdEFAQEnuoqOqStBG8fyU4TGS5XhPKjTr8 TfTiq0nZ0ySViHbathZwhT6sY2/DaRhcuI1AUltA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Qu Wenruo , Nikolay Borisov , Johannes Thumshirn , David Sterba Subject: [PATCH 5.0 095/238] btrfs: ensure that a DUP or RAID1 block group has exactly two stripes Date: Fri, 22 Mar 2019 12:15:14 +0100 Message-Id: <20190322111304.178662563@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322111258.383569278@linuxfoundation.org> References: <20190322111258.383569278@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 5.0-stable review patch. If anyone has any objections, please let me know. ------------------ From: Johannes Thumshirn commit 349ae63f40638a28c6fce52e8447c2d14b84cc0c upstream. 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: e06cd3dd7cea ("Btrfs: add validadtion checks for chunk loading") CC: stable@vger.kernel.org # 4.4+ Reviewed-by: Qu Wenruo Reviewed-by: Nikolay Borisov Signed-off-by: Johannes Thumshirn Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/volumes.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6782,10 +6782,10 @@ static int btrfs_check_chunk_valid(struc } if ((type & BTRFS_BLOCK_GROUP_RAID10 && sub_stripes != 2) || - (type & BTRFS_BLOCK_GROUP_RAID1 && num_stripes < 1) || + (type & BTRFS_BLOCK_GROUP_RAID1 && num_stripes != 2) || (type & BTRFS_BLOCK_GROUP_RAID5 && num_stripes < 2) || (type & BTRFS_BLOCK_GROUP_RAID6 && num_stripes < 3) || - (type & BTRFS_BLOCK_GROUP_DUP && num_stripes > 2) || + (type & BTRFS_BLOCK_GROUP_DUP && num_stripes != 2) || ((type & BTRFS_BLOCK_GROUP_PROFILE_MASK) == 0 && num_stripes != 1)) { btrfs_err(fs_info,