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

1ac2e0
From 1fab7a4d22151968645c995bc62580f40ae566ce Mon Sep 17 00:00:00 2001
1ac2e0
From: Julien Thierry <jthierry@redhat.com>
1ac2e0
Date: Fri, 2 Oct 2020 15:10:31 +0100
1ac2e0
Subject: [RHEL8.2 KPATCH] [fs] xfs: fix boundary test in xfs_attr_shortform_verify
1ac2e0
1ac2e0
Kernels:
1ac2e0
4.18.0-193.el8
1ac2e0
4.18.0-193.1.2.el8_2
1ac2e0
4.18.0-193.6.3.el8_2
1ac2e0
4.18.0-193.13.2.el8_2
1ac2e0
4.18.0-193.14.3.el8_2
1ac2e0
4.18.0-193.19.1.el8_2
1ac2e0
1ac2e0
Changes since last build:
1ac2e0
arches: x86_64 ppc64le
1ac2e0
xfs_attr_leaf.o: changed function: xfs_attr_shortform_verify
1ac2e0
---------------------------
1ac2e0
1ac2e0
Modifications:
1ac2e0
None
1ac2e0
1ac2e0
Testing: tried the commands in the commit message before and after the
1ac2e0
kpatch-patch. Without the kpatch-patch, the filesystem dies.
1ac2e0
1ac2e0
commit def0a18dc3b157ec347f018c1b367d8e4825dfca
1ac2e0
Author: Eric Sandeen <sandeen@redhat.com>
1ac2e0
Date:   Thu Sep 10 16:10:27 2020 -0300
1ac2e0
1ac2e0
    [fs] xfs: fix boundary test in xfs_attr_shortform_verify
1ac2e0
1ac2e0
    Message-id: <5f3f90ef-7bec-6c66-8567-a2eb0a71a63c@redhat.com>
1ac2e0
    Patchwork-id: 326142
1ac2e0
    Patchwork-instance: patchwork
1ac2e0
    O-Subject: [PATCH RHEL8.3] xfs: fix boundary test in xfs_attr_shortform_verify
1ac2e0
    Bugzilla: 1875316
1ac2e0
    Z-Bugzilla: 1881085
1ac2e0
    CVE: CVE-2020-14385
1ac2e0
    RH-Acked-by: Brian Foster <bfoster@redhat.com>
1ac2e0
    RH-Acked-by: Vladis Dronov <vdronov@redhat.com>
1ac2e0
1ac2e0
    Bugzilla: 1875316
1ac2e0
    Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
1ac2e0
    Build Info: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=31249120
1ac2e0
    Tested: With simple reproducer in commit + xfstests
1ac2e0
    CVE: CVE-2020-14385
1ac2e0
1ac2e0
    The boundary test for the fixed-offset parts of xfs_attr_sf_entry in
1ac2e0
    xfs_attr_shortform_verify is off by one, because the variable array
1ac2e0
    at the end is defined as nameval[1] not nameval[].
1ac2e0
    Hence we need to subtract 1 from the calculation.
1ac2e0
1ac2e0
    This can be shown by:
1ac2e0
1ac2e0
    # touch file
1ac2e0
    # setfattr -n root.a file
1ac2e0
1ac2e0
    and verifications will fail when it's written to disk.
1ac2e0
1ac2e0
    This only matters for a last attribute which has a single-byte name
1ac2e0
    and no value, otherwise the combination of namelen & valuelen will
1ac2e0
    push endp further out and this test won't fail.
1ac2e0
1ac2e0
    Fixes: 1e1bbd8e7ee06 ("xfs: create structure verifier function for shortform xattrs")
1ac2e0
    Signed-off-by: Eric Sandeen <sandeen@redhat.com>
1ac2e0
    Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
1ac2e0
    Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
1ac2e0
    Reviewed-by: Christoph Hellwig <hch@lst.de>
1ac2e0
    (cherry picked from commit f4020438fab05364018c91f7e02ebdd192085933)
1ac2e0
    Signed-off-by: Eric Sandeen <sandeen@redhat.com>
1ac2e0
    Signed-off-by: Bruno Meneguele <bmeneg@redhat.com>
1ac2e0
1ac2e0
Signed-off-by: Julien Thierry <jthierry@redhat.com>
1ac2e0
---
1ac2e0
 fs/xfs/libxfs/xfs_attr_leaf.c | 4 +++-
1ac2e0
 1 file changed, 3 insertions(+), 1 deletion(-)
1ac2e0
1ac2e0
diff --git a/fs/xfs/libxfs/xfs_attr_leaf.c b/fs/xfs/libxfs/xfs_attr_leaf.c
1ac2e0
index cbcc400f7634..7dbca5a14a90 100644
1ac2e0
--- a/fs/xfs/libxfs/xfs_attr_leaf.c
1ac2e0
+++ b/fs/xfs/libxfs/xfs_attr_leaf.c
1ac2e0
@@ -949,8 +949,10 @@ xfs_attr_shortform_verify(
1ac2e0
 		 * struct xfs_attr_sf_entry has a variable length.
1ac2e0
 		 * Check the fixed-offset parts of the structure are
1ac2e0
 		 * within the data buffer.
1ac2e0
+		 * xfs_attr_sf_entry is defined with a 1-byte variable
1ac2e0
+		 * array at the end, so we must subtract that off.
1ac2e0
 		 */
1ac2e0
-		if (((char *)sfep + sizeof(*sfep)) >= endp)
1ac2e0
+		if (((char *)sfep + sizeof(*sfep) - 1) >= endp)
1ac2e0
 			return __this_address;
1ac2e0
1ac2e0
 		/* Don't allow names with known bad length. */
1ac2e0
--
1ac2e0
2.25.4