Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp661325img; Fri, 22 Mar 2019 06:07:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqxuf1iz0UlousUPkIPqa8YjdgeEyjyBZKK7rYFCSdO07frk1JqXUN/AoDAOMO7WYIBej9mD X-Received: by 2002:a62:ae13:: with SMTP id q19mr8996502pff.152.1553260061388; Fri, 22 Mar 2019 06:07:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553260061; cv=none; d=google.com; s=arc-20160816; b=IlRvmYeRoZwzrcvDn4K9GiQEx90P0txSLX4a670qpkmBuFmYPMSxyKs8uianI4bGRS STmic+81AB9exEGevI2aXgDM279rz6dj6MQqLLLVdTi3qqT+oLTtvz/Ed7vCwWhbTE0K skqkSoJ6JjrH9xj4WaM/Oz/bive08Thrm3l+61pgphPSDSLFQcFHckl+wK5a55buQhQX vM4SlwIdJrtiaoxsqxYerS4mWvMuOn+9x1TD4e6AqHFE55APMzQOSDkEKLo+7LP9tOAC 87LOqjjf7Ne9GomQ32LqrUi9UCkSUTjSunxBlk0dQ7HETRlyyJNU+zBn5aprqfEaAQBq JXfQ== 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=agC6gWSvoQWR9VCUmhC7lOVARDcNDA2ijMg6rxIhtVE=; b=FDUxwxnfryhyBuSTBtxzSeO8KQUtnUS6MxWv4lvR1ODsQxETop2R1okfya6GX0DTBu iu5zcSuS6Sq7jrtPye4WTJiUzfNQ7ksupATjDxY8RPlVlRh/YPrV0M0E0IhG3Z1qlpiN Oga8hTfeiqmEZW+IvElYXATja/XCOZjnwC0BqHCpkbVtpiizQLkKY/AXD8UBnWr3fmsK JpZHhMqbFu6t50MHlVXgazPMaDbGd7dJDPY0RpqAYOyKYzmB6+rJO3I0jkKNEFV8YyP4 vtZSdQGeplFCaOSzC7GSDFlolWpL2WCm6jbWbEdcct+zbbMrqFFbX/RuI4o0wNQv8C5D EDww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="WSsmi5q/"; 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 d141si6892344pfd.81.2019.03.22.06.07.26; Fri, 22 Mar 2019 06:07:41 -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="WSsmi5q/"; 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 S1730891AbfCVLhx (ORCPT + 99 others); Fri, 22 Mar 2019 07:37:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:39332 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729774AbfCVLht (ORCPT ); Fri, 22 Mar 2019 07:37:49 -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 5EF2D218B0; Fri, 22 Mar 2019 11:37:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553254668; bh=l4+5m+qUwc54exU1Ux5n8xMZlQqXnLE6v7cQTUW3BTA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WSsmi5q/11kmCoQfPAMHKViIy91Lt/SViDgfJgAZrjkfHhV/TEOfK1qhzxb2Fyvjo pUr4t+5H8ROr7PwgNi4GUBIA/QqQWhLX4fBvAb14KK2OPtwp/ICuZolrkJbojQj166 FLVVB1WfN8gxUCLBbAqe7Sfna6fPmK6Xk6ocJ9nM= 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 4.4 190/230] btrfs: ensure that a DUP or RAID1 block group has exactly two stripes Date: Fri, 22 Mar 2019 12:15:28 +0100 Message-Id: <20190322111250.127951813@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322111236.796964179@linuxfoundation.org> References: <20190322111236.796964179@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 4.4-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 @@ -6287,10 +6287,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(root->fs_info,