Commit 28298232 authored by Alan Cox's avatar Alan Cox Committed by Linus Torvalds

[PATCH] tty: Fix bits and note more bits to fix

If your driver implements "break on" and "break off" this ensures you won't
get multiple overlapping requests or requests in parallel.  If your driver
has its own break handling then its still your problem as the driver
author.

Break is also now serialized against writes from user space properly but no
new guarantees are made driver level about writes from the line discipline
itself (eg flow control or echo)
Signed-off-by: default avatarAlan Cox <alan@redhat.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent de2a84f2
...@@ -2719,6 +2719,8 @@ static int tty_fasync(int fd, struct file * filp, int on) ...@@ -2719,6 +2719,8 @@ static int tty_fasync(int fd, struct file * filp, int on)
* Locking: * Locking:
* Called functions take tty_ldisc_lock * Called functions take tty_ldisc_lock
* current->signal->tty check is safe without locks * current->signal->tty check is safe without locks
*
* FIXME: may race normal receive processing
*/ */
static int tiocsti(struct tty_struct *tty, char __user *p) static int tiocsti(struct tty_struct *tty, char __user *p)
...@@ -2878,9 +2880,7 @@ static int fionbio(struct file *file, int __user *p) ...@@ -2878,9 +2880,7 @@ static int fionbio(struct file *file, int __user *p)
* Locking: * Locking:
* Takes tasklist lock internally to walk sessions * Takes tasklist lock internally to walk sessions
* Takes task_lock() when updating signal->tty * Takes task_lock() when updating signal->tty
* * Takes tty_mutex() to protect tty instance
* FIXME: tty_mutex is needed to protect signal->tty references.
* FIXME: why task_lock on the signal->tty reference ??
* *
*/ */
...@@ -2915,9 +2915,11 @@ static int tiocsctty(struct tty_struct *tty, int arg) ...@@ -2915,9 +2915,11 @@ static int tiocsctty(struct tty_struct *tty, int arg)
} else } else
return -EPERM; return -EPERM;
} }
mutex_lock(&tty_mutex);
task_lock(current); task_lock(current);
current->signal->tty = tty; current->signal->tty = tty;
task_unlock(current); task_unlock(current);
mutex_unlock(&tty_mutex);
current->signal->tty_old_pgrp = 0; current->signal->tty_old_pgrp = 0;
tty->session = current->signal->session; tty->session = current->signal->session;
tty->pgrp = process_group(current); tty->pgrp = process_group(current);
...@@ -2957,8 +2959,6 @@ static int tiocgpgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t ...@@ -2957,8 +2959,6 @@ static int tiocgpgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t
* permitted where the tty session is our session. * permitted where the tty session is our session.
* *
* Locking: None * Locking: None
*
* FIXME: current->signal->tty referencing is unsafe.
*/ */
static int tiocspgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p) static int tiocspgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p)
...@@ -3037,19 +3037,20 @@ static int tiocsetd(struct tty_struct *tty, int __user *p) ...@@ -3037,19 +3037,20 @@ static int tiocsetd(struct tty_struct *tty, int __user *p)
* timed break functionality. * timed break functionality.
* *
* Locking: * Locking:
* None * atomic_write_lock serializes
* *
* FIXME:
* What if two overlap
*/ */
static int send_break(struct tty_struct *tty, unsigned int duration) static int send_break(struct tty_struct *tty, unsigned int duration)
{ {
if (mutex_lock_interruptible(&tty->atomic_write_lock))
return -EINTR;
tty->driver->break_ctl(tty, -1); tty->driver->break_ctl(tty, -1);
if (!signal_pending(current)) { if (!signal_pending(current)) {
msleep_interruptible(duration); msleep_interruptible(duration);
} }
tty->driver->break_ctl(tty, 0); tty->driver->break_ctl(tty, 0);
mutex_unlock(&tty->atomic_write_lock);
if (signal_pending(current)) if (signal_pending(current))
return -EINTR; return -EINTR;
return 0; return 0;
...@@ -3142,6 +3143,8 @@ int tty_ioctl(struct inode * inode, struct file * file, ...@@ -3142,6 +3143,8 @@ int tty_ioctl(struct inode * inode, struct file * file,
if (tty_paranoia_check(tty, inode, "tty_ioctl")) if (tty_paranoia_check(tty, inode, "tty_ioctl"))
return -EINVAL; return -EINVAL;
/* CHECKME: is this safe as one end closes ? */
real_tty = tty; real_tty = tty;
if (tty->driver->type == TTY_DRIVER_TYPE_PTY && if (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
tty->driver->subtype == PTY_TYPE_MASTER) tty->driver->subtype == PTY_TYPE_MASTER)
......
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