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

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