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

n_tty: Lock access to tty->pgrp for POSIX job control

Concurrent access to tty->pgrp must be protected with tty->ctrl_lock.
Also, as noted in the comments, reading current->signal->tty is
safe because either,
  1) current->signal->tty is assigned by current, or
  2) current->signal->tty is set to NULL.

NB: for reference, tty_check_change() implements a similar POSIX
check for the ioctls corresponding to tcflush(), tcdrain(),
tcsetattr(), tcsetpgrp(), tcflow() and tcsendbreak().
Signed-off-by: default avatarPeter Hurley <peter@hurleysoftware.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 8c985d18
...@@ -1719,10 +1719,9 @@ extern ssize_t redirected_tty_write(struct file *, const char __user *, ...@@ -1719,10 +1719,9 @@ extern ssize_t redirected_tty_write(struct file *, const char __user *,
* and if appropriate send any needed signals and return a negative * and if appropriate send any needed signals and return a negative
* error code if action should be taken. * error code if action should be taken.
* *
* FIXME: * Locking: redirected write test is safe
* Locking: None - redirected write test is safe, testing * current->signal->tty check is safe
* current->signal should possibly lock current->sighand * ctrl_lock to safely reference tty->pgrp
* pgrp locking ?
*/ */
static int job_control(struct tty_struct *tty, struct file *file) static int job_control(struct tty_struct *tty, struct file *file)
...@@ -1732,19 +1731,22 @@ static int job_control(struct tty_struct *tty, struct file *file) ...@@ -1732,19 +1731,22 @@ static int job_control(struct tty_struct *tty, struct file *file)
/* NOTE: not yet done after every sleep pending a thorough /* NOTE: not yet done after every sleep pending a thorough
check of the logic of this change. -- jlc */ check of the logic of this change. -- jlc */
/* don't stop on /dev/console */ /* don't stop on /dev/console */
if (file->f_op->write != redirected_tty_write && if (file->f_op->write == redirected_tty_write ||
current->signal->tty == tty) { current->signal->tty != tty)
if (!tty->pgrp) return 0;
printk(KERN_ERR "n_tty_read: no tty->pgrp!\n");
else if (task_pgrp(current) != tty->pgrp) { spin_lock_irq(&tty->ctrl_lock);
if (is_ignored(SIGTTIN) || if (!tty->pgrp)
is_current_pgrp_orphaned()) printk(KERN_ERR "n_tty_read: no tty->pgrp!\n");
return -EIO; else if (task_pgrp(current) != tty->pgrp) {
kill_pgrp(task_pgrp(current), SIGTTIN, 1); spin_unlock_irq(&tty->ctrl_lock);
set_thread_flag(TIF_SIGPENDING); if (is_ignored(SIGTTIN) || is_current_pgrp_orphaned())
return -ERESTARTSYS; return -EIO;
} kill_pgrp(task_pgrp(current), SIGTTIN, 1);
set_thread_flag(TIF_SIGPENDING);
return -ERESTARTSYS;
} }
spin_unlock_irq(&tty->ctrl_lock);
return 0; return 0;
} }
......
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