From: "Darrick J. Wong" <djwong@kernel.org>
To: Dave Chinner <david@fromorbit.com>
Cc: linux-xfs@vger.kernel.org
Subject: Re: [PATCH 2/2] xfs: fix an integer overflow error in xfs_growfs_rt
Date: Tue, 13 Jul 2021 22:00:32 -0700 [thread overview]
Message-ID: <20210714050032.GF22402@magnolia> (raw)
In-Reply-To: <20210714011215.GU664593@dread.disaster.area>
On Wed, Jul 14, 2021 at 11:12:15AM +1000, Dave Chinner wrote:
> On Mon, Jul 12, 2021 at 03:07:31PM -0700, Darrick J. Wong wrote:
> > From: Darrick J. Wong <djwong@kernel.org>
> >
> > During a realtime grow operation, we run a single transaction for each
> > rt bitmap block added to the filesystem. This means that each step has
> > to be careful to increase sb_rblocks appropriately.
> >
> > Fix the integer overflow error in this calculation that can happen when
> > the extent size is very large. Found by running growfs to add a rt
> > volume to a filesystem formatted with a 1g rt extent size.
> >
> > Signed-off-by: Darrick J. Wong <djwong@kernel.org>
> > ---
> > fs/xfs/xfs_rtalloc.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> >
> > diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c
> > index 8920bce4fb0a..a47d43c30283 100644
> > --- a/fs/xfs/xfs_rtalloc.c
> > +++ b/fs/xfs/xfs_rtalloc.c
> > @@ -1019,7 +1019,7 @@ xfs_growfs_rt(
> > nsbp->sb_rbmblocks = bmbno + 1;
> > nsbp->sb_rblocks =
> > XFS_RTMIN(nrblocks,
> > - nsbp->sb_rbmblocks * NBBY *
> > + (xfs_rfsblock_t)nsbp->sb_rbmblocks * NBBY *
> > nsbp->sb_blocksize * nsbp->sb_rextsize);
> > nsbp->sb_rextents = nsbp->sb_rblocks;
> > do_div(nsbp->sb_rextents, nsbp->sb_rextsize);
>
> Oh, that's just nasty code. This needs a comment explaining that the
> cast is to avoid an overflow, otherwise someone will come along
> later and remove the "unnecessary" cast.
>
> Alternatively, because we do "nsbp->sb_rbmblocks = bmbno + 1;" a
> couple of lines above, this could be done differently without the
> need for a cast. Make bmbno a xfs_rfsblock_t, and simply write the
> code as:
>
> nsbp->sb_rblocks = min(nrblocks,
> (bmbno + 1) * NBBY *
> nsbp->sb_blocksize * nsbp->sb_rextsize);
> nsbp->sb_rbmblocks = bmbno + 1;
I like that, it'll get changed in the next revision.
> Notes for future cleanup:
>
> #define XFS_RTMIN(a,b) ((a) < (b) ? (a) : (b))
>
> Needs to die.
Heh, yes.
--D
>
> Cheers,
>
> Dave.
> --
> Dave Chinner
> david@fromorbit.com
next prev parent reply other threads:[~2021-07-14 5:00 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-12 22:07 [PATCHSET 0/2] xfs: small fixes to realtime growfs Darrick J. Wong
2021-07-12 22:07 ` [PATCH 1/2] xfs: improve FSGROWFSRT precondition checking Darrick J. Wong
2021-07-14 0:58 ` Dave Chinner
2021-07-14 4:59 ` Darrick J. Wong
2021-07-12 22:07 ` [PATCH 2/2] xfs: fix an integer overflow error in xfs_growfs_rt Darrick J. Wong
2021-07-14 1:12 ` Dave Chinner
2021-07-14 5:00 ` Darrick J. Wong [this message]
-- strict thread matches above, loose matches on Subject: below --
2021-07-14 21:25 [PATCHSET v2 0/2] xfs: small fixes to realtime growfs Darrick J. Wong
2021-07-14 21:25 ` [PATCH 2/2] xfs: fix an integer overflow error in xfs_growfs_rt Darrick J. Wong
2021-07-14 23:46 ` Dave Chinner
2021-07-15 6:06 ` Christoph Hellwig
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=20210714050032.GF22402@magnolia \
--to=djwong@kernel.org \
--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).