From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: Dave Chinner <david@fromorbit.com>
Cc: Bill O'Donnell <billodo@redhat.com>, linux-xfs@vger.kernel.org
Subject: Re: [PATCH] libxfs: add more bounds checking to sb sanity checks
Date: Tue, 17 Jul 2018 10:13:28 -0700 [thread overview]
Message-ID: <20180717171328.GS32415@magnolia> (raw)
In-Reply-To: <20180713234341.GX19934@dastard>
On Sat, Jul 14, 2018 at 09:43:41AM +1000, Dave Chinner wrote:
> On Fri, Jul 13, 2018 at 09:41:53AM -0700, Darrick J. Wong wrote:
> > On Fri, Jul 13, 2018 at 08:10:03AM -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>
> > > ---
> > > fs/xfs/libxfs/xfs_sb.c | 4 +++-
> > > 1 file changed, 3 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/fs/xfs/libxfs/xfs_sb.c b/fs/xfs/libxfs/xfs_sb.c
> > > index 350119eeaecb..cdede769ab88 100644
> > > --- a/fs/xfs/libxfs/xfs_sb.c
> > > +++ b/fs/xfs/libxfs/xfs_sb.c
> > > @@ -261,7 +261,9 @@ xfs_mount_validate_sb(
> > > sbp->sb_dblocks == 0 ||
> > > sbp->sb_dblocks > XFS_MAX_DBLOCKS(sbp) ||
> > > sbp->sb_dblocks < XFS_MIN_DBLOCKS(sbp) ||
> > > - sbp->sb_shared_vn != 0)) {
> > > + sbp->sb_shared_vn != 0 ||
> > > + sbp->sb_fdblocks > sbp->sb_dblocks ||
> > > + sbp->sb_ifree > sbp->sb_icount)) {
> >
> > Hmm. On its face this seems reasonable for the superblock verifier, but
> > then I started wondering, since these are /summary/ counters.
> >
> > If the free counts are off by this much, the admin won't be able to
> > mount the fs, and xfs_repair is the only other tool that can fix the
> > summary counts. However, if the log is dirty, the mount won't succeed
> > to recover the fs, which is too bad since we can reinitialize the
> > summary counts after log recovery. xfs_repair -L will be the only way
> > out, which will wreak havoc on the filesystem from discarding the log
> > contents.
>
> Yup, that's why I said "catch this on /write/", not "always reject
> bad counter values".
>
> i.e. we should never be writing a bad value, but we most definitely
> need to be able to mount the filesystem to reconstruct them.
>
> > So, would it be preferable to split this into two parts? For example,
> > have this as a corruption check in _sb_write_verify to prevent us from
> > writing out garbage counters
>
> yes.
>
> > and a clamp in _reinit_percpu_counters so
> > that we never present ridiculous free counts to users?
>
> percpu_counter_{read,sum}_positive() should be used for anything that is
> userspace facing. xfs_fs_counts() gets this right, but
> xfs_fs_statfs() doesn't - it should use
> percpu_counter_sum_positive().
I don't think that will solve this problem -- although sb_fdblocks is
larger than sb_dblocks, sd_fdblocks is not so insanely large that
percpu_counter_{read,sum} return negative values; returning to Eric's
analysis of the original complaint:
> sb_fdblocks 4461713825, counted 166746529
> - found root inode chunk
>
> that sb_fdblocks really is ~17T which indicates the problem
> really is on disk.
>
> 4461713825
> 100001001111100000101100110100001
^-- bit 32 of a signed 64-bit quantity
> 166746529
> 1001111100000101100110100001
So we still need a separate sb_fdblocks <= sb_dblocks clamp and/or
forced recalculation somewhere.
I agree that _fs_statfs should only return positive free blocks to avoid
reporting total garbage to userspace, but that's not the problme here.
I'll toss that onto my pile for 4.19 stuff.
> > (Does any of this make sense with !haslazysbcount filesystems?)
>
> Same thing - we can't verify the counters on read until after log
> recovery as all the changes are journalled.
>
> > Bonus question: What about checking frextents/rextents?
>
> Same as !lazycount - all changes are journalled.
Ok.
--D
> Cheers,
>
> Dave.
>
> --
> Dave Chinner
> david@fromorbit.com
> --
> 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-17 17:47 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 [this message]
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
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=20180717171328.GS32415@magnolia \
--to=darrick.wong@oracle.com \
--cc=billodo@redhat.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;
as well as URLs for NNTP newsgroup(s).