From: "Darrick J. Wong" <djwong@kernel.org>
To: Miao Zhao <muel@nova.gal>
Cc: linux-xfs@vger.kernel.org, cem@kernel.org, bfoster@redhat.com,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH xfs] xfs: validate remote attr value length in the leaf verifier
Date: Tue, 28 Jul 2026 08:11:16 -0700 [thread overview]
Message-ID: <20260728151116.GL2901224@frogsfrogsfrogs> (raw)
In-Reply-To: <20260728062451.1296908-1-muel@nova.gal>
On Tue, Jul 28, 2026 at 06:24:51AM +0000, Miao Zhao wrote:
> xfs_attr3_leaf_verify_entry() checks a remote attr entry's namelen and
> valueblk but never its valuelen. A crafted image can set valuelen to a
> value with the high bit set; xfs_attr3_leaf_getvalue() then stores it
> in the signed int args->rmtvaluelen, where it goes negative. The
> negative length bypasses the -ERANGE size check in xfs_attr_copy_value()
> because the comparison is signed, and xfs_attr_rmtval_get() then
> reinterprets it as a huge unsigned value, driving the memcpy loop in
> xfs_attr_rmtval_copyout() past the end of the getxattr(2) result buffer
> with image-controlled data (up to ~64KB on v5, where the remote block
> header verifier caps rm_offset + rm_bytes at XFS_XATTR_SIZE_MAX;
> unbounded on v4, where remote blocks carry no header at all).
>
> Any unprivileged user with read access to the file can trigger this
> with getxattr(2) once a crafted image is mounted, e.g. by a privileged
> auto-mount daemon:
>
> BUG: KASAN: slab-out-of-bounds in xfs_attr_rmtval_copyout
> Write of size 4040 at addr 0000000061bf4ee0 by task xattr_tool/37
> CPU: 0 UID: 65534 PID: 37 Comm: xattr_tool Not tainted 7.2.0-rc5 #1
> Call Trace:
> memcpy
> xfs_attr_rmtval_copyout
> xfs_attr_rmtval_get
> xfs_attr_copy_value
> xfs_attr3_leaf_getvalue
> xfs_attr_node_get
> xfs_attr_get
> xfs_xattr_get
> vfs_getxattr
> sys_getxattr
>
> The same unchecked valuelen is consumed on the INCOMPLETE sweep path
> (xfs_attr_inactive.c) to size stale remote blocks, so validate it for
> all remote entries: reject valuelen larger than XFS_XATTR_SIZE_MAX,
> and reject a zero valuelen on complete entries (a value is only stored
> remotely when it is too large for the local format, so zero is never
> valid there; INCOMPLETE entries legitimately carry a zeroed valuelen
> until the operation completes).
>
> Fixes: c84760659dcf ("xfs: check attribute leaf block structure")
> Cc: stable@vger.kernel.org
> Signed-off-by: Miao Zhao <muel@nova.gal>
Isn't this a duplicate of
https://lore.kernel.org/linux-xfs/20260707190038.3811440-3-qwe.aldo@gmail.com/#t
?
--D
> ---
> fs/xfs/libxfs/xfs_attr_leaf.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/fs/xfs/libxfs/xfs_attr_leaf.c b/fs/xfs/libxfs/xfs_attr_leaf.c
> index 86c5c09a5db4..b8ae25be639a 100644
> --- a/fs/xfs/libxfs/xfs_attr_leaf.c
> +++ b/fs/xfs/libxfs/xfs_attr_leaf.c
> @@ -336,8 +336,11 @@ xfs_attr3_leaf_verify_entry(
> name_end = (char *)rentry + namesize;
> if (rentry->namelen == 0)
> return __this_address;
> + if (be32_to_cpu(rentry->valuelen) > XFS_XATTR_SIZE_MAX)
> + return __this_address;
> if (!(ent->flags & XFS_ATTR_INCOMPLETE) &&
> - rentry->valueblk == 0)
> + (rentry->valueblk == 0 ||
> + be32_to_cpu(rentry->valuelen) == 0))
> return __this_address;
> }
>
> --
> 2.34.1
>
>
next prev parent reply other threads:[~2026-07-28 15:11 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-28 6:24 Miao Zhao
2026-07-28 15:11 ` Darrick J. Wong [this message]
2026-07-29 6:58 ` MuElnova
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260728151116.GL2901224@frogsfrogsfrogs \
--to=djwong@kernel.org \
--cc=bfoster@redhat.com \
--cc=cem@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=muel@nova.gal \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®