linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Josef Bacik <josef@toxicpanda.com>
To: linux-btrfs@vger.kernel.org, kernel-team@fb.com
Subject: [PATCH v3 2/9] btrfs-progs: check blocks in btrfs_next_sibling_block
Date: Mon, 23 Aug 2021 15:23:06 -0400	[thread overview]
Message-ID: <0bd15dc74561eba6fd6dc095848e3ba28539d6d3.1629746415.git.josef@toxicpanda.com> (raw)
In-Reply-To: <cover.1629746415.git.josef@toxicpanda.com>

By enabling the lowmem checks properly I uncovered the case where test
007 will infinite loop at the detection stage.  This is because when
checking the inode item we will just btrfs_next_item(), and because we
ignore check tree block failures at read time we don't get an -EIO from
btrfs_next_leaf.

This occurs because we allow fsck to raw-read blocks even if they fail
basic sanity checks, because we want the opportunity to repair the
blocks.  However this means corrupt blocks are sitting in cache marked
as uptodate.  btrfs_search_slot() handles this by doing a check_block()
on every block we add to the path, so that anything that is doing a
search gets a proper -EIO.

btrfs_next_sibling_block() needs a similar check.  With this fix we now
return -EIO on btrfs_next_leaf() properly and we no longer infinite loop
on 007 with lowmem.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 kernel-shared/ctree.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/kernel-shared/ctree.c b/kernel-shared/ctree.c
index 518718de..0845cc60 100644
--- a/kernel-shared/ctree.c
+++ b/kernel-shared/ctree.c
@@ -3125,6 +3125,13 @@ int btrfs_next_sibling_tree_block(struct btrfs_fs_info *fs_info,
 		free_extent_buffer(c);
 		path->nodes[level] = next;
 		path->slots[level] = 0;
+		/*
+		 * Fsck will happily load corrupt blocks in order to fix them,
+		 * so we need an extra check just to make sure this block isn't
+		 * marked uptodate but invalid.
+		 */
+		if (check_block(fs_info, path, level))
+			return -EIO;
 		if (level == path->lowest_level)
 			break;
 		if (path->reada)
-- 
2.26.3


  parent reply	other threads:[~2021-08-23 19:23 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-23 19:23 [PATCH v3 0/9] btrfs-progs: make check handle invalid bg items Josef Bacik
2021-08-23 19:23 ` [PATCH v3 1/9] btrfs-progs: tests: fix running lowmem checks Josef Bacik
2021-08-23 19:23 ` Josef Bacik [this message]
2021-08-24 16:48   ` [PATCH v3 2/9] btrfs-progs: check blocks in btrfs_next_sibling_block David Sterba
2021-08-23 19:23 ` [PATCH v3 3/9] btrfs-progs: check: propagate fs root errors in lowmem mode Josef Bacik
2021-08-23 19:23 ` [PATCH v3 4/9] btrfs-progs: check: propagate extent item " Josef Bacik
2021-08-23 19:23 ` [PATCH v3 5/9] btrfs-progs: do not double add unaligned extent records Josef Bacik
2021-08-23 19:23 ` [PATCH v3 6/9] btrfs-progs: check: detect and fix problems with super_bytes_used Josef Bacik
2021-08-23 19:23 ` [PATCH v3 7/9] btrfs-progs: check: detect issues with btrfs_super_used in lowmem check Josef Bacik
2021-08-23 19:23 ` [PATCH v3 8/9] btrfs-progs: test: add a test image with a corrupt block group item Josef Bacik
2021-08-24 17:00   ` David Sterba
2021-08-25 13:27     ` David Sterba
2021-08-23 19:23 ` [PATCH v3 9/9] btrfs-progs: tests: add a test image with an invalid super bytes_used Josef Bacik

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=0bd15dc74561eba6fd6dc095848e3ba28539d6d3.1629746415.git.josef@toxicpanda.com \
    --to=josef@toxicpanda.com \
    --cc=kernel-team@fb.com \
    --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).