public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: linux-xfs@vger.kernel.org
Cc: Dave Chinner <david@fromorbit.com>
Subject: [PATCH v2 2/4] xfs: validate the realtime geometry in xfs_validate_sb_common
Date: Tue, 24 Mar 2020 23:07:19 -0700	[thread overview]
Message-ID: <20200325060719.GX29339@magnolia> (raw)
In-Reply-To: <158510668306.922633.16796248628127177511.stgit@magnolia>

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

Validate the geometry of the realtime geometry when we mount the
filesystem, so that we don't abruptly shut down the filesystem later on.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
v2: remove the excess whitespace and unlikely() bits
---
 fs/xfs/libxfs/xfs_sb.c |   30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/fs/xfs/libxfs/xfs_sb.c b/fs/xfs/libxfs/xfs_sb.c
index 2f60fc3c99a0..9a0cd25ec22a 100644
--- a/fs/xfs/libxfs/xfs_sb.c
+++ b/fs/xfs/libxfs/xfs_sb.c
@@ -328,6 +328,36 @@ xfs_validate_sb_common(
 		return -EFSCORRUPTED;
 	}
 
+	/* Validate the realtime geometry; stolen from xfs_repair */
+	if (sbp->sb_rextsize * sbp->sb_blocksize > XFS_MAX_RTEXTSIZE ||
+	    sbp->sb_rextsize * sbp->sb_blocksize < XFS_MIN_RTEXTSIZE) {
+		xfs_notice(mp,
+			"realtime extent sanity check failed");
+		return -EFSCORRUPTED;
+	}
+
+	if (sbp->sb_rblocks == 0) {
+		if (sbp->sb_rextents != 0 || sbp->sb_rbmblocks != 0 ||
+		    sbp->sb_rextslog != 0 || sbp->sb_frextents != 0) {
+			xfs_notice(mp,
+				"realtime zeroed geometry sanity check failed");
+			return -EFSCORRUPTED;
+		}
+	} else {
+		xfs_rtblock_t	rexts;
+		uint32_t	temp;
+
+		rexts = div_u64_rem(sbp->sb_rblocks, sbp->sb_rextsize, &temp);
+		if (rexts != sbp->sb_rextents ||
+		    sbp->sb_rextslog != xfs_highbit32(sbp->sb_rextents) ||
+		    sbp->sb_rbmblocks != howmany(sbp->sb_rextents,
+						 NBBY * sbp->sb_blocksize)) {
+			xfs_notice(mp,
+				"realtime geometry sanity check failed");
+			return -EFSCORRUPTED;
+		}
+	}
+
 	if (sbp->sb_unit) {
 		if (!xfs_sb_version_hasdalign(sbp) ||
 		    sbp->sb_unit > sbp->sb_width ||

  parent reply	other threads:[~2020-03-25  6:07 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-25  3:24 [PATCH 0/4] xfs: random fixes Darrick J. Wong
2020-03-25  3:24 ` [PATCH 1/4] xfs: prohibit fs freezing when using empty transactions Darrick J. Wong
2020-03-25  4:53   ` Dave Chinner
2020-03-25  5:56     ` Darrick J. Wong
2020-03-25  6:06   ` [PATCH v2 " Darrick J. Wong
2020-03-25 23:26     ` Dave Chinner
2020-04-01 11:22   ` [PATCH " Chandan Rajendra
2020-03-25  3:24 ` [PATCH 2/4] xfs: validate the realtime geometry in xfs_validate_sb_common Darrick J. Wong
2020-03-25  5:00   ` Dave Chinner
2020-03-25  5:53     ` Darrick J. Wong
2020-03-25  6:07   ` Darrick J. Wong [this message]
2020-03-25 23:27     ` [PATCH v2 " Dave Chinner
2020-04-01 13:49   ` [PATCH " Chandan Rajendra
2020-03-25  3:24 ` [PATCH 3/4] xfs: drop all altpath buffers at the end of the sibling check Darrick J. Wong
2020-03-25  5:04   ` Dave Chinner
2020-04-02  3:05   ` Chandan Rajendra
2020-03-25  3:24 ` [PATCH 4/4] xfs: directory bestfree check should release buffers Darrick J. Wong
2020-03-25  5:05   ` Dave Chinner

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=20200325060719.GX29339@magnolia \
    --to=darrick.wong@oracle.com \
    --cc=david@fromorbit.com \
    --cc=linux-xfs@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