Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp801780ybe; Fri, 13 Sep 2019 06:36:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqwlSHJi4Gl0+MzmweV4nbj168BIDWKqRPI5xult7OOI5tfH6pKoB90P/BwbxRZIEXpJh6w8 X-Received: by 2002:a50:e885:: with SMTP id f5mr46751071edn.163.1568381787904; Fri, 13 Sep 2019 06:36:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568381787; cv=none; d=google.com; s=arc-20160816; b=j0hZreUgSWicipLL3pq9TK+/yGDQR6c9rjQxI3vdPnOyHOeOhi7/mworuAtY3EZz62 yV7YzfuiyJP7acwpAvDuXSsZdz86CD3mHw8DCagiYCoY81O5o7XPfHxxQV0Rwp9Gz81U Aj/DSq/hQ+FyA0/Bv+zkf2Mzl63LCdUjYbgUup0wlYAaoKkuQkZYg+cO+wLaRzRnwM5F wlc7WI7vd9JVXBIfYpiyn8mCyhFFsI+VMCuYyy4qJi22sZUGM5OFl54Ea3BxQCMnomkv I+Wsz8AS26qdmfD3GzXhM2uOTpRjpmg+iEVGipIcLn/3KDkqVaVVh1oUYahzQpmoD5fv 0fYQ== 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=yyJ36K+EFBjGqZlbI2PSZ0j3dnEKUv7amSQyRUfbAGw=; b=mAi2uzDrMcrRdhh+u7+c+oss0643KeyJ4qh1JPm1nPbBDxU2t0slWiudUESIgr0TXD CIZmo4kB6Yl00k/XWHIPHxTJEfh0wqhjYuLP4OO38LdB8oXnMEdjfK2HiYgEE/pCGDMy NRmUPVWasPi6NVwo52tMiwrkH+x3HD6LRtkPtA94Jf+1lNxBz3yIZAvcBagDNohXCPPo G9wrZ3OPgcvJct2IyuyYJBU9LZvI72lJka6UTh7HbP/mHH0r15CC+B1geIq4AWrPpR4E 67pJoHjeEE4wBC2QLW9eKmaaHi39PTsKwP5u9u0I6XQdSRJVie5ZQ/jtg2CxEqKYbGSU b0qA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cDj+Axa9; 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 oy1si11308037ejb.292.2019.09.13.06.36.04; Fri, 13 Sep 2019 06:36:27 -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=cDj+Axa9; 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 S2391705AbfIMNbM (ORCPT + 99 others); Fri, 13 Sep 2019 09:31:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:41674 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388745AbfIMNPZ (ORCPT ); Fri, 13 Sep 2019 09:15:25 -0400 Received: from localhost (unknown [104.132.45.99]) (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 A4F5A208C2; Fri, 13 Sep 2019 13:15:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1568380525; bh=QuVe6d5LdFxeyz/vanqYXnbMCvw8HZFJkhzvjfWyPao=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cDj+Axa9+WD6K+VNkp3wBb75mscCKNiiwR9+8EFhixgfplmCtnkTcaPJZlb+bYaxN TT8dwVXqfmGJFWauKKGeI74pNrMDHWOMMgyapgtiIYwkmFqAQ9DUpPx+oZ0JInoHe1 pSMC/wo0gKTbc5BA0PgZjNvDV1KdMR4Bk7UOQSok= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Filipe Manana , Qu Wenruo , David Sterba , Sasha Levin Subject: [PATCH 4.19 074/190] btrfs: Use real device structure to verify dev extent Date: Fri, 13 Sep 2019 14:05:29 +0100 Message-Id: <20190913130605.491752937@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190913130559.669563815@linuxfoundation.org> References: <20190913130559.669563815@linuxfoundation.org> User-Agent: quilt/0.66 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 [ Upstream commit 1b3922a8bc74231f9a767d1be6d9a061a4d4eeab ] [BUG] Linux v5.0-rc1 will fail fstests/btrfs/163 with the following kernel message: BTRFS error (device dm-6): dev extent devid 1 physical offset 13631488 len 8388608 is beyond device boundary 0 BTRFS error (device dm-6): failed to verify dev extents against chunks: -117 BTRFS error (device dm-6): open_ctree failed [CAUSE] Commit cf90d884b347 ("btrfs: Introduce mount time chunk <-> dev extent mapping check") introduced strict check on dev extents. We use btrfs_find_device() with dev uuid and fs uuid set to NULL, and only dependent on @devid to find the real device. For seed devices, we call clone_fs_devices() in open_seed_devices() to allow us search seed devices directly. However clone_fs_devices() just populates devices with devid and dev uuid, without populating other essential members, like disk_total_bytes. This makes any device returned by btrfs_find_device(fs_info, devid, NULL, NULL) is just a dummy, with 0 disk_total_bytes, and any dev extents on the seed device will not pass the device boundary check. [FIX] This patch will try to verify the device returned by btrfs_find_device() and if it's a dummy then re-search in seed devices. Fixes: cf90d884b347 ("btrfs: Introduce mount time chunk <-> dev extent mapping check") CC: stable@vger.kernel.org # 4.19+ Reported-by: Filipe Manana Signed-off-by: Qu Wenruo Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/volumes.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index c20708bfae561..a8297e7489d98 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -7469,6 +7469,18 @@ static int verify_one_dev_extent(struct btrfs_fs_info *fs_info, ret = -EUCLEAN; goto out; } + + /* It's possible this device is a dummy for seed device */ + if (dev->disk_total_bytes == 0) { + dev = find_device(fs_info->fs_devices->seed, devid, NULL); + if (!dev) { + btrfs_err(fs_info, "failed to find seed devid %llu", + devid); + ret = -EUCLEAN; + goto out; + } + } + if (physical_offset + physical_len > dev->disk_total_bytes) { btrfs_err(fs_info, "dev extent devid %llu physical offset %llu len %llu is beyond device boundary %llu", -- 2.20.1