Blame SOURCES/CVE-2021-33909.patch

983f35
From: Joe Lawrence <joe.lawrence@redhat.com>
983f35
Date: Tue,  6 Jul 2021 13:18:44 -0400
983f35
Subject: [kernel team] [EMBARGOED KPATCH 7.9] seq_file: kpatch fix for
983f35
	CVE-2021-33909
983f35
983f35
Kernels:
983f35
3.10.0-1160.el7
983f35
3.10.0-1160.2.1.el7
983f35
3.10.0-1160.2.2.el7
983f35
3.10.0-1160.6.1.el7
983f35
3.10.0-1160.11.1.el7
983f35
3.10.0-1160.15.2.el7
983f35
3.10.0-1160.21.1.el7
983f35
3.10.0-1160.24.1.el7
983f35
3.10.0-1160.25.1.el7
983f35
3.10.0-1160.31.1.el7
983f35
983f35
Changes since last build:
983f35
arches: x86_64 ppc64le
983f35
seq_file.o: changed function: seq_read
983f35
seq_file.o: changed function: single_open_size
983f35
seq_file.o: changed function: traverse
983f35
---------------------------
983f35
983f35
Kernels:
983f35
3.10.0-1160.el7
983f35
3.10.0-1160.2.1.el7
983f35
3.10.0-1160.2.2.el7
983f35
3.10.0-1160.6.1.el7
983f35
3.10.0-1160.11.1.el7
983f35
3.10.0-1160.15.2.el7
983f35
3.10.0-1160.21.1.el7
983f35
3.10.0-1160.24.1.el7
983f35
3.10.0-1160.25.1.el7
983f35
3.10.0-1160.31.1.el7
983f35
983f35
Modifications:
983f35
- inline PAGE_CACHE_SHIFT rather than including linux/pagemap.h and
983f35
  fighting kABI fallout (and potentially more inadvertent changes)
983f35
983f35
commit 1236d5dd5b9f13ccbb44979a5652a4b137b968a4
983f35
Author: Ian Kent <ikent@redhat.com>
983f35
Date:   Thu Jul 1 09:13:59 2021 +0800
983f35
983f35
    seq_file: Disallow extremely large seq buffer allocations
983f35
983f35
    Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1975251
983f35
983f35
    Brew build: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=37832573
983f35
983f35
    Testing: The patch has been tested by Qualys and it has been
983f35
             confirmed the patch fixes the problem.
983f35
983f35
    Upstream status: RHEL only (CVE-2021-33909)
983f35
983f35
    Conflicts: include/fs.h uses PAGE_CACHE_SHIFT in the definition of
983f35
      MAX_RW_COUNT which isn't defined in fs/seq_file.c and including
983f35
      linux/pagemap.h breaks kabi (since it makes kabi aware of additional
983f35
      structs) even though there are no changes to any structures. So the
983f35
      include needs to be added and excluded from the kabi calculation.
983f35
983f35
    Author: Eric Sandeen <sandeen@redhat.com>
983f35
983f35
    seq_file: Disallow extremely large seq buffer allocations
983f35
983f35
    There is no reasonable need for a buffer larger than this,
983f35
    and it avoids int overflow pitfalls.
983f35
983f35
    Suggested-by: Al Viro <viro@zeniv.linux.org.uk>
983f35
    Signed-off-by: Eric Sandeen <sandeen@redhat.com>
983f35
983f35
    Signed-off-by: Ian Kent <ikent@redhat.com>
983f35
983f35
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
983f35
Acked-by: Artem Savkov <asavkov@redhat.com>
983f35
Acked-by: Yannick Cote <ycote@redhat.com>
983f35
---
983f35
983f35
Z-MR: https://gitlab.com/redhat/prdsc/rhel/src/kernel-private/rhel-7/-/merge_requests/7
983f35
983f35
KT0 test PASS: https://beaker.engineering.redhat.com/jobs/5525685
983f35
for kpatch-patch-3_10_0-1160-1-7.el7 scratch build:
983f35
https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=37846414
983f35
983f35
 fs/seq_file.c | 23 +++++++++++++++++++++++
983f35
 1 file changed, 23 insertions(+)
983f35
983f35
diff --git a/fs/seq_file.c b/fs/seq_file.c
983f35
index bc7a9ec855aa..daef8f4bdbd0 100644
983f35
--- a/fs/seq_file.c
983f35
+++ b/fs/seq_file.c
983f35
@@ -5,6 +5,26 @@
983f35
  * initial implementation -- AV, Oct 2001.
983f35
  */
983f35
 
983f35
+/* inline linux/pagemap.h :: PAGE_CACHE_MASK and dependency values */
983f35
+
983f35
+/* arch/x86/include/asm/page_types.h */
983f35
+#ifdef __x86_64__
983f35
+# define PAGE_CACHE_MASK	(~((1UL << 12)-1))
983f35
+#endif
983f35
+
983f35
+/* arch/powerpc/include/asm/page.h */
983f35
+#ifdef __powerpc64__
983f35
+# if defined(CONFIG_PPC_256K_PAGES)
983f35
+#  define PAGE_CACHE_MASK	(~((1 << 18) - 1))
983f35
+# elif defined(CONFIG_PPC_64K_PAGES)
983f35
+#  define PAGE_CACHE_MASK	(~((1 << 16) - 1))
983f35
+# elif defined(CONFIG_PPC_16K_PAGES)
983f35
+#  define PAGE_CACHE_MASK	(~((1 << 14) - 1))
983f35
+# else
983f35
+#  define PAGE_CACHE_MASK	(~((1 << 12) - 1))
983f35
+# endif
983f35
+#endif
983f35
+
983f35
 #include <linux/fs.h>
983f35
 #include <linux/export.h>
983f35
 #include <linux/seq_file.h>
983f35
@@ -26,6 +46,9 @@ static void seq_set_overflow(struct seq_file *m)
983f35
 
983f35
 static void *seq_buf_alloc(unsigned long size)
983f35
 {
983f35
+	if (unlikely(size > MAX_RW_COUNT))
983f35
+		return NULL;
983f35
+
983f35
 	return kvmalloc(size, GFP_KERNEL);
983f35
 }
983f35
 
983f35
-- 
983f35
2.26.3
983f35
983f35