Blame SOURCES/fs-xfs-fix-boundary-test-in-xfs_attr_shortform_verify.patch

a15850
From 4801d9a446569eb73191c8cb3b769aadcd3f0994 Mon Sep 17 00:00:00 2001
a15850
From: Julien Thierry <jthierry@redhat.com>
a15850
Date: Fri, 30 Oct 2020 09:00:20 +0000
a15850
Subject: [PATCH] [fs] xfs: fix boundary test in xfs_attr_shortform_verify
a15850
a15850
Kernels:
a15850
3.10.0-1160.el7
a15850
3.10.0-1160.2.1.el7
a15850
3.10.0-1160.2.2.el7
a15850
3.10.0-1160.6.1.el7
a15850
a15850
Changes since last build:
a15850
arches: x86_64 ppc64le
a15850
xfs_attr_leaf.o: changed function: xfs_attr_shortform_verify
a15850
---------------------------
a15850
a15850
Modifications:
a15850
None
a15850
a15850
Testing: tried the commands in the commit message before and after the
a15850
kpatch-patch. Without the kpatch-patch, the filesystem dies.
a15850
a15850
commit b2f2f4aef9d49b0b9fd349f0376f5ffe735e5823
a15850
Author: Eric Sandeen <sandeen@redhat.com>
a15850
Date:   Wed Sep 9 22:17:43 2020 -0400
a15850
a15850
    [fs] xfs: fix boundary test in xfs_attr_shortform_verify
a15850
a15850
    Message-id: <98c52b4e-9e63-55e1-5e8e-4f8d193b3762@redhat.com>
a15850
    Patchwork-id: 326026
a15850
    Patchwork-instance: patchwork
a15850
    O-Subject: [PATCH RHEL7.9.z] xfs: fix boundary test in xfs_attr_shortform_verify
a15850
    Bugzilla: 1875317
a15850
    CVE: CVE-2020-14385
a15850
    RH-Acked-by: Carlos Maiolino <cmaiolino@redhat.com>
a15850
    RH-Acked-by: Brian Foster <bfoster@redhat.com>
a15850
a15850
    Bugzilla: 1875317
a15850
    Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
a15850
    Build Info: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=31247080
a15850
    Tested: With simple reproducer in commit + xfstests
a15850
    CVE: CVE-2020-14385
a15850
a15850
    The boundary test for the fixed-offset parts of xfs_attr_sf_entry in
a15850
    xfs_attr_shortform_verify is off by one, because the variable array
a15850
    at the end is defined as nameval[1] not nameval[].
a15850
    Hence we need to subtract 1 from the calculation.
a15850
a15850
    This can be shown by:
a15850
a15850
    # touch file
a15850
    # setfattr -n root.a file
a15850
a15850
    and verifications will fail when it's written to disk.
a15850
a15850
    This only matters for a last attribute which has a single-byte name
a15850
    and no value, otherwise the combination of namelen & valuelen will
a15850
    push endp further out and this test won't fail.
a15850
a15850
    Fixes: 1e1bbd8e7ee06 ("xfs: create structure verifier function for shortform xattrs")
a15850
    Signed-off-by: Eric Sandeen <sandeen@redhat.com>
a15850
    Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
a15850
    Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
a15850
    Reviewed-by: Christoph Hellwig <hch@lst.de>
a15850
    (cherry picked from commit f4020438fab05364018c91f7e02ebdd192085933)
a15850
    Signed-off-by: Eric Sandeen <sandeen@redhat.com>
a15850
    Signed-off-by: Augusto Caringi <acaringi@redhat.com>
a15850
a15850
Signed-off-by: Julien Thierry <jthierry@redhat.com>
a15850
---
a15850
 fs/xfs/libxfs/xfs_attr_leaf.c | 4 +++-
a15850
 1 file changed, 3 insertions(+), 1 deletion(-)
a15850
a15850
diff --git a/fs/xfs/libxfs/xfs_attr_leaf.c b/fs/xfs/libxfs/xfs_attr_leaf.c
a15850
index 2c892846929..1d2bedd4c1a 100644
a15850
--- a/fs/xfs/libxfs/xfs_attr_leaf.c
a15850
+++ b/fs/xfs/libxfs/xfs_attr_leaf.c
a15850
@@ -923,8 +923,10 @@ xfs_attr_shortform_verify(
a15850
 		 * struct xfs_attr_sf_entry has a variable length.
a15850
 		 * Check the fixed-offset parts of the structure are
a15850
 		 * within the data buffer.
a15850
+		 * xfs_attr_sf_entry is defined with a 1-byte variable
a15850
+		 * array at the end, so we must subtract that off.
a15850
 		 */
a15850
-		if (((char *)sfep + sizeof(*sfep)) >= endp)
a15850
+		if (((char *)sfep + sizeof(*sfep) - 1) >= endp)
a15850
 			return __this_address;
a15850
 
a15850
 		/* Don't allow names with known bad length. */
a15850
-- 
a15850
2.25.4
a15850