From: Liu Bo <bo.li.liu@oracle.com>
To: linux-btrfs@vger.kernel.org
Cc: David Sterba <dsterba@suse.cz>
Subject: [PATCH] Btrfs: detect corruption when non-root leaf has zero item
Date: Wed, 3 Aug 2016 21:57:08 -0700 [thread overview]
Message-ID: <1470286628-4123-1-git-send-email-bo.li.liu@oracle.com> (raw)
Right now we treat leaf which has zero item as a valid one
because we could have an empty tree, that is, a root that is
also a leaf without any item, however, in the same case but
when the leaf is not a root, we can end up with hitting the
BUG_ON(1) in btrfs_extend_item() called by
setup_inline_extent_backref().
This makes us check the situation as a corruption if leaf is
not its own root.
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
fs/btrfs/disk-io.c | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index a5a22be..dfaeb96 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -559,8 +559,28 @@ static noinline int check_leaf(struct btrfs_root *root,
u32 nritems = btrfs_header_nritems(leaf);
int slot;
- if (nritems == 0)
+ if (nritems == 0) {
+ struct btrfs_root *r;
+
+ key.objectid = btrfs_header_owner(leaf);
+ key.type = BTRFS_ROOT_ITEM_KEY;
+ key.offset = -1ULL;
+
+ r = btrfs_get_fs_root(root->fs_info, &key, false);
+ /*
+ * The only reason we also check NULL here is that during
+ * open_ctree() some roots has not yet been set up.
+ */
+ if (!IS_ERR_OR_NULL(r)) {
+ /* if leaf is the root, then it's fine */
+ if (leaf->start != btrfs_root_bytenr(&r->root_item)) {
+ CORRUPT("non-root leaf's nritems is 0",
+ leaf, root, 0);
+ return -EIO;
+ }
+ }
return 0;
+ }
/* Check the 0 item */
if (btrfs_item_offset_nr(leaf, 0) + btrfs_item_size_nr(leaf, 0) !=
--
2.5.5
next reply other threads:[~2016-08-04 4:53 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-04 4:57 Liu Bo [this message]
2016-08-16 17:07 ` [PATCH] Btrfs: detect corruption when non-root leaf has zero item David Sterba
2016-08-22 0:04 ` Liu Bo
2016-08-23 22:22 ` [PATCH v2] " Liu Bo
2016-08-24 11:51 ` David Sterba
2016-09-02 5:26 ` Jeff Mahoney
2016-09-02 19:33 ` Liu Bo
2016-09-02 19:35 ` [PATCH] Btrfs: fix BUG_ON in btrfs_mark_buffer_dirty Liu Bo
2016-09-05 15:28 ` Filipe Manana
2016-09-06 21:51 ` Liu Bo
2016-09-07 14:25 ` Jeff Mahoney
2016-09-07 21:36 ` Liu Bo
2016-10-12 21:23 ` Filipe Manana
2016-10-13 0:37 ` Liu Bo
2016-10-13 8:47 ` Filipe Manana
2016-10-17 13:00 ` David Sterba
2016-10-17 15:44 ` Liu Bo
2016-11-23 13:15 ` Filipe Manana
2016-11-23 17:48 ` Filipe Manana
2016-11-23 21:39 ` Liu Bo
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=1470286628-4123-1-git-send-email-bo.li.liu@oracle.com \
--to=bo.li.liu@oracle.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).