]> git.hungrycats.org Git - linux/commitdiff
xfs: reject out-of-range attribute value lengths in xfs_attr_copy_value
authorAldo Ariel Panzardo <qwe.aldo@gmail.com>
Wed, 23 Sep 2026 11:58:22 +0000 (08:58 -0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 6 Nov 2026 17:06:01 +0000 (12:06 -0500)
commit 0643549ffecaeb716c0b75590a9b76dfa5eb35b3 upstream.

xfs_attr_copy_value() takes the value length as a signed int and, for a
remote xattr, is handed args->rmtvaluelen.  That field is filled from the
on-disk __be32 xfs_attr_leaf_name_remote.valuelen in
xfs_attr3_leaf_getvalue(), so a crafted length such as 0x80000000 is
stored into the signed rmtvaluelen as a negative number.

The "buffer too small" guard in xfs_attr_copy_value() is a signed
comparison:

if (args->valuelen < valuelen)
return -ERANGE;

A negative valuelen therefore compares as smaller than the caller's
buffer size, skips the -ERANGE path, and is then used as a copy length,
leading to an out-of-bounds copy of a full remote block into a small
getxattr(2) buffer on a mounted crafted image.

Reject a value length that is negative or larger than the maximum xattr
size before it is used, so a bogus on-disk length can no longer slip
through the value copier.

Fixes: 9df243a1a9e6 ("xfs: consolidate attribute value copying")
Cc: stable@vger.kernel.org
Signed-off-by: Aldo Ariel Panzardo <qwe.aldo@gmail.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/xfs/libxfs/xfs_attr_leaf.c

index dd3923fdcb205707318536061a1aa9403a2a243e..4d58718cd965a15565fdf863c29857563ef75240 100644 (file)
@@ -581,6 +581,17 @@ xfs_attr_copy_value(
        unsigned char           *value,
        int                     valuelen)
 {
+       /*
+        * A value length that is negative or larger than the maximum xattr
+        * size is on-disk corruption.  The remote value length is an on-disk
+        * __be32 stored into the signed args->rmtvaluelen, so a crafted value
+        * such as 0x80000000 becomes negative and would slip past the
+        * "args->valuelen < valuelen" check below and be used as a copy
+        * length.  Reject it before that can happen.
+        */
+       if (valuelen < 0 || valuelen > XFS_XATTR_SIZE_MAX)
+               return -EFSCORRUPTED;
+
        /*
         * Parent pointer lookups require the caller to specify the name and
         * value, so don't copy anything.