mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: Hongling Zeng <zenghongling@kylinos.cn>
Cc: cem@kernel.org, leo.lilong@huawei.com, bfoster@redhat.com,
	linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org,
	zhongling0719@126.com, stable@vger.kernel.org
Subject: Re: [PATCH] xfs: validate attr entry pointer before field access
Date: Tue, 28 Jul 2026 08:12:59 -0700	[thread overview]
Message-ID: <20260728151259.GM2901224@frogsfrogsfrogs> (raw)
In-Reply-To: <20260728074340.84166-1-zenghongling@kylinos.cn>

On Tue, Jul 28, 2026 at 03:43:40PM +0800, Hongling Zeng wrote:
> xfs_attr3_leaf_verify_entry() accesses lentry/rentry fields (namelen,
> valuelen) before checking if the entry pointer itself is within bounds.
> If nameidx is crafted to point near the end of the buffer, these field
> accesses can read out-of-bounds before the bounds check at
> name_end > buf_end is performed.
> 
> Add explicit bounds checks for entry pointers before accessing their
> fields. Use offsetof() to check that the start of the flexible array
> member (nameval/name) is within bounds, which ensures all preceding
> fields are safe to access.
> 
> Fixes: c84760659dcf2 ("xfs: check attribute leaf block structure")
> Cc: <stable@vger.kernel.org>

Cc: <stable@vger.kernel.org> # v5.5

(for automatic backport)

> Signed-off-by: Hongling Zeng <zenghongling@kylinos.cn>

Looks correct to me;
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>

--D

> ---
>  fs/xfs/libxfs/xfs_attr_leaf.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/fs/xfs/libxfs/xfs_attr_leaf.c b/fs/xfs/libxfs/xfs_attr_leaf.c
> index 86c5c09a5db4..b6288395f853 100644
> --- a/fs/xfs/libxfs/xfs_attr_leaf.c
> +++ b/fs/xfs/libxfs/xfs_attr_leaf.c
> @@ -325,6 +325,13 @@ xfs_attr3_leaf_verify_entry(
>  	 */
>  	if (ent->flags & XFS_ATTR_LOCAL) {
>  		lentry = xfs_attr3_leaf_name_local(leaf, idx);
> +
> +		/* Validate lentry pointer is within bounds before field access */
> +		if ((char *)lentry >= buf_end)
> +			return __this_address;
> +		if ((char *)lentry + offsetof(struct xfs_attr_leaf_name_local, nameval) > buf_end)
> +			return __this_address;
> +
>  		namesize = xfs_attr_leaf_entsize_local(lentry->namelen,
>  				be16_to_cpu(lentry->valuelen));
>  		name_end = (char *)lentry + namesize;
> @@ -332,6 +339,13 @@ xfs_attr3_leaf_verify_entry(
>  			return __this_address;
>  	} else {
>  		rentry = xfs_attr3_leaf_name_remote(leaf, idx);
> +
> +		/* Validate rentry pointer is within bounds before field access */
> +		if ((char *)rentry >= buf_end)
> +			return __this_address;
> +		if ((char *)rentry + offsetof(struct xfs_attr_leaf_name_remote, name) > buf_end)
> +			return __this_address;
> +
>  		namesize = xfs_attr_leaf_entsize_remote(rentry->namelen);
>  		name_end = (char *)rentry + namesize;
>  		if (rentry->namelen == 0)
> -- 
> 2.25.1
> 
> 

  reply	other threads:[~2026-07-28 15:13 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-28  7:43 Hongling Zeng
2026-07-28 15:12 ` Darrick J. Wong [this message]
2026-08-10 11:55 ` Carlos Maiolino

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=20260728151259.GM2901224@frogsfrogsfrogs \
    --to=djwong@kernel.org \
    --cc=bfoster@redhat.com \
    --cc=cem@kernel.org \
    --cc=leo.lilong@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=zenghongling@kylinos.cn \
    --cc=zhongling0719@126.com \
    /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®