aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/tty
diff options
context:
space:
mode:
authorPeter Hurley <peter@hurleysoftware.com>2013-09-27 13:27:05 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-09-30 22:05:56 -0400
commitf8747d4a466ab2cafe56112c51b3379f9fdb7a12 (patch)
tree5d3fbaa52d7967a924f790f1d0cb363a7ed0f498 /drivers/tty
parent15c03dd4859ab16f9212238f29dd315654aa94f6 (diff)
tty: Fix pty master read() after slave closes
Commit f95499c3030fe1bfad57745f2db1959c5b43dca8, n_tty: Don't wait for buffer work in read() loop creates a race window which can cause a pty master read() to miss the last pty slave write(s) and return -EIO instead, thus signalling the pty slave is closed. This can happen when the pty slave is written and immediately closed but before the tty buffer i/o loop receives the new input; the pty master read() is scheduled, sees its read buffer is empty and the pty slave has been closed, and exits. Because tty_flush_to_ldisc() has significant performance impact for parallel i/o, rather than revert the commit, special case this condition (ie., when the read buffer is empty and the 'other' pty has been closed) and, only then, wait for buffer work to complete before re-testing if the read buffer is still empty. As before, subsequent pty master reads return any available data until no more data is available, and then returns -EIO to indicate the pty slave has closed. Reported-by: Mikael Pettersson <mikpelinux@gmail.com> Signed-off-by: Peter Hurley <peter@hurleysoftware.com> Tested-by: Mikael Pettersson <mikpelinux@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/tty')
-rw-r--r--drivers/tty/n_tty.c46
1 files changed, 26 insertions, 20 deletions
diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index 01bf5eb4f238..7a744b69c3d1 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -2183,28 +2183,34 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file,
2183 2183
2184 if (!input_available_p(tty, 0)) { 2184 if (!input_available_p(tty, 0)) {
2185 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) { 2185 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) {
2186 retval = -EIO; 2186 up_read(&tty->termios_rwsem);
2187 break; 2187 tty_flush_to_ldisc(tty);
2188 } 2188 down_read(&tty->termios_rwsem);
2189 if (tty_hung_up_p(file)) 2189 if (!input_available_p(tty, 0)) {
2190 break; 2190 retval = -EIO;
2191 if (!timeout) 2191 break;
2192 break; 2192 }
2193 if (file->f_flags & O_NONBLOCK) { 2193 } else {
2194 retval = -EAGAIN; 2194 if (tty_hung_up_p(file))
2195 break; 2195 break;
2196 } 2196 if (!timeout)
2197 if (signal_pending(current)) { 2197 break;
2198 retval = -ERESTARTSYS; 2198 if (file->f_flags & O_NONBLOCK) {
2199 break; 2199 retval = -EAGAIN;
2200 } 2200 break;
2201 n_tty_set_room(tty); 2201 }
2202 up_read(&tty->termios_rwsem); 2202 if (signal_pending(current)) {
2203 retval = -ERESTARTSYS;
2204 break;
2205 }
2206 n_tty_set_room(tty);
2207 up_read(&tty->termios_rwsem);
2203 2208
2204 timeout = schedule_timeout(timeout); 2209 timeout = schedule_timeout(timeout);
2205 2210
2206 down_read(&tty->termios_rwsem); 2211 down_read(&tty->termios_rwsem);
2207 continue; 2212 continue;
2213 }
2208 } 2214 }
2209 __set_current_state(TASK_RUNNING); 2215 __set_current_state(TASK_RUNNING);
2210 2216