Skip to contentSkip to conversation

xfs: random fixes

PATCH In review Darrick J. Wong 3 participants 12 messages Mar 11, 2020 XFS filesystem

lore
Share & tools
lore
#0 lore raw

cover xfs: random fixes

Hi all,

Fixes for a couple of minor bugs that I found.

If you're going to start using this mess, you probably ought to just pull from my git trees, which are linked below.

This is an extraordinary way to destroy everything. Enjoy! Comments and questions are, as always, welcome.

--D

kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=random-fixes

xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=random-fixes

fstests git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfstests-dev.git/log/?h=random-fixes

#1 lore raw

PATCH 1/2 xfs: fix use-after-free when aborting corrupt attr inactivation

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

Log the corrupt buffer before we release the buffer.

Fixes a5155b870d687 ("xfs: always log corruption errors")
---
 fs/xfs/xfs_attr_inactive.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_attr_inactive.c +1 -1
index bbfa6ba84dcd..fe8f60b59ec4 100644
@@ -145,8 +145,8 @@ xfs_attr3_node_inactive(
 	 * Since this code is recursive (gasp!) we must protect ourselves.
 	 */
 	if (level > XFS_DA_NODE_MAXDEPTH) {
-		xfs_trans_brelse(*trans, bp);	/* no locks for later trans */
 		xfs_buf_corruption_error(bp);
+		xfs_trans_brelse(*trans, bp);	/* no locks for later trans */
 		return -EFSCORRUPTED;
 	}
 
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] xfs: fix use-after-free when aborting corrupt attr inactivation

Quoted 16 lines · Darrick J. Wong

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

Log the corrupt buffer before we release the buffer.

Fixes a5155b870d687 ("xfs: always log corruption errors")
---
 fs/xfs/xfs_attr_inactive.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_attr_inactive.c +0 -0
index bbfa6ba84dcd..fe8f60b59ec4 100644

fs/xfs/xfs_attr_inactive.c xfs_attr3_node_inactive( · line 149

Quoted 6 lines
fs/xfs/xfs_attr_inactive.c +1 -1
@@ -145,8 +145,8 @@ xfs_attr3_node_inactive(
 	 * Since this code is recursive (gasp!) we must protect ourselves.
 	 */
 	if (level > XFS_DA_NODE_MAXDEPTH) {
-		xfs_trans_brelse(*trans, bp);	/* no locks for later trans */
 		xfs_buf_corruption_error(bp);
+		xfs_trans_brelse(*trans, bp);	/* no locks for later trans */

Yup, that needs fixing.

Signature · 2 lines
Dave Chinner
[email protected]
#4 lore raw

PATCH 2/2 xfs: fix xfs_rmap_has_other_keys usage of ECANCELED

In reply to Darrick J. Wong

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

In e7ee96dfb8c26, we converted all ITER_ABORT users to use ECANCELED instead, but we forgot to teach xfs_rmap_has_other_keys not to return that magic value to callers. Fix it now.

Fixes e7ee96dfb8c26 ("xfs: remove all *_ITER_ABORT values")
---
 fs/xfs/libxfs/xfs_rmap.c |   13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
fs/xfs/libxfs/xfs_rmap.c +6 -7
index ff9412f113c4..dae1a2bf28eb 100644
@@ -2694,7 +2694,6 @@ struct xfs_rmap_key_state {
 	uint64_t			owner;
 	uint64_t			offset;
 	unsigned int			flags;
-	bool				has_rmap;
 };
 
 /* For each rmap given, figure out if it doesn't match the key we want. */
@@ -2709,7 +2708,6 @@ xfs_rmap_has_other_keys_helper(
 	if (rks->owner == rec->rm_owner && rks->offset == rec->rm_offset &&
 	    ((rks->flags & rec->rm_flags) & XFS_RMAP_KEY_FLAGS) == rks->flags)
 		return 0;
-	rks->has_rmap = true;
 	return -ECANCELED;
 }
 
@@ -2731,7 +2729,7 @@ xfs_rmap_has_other_keys(
 	int				error;
 
 	xfs_owner_info_unpack(oinfo, &rks.owner, &rks.offset, &rks.flags);
-	rks.has_rmap = false;
+	*has_rmap = false;
 
 	low.rm_startblock = bno;
 	memset(&high, 0xFF, sizeof(high));
@@ -2739,11 +2737,12 @@ xfs_rmap_has_other_keys(
 
 	error = xfs_rmap_query_range(cur, &low, &high,
 			xfs_rmap_has_other_keys_helper, &rks);
-	if (error < 0)
-		return error;
+	if (error == -ECANCELED) {
+		*has_rmap = true;
+		return 0;
+	}
 
-	*has_rmap = rks.has_rmap;
-	return 0;
+	return error;
 }
 
 const struct xfs_owner_info XFS_RMAP_OINFO_SKIP_UPDATE = {
Reviewed-by on v1 2/2
#5 lore raw

Re: [PATCH 2/2] xfs: fix xfs_rmap_has_other_keys usage of ECANCELED

Quoted 8 lines · Darrick J. Wong

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

In e7ee96dfb8c26, we converted all ITER_ABORT users to use ECANCELED instead, but we forgot to teach xfs_rmap_has_other_keys not to return that magic value to callers. Fix it now.

Fixes e7ee96dfb8c26 ("xfs: remove all *_ITER_ABORT values")

/me had to go look at that commit to see what this was fixing.

Quoted 39 lines
---
 fs/xfs/libxfs/xfs_rmap.c |   13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
fs/xfs/libxfs/xfs_rmap.c +1 -4
index ff9412f113c4..dae1a2bf28eb 100644
@@ -2694,7 +2694,6 @@ struct xfs_rmap_key_state {
 	uint64_t			owner;
 	uint64_t			offset;
 	unsigned int			flags;
-	bool				has_rmap;
 };
 
 /* For each rmap given, figure out if it doesn't match the key we want. */
@@ -2709,7 +2708,6 @@ xfs_rmap_has_other_keys_helper(
 	if (rks->owner == rec->rm_owner && rks->offset == rec->rm_offset &&
 	    ((rks->flags & rec->rm_flags) & XFS_RMAP_KEY_FLAGS) == rks->flags)
 		return 0;
-	rks->has_rmap = true;
 	return -ECANCELED;
 }
 
@@ -2731,7 +2729,7 @@ xfs_rmap_has_other_keys(
 	int				error;
 
 	xfs_owner_info_unpack(oinfo, &rks.owner, &rks.offset, &rks.flags);
-	rks.has_rmap = false;
+	*has_rmap = false;
 
 	low.rm_startblock = bno;
 	memset(&high, 0xFF, sizeof(high));
@@ -2739,11 +2737,12 @@ xfs_rmap_has_other_keys(
 
 	error = xfs_rmap_query_range(cur, &low, &high,
 			xfs_rmap_has_other_keys_helper, &rks);
-	if (error < 0)

fs/xfs/libxfs/xfs_rmap.c xfs_rmap_has_other_keys( · line 2746

Quoted 10 lines
fs/xfs/libxfs/xfs_rmap.c +5 -3
-		return error;
+	if (error == -ECANCELED) {
+		*has_rmap = true;
+		return 0;
+	}
 
-	*has_rmap = rks.has_rmap;
-	return 0;
+	return error;
 }

Ok, so there's two things here. The first is catching ECANCELED and returning the correct value(0). The second is we no longer need the rks.has_rmap member to be passed to the helper, because -ECANCELED indicates that we found an rmap.

Ok, makes sense.

Signature · 2 lines
Dave Chinner
[email protected]
#6 lore raw

Re: [PATCH 2/2] xfs: fix xfs_rmap_has_other_keys usage of ECANCELED

In reply to Darrick J. Wong
Quoted 5 lines · Darrick J. Wong

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

In e7ee96dfb8c26, we converted all ITER_ABORT users to use ECANCELED instead, but we forgot to teach xfs_rmap_has_other_keys not to return that magic value to callers. Fix it now.

This doesn't document the remap of the has_rmap flag. As far as I can tell that isn't needed now the caller checks for ECANCELED, but it takes a while to figure that out. It'll need to be documented properly in the commit log.

#7 lore raw

Re: [PATCH 2/2] xfs: fix xfs_rmap_has_other_keys usage of ECANCELED

Quoted 11 lines · Christoph Hellwig
Quoted 5 lines · Darrick J. Wong

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

In e7ee96dfb8c26, we converted all ITER_ABORT users to use ECANCELED instead, but we forgot to teach xfs_rmap_has_other_keys not to return that magic value to callers. Fix it now.

This doesn't document the remap of the has_rmap flag. As far as I can tell that isn't needed now the caller checks for ECANCELED, but it takes a while to figure that out. It'll need to be documented properly in the commit log.

"Fix it now by using ECANCELED both to abort the iteration and to signal that we found another reverse mapping. This enables us to drop the separate boolean flag." ?

--D

#8 lore raw

Re: [PATCH 2/2] xfs: fix xfs_rmap_has_other_keys usage of ECANCELED

Quoted 8 lines · Darrick J. Wong
Quoted 7 lines · Christoph Hellwig
Quoted 5 lines · Darrick J. Wong

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

In e7ee96dfb8c26, we converted all ITER_ABORT users to use ECANCELED instead, but we forgot to teach xfs_rmap_has_other_keys not to return that magic value to callers. Fix it now.

Quoted 8 lines
Quoted 4 lines

This doesn't document the remap of the has_rmap flag. As far as I can tell that isn't needed now the caller checks for ECANCELED, but it takes a while to figure that out. It'll need to be documented properly in the commit log.

"Fix it now by using ECANCELED both to abort the iteration and to signal that we found another reverse mapping. This enables us to drop the separate boolean flag." ?

Sounds good.

#9 lore raw

Re: [PATCH 2/2] xfs: fix xfs_rmap_has_other_keys usage of ECANCELED

Quoted 14 lines · Christoph Hellwig
Quoted 13 lines · Darrick J. Wong
Quoted 11 lines · Christoph Hellwig
Quoted 5 lines · Darrick J. Wong

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

In e7ee96dfb8c26, we converted all ITER_ABORT users to use ECANCELED instead, but we forgot to teach xfs_rmap_has_other_keys not to return that magic value to callers. Fix it now.

This doesn't document the remap of the has_rmap flag. As far as I can tell that isn't needed now the caller checks for ECANCELED, but it takes a while to figure that out. It'll need to be documented properly in the commit log.

Quoted 5 lines
Quoted 3 lines

"Fix it now by using ECANCELED both to abort the iteration and to signal that we found another reverse mapping. This enables us to drop the separate boolean flag." ?

Sounds good.

Ok, I'll respin this one.

--D

#10 lore raw

PATCH v2 2/2 xfs: fix xfs_rmap_has_other_keys usage of ECANCELED

In reply to Darrick J. Wong

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

In e7ee96dfb8c26, we converted all ITER_ABORT users to use ECANCELED instead, but we forgot to teach xfs_rmap_has_other_keys not to return that magic value to callers. Fix it now by using ECANCELED both to abort the iteration and to signal that we found another reverse mapping. This enables us to drop the separate boolean flag.

Fixes e7ee96dfb8c26 ("xfs: remove all *_ITER_ABORT values")

---
v2: fix commit message per hch feedback

---
 fs/xfs/libxfs/xfs_rmap.c |   13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
fs/xfs/libxfs/xfs_rmap.c +6 -7
index ff9412f113c4..dae1a2bf28eb 100644
@@ -2694,7 +2694,6 @@ struct xfs_rmap_key_state {
 	uint64_t			owner;
 	uint64_t			offset;
 	unsigned int			flags;
-	bool				has_rmap;
 };
 
 /* For each rmap given, figure out if it doesn't match the key we want. */
@@ -2709,7 +2708,6 @@ xfs_rmap_has_other_keys_helper(
 	if (rks->owner == rec->rm_owner && rks->offset == rec->rm_offset &&
 	    ((rks->flags & rec->rm_flags) & XFS_RMAP_KEY_FLAGS) == rks->flags)
 		return 0;
-	rks->has_rmap = true;
 	return -ECANCELED;
 }
 
@@ -2731,7 +2729,7 @@ xfs_rmap_has_other_keys(
 	int				error;
 
 	xfs_owner_info_unpack(oinfo, &rks.owner, &rks.offset, &rks.flags);
-	rks.has_rmap = false;
+	*has_rmap = false;
 
 	low.rm_startblock = bno;
 	memset(&high, 0xFF, sizeof(high));
@@ -2739,11 +2737,12 @@ xfs_rmap_has_other_keys(
 
 	error = xfs_rmap_query_range(cur, &low, &high,
 			xfs_rmap_has_other_keys_helper, &rks);
-	if (error < 0)
-		return error;
+	if (error == -ECANCELED) {
+		*has_rmap = true;
+		return 0;
+	}
 
-	*has_rmap = rks.has_rmap;
-	return 0;
+	return error;
 }
 
 const struct xfs_owner_info XFS_RMAP_OINFO_SKIP_UPDATE = {
Reviewed-by on v2 2/2
#11 lore raw

Re: [PATCH v2 2/2] xfs: fix xfs_rmap_has_other_keys usage of ECANCELED

Quoted 11 lines · Darrick J. Wong

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

In e7ee96dfb8c26, we converted all ITER_ABORT users to use ECANCELED instead, but we forgot to teach xfs_rmap_has_other_keys not to return that magic value to callers. Fix it now by using ECANCELED both to abort the iteration and to signal that we found another reverse mapping. This enables us to drop the separate boolean flag.

Fixes e7ee96dfb8c26 ("xfs: remove all *_ITER_ABORT values")

Looks good,