From: Dave Chinner <david@fromorbit.com>
To: "Darrick J. Wong" <djwong@kernel.org>
Cc: sandeen@sandeen.net, linux-xfs@vger.kernel.org
Subject: Re: [PATCH 1/6] xfs_copy: don't use cached buffer reads until after libxfs_mount
Date: Wed, 29 Jun 2022 08:56:29 +1000 [thread overview]
Message-ID: <20220628225629.GN227878@dread.disaster.area> (raw)
In-Reply-To: <165644936019.1089996.1994101193208059510.stgit@magnolia>
On Tue, Jun 28, 2022 at 01:49:20PM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
>
> I accidentally tried to xfs_copy an ext4 filesystem, but instead of
> rejecting the filesystem, the program instead crashed. I figured out
> that zeroing the superblock was enough to trigger this:
>
> # dd if=/dev/zero of=/dev/sda bs=1024k count=1
> # xfs_copy /dev/sda /dev/sdb
> Floating point exception
>
> The exact crash happens in this line from libxfs_getbuf_flags, which is
> called from the main() routine of xfs_copy:
>
> if (btp == btp->bt_mount->m_ddev_targp) {
> (*bpp)->b_pag = xfs_perag_get(btp->bt_mount,
> xfs_daddr_to_agno(btp->bt_mount, blkno));
>
> The problem here is that the uncached read filled the incore superblock
> with zeroes, which means mbuf.sb_agblocks is zero. This causes a
> division by zero in xfs_daddr_to_agno, thereby crashing the program.
>
> In commit f8b581d6, we made it so that xfs_buf structures contain a
> passive reference to the associated perag structure. That commit
> assumes that no program would try a cached buffer read until the buffer
> cache is fully set up, which is true throughout xfsprogs... except for
> the beginning of xfs_copy. For whatever reason, it attempts an uncached
> read of the superblock to figure out the real superblock size, then
> performs a *cached* read with the proper buffer length and verifier.
> The cached read crashes the program.
>
> Fix the problem by changing the (second) cached read into an uncached read.
>
> Fixes: f8b581d6 ("libxfs: actually make buffers track the per-ag structures")
> Signed-off-by: Darrick J. Wong <djwong@kernel.org>
> ---
> copy/xfs_copy.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>
> diff --git a/copy/xfs_copy.c b/copy/xfs_copy.c
> index 41f594bd..79f65946 100644
> --- a/copy/xfs_copy.c
> +++ b/copy/xfs_copy.c
> @@ -748,7 +748,7 @@ main(int argc, char **argv)
> /* Do it again, now with proper length and verifier */
> libxfs_buf_relse(sbp);
>
> - error = -libxfs_buf_read(mbuf.m_ddev_targp, XFS_SB_DADDR,
> + error = -libxfs_buf_read_uncached(mbuf.m_ddev_targp, XFS_SB_DADDR,
> 1 << (sb->sb_sectlog - BBSHIFT), 0, &sbp,
> &xfs_sb_buf_ops);
> if (error) {
Looks good.
Reviewed-by: Dave Chinner <dchinner@redhat.com>
--
Dave Chinner
david@fromorbit.com
next prev parent reply other threads:[~2022-06-28 22:56 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-28 20:49 [PATCHSET 0/6] xfsprogs: random fixes Darrick J. Wong
2022-06-28 20:49 ` [PATCH 1/6] xfs_copy: don't use cached buffer reads until after libxfs_mount Darrick J. Wong
2022-06-28 22:56 ` Dave Chinner [this message]
2022-06-29 7:44 ` Christoph Hellwig
2022-06-28 20:49 ` [PATCH 2/6] xfs_repair: clear DIFLAG2_NREXT64 when filesystem doesn't support nrext64 Darrick J. Wong
2022-06-28 22:58 ` Dave Chinner
2022-06-29 23:10 ` Darrick J. Wong
2022-06-30 22:51 ` Dave Chinner
2022-07-01 0:08 ` Darrick J. Wong
2022-07-01 0:12 ` [PATCH v2 " Darrick J. Wong
2022-07-01 1:08 ` Dave Chinner
2022-06-28 20:49 ` [PATCH 3/6] xfs_repair: detect and fix padding fields that changed with nrext64 Darrick J. Wong
2022-06-28 22:59 ` Dave Chinner
2022-06-28 20:49 ` [PATCH 4/6] mkfs: preserve DIFLAG2_NREXT64 when setting other inode attributes Darrick J. Wong
2022-06-28 22:59 ` Dave Chinner
2022-06-28 20:49 ` [PATCH 5/6] mkfs: document the large extent count switch in the --help screen Darrick J. Wong
2022-06-28 23:00 ` Dave Chinner
2022-06-28 20:49 ` [PATCH 6/6] mkfs: always use new_diflags2 to initialize new inodes Darrick J. Wong
2022-06-28 23:01 ` Dave Chinner
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=20220628225629.GN227878@dread.disaster.area \
--to=david@fromorbit.com \
--cc=djwong@kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=sandeen@sandeen.net \
/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