Blame SOURCES/CVE-2021-33909.patch

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