]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: fix endianness issue in xfs_ag_shrink_space
authorDarrick J. Wong <djwong@kernel.org>
Fri, 15 Oct 2021 20:28:27 +0000 (16:28 -0400)
committerEric Sandeen <sandeen@sandeen.net>
Fri, 15 Oct 2021 20:28:27 +0000 (16:28 -0400)
Source kernel commit: a8f3522c9a1f4a31e93b17f2b5310a2b615f5581

The AGI buffer is in big-endian format, so we must convert the
endianness to CPU format to do any comparisons.

Fixes: 46141dc891f7 ("xfs: introduce xfs_ag_shrink_space()")
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
libxfs/xfs_ag.c

index a1a2d0d9dd0600e6bbdc2eed79a2131f7c3e6cb4..3e78d25308511a59b6bd7c2cd32e6555d9d5712e 100644 (file)
@@ -777,6 +777,7 @@ xfs_ag_shrink_space(
        struct xfs_buf          *agibp, *agfbp;
        struct xfs_agi          *agi;
        struct xfs_agf          *agf;
+       xfs_agblock_t           aglen;
        int                     error, err2;
 
        ASSERT(agno == mp->m_sb.sb_agcount - 1);
@@ -791,14 +792,14 @@ xfs_ag_shrink_space(
                return error;
 
        agf = agfbp->b_addr;
+       aglen = be32_to_cpu(agi->agi_length);
        /* some extra paranoid checks before we shrink the ag */
        if (XFS_IS_CORRUPT(mp, agf->agf_length != agi->agi_length))
                return -EFSCORRUPTED;
-       if (delta >= agi->agi_length)
+       if (delta >= aglen)
                return -EINVAL;
 
-       args.fsbno = XFS_AGB_TO_FSB(mp, agno,
-                                   be32_to_cpu(agi->agi_length) - delta);
+       args.fsbno = XFS_AGB_TO_FSB(mp, agno, aglen - delta);
 
        /*
         * Disable perag reservations so it doesn't cause the allocation request