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

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