From patchwork Mon Apr 8 04:27:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 10888773 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1F2EE1708 for ; Mon, 8 Apr 2019 04:28:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 08CF2285B6 for ; Mon, 8 Apr 2019 04:28:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F092B2860B; Mon, 8 Apr 2019 04:28:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 79EEC285B6 for ; Mon, 8 Apr 2019 04:28:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725953AbfDHE2E (ORCPT ); Mon, 8 Apr 2019 00:28:04 -0400 Received: from mx2.suse.de ([195.135.220.15]:46164 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725877AbfDHE2E (ORCPT ); Mon, 8 Apr 2019 00:28:04 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id E7207ADE1 for ; Mon, 8 Apr 2019 04:28:02 +0000 (UTC) From: Qu Wenruo To: linux-btrfs@vger.kernel.org, dsterba@suse.cz Subject: [PATCH] btrfs: tree-checker: Don't check device size as we can have valid 0 total_bytes Date: Mon, 8 Apr 2019 12:27:56 +0800 Message-Id: <20190408042756.25969-1-wqu@suse.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Under the following call traces, btrfs can commit device with 0 total_bytes onto disk: btrfs_rm_device() |- btrfs_shrink_device() | |- btrfs_device_set_total_bytes(device, 0) | |- btrfs_update_device() | |- btrfs_commit_transaction() #1 |- btrfs_rm_dev_item() This will trigger write time tree checker warning. And further more, this can create valid btrfs with device->total_bytes == 0 and triggering read time tree-checker if power loss happens after above transaction #1 but before next transaction. So this dev item check is too restrict. Please fold this patch into commit 87d87c6dcbbe ("btrfs: tree-checker: Verify dev item") in misc-next branch. The fuzzed image can be already addressed by commit 1b3922a8bc74 ("btrfs: Use real device structure to verify dev extent") thus we don't need that strict check anymore. Signed-off-by: Qu Wenruo --- fs/btrfs/tree-checker.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/fs/btrfs/tree-checker.c b/fs/btrfs/tree-checker.c index d2c3c1f8870d..974208ac56da 100644 --- a/fs/btrfs/tree-checker.c +++ b/fs/btrfs/tree-checker.c @@ -657,16 +657,11 @@ static int check_dev_item(struct extent_buffer *leaf, } /* - * Since btrfs device add doesn't check device size at all, we could - * have device item whose size is smaller than 1M which is useless, but - * still valid. - * So here we can only check the obviously wrong case. + * For device total_bytes, we don't have solid way to check it, as it can + * be 0 for device removal. + * device size check can only be done by dev extents check. */ - if (btrfs_device_total_bytes(leaf, ditem) == 0) { - dev_item_err(leaf, slot, - "invalid total bytes: have 0"); - return -EUCLEAN; - } + if (btrfs_device_bytes_used(leaf, ditem) > btrfs_device_total_bytes(leaf, ditem)) { dev_item_err(leaf, slot,