]> git.baikalelectronics.ru Git - kernel.git/commit
tty: Fix ->pgrp locking in tiocspgrp()
authorJann Horn <jannh@google.com>
Thu, 3 Dec 2020 01:25:04 +0000 (02:25 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 4 Dec 2020 16:38:48 +0000 (17:38 +0100)
commit0f6548ee5cca24fc709f92c318bf1060eda1ae6c
treeb30e76730582ec6960a35741dea3023040afbaf0
parent27d6e1d4ad8f79c1da44b64611df2b59be6180e2
tty: Fix ->pgrp locking in tiocspgrp()

tiocspgrp() takes two tty_struct pointers: One to the tty that userspace
passed to ioctl() (`tty`) and one to the TTY being changed (`real_tty`).
These pointers are different when ioctl() is called with a master fd.

To properly lock real_tty->pgrp, we must take real_tty->ctrl_lock.

This bug makes it possible for racing ioctl(TIOCSPGRP, ...) calls on
both sides of a PTY pair to corrupt the refcount of `struct pid`,
leading to use-after-free errors.

Fixes: c3e47648229e ("redo locking of tty->pgrp")
CC: stable@kernel.org
Signed-off-by: Jann Horn <jannh@google.com>
Reviewed-by: Jiri Slaby <jirislaby@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/tty_jobctrl.c