Commit a8f3a297 authored by Peter Hurley's avatar Peter Hurley Committed by Greg Kroah-Hartman

tty: Fix ioctl(FIOASYNC) on hungup file

A small race window exists which allows signal-driven async i/o to be
enabled for the tty when the file ptr has already been hungup and
signal-driven i/o has been disabled:

CPU 0                                CPU 1
-----                                ------
ioctl_fioasync(on)
  filp->f_op->fasync(on)             __tty_hangup()
    tty_fasync(on)                     tty_lock()
      tty_lock()                       ...
        .                              filp->f_op = &hung_up_tty_fops;
      (waiting)                       __tty_fasync(off)
        .                              tty_unlock()
      /* gets tty lock  */
      /* enables FASYNC */

Check the tty has not been hungup while holding tty_lock.
Signed-off-by: default avatarPeter Hurley <peter@hurleysoftware.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent f557474c
...@@ -2260,9 +2260,10 @@ static int __tty_fasync(int fd, struct file *filp, int on) ...@@ -2260,9 +2260,10 @@ static int __tty_fasync(int fd, struct file *filp, int on)
static int tty_fasync(int fd, struct file *filp, int on) static int tty_fasync(int fd, struct file *filp, int on)
{ {
struct tty_struct *tty = file_tty(filp); struct tty_struct *tty = file_tty(filp);
int retval; int retval = -ENOTTY;
tty_lock(tty); tty_lock(tty);
if (!tty_hung_up_p(filp))
retval = __tty_fasync(fd, filp, on); retval = __tty_fasync(fd, filp, on);
tty_unlock(tty); tty_unlock(tty);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment