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

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