All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: sandeen@sandeen.net
Cc: linux-xfs@vger.kernel.org, hch@infradead.org
Subject: [PATCH v2 01/16] xfs_repair: fix missing dir buffer corruption checks
Date: Tue, 12 May 2020 10:29:25 -0700	[thread overview]
Message-ID: <20200512172925.GJ6714@magnolia> (raw)
In-Reply-To: <158904179840.982941.17275782452712518850.stgit@magnolia>

From: Darrick J. Wong <darrick.wong@oracle.com>

The da_read_buf() function operates in "salvage" mode, which means that
if the verifiers fail, it will return a buffer with b_error set.  The
callers of da_read_buf, however, do not adequately check for verifier
errors, which means that repair can fail to flag a corrupt filesystem.

Fix the callers to do this properly.  The dabtree block walker and the
dabtree path checker functions to complain any time the da node / leafn
verifiers fail.  Fix the directory block walking functions to complain
about EFSCORRUPTED, since they already dealt with EFSBADCRC.

Found by running xfs/496 against lhdr.stale = middlebit.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
v2: check for corruption before checking magics; expand corruption
checks to other da_read_buf callers
---
 repair/da_util.c |   25 ++++++++++++++++---------
 repair/dir2.c    |   21 +++++++++++++++++++++
 2 files changed, 37 insertions(+), 9 deletions(-)

diff --git a/repair/da_util.c b/repair/da_util.c
index 5061880f..7239c2e2 100644
--- a/repair/da_util.c
+++ b/repair/da_util.c
@@ -134,6 +134,15 @@ _("can't read %s block %u for inode %" PRIu64 "\n"),
 			goto error_out;
 		}
 
+		/* corrupt leafn/node; rebuild the dir. */
+		if (bp->b_error == -EFSBADCRC || bp->b_error == -EFSCORRUPTED) {
+			do_warn(
+_("corrupt %s tree block %u for inode %" PRIu64 "\n"),
+				FORKNAME(whichfork), bno, da_cursor->ino);
+			libxfs_buf_relse(bp);
+			goto error_out;
+		}
+
 		node = bp->b_addr;
 		libxfs_da3_node_hdr_from_disk(mp, &nodehdr, node);
 
@@ -160,15 +169,6 @@ _("bad %s magic number 0x%x in inode %" PRIu64 " bno = %u\n"),
 			goto error_out;
 		}
 
-		/* corrupt node; rebuild the dir. */
-		if (bp->b_error == -EFSBADCRC || bp->b_error == -EFSCORRUPTED) {
-			libxfs_buf_relse(bp);
-			do_warn(
-_("corrupt %s tree block %u for inode %" PRIu64 "\n"),
-				FORKNAME(whichfork), bno, da_cursor->ino);
-			goto error_out;
-		}
-
 		if (nodehdr.count > geo->node_ents) {
 			do_warn(
 _("bad %s record count in inode %" PRIu64 ", count = %d, max = %d\n"),
@@ -562,6 +562,13 @@ _("can't read %s block %u for inode %" PRIu64 "\n"),
 				FORKNAME(whichfork), dabno, cursor->ino);
 			return 1;
 		}
+		if (bp->b_error == -EFSCORRUPTED || bp->b_error == -EFSBADCRC) {
+			do_warn(
+_("corrupt %s tree block %u for inode %" PRIu64 "\n"),
+				FORKNAME(whichfork), dabno, cursor->ino);
+			libxfs_buf_relse(bp);
+			return 1;
+		}
 
 		newnode = bp->b_addr;
 		libxfs_da3_node_hdr_from_disk(mp, &nodehdr, newnode);
diff --git a/repair/dir2.c b/repair/dir2.c
index cbbce601..b374bc7b 100644
--- a/repair/dir2.c
+++ b/repair/dir2.c
@@ -983,6 +983,13 @@ _("can't read block %u for directory inode %" PRIu64 "\n"),
 			mp->m_dir_geo->datablk, ino);
 		return 1;
 	}
+	if (bp->b_error == -EFSCORRUPTED) {
+		do_warn(
+_("corrupt directory block %u for inode %" PRIu64 "\n"),
+			mp->m_dir_geo->datablk, ino);
+		libxfs_buf_relse(bp);
+		return 1;
+	}
 	/*
 	 * Verify the block
 	 */
@@ -1122,6 +1129,13 @@ _("can't read file block %u for directory inode %" PRIu64 "\n"),
 				da_bno, ino);
 			goto error_out;
 		}
+		if (bp->b_error == -EFSCORRUPTED) {
+			do_warn(
+_("corrupt directory leafn block %u for inode %" PRIu64 "\n"),
+				da_bno, ino);
+			libxfs_buf_relse(bp);
+			goto error_out;
+		}
 		leaf = bp->b_addr;
 		libxfs_dir2_leaf_hdr_from_disk(mp, &leafhdr, leaf);
 		/*
@@ -1324,6 +1338,13 @@ _("can't read block %" PRIu64 " for directory inode %" PRIu64 "\n"),
 				dbno, ino);
 			continue;
 		}
+		if (bp->b_error == -EFSCORRUPTED) {
+			do_warn(
+_("corrupt directory data block %lu for inode %" PRIu64 "\n"),
+				dbno, ino);
+			libxfs_buf_relse(bp);
+			continue;
+		}
 		data = bp->b_addr;
 		if (!(be32_to_cpu(data->magic) == XFS_DIR2_DATA_MAGIC ||
 		      be32_to_cpu(data->magic) == XFS_DIR3_DATA_MAGIC))

  parent reply	other threads:[~2020-05-12 17:29 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-09 16:29 [PATCH 00/16] xfs_repair: catch things that xfs_check misses Darrick J. Wong
2020-05-09 16:29 ` [PATCH 01/16] xfs_repair: fix missing dir buffer corruption checks Darrick J. Wong
2020-05-09 17:08   ` Christoph Hellwig
2020-05-11 16:44     ` Darrick J. Wong
2020-05-11 17:36       ` Darrick J. Wong
2020-05-12 17:29   ` Darrick J. Wong [this message]
2020-05-13  6:22     ` [PATCH v2 " Christoph Hellwig
2020-05-13 15:35       ` Darrick J. Wong
2020-05-09 16:30 ` [PATCH 02/16] xfs_repair: warn when we would have rebuilt a directory Darrick J. Wong
2020-05-09 17:09   ` Christoph Hellwig
2020-05-09 16:30 ` [PATCH 03/16] xfs_repair: check for AG btree records that would wrap around Darrick J. Wong
2020-05-09 17:09   ` Christoph Hellwig
2020-05-09 16:30 ` [PATCH 04/16] xfs_repair: fix bnobt and refcountbt record order checks Darrick J. Wong
2020-05-09 17:10   ` Christoph Hellwig
2020-05-09 16:30 ` [PATCH 05/16] xfs_repair: check for out-of-order inobt records Darrick J. Wong
2020-05-09 17:11   ` Christoph Hellwig
2020-05-09 16:30 ` [PATCH 06/16] xfs_repair: fix rmapbt record order check Darrick J. Wong
2020-05-10  7:33   ` Christoph Hellwig
2020-05-09 16:30 ` [PATCH 07/16] xfs_repair: tag inobt vs finobt errors properly Darrick J. Wong
2020-05-09 17:14   ` Christoph Hellwig
2020-05-09 16:30 ` [PATCH 08/16] xfs_repair: complain about bad interior btree pointers Darrick J. Wong
2020-05-09 17:15   ` Christoph Hellwig
2020-05-09 16:30 ` [PATCH 09/16] xfs_repair: convert to libxfs_verify_agbno Darrick J. Wong
2020-05-09 17:18   ` Christoph Hellwig
2020-05-11 16:22     ` Darrick J. Wong
2020-05-12  8:07       ` Christoph Hellwig
2020-05-09 16:31 ` [PATCH 10/16] xfs_repair: refactor verify_dfsbno_range Darrick J. Wong
2020-05-10  7:24   ` Christoph Hellwig
2020-05-09 16:31 ` [PATCH 11/16] xfs_repair: remove verify_dfsbno Darrick J. Wong
2020-05-10  7:24   ` Christoph Hellwig
2020-05-09 16:31 ` [PATCH 12/16] xfs_repair: remove verify_aginum Darrick J. Wong
2020-05-10  7:25   ` Christoph Hellwig
2020-05-09 16:31 ` [PATCH 13/16] xfs_repair: mark entire free space btree record as free1 Darrick J. Wong
2020-05-10  7:26   ` Christoph Hellwig
2020-05-09 16:31 ` [PATCH 14/16] xfs_repair: complain about free space only seen by one btree Darrick J. Wong
2020-05-10  7:26   ` Christoph Hellwig
2020-05-09 16:31 ` [PATCH 15/16] xfs_repair: complain about extents in unknown state Darrick J. Wong
2020-05-10  7:27   ` Christoph Hellwig
2020-05-09 16:31 ` [PATCH 16/16] xfs_repair: complain about any nonzero inprogress value, not just 1 Darrick J. Wong
2020-05-10  7:27   ` Christoph Hellwig

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=20200512172925.GJ6714@magnolia \
    --to=darrick.wong@oracle.com \
    --cc=hch@infradead.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=sandeen@sandeen.net \
    /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.