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

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