Skip to content

Commit 54ffccb

Browse files
thejhgregkh
authored andcommitted
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: 47f8683 ("redo locking of tty->pgrp") CC: [email protected] Signed-off-by: Jann Horn <[email protected]> Reviewed-by: Jiri Slaby <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 418baf2 commit 54ffccb

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/tty/tty_jobctrl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,10 +494,10 @@ static int tiocspgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t
494494
if (session_of_pgrp(pgrp) != task_session(current))
495495
goto out_unlock;
496496
retval = 0;
497-
spin_lock_irq(&tty->ctrl_lock);
497+
spin_lock_irq(&real_tty->ctrl_lock);
498498
put_pid(real_tty->pgrp);
499499
real_tty->pgrp = get_pid(pgrp);
500-
spin_unlock_irq(&tty->ctrl_lock);
500+
spin_unlock_irq(&real_tty->ctrl_lock);
501501
out_unlock:
502502
rcu_read_unlock();
503503
return retval;

0 commit comments

Comments
 (0)