Blame SOURCES/CVE-2020-0466.patch

06f91a
From c17b58ebffbfa862b3f1815e208db340bd1664eb Mon Sep 17 00:00:00 2001
06f91a
From: Yannick Cote <ycote@redhat.com>
06f91a
Date: Tue, 1 Feb 2022 14:14:41 -0500
06f91a
Subject: [KPATCH CVE-2020-0466] epoll: kpatch fixes for CVE-2020-0466
06f91a
06f91a
Kernels:
06f91a
3.10.0-1160.15.2.el7
06f91a
3.10.0-1160.21.1.el7
06f91a
3.10.0-1160.24.1.el7
06f91a
3.10.0-1160.25.1.el7
06f91a
3.10.0-1160.31.1.el7
06f91a
3.10.0-1160.36.2.el7
06f91a
3.10.0-1160.41.1.el7
06f91a
3.10.0-1160.42.2.el7
06f91a
3.10.0-1160.45.1.el7
06f91a
3.10.0-1160.49.1.el7
06f91a
3.10.0-1160.53.1.el7
06f91a
06f91a
Changes since last build:
06f91a
[x86_64]:
06f91a
eventpoll.o: changed function: SyS_epoll_ctl
06f91a
eventpoll.o: changed function: clear_tfile_check_list
06f91a
eventpoll.o: changed function: ep_loop_check_proc
06f91a
06f91a
[ppc64le]:
06f91a
eventpoll.o: changed function: SyS_epoll_ctl
06f91a
eventpoll.o: changed function: ep_loop_check_proc
06f91a
06f91a
---------------------------
06f91a
06f91a
Kpatch-MR: https://gitlab.com/redhat/prdsc/rhel/src/kpatch/rhel-7/-/merge_requests/22
06f91a
Approved-by: Artem Savkov (@artem.savkov)
06f91a
Kernels:
06f91a
3.10.0-1160.21.1.el7
06f91a
3.10.0-1160.24.1.el7
06f91a
3.10.0-1160.25.1.el7
06f91a
3.10.0-1160.31.1.el7
06f91a
3.10.0-1160.36.2.el7
06f91a
3.10.0-1160.41.1.el7
06f91a
3.10.0-1160.42.2.el7
06f91a
3.10.0-1160.45.1.el7
06f91a
3.10.0-1160.49.1.el7
06f91a
3.10.0-1160.53.1.el7
06f91a
06f91a
Modifications: none
06f91a
06f91a
commit f771ed0537c55c506dc846cb8f3da60f6383a2b3
06f91a
Author: Carlos Maiolino <cmaiolino@redhat.com>
06f91a
Date:   Sat Dec 18 09:23:31 2021 +0100
06f91a
06f91a
    epoll: Keep a reference on files added to the check list
06f91a
06f91a
    Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2042760
06f91a
    Tested: Sanity check only
06f91a
    CVE: CVE-2020-0466
06f91a
06f91a
    Conflicts:
06f91a
            - RHEL7 has no support for non-blocking do_epoll_ctl(), so the
06f91a
              original patch got this part stripped.
06f91a
06f91a
    When adding a new fd to an epoll, and that this new fd is an
06f91a
    epoll fd itself, we recursively scan the fds attached to it
06f91a
    to detect cycles, and add non-epool files to a "check list"
06f91a
    that gets subsequently parsed.
06f91a
06f91a
    However, this check list isn't completely safe when deletions
06f91a
    can happen concurrently. To sidestep the issue, make sure that
06f91a
    a struct file placed on the check list sees its f_count increased,
06f91a
    ensuring that a concurrent deletion won't result in the file
06f91a
    disapearing from under our feet.
06f91a
06f91a
    Cc: stable@vger.kernel.org
06f91a
    Signed-off-by: Marc Zyngier <maz@kernel.org>
06f91a
    Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
06f91a
    (cherry picked from commit a9ed4a6560b8562b7e2e2bed9527e88001f7b682)
06f91a
06f91a
    Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
06f91a
06f91a
commit 0875a380011a7ff7f4504b72890c29fec420d1cd
06f91a
Author: Carlos Maiolino <cmaiolino@redhat.com>
06f91a
Date:   Sat Dec 18 09:23:47 2021 +0100
06f91a
06f91a
    fix regression in "epoll: Keep a reference on files added to the check list"
06f91a
06f91a
    Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2042760
06f91a
    Tested: Sanity check only
06f91a
    CVE: CVE-2020-0466
06f91a
06f91a
    epoll_loop_check_proc() can run into a file already committed to destruction;
06f91a
    we can't grab a reference on those and don't need to add them to the set for
06f91a
    reverse path check anyway.
06f91a
06f91a
    Tested-by: Marc Zyngier <maz@kernel.org>
06f91a
    Fixes: a9ed4a6560b8 ("epoll: Keep a reference on files added to the check list")
06f91a
    Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
06f91a
    (cherry picked from commit 77f4689de17c0887775bb77896f4cc11a39bf848)
06f91a
06f91a
    Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
06f91a
06f91a
Signed-off-by: Yannick Cote <ycote@redhat.com>
06f91a
---
06f91a
 fs/eventpoll.c | 13 +++++++++----
06f91a
 1 file changed, 9 insertions(+), 4 deletions(-)
06f91a
06f91a
diff --git a/fs/eventpoll.c b/fs/eventpoll.c
06f91a
index 6731b99a481f..ca0eb701eeb4 100644
06f91a
--- a/fs/eventpoll.c
06f91a
+++ b/fs/eventpoll.c
06f91a
@@ -1750,9 +1750,11 @@ static int ep_loop_check_proc(void *priv, void *cookie, int call_nests)
06f91a
 			 * not already there, and calling reverse_path_check()
06f91a
 			 * during ep_insert().
06f91a
 			 */
06f91a
-			if (list_empty(&epi->ffd.file->f_tfile_llink))
06f91a
-				list_add(&epi->ffd.file->f_tfile_llink,
06f91a
-					 &tfile_check_list);
06f91a
+			if (list_empty(&epi->ffd.file->f_tfile_llink)) {
06f91a
+				if (get_file_rcu(epi->ffd.file))
06f91a
+					list_add(&epi->ffd.file->f_tfile_llink,
06f91a
+						 &tfile_check_list);
06f91a
+			}
06f91a
 		}
06f91a
 	}
06f91a
 	mutex_unlock(&ep->mtx);
06f91a
@@ -1796,6 +1798,7 @@ static void clear_tfile_check_list(void)
06f91a
 		file = list_first_entry(&tfile_check_list, struct file,
06f91a
 					f_tfile_llink);
06f91a
 		list_del_init(&file->f_tfile_llink);
06f91a
+		fput(file);
06f91a
 	}
06f91a
 	INIT_LIST_HEAD(&tfile_check_list);
06f91a
 }
06f91a
@@ -1951,9 +1954,11 @@ SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd,
06f91a
 					clear_tfile_check_list();
06f91a
 					goto error_tgt_fput;
06f91a
 				}
06f91a
-			} else
06f91a
+			} else {
06f91a
+				get_file(tf.file);
06f91a
 				list_add(&tf.file->f_tfile_llink,
06f91a
 							&tfile_check_list);
06f91a
+			}
06f91a
 			mutex_lock_nested(&ep->mtx, 0);
06f91a
 			if (is_file_epoll(tf.file)) {
06f91a
 				tep = tf.file->private_data;
06f91a
-- 
06f91a
2.26.3
06f91a
06f91a