Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp4293700pxu; Tue, 1 Dec 2020 01:03:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJzW5wQpjSyykRtpEI4HrWtg0VGsYLuScC1vcVnQz3JKWUfnuHjeJmpuoefjCuchHSdXJ7Zr X-Received: by 2002:a17:906:770d:: with SMTP id q13mr1917674ejm.409.1606813397958; Tue, 01 Dec 2020 01:03:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606813397; cv=none; d=google.com; s=arc-20160816; b=A1xAv+gNgWh0I0nwQSHaKjiL88O4PKRFvIUbWj58EHy3BJzchOFJxAm5MlDYBLcvm7 yZTR0AMPRoI9bAgNTzepKp6BEDHZ5eEBHDY44UGhrDkV5Eacq2qyxhwRq1MXHPhPNwes Lx0UHcZcG5KICeaM547/PcqwOmTOM4blgrQlMilYVGnOQi0JR5+owbpXYlyUvTmCYr5n fcs1hrwCzwwGmAOudB4/m1SfZQJcY9SnFGJ6ZBxrASKLhh5WmK801pF09a4SzWwcBQgW fOo7TdruVrBC8m1bYdrnYOI0x0Fc6I+/b5tl0Jki7v168StBRICJ9mE23IEl3/4kNSGe N7CQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=OLc6F0Z7Z8mAJDdFoLyrJMRNIqBIjQmlqIFbCf8aNhw=; b=wBGiLmhP8bdX46c7YJHZ+IgQdfRbkq7sL3eRKRAdWY+eH6/kH2yu/Ngl2VZ8qVYpdP edbrnXYFI+zUC0fHYxUn9UfzE/G8W1O6sNVgdrXcC+RX+0BzriEF3SCZW7YhEGqMGKzG hLIvMTqRaUTsaZXzaEOhoxyVzfhaQU8Zdj+MTkQVcDtsnUOqhOuyfspC9cFqfZ9AxfsM A5a9OJs23a+YbCvB8dR0dfy/iY4zmjzbQT5CU9gRDl4Bzu5eePfHCSvbZnc/vcjhMOBW ypdwUZ8+Zi6kK2ZW+ZgAORA/MPi/+blmHunrwe/sFDTgbpdNdzXK7py15LV3z8Nq/U2v v4Ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tkHBD9BT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y6si766900edm.399.2020.12.01.01.02.55; Tue, 01 Dec 2020 01:03:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tkHBD9BT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387969AbgLAI6g (ORCPT + 99 others); Tue, 1 Dec 2020 03:58:36 -0500 Received: from mail.kernel.org ([198.145.29.99]:34062 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387941AbgLAI62 (ORCPT ); Tue, 1 Dec 2020 03:58:28 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 9873422240; Tue, 1 Dec 2020 08:57:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606813067; bh=YZtaefy9uoNlDPS+o8ED9HYB3bje0g4jljsMjuh5R18=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tkHBD9BTqjgCXAuuso2EcwLWsi6EmDG5my21bzVLLldj/su+xcjDkaaDirwdzy91h tK28jyfUX60suo9V6luALtQeCtyUhFQi3cjXpnjeFP4wzQbPbczrtQ8TANMJIOMIJn 0OFo3X/Es+WOa2HwDpjPpOScM/ZCsSgfOObBC1mU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yoon Jungyeon , Nikolay Borisov , Johannes Thumshirn , Qu Wenruo , David Sterba , Sudip Mukherjee Subject: [PATCH 4.14 06/50] btrfs: tree-checker: Enhance chunk checker to validate chunk profile Date: Tue, 1 Dec 2020 09:53:05 +0100 Message-Id: <20201201084645.518121976@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201201084644.803812112@linuxfoundation.org> References: <20201201084644.803812112@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Qu Wenruo commit 80e46cf22ba0bcb57b39c7c3b52961ab3a0fd5f2 upstream Btrfs-progs already have a comprehensive type checker, to ensure there is only 0 (SINGLE profile) or 1 (DUP/RAID0/1/5/6/10) bit set for chunk profile bits. Do the same work for kernel. Reported-by: Yoon Jungyeon Link: https://bugzilla.kernel.org/show_bug.cgi?id=202765 Reviewed-by: Nikolay Borisov Reviewed-by: Johannes Thumshirn Signed-off-by: Qu Wenruo Reviewed-by: David Sterba Signed-off-by: David Sterba [sudip: manually backport and use btrfs_err instead of chunk_err] Signed-off-by: Sudip Mukherjee Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/volumes.c | 7 +++++++ 1 file changed, 7 insertions(+) --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6406,6 +6406,13 @@ static int btrfs_check_chunk_valid(struc return -EIO; } + if (!is_power_of_2(type & BTRFS_BLOCK_GROUP_PROFILE_MASK) && + (type & BTRFS_BLOCK_GROUP_PROFILE_MASK) != 0) { + btrfs_err(fs_info, + "invalid chunk profile flag: 0x%llx, expect 0 or 1 bit set", + type & BTRFS_BLOCK_GROUP_PROFILE_MASK); + return -EUCLEAN; + } if ((type & BTRFS_BLOCK_GROUP_TYPE_MASK) == 0) { btrfs_err(fs_info, "missing chunk type flag: 0x%llx", type); return -EIO;