All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tty: Fix unreasonable write toward closed pty.
@ 2012-12-19 18:59 Ilya Zykov
  2012-12-19 19:10 ` Alan Cox
  2012-12-21 21:55 ` Alan Cox
  0 siblings, 2 replies; 4+ messages in thread
From: Ilya Zykov @ 2012-12-19 18:59 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Alan Cox, Jiri Slaby, Peter Hurley, Sasha Levin, linux-serial,
	linux-kernel

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 <ilya@ilyx.ru>
---
 drivers/tty/pty.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
index a82b399..1ce1362 100644
--- a/drivers/tty/pty.c
+++ b/drivers/tty/pty.c
@@ -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)

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] tty: Fix unreasonable write toward closed pty.
  2012-12-19 18:59 [PATCH] tty: Fix unreasonable write toward closed pty Ilya Zykov
@ 2012-12-19 19:10 ` Alan Cox
  2012-12-19 19:38   ` Ilya Zykov
  2012-12-21 21:55 ` Alan Cox
  1 sibling, 1 reply; 4+ messages in thread
From: Alan Cox @ 2012-12-19 19:10 UTC (permalink / raw)
  To: Ilya Zykov
  Cc: Greg Kroah-Hartman, Alan Cox, Jiri Slaby, Peter Hurley,
	Sasha Levin, linux-serial, linux-kernel

> diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
> index a82b399..1ce1362 100644
> --- a/drivers/tty/pty.c
> +++ b/drivers/tty/pty.c
> @@ -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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] tty: Fix unreasonable write toward closed pty.
  2012-12-19 19:10 ` Alan Cox
@ 2012-12-19 19:38   ` Ilya Zykov
  0 siblings, 0 replies; 4+ messages in thread
From: Ilya Zykov @ 2012-12-19 19:38 UTC (permalink / raw)
  To: Alan Cox
  Cc: Greg Kroah-Hartman, Alan Cox, Jiri Slaby, Peter Hurley,
	Sasha Levin, linux-serial, linux-kernel

On 19.12.2012 23:10, Alan Cox wrote:
>> diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
>> index a82b399..1ce1362 100644
>> --- a/drivers/tty/pty.c
>> +++ b/drivers/tty/pty.c
>> @@ -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
> 

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] tty: Fix unreasonable write toward closed pty.
  2012-12-19 18:59 [PATCH] tty: Fix unreasonable write toward closed pty Ilya Zykov
  2012-12-19 19:10 ` Alan Cox
@ 2012-12-21 21:55 ` Alan Cox
  1 sibling, 0 replies; 4+ messages in thread
From: Alan Cox @ 2012-12-21 21:55 UTC (permalink / raw)
  To: Ilya Zykov
  Cc: Greg Kroah-Hartman, Jiri Slaby, Peter Hurley, Sasha Levin,
	linux-serial, linux-kernel

On Wed, 19 Dec 2012 22:59:19 +0400
Ilya Zykov <ilya@ilyx.ru> 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 <ilya@ilyx.ru>
> ---
>  drivers/tty/pty.c |    2 ++
>  1 files changed, 2 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
> index a82b399..1ce1362 100644
> --- a/drivers/tty/pty.c
> +++ b/drivers/tty/pty.c
> @@ -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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-12-21 21:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-19 18:59 [PATCH] tty: Fix unreasonable write toward closed pty Ilya Zykov
2012-12-19 19:10 ` Alan Cox
2012-12-19 19:38   ` Ilya Zykov
2012-12-21 21:55 ` Alan Cox

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.