linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: Bill O'Donnell <billodo@redhat.com>
Cc: linux-xfs@vger.kernel.org
Subject: Re: [PATCH v2] libxfs: add more bounds checking to sb sanity checks
Date: Tue, 17 Jul 2018 10:06:54 -0700	[thread overview]
Message-ID: <20180717170654.GR32415@magnolia> (raw)
In-Reply-To: <20180716192655.27792-1-billodo@redhat.com>

On Mon, Jul 16, 2018 at 02:26:55PM -0500, Bill O'Donnell wrote:
> Current sb verifier doesn't check bounds on sb_fdblocks and sb_ifree.
> Add sanity checks for these parameters.
> 
> Signed-off-by: Bill O'Donnell <billodo@redhat.com>
> ---
> v2: make extra sanity checks exclusive to writes (allow read)
> 
>  fs/xfs/libxfs/xfs_sb.c | 22 +++++++++++++++++-----
>  1 file changed, 17 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/xfs/libxfs/xfs_sb.c b/fs/xfs/libxfs/xfs_sb.c
> index 350119eeaecb..6a98ec68e8ad 100644
> --- a/fs/xfs/libxfs/xfs_sb.c
> +++ b/fs/xfs/libxfs/xfs_sb.c
> @@ -104,7 +104,8 @@ xfs_mount_validate_sb(
>  	xfs_mount_t	*mp,
>  	xfs_sb_t	*sbp,
>  	bool		check_inprogress,
> -	bool		check_version)
> +	bool		check_version,
> +	bool		write_flag)

I notice that check_version and write_flag are always xor -- either
we're reading the sb and set check_version, or we're writing the sb and
set write_flag.  Perhaps we can combine these two as write_flag?

if (check_version)
	check version stuff...

becomes:

if (!write_flag)
	check version stuff...

and we only have to pass around one flag.

>  {
>  	uint32_t	agcount = 0;
>  	uint32_t	rem;
> @@ -266,6 +267,15 @@ xfs_mount_validate_sb(
>  		return -EFSCORRUPTED;
>  	}
>  
> +	/* Additional sb sanity checks for writes */
> +	if (write_flag) {
> +		if (sbp->sb_fdblocks > sbp->sb_dblocks ||
> +		    sbp->sb_ifree > sbp->sb_icount) {

Hmm, we still need something that will detect this on read and set a
flag to force recalculation of the summary counters... though since a
patch to implement that flag is sitting in my tree I'll take care of
that part separately.

--D

> +			    xfs_notice(mp, "SB sanity check failed");
> +			    return -EFSCORRUPTED;
> +		}
> +	}
> +
>  	if (sbp->sb_unit) {
>  		if (!xfs_sb_version_hasdalign(sbp) ||
>  		    sbp->sb_unit > sbp->sb_width ||
> @@ -599,7 +609,9 @@ xfs_sb_to_disk(
>  static int
>  xfs_sb_verify(
>  	struct xfs_buf	*bp,
> -	bool		check_version)
> +	bool		check_version,
> +	bool		write_flag)
> +
>  {
>  	struct xfs_mount *mp = bp->b_target->bt_mount;
>  	struct xfs_sb	sb;
> @@ -616,7 +628,7 @@ xfs_sb_verify(
>  	 */
>  	return xfs_mount_validate_sb(mp, &sb,
>  				     bp->b_maps[0].bm_bn == XFS_SB_DADDR,
> -				     check_version);
> +				     check_version, write_flag);
>  }
>  
>  /*
> @@ -657,7 +669,7 @@ xfs_sb_read_verify(
>  			}
>  		}
>  	}
> -	error = xfs_sb_verify(bp, true);
> +	error = xfs_sb_verify(bp, true, false);
>  
>  out_error:
>  	if (error == -EFSCORRUPTED || error == -EFSBADCRC)
> @@ -695,7 +707,7 @@ xfs_sb_write_verify(
>  	struct xfs_buf_log_item	*bip = bp->b_log_item;
>  	int			error;
>  
> -	error = xfs_sb_verify(bp, false);
> +	error = xfs_sb_verify(bp, false, true);
>  	if (error) {
>  		xfs_verifier_error(bp, error, __this_address);
>  		return;
> -- 
> 2.17.1
> 
> --
> 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

  parent reply	other threads:[~2018-07-17 17:40 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-13 13:10 [PATCH] libxfs: add more bounds checking to sb sanity checks Bill O'Donnell
2018-07-13 16:41 ` Darrick J. Wong
2018-07-13 20:06   ` Bill O'Donnell
2018-07-13 23:43   ` Dave Chinner
2018-07-17 17:13     ` Darrick J. Wong
2018-07-16 19:26 ` [PATCH v2] " Bill O'Donnell
2018-07-17  9:17   ` Carlos Maiolino
2018-07-17 17:06   ` Darrick J. Wong [this message]
2018-07-17 17:17     ` Bill O'Donnell
2018-07-17 19:12       ` Bill O'Donnell
2018-07-17 20:33         ` Darrick J. Wong
2018-07-17 23:26           ` Dave Chinner
2018-07-18 20:07             ` Bill O'Donnell
2018-07-25 21:33 ` [PATCH v3] " Bill O'Donnell
2018-07-25 21:47   ` Darrick J. Wong
2018-07-25 21:58     ` Bill O'Donnell
2018-07-25 22:48   ` Eric Sandeen
2018-07-25 22:55     ` Darrick J. Wong
2018-07-26 16:40 ` [PATCH v4] " Bill O'Donnell
2018-07-26 17:07   ` Darrick J. Wong
2018-07-26 17:19     ` Bill O'Donnell

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=20180717170654.GR32415@magnolia \
    --to=darrick.wong@oracle.com \
    --cc=billodo@redhat.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).