linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bill O'Donnell <billodo@redhat.com>
To: "Darrick J. Wong" <darrick.wong@oracle.com>
Cc: linux-xfs@vger.kernel.org
Subject: Re: [PATCH v4] libxfs: add more bounds checking to sb sanity checks
Date: Thu, 26 Jul 2018 12:19:41 -0500	[thread overview]
Message-ID: <20180726171941.GA19621@redhat.com> (raw)
In-Reply-To: <20180726170734.GF30972@magnolia>

On Thu, Jul 26, 2018 at 10:07:34AM -0700, Darrick J. Wong wrote:
> On Thu, Jul 26, 2018 at 11:40:46AM -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>
> > ---
> > 
> > v4: adjust control flow to standard error checking. Add
> >     more descriptive comment. Add validation for sb_icount.
> > v3: eliminate need for additional write_flag, doing those
> >     unique checks in xfs_sb_write_verify()
> > v2: make extra sanity checks exclusive to writes
> > 
> >  fs/xfs/libxfs/xfs_sb.c | 46 +++++++++++++++++++++++++++++++++---------
> >  1 file changed, 36 insertions(+), 10 deletions(-)
> > 
> > diff --git a/fs/xfs/libxfs/xfs_sb.c b/fs/xfs/libxfs/xfs_sb.c
> > index b3ad15956366..8d8e579ca426 100644
> > --- a/fs/xfs/libxfs/xfs_sb.c
> > +++ b/fs/xfs/libxfs/xfs_sb.c
> > @@ -599,22 +599,16 @@ xfs_sb_to_disk(
> >  static int
> >  xfs_sb_verify(
> >  	struct xfs_buf	*bp,
> > +	struct xfs_sb	*sb,
> >  	bool		check_version)
> >  {
> >  	struct xfs_mount *mp = bp->b_target->bt_mount;
> > -	struct xfs_sb	sb;
> > -
> > -	/*
> > -	 * Use call variant which doesn't convert quota flags from disk 
> > -	 * format, because xfs_mount_validate_sb checks the on-disk flags.
> > -	 */
> > -	__xfs_sb_from_disk(&sb, XFS_BUF_TO_SBP(bp), false);
> >  
> >  	/*
> >  	 * Only check the in progress field for the primary superblock as
> >  	 * mkfs.xfs doesn't clear it from secondary superblocks.
> >  	 */
> > -	return xfs_mount_validate_sb(mp, &sb,
> > +	return xfs_mount_validate_sb(mp, sb,
> >  				     bp->b_maps[0].bm_bn == XFS_SB_DADDR,
> >  				     check_version);
> >  }
> > @@ -637,6 +631,7 @@ xfs_sb_read_verify(
> >  {
> >  	struct xfs_mount *mp = bp->b_target->bt_mount;
> >  	struct xfs_dsb	*dsb = XFS_BUF_TO_SBP(bp);
> > +	struct xfs_sb	sb;
> >  	int		error;
> >  
> >  	/*
> > @@ -657,7 +652,13 @@ xfs_sb_read_verify(
> >  			}
> >  		}
> >  	}
> > -	error = xfs_sb_verify(bp, true);
> > +
> > +	/*
> > +	 * Use call variant which doesn't convert quota flags from disk
> > +	 * format, because xfs_mount_validate_sb checks the on-disk flags.
> > +	 */
> > +	__xfs_sb_from_disk(&sb, XFS_BUF_TO_SBP(bp), false);
> > +	error = xfs_sb_verify(bp, &sb, true);
> >  
> >  out_error:
> >  	if (error == -EFSCORRUPTED || error == -EFSBADCRC)
> > @@ -693,9 +694,34 @@ xfs_sb_write_verify(
> >  {
> >  	struct xfs_mount	*mp = bp->b_target->bt_mount;
> >  	struct xfs_buf_log_item	*bip = bp->b_log_item;
> > +	struct xfs_sb		sb;
> >  	int			error;
> >  
> > -	error = xfs_sb_verify(bp, false);
> > +	/*
> > +	 * Use call variant which doesn't convert quota flags from disk
> > +	 * format, because xfs_mount_validate_sb checks the on-disk flags.
> > +	 */
> > +	__xfs_sb_from_disk(&sb, XFS_BUF_TO_SBP(bp), false);
> > +
> > +	error = xfs_sb_verify(bp, &sb, false);
> > +	if (error)
> > +		goto err;
> > +
> > +	/*
> > +	 * Carry out additional sb sanity checks exclusively for writes.
> > +	 * We don't do these checks for reads, since faulty parameters could
> > +	 * already be on disk, and we shouldn't preclude reads for those
> > +	 * cases.
> > +	 */
> > +	if (sb.sb_fdblocks > sb.sb_dblocks ||
> > +	    sb.sb_icount / sb.sb_inopblock > sb.sb_dblocks ||
> 
> This is a 64-bit division, which won't work on 32-bit builds.
> 
> That said, I also wrote a xfs_verify_icount function for the fs summary
> scrub patch, so perhaps we should collaborate to land both of these?
> Send a v5 without this test and I'll immediately send a patch adding
> both the _verify_icount and putting it to use here.
> 
> Actually, I could just modify your patch, add mine, and send both of
> them.  That'd be easier...

That sounds fine. Thanks!
Bill

> 
> --D
> 
> > +	    sb.sb_ifree > sb.sb_icount) {
> > +		xfs_notice(mp, "SB sanity check failed");
> > +		error = -EFSCORRUPTED;
> > +		goto err;
> > +	}
> > +
> > +err:
> >  	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

      reply	other threads:[~2018-07-26 18:37 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
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 [this message]

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=20180726171941.GA19621@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).