tty: fix race in tty_fasync

We need to keep the lock held over the call to __f_setown() to
prevent a PID race.

Thanks to Al Viro for pointing out the problem, and to Travis for
making us look here in the first place.

Cc: Eric W. Biederman <[email protected]>
Cc: Al Viro <[email protected]>
Cc: Alan Cox <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Tavis Ormandy <[email protected]>
Cc: Jeff Dike <[email protected]>
Cc: Julien Tinnes <[email protected]>
Cc: Matt Mackall <[email protected]>
Cc: stable <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
This commit is contained in:
Greg Kroah-Hartman 2009-12-17 07:07:19 -08:00
commit 7036251180

View file

@ -1951,8 +1951,8 @@ static int tty_fasync(int fd, struct file *filp, int on)
pid = task_pid(current);
type = PIDTYPE_PID;
}
spin_unlock_irqrestore(&tty->ctrl_lock, flags);
retval = __f_setown(filp, pid, type, 0);
spin_unlock_irqrestore(&tty->ctrl_lock, flags);
if (retval)
goto out;
} else {