tty: Fix unreasonable write toward closed pty.
PATCH 1/1 tty: Fix unreasonable write toward closed pty.
We should not write toward the closed pty.
Now it happens, if one side close last file descriptor, and other side in this moment write to it.
It also prevents scheduling unnecessary work.
--- drivers/tty/pty.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
drivers/tty/pty.c +2 -0
@@ -116,6 +116,8 @@ static int pty_space(struct tty_struct *to)static int pty_write (struct tty_struct *tty,const unsigned char *buf,int c) { +if (test_bit (TTY_OTHER_CLOSED , &tty->flags)) +return -EIO ;struct tty_struct *to = tty->link;if (tty->stopped)
drivers/tty/pty.c static int pty_space(struct tty_struct *to) · line 120
Quoted 10 lines
drivers/tty/pty.c +2
-0@@ -116,6 +116,8 @@ static int pty_space(struct tty_struct *to)static int pty_write (struct tty_struct *tty,const unsigned char *buf,int c) { +if (test_bit (TTY_OTHER_CLOSED , &tty->flags)) +return -EIO ;
The flag can change between the test and ny further code being executed ?
Alan
Quoted 6 lines · Alan Cox
Quoted 6 lines
drivers/tty/pty.c +0
-0@@ -116,6 +116,8 @@ static int pty_space(struct tty_struct *to)
Quoted 9 lines
drivers/tty/pty.c static int pty_space(struct tty_struct *to) · line 120
Quoted 4 lines
drivers/tty/pty.c +2
-0static int pty_write (struct tty_struct *tty,const unsigned char *buf,int c) { +if (test_bit (TTY_OTHER_CLOSED , &tty->flags)) +return -EIO ;The flag can change between the test and ny further code being executed ?
Alan
Yes, if I understand you correctly, but this is no matter here, because ldisc's layer will wait, flush this data later. Here, only beginning stage of tty_close.
This is safe later stage from unnecessary data.
Ilya
Quoted 15 lines · On Wed, 19 Dec 2012 22:59:19 +0400 Ilya Zykov <[email protected]> wrote:
We should not write toward the closed pty.
Now it happens, if one side close last file descriptor, and other side in this moment write to it.
It also prevents scheduling unnecessary work.Signed-off-by Ilya Zykov <[email protected]>--- drivers/tty/pty.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)drivers/tty/pty.c +0
-0
drivers/tty/pty.c static int pty_space(struct tty_struct *to) · line 121
Quoted 6 lines
drivers/tty/pty.c +2
-0@@ -116,6 +116,8 @@ static int pty_space(struct tty_struct *to)static int pty_write (struct tty_struct *tty,const unsigned char *buf,int c) { +if (test_bit (TTY_OTHER_CLOSED , &tty->flags)) +return -EIO ;struct tty_struct *to = tty->link;
This
a) doesn't do anything in many cases because there is no lock to make the test_bit meaningful
b) produces an obvious compiler warning