All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
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	[thread overview]
Message-ID: <20190408042756.25969-1-wqu@suse.com> (raw)

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 <wqu@suse.com>
---
 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,
-- 
2.21.0


             reply	other threads:[~2019-04-08  4:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-08  4:27 Qu Wenruo [this message]
2019-04-08  4:34 ` [PATCH] btrfs: tree-checker: Don't check device size as we can have valid 0 total_bytes Qu Wenruo
2019-04-08 21:49   ` David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190408042756.25969-1-wqu@suse.com \
    --to=wqu@suse.com \
    --cc=dsterba@suse.cz \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.