Skip to contentSkip to conversation

xfs: fix a UAF problem in xattr repair

PATCH In review Darrick J. Wong 2 participants 3 messages Dec 4, 2025 – Dec 5, 2025 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs: fix a UAF problem in xattr repair

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

The xchk_setup_xattr_buf function can allocate a new value buffer, which means that any reference to ab->value before the call could become a dangling pointer. Fix this by moving an assignment to after the buffer setup.

Cc <[email protected]> # v6.10
Fixes e47dcf113ae348 ("xfs: repair extended attributes")
---
 fs/xfs/scrub/attr_repair.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/scrub/attr_repair.c +1 -1
index c7eb94069cafcd..09d63aa10314b0 100644
@@ -333,7 +333,6 @@ xrep_xattr_salvage_remote_attr(
 		.attr_filter		= ent->flags & XFS_ATTR_NSP_ONDISK_MASK,
 		.namelen		= rentry->namelen,
 		.name			= rentry->name,
-		.value			= ab->value,
 		.valuelen		= be32_to_cpu(rentry->valuelen),
 	};
 	unsigned int			namesize;
@@ -363,6 +362,7 @@ xrep_xattr_salvage_remote_attr(
 		error = -EDEADLOCK;
 	if (error)
 		return error;
+	args.value = ab->value;
 
 	/* Look up the remote value and stash it for reconstruction. */
 	error = xfs_attr3_leaf_getvalue(leaf_bp, &args);
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Darrick J. Wong

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

The xchk_setup_xattr_buf function can allocate a new value buffer, which means that any reference to ab->value before the call could become a dangling pointer. Fix this by moving an assignment to after the buffer setup.

Looks good:

Do you have a test case for this?

#2 lore raw
Quoted 8 lines · Christoph Hellwig
Quoted 6 lines · Darrick J. Wong

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

The xchk_setup_xattr_buf function can allocate a new value buffer, which means that any reference to ab->value before the call could become a dangling pointer. Fix this by moving an assignment to after the buffer setup.

Quoted 5 lines

Looks good:

Do you have a test case for this?

Not yet, but working on it. I'm working on a corruption problem I occasionally see in the xattr leaf freemap code, so I think the trick is that you have to generate a leaf block with a corruption that will cause the scrubber to exit early having called xchk_*_set_corrupt, and then a remote xattr with a value larger than xfs_attr_leaf_entsize_local_max.

Obviously this is easy to reproduce after I added a verifier check for corrupt freemap data, but for older kernels I'd need to inject some sort of corruption. Probably twiddling the crc or something would suffice, but ATM I'm a little absorbed in sorting out the freemap code and stamping out the bugs.

--D