xfs: fix a UAF problem in xattr repair
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.
--- fs/xfs/scrub/attr_repair.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/scrub/attr_repair.c +1 -1
@@ -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);
Quoted 6 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
The
xchk_setup_xattr_buffunction can allocate a new value buffer, which means that any reference toab->valuebefore 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?
Quoted 8 lines · Christoph Hellwig
Quoted 6 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
The
xchk_setup_xattr_buffunction can allocate a new value buffer, which means that any reference toab->valuebefore the call could become a dangling pointer. Fix this by moving an assignment to after the buffer setup.
Quoted 5 lines
Looks good:
Reviewed-by Christoph Hellwig <[email protected]>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