diff mbox series

[4/7] xfs_repair: complain about unwritten extents when they're not appropriate

Message ID 159950114274.567790.13140838452739405641.stgit@magnolia (mailing list archive)
State Accepted
Headers show
Series xfs_repair: more fuzzer fixes | expand

Commit Message

Darrick J. Wong Sept. 7, 2020, 5:52 p.m. UTC
From: Darrick J. Wong <darrick.wong@oracle.com>

We don't allow unwritten extents in the attr fork, and we don't allow
them in the data fork except for regular files.  Check that this is the
case.

Found by manually fuzzing the extentflag field of an attr fork to one.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 repair/dinode.c |   22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

Comments

Christoph Hellwig Sept. 8, 2020, 2:51 p.m. UTC | #1
On Mon, Sep 07, 2020 at 10:52:22AM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> We don't allow unwritten extents in the attr fork, and we don't allow
> them in the data fork except for regular files.  Check that this is the
> case.
> 
> Found by manually fuzzing the extentflag field of an attr fork to one.

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>
diff mbox series

Patch

diff --git a/repair/dinode.c b/repair/dinode.c
index d552db2d5f1a..1fe68bd41117 100644
--- a/repair/dinode.c
+++ b/repair/dinode.c
@@ -347,6 +347,28 @@  _("bmap rec out of order, inode %" PRIu64" entry %d "
 		cp = irec.br_blockcount;
 		sp = irec.br_startblock;
 
+		if (irec.br_state != XFS_EXT_NORM) {
+			/* No unwritten extents in the attr fork */
+			if (whichfork == XFS_ATTR_FORK) {
+				do_warn(
+_("unwritten extent (off = %" PRIu64 ", fsbno = %" PRIu64 ") in ino %" PRIu64 " attr fork\n"),
+					irec.br_startoff,
+					irec.br_startblock,
+					ino);
+				goto done;
+			}
+
+			/* No unwritten extents in non-regular files */
+			if (type != XR_INO_DATA && type != XR_INO_RTDATA) {
+				do_warn(
+_("unwritten extent (off = %" PRIu64 ", fsbno = %" PRIu64 ") in non-regular file ino %" PRIu64 "\n"),
+					irec.br_startoff,
+					irec.br_startblock,
+					ino);
+				goto done;
+			}
+		}
+
 		/*
 		 * check numeric validity of the extent
 		 */