From: Bill O'Donnell <billodo@redhat.com>
To: "Darrick J. Wong" <darrick.wong@oracle.com>
Cc: linux-xfs@vger.kernel.org
Subject: Re: [PATCH 2/2] xfs: verify icount in superblock write
Date: Thu, 26 Jul 2018 12:48:21 -0500 [thread overview]
Message-ID: <20180726174820.GA20780@redhat.com> (raw)
In-Reply-To: <153262652554.8934.816888163232208002.stgit@magnolia>
On Thu, Jul 26, 2018 at 10:35:25AM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
>
> Add a helper predicate to check the inode count for sanity, then use it
> in the superblock write verifier to inspect sb_icount.
>
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
Looks good.
Thanks.
Reviewed-by: Bill O'Donnell <billodo@redhat.com>
> fs/xfs/libxfs/xfs_sb.c | 1 +
> fs/xfs/libxfs/xfs_types.c | 34 ++++++++++++++++++++++++++++++++++
> fs/xfs/libxfs/xfs_types.h | 1 +
> 3 files changed, 36 insertions(+)
>
>
> diff --git a/fs/xfs/libxfs/xfs_sb.c b/fs/xfs/libxfs/xfs_sb.c
> index b2c683588519..1659016875f9 100644
> --- a/fs/xfs/libxfs/xfs_sb.c
> +++ b/fs/xfs/libxfs/xfs_sb.c
> @@ -714,6 +714,7 @@ xfs_sb_write_verify(
> * cases.
> */
> if (sb.sb_fdblocks > sb.sb_dblocks ||
> + !xfs_verify_icount(mp, sb.sb_icount) ||
> sb.sb_ifree > sb.sb_icount) {
> xfs_notice(mp, "SB summary counter sanity check failed");
> error = -EFSCORRUPTED;
> diff --git a/fs/xfs/libxfs/xfs_types.c b/fs/xfs/libxfs/xfs_types.c
> index 2e2a243cef2e..2e9c0c25ccb6 100644
> --- a/fs/xfs/libxfs/xfs_types.c
> +++ b/fs/xfs/libxfs/xfs_types.c
> @@ -171,3 +171,37 @@ xfs_verify_rtbno(
> {
> return rtbno < mp->m_sb.sb_rblocks;
> }
> +
> +/* Calculate the range of valid icount values. */
> +static void
> +xfs_icount_range(
> + struct xfs_mount *mp,
> + unsigned long long *min,
> + unsigned long long *max)
> +{
> + unsigned long long nr_inos = 0;
> + xfs_agnumber_t agno;
> +
> + /* root, rtbitmap, rtsum all live in the first chunk */
> + *min = XFS_INODES_PER_CHUNK;
> +
> + for (agno = 0; agno < mp->m_sb.sb_agcount; agno++) {
> + xfs_agino_t first, last;
> +
> + xfs_agino_range(mp, agno, &first, &last);
> + nr_inos += first - last + 1;
> + }
> + *max = nr_inos;
> +}
> +
> +/* Sanity-checking of inode counts. */
> +bool
> +xfs_verify_icount(
> + struct xfs_mount *mp,
> + unsigned long long icount)
> +{
> + unsigned long long min, max;
> +
> + xfs_icount_range(mp, &min, &max);
> + return icount >= min && icount < max;
> +}
> diff --git a/fs/xfs/libxfs/xfs_types.h b/fs/xfs/libxfs/xfs_types.h
> index 4055d62f690c..b9e6c89284c3 100644
> --- a/fs/xfs/libxfs/xfs_types.h
> +++ b/fs/xfs/libxfs/xfs_types.h
> @@ -165,5 +165,6 @@ bool xfs_verify_ino(struct xfs_mount *mp, xfs_ino_t ino);
> bool xfs_internal_inum(struct xfs_mount *mp, xfs_ino_t ino);
> bool xfs_verify_dir_ino(struct xfs_mount *mp, xfs_ino_t ino);
> bool xfs_verify_rtbno(struct xfs_mount *mp, xfs_rtblock_t rtbno);
> +bool xfs_verify_icount(struct xfs_mount *mp, unsigned long long icount);
>
> #endif /* __XFS_TYPES_H__ */
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2018-07-26 19:06 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-26 17:35 [PATCH 1/2] libxfs: add more bounds checking to sb sanity checks Darrick J. Wong
2018-07-26 17:35 ` [PATCH 2/2] xfs: verify icount in superblock write Darrick J. Wong
2018-07-26 17:48 ` Bill O'Donnell [this message]
2018-07-26 23:20 ` Dave Chinner
2018-07-27 0:07 ` Darrick J. Wong
2018-07-27 10:44 ` Brian Foster
2018-07-27 14:30 ` Eric Sandeen
2018-07-27 22:13 ` Darrick J. Wong
2018-07-29 4:39 ` Dave Chinner
2018-07-30 12:36 ` Brian Foster
2018-07-26 18:25 ` [PATCH 1/2] libxfs: add more bounds checking to sb sanity checks Bill O'Donnell
2018-07-26 23:28 ` Dave Chinner
2018-07-27 15:05 ` Eric Sandeen
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=20180726174820.GA20780@redhat.com \
--to=billodo@redhat.com \
--cc=darrick.wong@oracle.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;
as well as URLs for NNTP newsgroup(s).