lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Thu, 9 Apr 2015 10:43:13 -0700
From:	"H.J. Lu" <hjl.tools@...il.com>
To:	Peter Hurley <peter@...leysoftware.com>
Cc:	Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
	Jiri Slaby <jslaby@...e.cz>,
	LKML <linux-kernel@...r.kernel.org>,
	Alan Cox <alan@...ux.intel.com>,
	Andy Whitcroft <apw@...onical.com>,
	Josh Boyer <jwboyer@...hat.com>, stable@...r.kernel.org
Subject: Re: [PATCH] pty: Fix input race when closing

On Thu, Apr 9, 2015 at 7:54 AM, Peter Hurley <peter@...leysoftware.com> wrote:
> A read() from a pty master may mistakenly indicate EOF (errno == -EIO)
> after the pty slave has closed, even though input data remains to be read.
> For example,
>
>        pty slave       |        input worker        |    pty master
>                        |                            |
>                        |                            |   n_tty_read()
> pty_write()            |                            |     input avail? no
>   add data             |                            |     sleep
>   schedule worker  --->|                            |     .
>                        |---> flush_to_ldisc()       |     .
> pty_close()            |       fill read buffer     |     .
>   wait for worker      |       wakeup reader    --->|     .
>                        |       read buffer full?    |---> input avail ? yes
>                        |<---   yes - exit worker    |     copy 4096 bytes to user
>   TTY_OTHER_CLOSED <---|                            |<--- kick worker
>                        |                            |
>
>                                 **** New read() before worker starts ****
>
>                        |                            |   n_tty_read()
>                        |                            |     input avail? no
>                        |                            |     TTY_OTHER_CLOSED? yes
>                        |                            |     return -EIO
>
> Several conditions are required to trigger this race:
> 1. the ldisc read buffer must become full so the input worker exits
> 2. the read() count parameter must be >= 4096 so the ldisc read buffer
>    is empty
> 3. the subsequent read() occurs before the kicked worker has processed
>    more input
>
> However, the underlying cause of the race is that data is pipelined, while
> tty state is not; ie., data already written by the pty slave end is not
> yet visible to the pty master end, but state changes by the pty slave end
> are visible to the pty master end immediately.
>
> Pipeline the TTY_OTHER_CLOSED state through input worker to the reader.
> 1. Introduce TTY_OTHER_DONE which is set by the input worker when
>    TTY_OTHER_CLOSED is set and either the input buffers are flushed or
>    input processing has completed. Readers/polls are woken when
>    TTY_OTHER_DONE is set.
> 2. Reader/poll checks TTY_OTHER_DONE instead of TTY_OTHER_CLOSED.
> 3. A new input worker is started from pty_close() after setting
>    TTY_OTHER_CLOSED, which ensures the TTY_OTHER_DONE state will be
>    set if the last input worker is already finished (or just about to
>    exit).
>
> Remove tty_flush_to_ldisc(); no in-tree callers.
>
> Fixes: 52bce7f8d4fc ("pty, n_tty: Simplify input processing on final close")
> Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=96311
> BugLink: http://bugs.launchpad.net/bugs/1429756
> Cc: <stable@...r.kernel.org> # 3.19+
> Reported-by: Andy Whitcroft <apw@...onical.com>
> Reported-by: H.J. Lu <hjl.tools@...il.com>
> Signed-off-by: Peter Hurley <peter@...leysoftware.com>
> ---
>  Documentation/serial/tty.txt |  3 +++
>  drivers/tty/n_hdlc.c         |  4 ++--
>  drivers/tty/n_tty.c          |  4 ++--
>  drivers/tty/pty.c            |  3 +--
>  drivers/tty/tty_buffer.c     | 25 +++++++++++--------------
>  include/linux/tty.h          |  2 +-
>  6 files changed, 20 insertions(+), 21 deletions(-)
>

I tried it on 3.19.3 and it doesn't work with the testcase in

https://bugzilla.kernel.org/show_bug.cgi?id=96311


-- 
H.J.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ