1. 20 6月, 2014 1 次提交
    • P
      tty: Correct INPCK handling · 66528f90
      Peter Hurley 提交于
      If INPCK is not set, input parity detection should be disabled. This means
      parity errors should not be received from the tty driver, and the data
      received should be treated normally.
      
      SUS v3, 11.2.2, General Terminal Interface - Input Modes, states:
        "If INPCK is set, input parity checking shall be enabled. If INPCK is
         not set, input parity checking shall be disabled, allowing output parity
         generation without input parity errors. Note that whether input parity
         checking is enabled or disabled is independent of whether parity detection
         is enabled or disabled (see Control Modes). If parity detection is enabled
         but input parity checking is disabled, the hardware to which the terminal
         is connected shall recognize the parity bit, but the terminal special file
         shall not check whether or not this bit is correctly set."
      
      Ignore parity errors reported by the tty driver when INPCK is not set, and
      handle the received data normally.
      
      Fixes: Bugzilla #71681, 'Improvement of n_tty_receive_parity_error from n_tty.c'
      Reported-by: NIvan <athlon_@mail.ru>
      Signed-off-by: NPeter Hurley <peter@hurleysoftware.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      66528f90
  2. 04 5月, 2014 1 次提交
    • P
      n_tty: Fix n_tty_write crash when echoing in raw mode · 4291086b
      Peter Hurley 提交于
      The tty atomic_write_lock does not provide an exclusion guarantee for
      the tty driver if the termios settings are LECHO & !OPOST.  And since
      it is unexpected and not allowed to call TTY buffer helpers like
      tty_insert_flip_string concurrently, this may lead to crashes when
      concurrect writers call pty_write. In that case the following two
      writers:
      * the ECHOing from a workqueue and
      * pty_write from the process
      race and can overflow the corresponding TTY buffer like follows.
      
      If we look into tty_insert_flip_string_fixed_flag, there is:
        int space = __tty_buffer_request_room(port, goal, flags);
        struct tty_buffer *tb = port->buf.tail;
        ...
        memcpy(char_buf_ptr(tb, tb->used), chars, space);
        ...
        tb->used += space;
      
      so the race of the two can result in something like this:
                    A                                B
      __tty_buffer_request_room
                                        __tty_buffer_request_room
      memcpy(buf(tb->used), ...)
      tb->used += space;
                                        memcpy(buf(tb->used), ...) ->BOOM
      
      B's memcpy is past the tty_buffer due to the previous A's tb->used
      increment.
      
      Since the N_TTY line discipline input processing can output
      concurrently with a tty write, obtain the N_TTY ldisc output_lock to
      serialize echo output with normal tty writes.  This ensures the tty
      buffer helper tty_insert_flip_string is not called concurrently and
      everything is fine.
      
      Note that this is nicely reproducible by an ordinary user using
      forkpty and some setup around that (raw termios + ECHO). And it is
      present in kernels at least after commit
      d945cb9c (pty: Rework the pty layer to
      use the normal buffering logic) in 2.6.31-rc3.
      
      js: add more info to the commit log
      js: switch to bool
      js: lock unconditionally
      js: lock only the tty->ops->write call
      
      References: CVE-2014-0196
      Reported-and-tested-by: NJiri Slaby <jslaby@suse.cz>
      Signed-off-by: NPeter Hurley <peter@hurleysoftware.com>
      Signed-off-by: NJiri Slaby <jslaby@suse.cz>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4291086b
  3. 18 4月, 2014 1 次提交
  4. 14 2月, 2014 3 次提交
  5. 18 12月, 2013 2 次提交
    • P
      n_tty: Fix apparent order of echoed output · 1075a6e2
      Peter Hurley 提交于
      With block processing of echoed output, observed output order is still
      required. Push completed echoes and echo commands prior to output.
      
      Introduce echo_mark echo buffer index, which tracks completed echo
      commands; ie., those submitted via commit_echoes but which may not
      have been committed. Ensure that completed echoes are output prior
      to subsequent terminal writes in process_echoes().
      
      Fixes newline/prompt output order in cooked mode shell.
      
      Cc: <stable@vger.kernel.org> # 3.12.x : 39434abd n_tty: Fix missing newline echo
      Reported-by: NKarl Dahlke <eklhad@comcast.net>
      Reported-by: NMikulas Patocka <mpatocka@redhat.com>
      Signed-off-by: NPeter Hurley <peter@hurleysoftware.com>
      Tested-by: NKarl Dahlke <eklhad@comcast.net>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1075a6e2
    • P
      n_tty: Fix buffer overruns with larger-than-4k pastes · 4d0ed182
      Peter Hurley 提交于
      readline() inadvertently triggers an error recovery path when
      pastes larger than 4k overrun the line discipline buffer. The
      error recovery path discards input when the line discipline buffer
      is full and operating in canonical mode and no newline has been
      received. Because readline() changes the termios to non-canonical
      mode to read the line char-by-char, the line discipline buffer
      can become full, and then when readline() restores termios back
      to canonical mode for the caller, the now-full line discipline
      buffer triggers the error recovery.
      
      When changing termios from non-canon to canon mode and the read
      buffer contains data, simulate an EOF push _without_ the
      DISABLED_CHAR in the read buffer.
      
      Importantly for the readline() problem, the termios can be
      changed back to non-canonical mode without changes to the read
      buffer occurring; ie., as if the previous termios change had not
      happened (as long as no intervening read took place).
      
      Preserve existing userspace behavior which allows '\0's already
      received in non-canon mode to be read as '\0's in canon mode
      (rather than trigger add'l EOF pushes or an actual EOF).
      
      Patch based on original proposal and discussion here
      https://bugzilla.kernel.org/show_bug.cgi?id=55991
      by Stas Sergeev <stsp@users.sourceforge.net>
      Reported-by: NMargarita Manterola <margamanterola@gmail.com>
      Cc: Maximiliano Curia <maxy@gnuservers.com.ar>
      Cc: Pavel Machek <pavel@ucw.cz>
      Cc: Arkadiusz Miskiewicz <a.miskiewicz@gmail.com>
      Acked-by: NStas Sergeev <stsp@users.sourceforge.net>
      Signed-off-by: NPeter Hurley <peter@hurleysoftware.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4d0ed182
  6. 09 12月, 2013 6 次提交
  7. 30 11月, 2013 1 次提交
  8. 26 11月, 2013 4 次提交
  9. 17 10月, 2013 1 次提交
  10. 01 10月, 2013 1 次提交
    • P
      tty: Fix pty master read() after slave closes · f8747d4a
      Peter Hurley 提交于
      Commit f95499c3,
        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: NMikael Pettersson <mikpelinux@gmail.com>
      Signed-off-by: NPeter Hurley <peter@hurleysoftware.com>
      Tested-by: NMikael Pettersson <mikpelinux@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f8747d4a
  11. 26 9月, 2013 3 次提交
  12. 18 9月, 2013 1 次提交
  13. 13 8月, 2013 1 次提交
    • P
      n_tty: Fix termios_rwsem lockdep false positive · aefceaf4
      Peter Hurley 提交于
      Lockdep reports a circular lock dependency between
      atomic_read_lock and termios_rwsem [1]. However, a lock
      order deadlock is not possible since CPU1 only holds a
      read lock which cannot prevent CPU0 from also acquiring
      a read lock on the same r/w semaphore.
      
      Unfortunately, lockdep cannot currently distinguish whether
      the locks are read or write for any particular lock graph,
      merely that the locks _were_ previously read and/or write.
      
      Until lockdep is fixed, re-order atomic_read_lock so
      termios_rwsem can be dropped and reacquired without
      triggering lockdep.
      
      Patch based on original posted here https://lkml.org/lkml/2013/8/1/510
      by Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
      
      [1] Initial lockdep report from Artem Savkov <artem.savkov@gmail.com>
      
       ======================================================
       [ INFO: possible circular locking dependency detected ]
       3.11.0-rc3-next-20130730+ #140 Tainted: G        W
       -------------------------------------------------------
       bash/1198 is trying to acquire lock:
        (&tty->termios_rwsem){++++..}, at: [<ffffffff816aa3bb>] n_tty_read+0x49b/0x660
      
       but task is already holding lock:
        (&ldata->atomic_read_lock){+.+...}, at: [<ffffffff816aa0f0>] n_tty_read+0x1d0/0x660
      
       which lock already depends on the new lock.
      
       the existing dependency chain (in reverse order) is:
      
       -> #1 (&ldata->atomic_read_lock){+.+...}:
              [<ffffffff811111cc>] validate_chain+0x73c/0x850
              [<ffffffff811117e0>] __lock_acquire+0x500/0x5d0
              [<ffffffff81111a29>] lock_acquire+0x179/0x1d0
              [<ffffffff81d34b9c>] mutex_lock_interruptible_nested+0x7c/0x540
              [<ffffffff816aa0f0>] n_tty_read+0x1d0/0x660
              [<ffffffff816a3bb6>] tty_read+0x86/0xf0
              [<ffffffff811f21d3>] vfs_read+0xc3/0x130
              [<ffffffff811f2702>] SyS_read+0x62/0xa0
              [<ffffffff81d45259>] system_call_fastpath+0x16/0x1b
      
       -> #0 (&tty->termios_rwsem){++++..}:
              [<ffffffff8111064f>] check_prev_add+0x14f/0x590
              [<ffffffff811111cc>] validate_chain+0x73c/0x850
              [<ffffffff811117e0>] __lock_acquire+0x500/0x5d0
              [<ffffffff81111a29>] lock_acquire+0x179/0x1d0
              [<ffffffff81d372c1>] down_read+0x51/0xa0
              [<ffffffff816aa3bb>] n_tty_read+0x49b/0x660
              [<ffffffff816a3bb6>] tty_read+0x86/0xf0
              [<ffffffff811f21d3>] vfs_read+0xc3/0x130
              [<ffffffff811f2702>] SyS_read+0x62/0xa0
              [<ffffffff81d45259>] system_call_fastpath+0x16/0x1b
      
       other info that might help us debug this:
      
        Possible unsafe locking scenario:
      
              CPU0                    CPU1
              ----                    ----
         lock(&ldata->atomic_read_lock);
                                      lock(&tty->termios_rwsem);
                                      lock(&ldata->atomic_read_lock);
         lock(&tty->termios_rwsem);
      
        *** DEADLOCK ***
      
       2 locks held by bash/1198:
        #0:  (&tty->ldisc_sem){.+.+.+}, at: [<ffffffff816ade04>] tty_ldisc_ref_wait+0x24/0x60
        #1:  (&ldata->atomic_read_lock){+.+...}, at: [<ffffffff816aa0f0>] n_tty_read+0x1d0/0x660
      
       stack backtrace:
       CPU: 1 PID: 1198 Comm: bash Tainted: G        W    3.11.0-rc3-next-20130730+ #140
       Hardware name: Bochs Bochs, BIOS Bochs 01/01/2007
        0000000000000000 ffff880019acdb28 ffffffff81d34074 0000000000000002
        0000000000000000 ffff880019acdb78 ffffffff8110ed75 ffff880019acdb98
        ffff880019fd0000 ffff880019acdb78 ffff880019fd0638 ffff880019fd0670
       Call Trace:
        [<ffffffff81d34074>] dump_stack+0x59/0x7d
        [<ffffffff8110ed75>] print_circular_bug+0x105/0x120
        [<ffffffff8111064f>] check_prev_add+0x14f/0x590
        [<ffffffff81d3ab5f>] ? _raw_spin_unlock_irq+0x4f/0x70
        [<ffffffff811111cc>] validate_chain+0x73c/0x850
        [<ffffffff8110ae0f>] ? trace_hardirqs_off_caller+0x1f/0x190
        [<ffffffff811117e0>] __lock_acquire+0x500/0x5d0
        [<ffffffff81111a29>] lock_acquire+0x179/0x1d0
        [<ffffffff816aa3bb>] ? n_tty_read+0x49b/0x660
        [<ffffffff81d372c1>] down_read+0x51/0xa0
        [<ffffffff816aa3bb>] ? n_tty_read+0x49b/0x660
        [<ffffffff816aa3bb>] n_tty_read+0x49b/0x660
        [<ffffffff810e4130>] ? try_to_wake_up+0x210/0x210
        [<ffffffff816a3bb6>] tty_read+0x86/0xf0
        [<ffffffff811f21d3>] vfs_read+0xc3/0x130
        [<ffffffff811f2702>] SyS_read+0x62/0xa0
        [<ffffffff815e24ee>] ? trace_hardirqs_on_thunk+0x3a/0x3f
        [<ffffffff81d45259>] system_call_fastpath+0x16/0x1b
      Reported-by: NArtem Savkov <artem.savkov@gmail.com>
      Reported-by: NSergey Senozhatsky <sergey.senozhatsky@gmail.com>
      Signed-off-by: NPeter Hurley <peter@hurleysoftware.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      aefceaf4
  14. 25 7月, 2013 9 次提交
  15. 24 7月, 2013 5 次提交