Skip to contentSkip to conversation

xfs: fixes and clean up for attr item

PATCH Applied Long Li 3 participants 7 messages Mar 20 – Mar 23 XFS filesystem

lore
Share & tools
lore

Long Li

author
#0 lore raw

v3 cover xfs: fixes and clean up for attr item

This patch set fixes and cleans up several minor issues in the attr item.

V2->v3:
- Patch1 is discarded, as Darrick has already fixed it.
- Update the comments and add the reviewed tag

V1->V2:
- Fix ip is not initialized issuse in patch-1
- Add the reproduction script in patch-2.
- Delete only the redundant code, and leave the rest unchanged in patch-3.

Long Li (2):
xfs: fix ri_total validation in xlog_recover_attri_commit_pass2
xfs: remove redundant validation in xlog_recover_attri_commit_pass2

 fs/xfs/xfs_attr_item.c | 50 ++----------------------------------------
 1 file changed, 2 insertions(+), 48 deletions(-)
Signature · 1 line
2.39.2
author
#1 lore raw

PATCH v3 1/2 xfs: fix ri_total validation in xlog_recover_attri_commit_pass2

The ri_total checks for SET/REPLACE operations are hardcoded to 3, but xfs_attri_item_size() only emits a value iovec when value_len > 0, so ri_total is 2 when value_len == 0.

For PPTR_SET/PPTR_REMOVE/PPTR_REPLACE, value_len is validated by xfs_attri_validate() to be exactly sizeof(struct xfs_parent_rec) and is never zero, so their hardcoded checks remain correct.

This problem may cause log recovery failures. The following script can be used to reproduce the problem:

#!/bin/bash
mkfs.xfs -f /dev/sda
mount /dev/sda /mnt/test/
touch /mnt/test/file
for i in {1..200}; do

         attr -s "user.attr_$i" -V "value_$i" /mnt/test/file > /dev/null

done
echo 1 > /sys/fs/xfs/debug/larp
echo 1 > /sys/fs/xfs/sda/errortag/larp
attr -s "user.zero" -V "" /mnt/test/file
echo 0 > /sys/fs/xfs/sda/errortag/larp
umount /mnt/test
mount /dev/sda /mnt/test/ # mount failed

Fix this by deriving the expected count dynamically as "2 + !!value_len" for SET/REPLACE operations.

Cc <[email protected]> # v6.9
Fixes ad206ae50eca ("xfs: check opcode and iovec count match in xlog_recover_attri_commit_pass2")
---
 fs/xfs/xfs_attr_item.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/xfs/xfs_attr_item.c +2 -2
index 354472bf45f1..83d09635b200 100644
@@ -1047,8 +1047,8 @@ xlog_recover_attri_commit_pass2(
 		break;
 	case XFS_ATTRI_OP_FLAGS_SET:
 	case XFS_ATTRI_OP_FLAGS_REPLACE:
-		/* Log item, attr name, attr value */
-		if (item->ri_total != 3) {
+		/* Log item, attr name, optional attr value */
+		if (item->ri_total != 2 + !!attri_formatp->alfi_value_len) {
 			XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
 					     attri_formatp, len);
 			return -EFSCORRUPTED;
Signature · 1 line
2.39.2
Reviewed-by on v3 1/2
#2 lore raw

Re: [PATCH v3 1/2] xfs: fix ri_total validation in xlog_recover_attri_commit_pass2

Quoted 2 lines · Long Li

This problem may cause log recovery failures. The following script can be used to reproduce the problem:

Can you add this to xfstests, please?

Otherwise looks good:

author
#3 lore raw

Re: [PATCH v3 1/2] xfs: fix ri_total validation in xlog_recover_attri_commit_pass2

Quoted 5 lines · Christoph Hellwig
Quoted 2 lines · Long Li

This problem may cause log recovery failures. The following script can be used to reproduce the problem:

Can you add this to xfstests, please?

Okay.

Quoted 6 lines

Otherwise looks good:

Thanks for your review.

Long Li

author
#4 lore raw

PATCH v3 2/2 xfs: remove redundant validation in xlog_recover_attri_commit_pass2

In reply to Long Li

Remove the redundant post-parse validation switch. By the time that block is reached, xfs_attri_validate() has already guaranteed all name lengths are non-zero via xfs_attri_validate_namelen(), and xfs_attri_validate_name_iovec() has already returned -EFSCORRUPTED for NULL names. For the REMOVE case, attr_value and value_len are structurally guaranteed to be NULL/zero because the parsing loop only populates them when value_len != 0. All checks in that switch are therefore dead code.

---
 fs/xfs/xfs_attr_item.c | 46 ------------------------------------------
 1 file changed, 46 deletions(-)
fs/xfs/xfs_attr_item.c +0 -46
index 83d09635b200..82324f42537b 100644
@@ -1132,52 +1132,6 @@ xlog_recover_attri_commit_pass2(
 		return -EFSCORRUPTED;
 	}
 
-	switch (op) {
-	case XFS_ATTRI_OP_FLAGS_REMOVE:
-		/* Regular remove operations operate only on names. */
-		if (attr_value != NULL || value_len != 0) {
-			XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
-					     attri_formatp, len);
-			return -EFSCORRUPTED;
-		}
-		fallthrough;
-	case XFS_ATTRI_OP_FLAGS_PPTR_REMOVE:
-	case XFS_ATTRI_OP_FLAGS_PPTR_SET:
-	case XFS_ATTRI_OP_FLAGS_SET:
-	case XFS_ATTRI_OP_FLAGS_REPLACE:
-		/*
-		 * Regular xattr set/remove/replace operations require a name
-		 * and do not take a newname.  Values are optional for set and
-		 * replace.
-		 *
-		 * Name-value set/remove operations must have a name, do not
-		 * take a newname, and can take a value.
-		 */
-		if (attr_name == NULL || name_len == 0) {
-			XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
-					     attri_formatp, len);
-			return -EFSCORRUPTED;
-		}
-		break;
-	case XFS_ATTRI_OP_FLAGS_PPTR_REPLACE:
-		/*
-		 * Name-value replace operations require the caller to
-		 * specify the old and new names and values explicitly.
-		 * Values are optional.
-		 */
-		if (attr_name == NULL || name_len == 0) {
-			XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
-					     attri_formatp, len);
-			return -EFSCORRUPTED;
-		}
-		if (attr_new_name == NULL || new_name_len == 0) {
-			XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
-					     attri_formatp, len);
-			return -EFSCORRUPTED;
-		}
-		break;
-	}
-
 	/*
 	 * Memory alloc failure will cause replay to abort.  We attach the
 	 * name/value buffer to the recovered incore log item and drop our
Signature · 1 line
2.39.2
Reviewed-by on v3 2/2
#5 lore raw

Re: [PATCH v3 2/2] xfs: remove redundant validation in xlog_recover_attri_commit_pass2

Quoted 8 lines · Long Li

Remove the redundant post-parse validation switch. By the time that block is reached, xfs_attri_validate() has already guaranteed all name lengths are non-zero via xfs_attri_validate_namelen(), and xfs_attri_validate_name_iovec() has already returned -EFSCORRUPTED for NULL names. For the REMOVE case, attr_value and value_len are structurally guaranteed to be NULL/zero because the parsing loop only populates them when value_len != 0. All checks in that switch are therefore dead code.

Looks good:

maintainer Applied
#6 lore raw
In reply to Long Li
Quoted 6 lines · Long Li

This patch set fixes and cleans up several minor issues in the attr item.

V2->v3:
- Patch1 is discarded, as Darrick has already fixed it.
- Update the comments and add the reviewed tag

Quoted 6 lines

V1->V2:
- Fix ip is not initialized issuse in patch-1
- Add the reproduction script in patch-2.
- Delete only the redundant code, and leave the rest unchanged in patch-3.

[...]

Applied to for-next, thanks!

[1/2] xfs: fix ri_total validation in xlog_recover_attri_commit_pass2

      commit: d72f2084e30966097c8eae762e31986a33c3c0ae
[2/2] xfs: remove redundant validation in xlog_recover_attri_commit_pass2
      commit: c6c56ff975f046be25f527231a239e37920aca5e

Best regards,

Signature · 1 line
Carlos Maiolino <[email protected]>