From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794585979; b=5FfkqZluQrJmqmkaDqnLUpEG2BAbVLwkufvRQfjYtqysRCAK/7htMDSHxovKAkEuttJg /rTwmcWfAis57rmGpIBwqzZQF1IcHgQ6bi3rg0iOW1y+Os4RZa3SrPgumTcNKvu3U4siy 0cv7q4c9jMzk3VpK+aVzU9jA1RvRLQmPkMAJITQkUzEAVf+ZdAVFd83QvCQB8BF1KN5Xb wi/IBR/psIlwWzLP56D5MII2uO7gzeaz9+DyNSbUDJbQ9CpkN3n04nep9f7prPsYpTbw/ +RGFPTZhXsmiTrW112FeoM+GSPUOtIT1sK+shHjEydDrA5SuSQ9+T2VxxSDwPNQXqNQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794585979; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=+LJJpMrc9FioyauGZLI+wbRSRykNe+EAz/tR2ug/Jbs=; b=JD2K9XmgfmYLqMz71qurjLLo6s674r1Qk81PDkI5w16HqaRBUX7+KsZ8YTzYJPYd/ypW t99ifNT1CWK4lgicTAGIWGdZFQ2B5lUNoE6msIqwfLIbiCBvDbn9XSxtT+Ni57TKcJqEL CASue6XWX3kkYJBgB5BzEthNyq/OPhcifciPy8l2SFflcfIGkglCu/FU37k4GX52+rhDl yI/PAeiUWXpT6o/ncIdE8kZ7Pc9NwmJKoMrjlg/2eTvQ+9lMx5bZ0xxGBBzuWOEFVVh5A PjZLfdxjveexVDlWjfgXosgRZFSJJgOzpFzFXQIBz59W4EFEo++6fjTM/gMEND9nQAg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=Grk0GU83; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9CDA26072323; Fri, 13 Nov 2026 16:06:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=Grk0GU83 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 480E81F000C4; Fri, 13 Nov 2026 16:06:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1794585979; bh=+LJJpMrc9FioyauGZLI+wbRSRykNe+EAz/tR2ug/Jbs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Grk0GU83sch2LEa/Q6N543cjm06mihRmUAdUaOAS46pX3MtcA3z2uslZnpx/6EfTt 8HKWlKlUnmCBSTRwA/szBzvcTxHp9jaLGov0okljYtgxLAPX9zuwk+m+HizuCzFuT7 SsjgwcZVleRaWIvXzom7wm/P7W2u9MouGHrwOdgk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Darrick J. Wong" , Christoph Hellwig , Carlos Maiolino , Sasha Levin Subject: [PATCH 6.18 026/686] xfs: break out xattr entry checks into separate functions Date: Fri, 13 Nov 2026 10:42:39 -0500 Message-ID: <20261113153821.865731831@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261113153820.902362109@linuxfoundation.org> References: <20261113153820.902362109@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Darrick J. Wong [ Upstream commit 9eb04a6d41c7e474d4665118895c3c2d8e5a2741 ] We're going to add more xattr entry checking code in xchk_xattr_entry so break these out into separate functions so that we don't go crazy indenting. There's a slight behavior change here where we skip updating the usedmap if we've decided the xattr structure is corrupt. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Carlos Maiolino Stable-dep-of: 91c41f952490 ("xfs: check for buffer overruns when examining local/remote xattr entries") Signed-off-by: Sasha Levin --- fs/xfs/scrub/attr.c | 90 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 68 insertions(+), 22 deletions(-) diff --git a/fs/xfs/scrub/attr.c b/fs/xfs/scrub/attr.c index 7315d0cb1e2e7..84507c80cf945 100644 --- a/fs/xfs/scrub/attr.c +++ b/fs/xfs/scrub/attr.c @@ -293,6 +293,66 @@ xchk_xattr_set_map( return ret; } +static unsigned int +xchk_xattr_local_entry( + struct xchk_da_btree *ds, + int level, + char *buf_end, + struct xfs_attr_leafblock *leaf, + int idx) +{ + struct xfs_attr_leaf_name_local *lentry = + xfs_attr3_leaf_name_local(leaf, idx); + char *name_end; + unsigned int namesize; + + namesize = xfs_attr_leaf_entsize_local(lentry->namelen, + be16_to_cpu(lentry->valuelen)); + name_end = (char *)lentry + namesize; + if (lentry->namelen == 0) { + xchk_da_set_corrupt(ds, level); + return 0; + } + if (name_end > buf_end) { + xchk_da_set_corrupt(ds, level); + return 0; + } + + return namesize; +} + +static unsigned int +xchk_xattr_remote_entry( + struct xchk_da_btree *ds, + int level, + char *buf_end, + struct xfs_attr_leafblock *leaf, + int idx, + struct xfs_attr_leaf_entry *ent) +{ + struct xfs_attr_leaf_name_remote *rentry = + xfs_attr3_leaf_name_remote(leaf, idx); + char *name_end; + unsigned int namesize; + + namesize = xfs_attr_leaf_entsize_remote(rentry->namelen); + name_end = (char *)rentry + namesize; + if (rentry->namelen == 0) { + xchk_da_set_corrupt(ds, level); + return 0; + } + if (rentry->valueblk == 0 && !(ent->flags & XFS_ATTR_INCOMPLETE)) { + xchk_da_set_corrupt(ds, level); + return 0; + } + if (name_end > buf_end) { + xchk_da_set_corrupt(ds, level); + return 0; + } + + return namesize; +} + /* * Check this leaf entry's relations to everything else. * Returns the number of bytes used for the name/value data. @@ -311,9 +371,6 @@ xchk_xattr_entry( { struct xfs_mount *mp = ds->state->mp; struct xchk_xattr_buf *ab = ds->sc->buf; - char *name_end; - struct xfs_attr_leaf_name_local *lentry; - struct xfs_attr_leaf_name_remote *rentry; unsigned int nameidx; unsigned int namesize; @@ -333,25 +390,14 @@ xchk_xattr_entry( } /* Check the name information. */ - if (ent->flags & XFS_ATTR_LOCAL) { - lentry = xfs_attr3_leaf_name_local(leaf, idx); - namesize = xfs_attr_leaf_entsize_local(lentry->namelen, - be16_to_cpu(lentry->valuelen)); - name_end = (char *)lentry + namesize; - if (lentry->namelen == 0) - xchk_da_set_corrupt(ds, level); - } else { - rentry = xfs_attr3_leaf_name_remote(leaf, idx); - namesize = xfs_attr_leaf_entsize_remote(rentry->namelen); - name_end = (char *)rentry + namesize; - if (rentry->namelen == 0) - xchk_da_set_corrupt(ds, level); - if (rentry->valueblk == 0 && - !(ent->flags & XFS_ATTR_INCOMPLETE)) - xchk_da_set_corrupt(ds, level); - } - if (name_end > buf_end) - xchk_da_set_corrupt(ds, level); + if (ent->flags & XFS_ATTR_LOCAL) + namesize = xchk_xattr_local_entry(ds, level, buf_end, leaf, + idx); + else + namesize = xchk_xattr_remote_entry(ds, level, buf_end, leaf, + idx, ent); + if (!namesize) + return; if (!xchk_xattr_set_map(ds->sc, ab->usedmap, nameidx, namesize)) xchk_da_set_corrupt(ds, level); -- 2.53.0