Skip to contentSkip to conversation

xfs: a couple of syzbot fixes

PATCH In review Dave Chinner 3 participants 8 messages Apr 11, 2023 – Apr 12, 2023 XFS filesystem

lore
Share & tools
lore
#0 lore raw

cover xfs: a couple of syzbot fixes

Hi folks,

Here are a couple of simple patches that reduce the syzbot noise we've been getting. The superblock version verifier change is cc'd for stable so that it gets back to stable kernels and distros so they behave consistently with upstream w.r.t. future on-disk format versions.

-Dave.

#1 lore raw

PATCH 1/2 xfs: remove WARN when dquot cache insertion fails

From: Dave Chinner <[email protected]>

It just creates unnecessary bot noise these days.

---
 fs/xfs/xfs_dquot.c | 1 -
 1 file changed, 1 deletion(-)
fs/xfs/xfs_dquot.c +0 -1
index 8fb90da89787..7f071757f278 100644
@@ -798,7 +798,6 @@ xfs_qm_dqget_cache_insert(
 	error = radix_tree_insert(tree, id, dqp);
 	if (unlikely(error)) {
 		/* Duplicate found!  Caller must try again. */
-		WARN_ON(error != -EEXIST);
 		mutex_unlock(&qi->qi_tree_lock);
 		trace_xfs_dqget_dup(dqp);
 		return error;
Signature · 1 line
2.39.2
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] xfs: remove WARN when dquot cache insertion fails

Quoted 6 lines · Dave Chinner

From: Dave Chinner <[email protected]>

It just creates unnecessary bot noise these days.

--D

Quoted 19 lines
---
 fs/xfs/xfs_dquot.c | 1 -
 1 file changed, 1 deletion(-)
fs/xfs/xfs_dquot.c +0 -1
index 8fb90da89787..7f071757f278 100644
@@ -798,7 +798,6 @@ xfs_qm_dqget_cache_insert(
 	error = radix_tree_insert(tree, id, dqp);
 	if (unlikely(error)) {
 		/* Duplicate found!  Caller must try again. */
-		WARN_ON(error != -EEXIST);
 		mutex_unlock(&qi->qi_tree_lock);
 		trace_xfs_dqget_dup(dqp);
 		return error;
Signature · 1 line
2.39.2
#4 lore raw

PATCH 2/2 xfs: don't consider future format versions valid

In reply to Dave Chinner

From: Dave Chinner <[email protected]>

In commit fe08cc504448 we reworked the valid superblock version checks. If it is a V5 filesystem, it is always valid, then we checked if the version was less than V4 (reject) and then checked feature fields in the V4 flags to determine if it was valid.

What we missed was that if the version is not V4 at this point, we shoudl reject the fs. i.e. the check current treats V6+ filesystems as if it was a v4 filesystem. Fix this.

Fixes fe08cc504448 ("xfs: open code sb verifier feature checks")
---
 fs/xfs/libxfs/xfs_sb.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
fs/xfs/libxfs/xfs_sb.c +6 -5
index 99cc03a298e2..ba0f17bc1dc0 100644
@@ -72,7 +72,8 @@ xfs_sb_validate_v5_features(
 }
 
 /*
- * We support all XFS versions newer than a v4 superblock with V2 directories.
+ * We current support XFS v5 formats with known features and v4 superblocks with
+ * at least V2 directories.
  */
 bool
 xfs_sb_good_version(
@@ -86,16 +87,16 @@ xfs_sb_good_version(
 	if (xfs_sb_is_v5(sbp))
 		return xfs_sb_validate_v5_features(sbp);
 
+	/* versions prior to v4 are not supported */
+	if (XFS_SB_VERSION_NUM(sbp) != XFS_SB_VERSION_4)
+		return false;
+
 	/* We must not have any unknown v4 feature bits set */
 	if ((sbp->sb_versionnum & ~XFS_SB_VERSION_OKBITS) ||
 	    ((sbp->sb_versionnum & XFS_SB_VERSION_MOREBITSBIT) &&
 	     (sbp->sb_features2 & ~XFS_SB_VERSION2_OKBITS)))
 		return false;
 
-	/* versions prior to v4 are not supported */
-	if (XFS_SB_VERSION_NUM(sbp) < XFS_SB_VERSION_4)
-		return false;
-
 	/* V4 filesystems need v2 directories and unwritten extents */
 	if (!(sbp->sb_versionnum & XFS_SB_VERSION_DIRV2BIT))
 		return false;
Signature · 1 line
2.39.2
Reviewed-by on v1 2/2
#5 lore raw

Re: [PATCH 2/2] xfs: don't consider future format versions valid

Quoted 7 lines · Dave Chinner

From: Dave Chinner <[email protected]>

In commit fe08cc504448 we reworked the valid superblock version checks. If it is a V5 filesystem, it is always valid, then we checked if the version was less than V4 (reject) and then checked feature fields in the V4 flags to determine if it was valid.

Quoted 7 lines

What we missed was that if the version is not V4 at this point, we shoudl reject the fs. i.e. the check current treats V6+ filesystems as if it was a v4 filesystem. Fix this.

Fixes fe08cc504448 ("xfs: open code sb verifier feature checks")

Ugh, old code...

--D

Quoted 42 lines
---
 fs/xfs/libxfs/xfs_sb.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
fs/xfs/libxfs/xfs_sb.c +6 -5
index 99cc03a298e2..ba0f17bc1dc0 100644
@@ -72,7 +72,8 @@ xfs_sb_validate_v5_features(
 }
 
 /*
- * We support all XFS versions newer than a v4 superblock with V2 directories.
+ * We current support XFS v5 formats with known features and v4 superblocks with
+ * at least V2 directories.
  */
 bool
 xfs_sb_good_version(
@@ -86,16 +87,16 @@ xfs_sb_good_version(
 	if (xfs_sb_is_v5(sbp))
 		return xfs_sb_validate_v5_features(sbp);
 
+	/* versions prior to v4 are not supported */
+	if (XFS_SB_VERSION_NUM(sbp) != XFS_SB_VERSION_4)
+		return false;
+
 	/* We must not have any unknown v4 feature bits set */
 	if ((sbp->sb_versionnum & ~XFS_SB_VERSION_OKBITS) ||
 	    ((sbp->sb_versionnum & XFS_SB_VERSION_MOREBITSBIT) &&
 	     (sbp->sb_features2 & ~XFS_SB_VERSION2_OKBITS)))
 		return false;
 
-	/* versions prior to v4 are not supported */
-	if (XFS_SB_VERSION_NUM(sbp) < XFS_SB_VERSION_4)
-		return false;
-
 	/* V4 filesystems need v2 directories and unwritten extents */
 	if (!(sbp->sb_versionnum & XFS_SB_VERSION_DIRV2BIT))
 		return false;
Signature · 1 line
2.39.2
#6 lore raw

Re: [PATCH 2/2] xfs: don't consider future format versions valid

In reply to Dave Chinner

fs/xfs/libxfs/xfs_sb.c xfs_sb_good_version( · line 92

Quoted 7 lines
fs/xfs/libxfs/xfs_sb.c +3 -0
@@ -86,16 +87,16 @@ xfs_sb_good_version(
 	if (xfs_sb_is_v5(sbp))
 		return xfs_sb_validate_v5_features(sbp);
 
+	/* versions prior to v4 are not supported */
+	if (XFS_SB_VERSION_NUM(sbp) != XFS_SB_VERSION_4)
+		return false;

The comment is a bit confusing now. But maybe the v4 checks should move into a xfs_sb_validate_v4_features helper anyway, which would lead to a quite nice flow here:

	if (xfs_sb_is_v5(sbp))
	 	return xfs_sb_validate_v5_features(sbp);
	if (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4)
	 	return xfs_sb_validate_v4_features(sbp);
	return false;
#7 lore raw

Re: [PATCH 2/2] xfs: don't consider future format versions valid

Quoted 12 lines · Christoph Hellwig

fs/xfs/libxfs/xfs_sb.c xfs_sb_good_version( · line 92

Quoted 7 lines
fs/xfs/libxfs/xfs_sb.c +3 -0
@@ -86,16 +87,16 @@ xfs_sb_good_version(
 	if (xfs_sb_is_v5(sbp))
 		return xfs_sb_validate_v5_features(sbp);
 
+	/* versions prior to v4 are not supported */
+	if (XFS_SB_VERSION_NUM(sbp) != XFS_SB_VERSION_4)
+		return false;

The comment is a bit confusing now. But maybe the v4 checks should move into a xfs_sb_validate_v4_features helper anyway, which would lead to a quite nice flow here:

Quoted 5 lines
	if (xfs_sb_is_v5(sbp))
	 	return xfs_sb_validate_v5_features(sbp);
	if (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4)
	 	return xfs_sb_validate_v4_features(sbp);
	return false;

Sure. Care to send a patch that does that cleanup?

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]