Blame SOURCES/tty-Fix-pgrp-locking-in-tiocspgrp.patch

77e4e1
From 8a9cce994f0c37c1b4dfc313a1b01fb009c55d01 Mon Sep 17 00:00:00 2001
77e4e1
From: Julien Thierry <jthierry@redhat.com>
77e4e1
Date: Thu, 21 Jan 2021 14:41:40 +0100
77e4e1
Subject: [PATCH] [tty] Fix ->pgrp locking in tiocspgrp()
77e4e1
77e4e1
Kernels:
77e4e1
3.10.0-1160.el7
77e4e1
3.10.0-1160.2.1.el7
77e4e1
3.10.0-1160.2.2.el7
77e4e1
3.10.0-1160.6.1.el7
77e4e1
3.10.0-1160.11.1.el7
77e4e1
3.10.0-1160.15.1.el7
77e4e1
77e4e1
Changes since last build:
77e4e1
arches: x86_64 ppc64le
77e4e1
tty_io.o: changed function: tty_ioctl
77e4e1
---------------------------
77e4e1
77e4e1
Modifications:
77e4e1
None
77e4e1
77e4e1
commit ba0ec80fb32a3ca6e15d51ddcb54c1095f04cf2a
77e4e1
Author: Chris von Recklinghausen <crecklin@redhat.com>
77e4e1
Date:   Wed Jan 6 19:26:01 2021 -0500
77e4e1
77e4e1
    [tty] Fix ->pgrp locking in tiocspgrp()
77e4e1
77e4e1
    Message-id: <20210106192601.11675-1-crecklin@redhat.com>
77e4e1
    Patchwork-id: 10200
77e4e1
    Patchwork-instance: patchwork-private
77e4e1
    O-Subject: [kernel team] [RHEL 7.9.Z bz1908193 CVE-2020-29661 PATCH] tty: Fix ->pgrp locking in tiocspgrp()
77e4e1
    Bugzilla: 1908193
77e4e1
    CVE: CVE-2020-29661
77e4e1
    RH-Acked-by: Oleg Nesterov <oleg@redhat.com>
77e4e1
    RH-Acked-by: Waiman Long <longman@redhat.com>
77e4e1
77e4e1
    From: Jann Horn <jannh@google.com>
77e4e1
77e4e1
    Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1908193
77e4e1
    Brew: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=34103731
77e4e1
    CVE: CVE-2020-29661
77e4e1
    Upstream Status: linux
77e4e1
    Tested: CKI https://beaker.engineering.redhat.com/jobs/?jobsearch-0.table=Whiteboard&jobsearch-0.operation=contains&jobsearch-0.value=cki%40gitlab%3A620704
77e4e1
            bug has no reproducer
77e4e1
77e4e1
    Conflicts: tiocspgrp is defined in drivers/tty/tty_io.c in rhel7 so make
77e4e1
                    change there.
77e4e1
            drop changes to drivers/tty/tty_jobctrl.c
77e4e1
77e4e1
    tiocspgrp() takes two tty_struct pointers: One to the tty that userspace
77e4e1
    passed to ioctl() (`tty`) and one to the TTY being changed (`real_tty`).
77e4e1
    These pointers are different when ioctl() is called with a master fd.
77e4e1
77e4e1
    To properly lock real_tty->pgrp, we must take real_tty->ctrl_lock.
77e4e1
77e4e1
    This bug makes it possible for racing ioctl(TIOCSPGRP, ...) calls on
77e4e1
    both sides of a PTY pair to corrupt the refcount of `struct pid`,
77e4e1
    leading to use-after-free errors.
77e4e1
77e4e1
    Fixes: 47f86834bbd4 ("redo locking of tty->pgrp")
77e4e1
    CC: stable@kernel.org
77e4e1
    Signed-off-by: Jann Horn <jannh@google.com>
77e4e1
    Reviewed-by: Jiri Slaby <jirislaby@kernel.org>
77e4e1
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
77e4e1
    (cherry picked from commit 54ffccbf053b5b6ca4f6e45094b942fab92a25fc)
77e4e1
77e4e1
    Conflicts:
77e4e1
            drivers/tty/tty_jobctrl.c
77e4e1
    Signed-off-by: Chris von Recklinghausen <crecklin@redhat.com>
77e4e1
    Signed-off-by: Augusto Caringi <acaringi@redhat.com>
77e4e1
77e4e1
Signed-off-by: Julien Thierry <jthierry@redhat.com>
77e4e1
---
77e4e1
 drivers/tty/tty_io.c | 4 ++--
77e4e1
 1 file changed, 2 insertions(+), 2 deletions(-)
77e4e1
77e4e1
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
77e4e1
index c6e277aae06..713e1ad5c09 100644
77e4e1
--- a/drivers/tty/tty_io.c
77e4e1
+++ b/drivers/tty/tty_io.c
77e4e1
@@ -2542,10 +2542,10 @@ static int tiocspgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t
77e4e1
 	if (session_of_pgrp(pgrp) != task_session(current))
77e4e1
 		goto out_unlock;
77e4e1
 	retval = 0;
77e4e1
-	spin_lock_irqsave(&tty->ctrl_lock, flags);
77e4e1
+	spin_lock_irqsave(&real_tty->ctrl_lock, flags);
77e4e1
 	put_pid(real_tty->pgrp);
77e4e1
 	real_tty->pgrp = get_pid(pgrp);
77e4e1
-	spin_unlock_irqrestore(&tty->ctrl_lock, flags);
77e4e1
+	spin_unlock_irqrestore(&real_tty->ctrl_lock, flags);
77e4e1
 out_unlock:
77e4e1
 	rcu_read_unlock();
77e4e1
 	return retval;
77e4e1
-- 
77e4e1
2.25.4
77e4e1