Skip to contentSkip to conversation

xfs: fix endianness issue in xfs_ag_shrink_space

PATCH In review Darrick J. Wong 3 participants 4 messages Jun 21, 2021 – Jun 22, 2021 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs: fix endianness issue in xfs_ag_shrink_space

From: Darrick J. Wong <[email protected]>

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()")
---
 fs/xfs/libxfs/xfs_ag.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
fs/xfs/libxfs/xfs_ag.c +4 -3
index c68a36688474..afff2ab7e9f1 100644
@@ -510,6 +510,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);
@@ -524,14 +525,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
Reviewed-by on v1 1/1
#1 lore raw
Quoted 28 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

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()")
---
 fs/xfs/libxfs/xfs_ag.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
fs/xfs/libxfs/xfs_ag.c +2 -0
index c68a36688474..afff2ab7e9f1 100644
@@ -510,6 +510,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);
@@ -524,14 +525,14 @@ xfs_ag_shrink_space(
 		return error;
 
 	agf = agfbp->b_addr;
+	aglen = be32_to_cpu(agi->agi_length);

fs/xfs/libxfs/xfs_ag.c xfs_ag_shrink_space( · line 535

Quoted 10 lines
fs/xfs/libxfs/xfs_ag.c +2 -3
 	/* 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);

Looks fine.

FWIW, my plan for this stuff is to move the perag geometry stuff into the xfs_perag. That gets rid of all this "need the on disk buffer to get AG size" stuff. It also avoids having to calculate valid ranges of types on every verify call (expensive) because, at most per-ag type verifier call sites, we already have the perag on hand...

Cheers,

Signature · 2 lines
Dave Chinner
[email protected]
#2 lore raw
Quoted 42 lines · Dave Chinner
Quoted 28 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

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()")
---
 fs/xfs/libxfs/xfs_ag.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
fs/xfs/libxfs/xfs_ag.c +2 -0
index c68a36688474..afff2ab7e9f1 100644
@@ -510,6 +510,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);
@@ -524,14 +525,14 @@ xfs_ag_shrink_space(
 		return error;
 
 	agf = agfbp->b_addr;
+	aglen = be32_to_cpu(agi->agi_length);

fs/xfs/libxfs/xfs_ag.c xfs_ag_shrink_space( · line 535

Quoted 10 lines
fs/xfs/libxfs/xfs_ag.c +2 -3
 	/* 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);

Looks fine.

Quoted 8 lines

FWIW, my plan for this stuff is to move the perag geometry stuff into the xfs_perag. That gets rid of all this "need the on disk buffer to get AG size" stuff. It also avoids having to calculate valid ranges of types on every verify call (expensive) because, at most per-ag type verifier call sites, we already have the perag on hand...

woo!

--D

Quoted 4 lines

Cheers,

Signature · 2 lines
Dave Chinner
[email protected]