n_tty: Fix n_tty_write crash when echoing in raw mode

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
d945cb9cce20ac7143c2de8d88b187f62db99bdc (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

Change-Id: Ie0b03989fa8cfd6ffe40d1f770044fe7447dda05
References: CVE-2014-0196
Reported-and-tested-by: Jiri Slaby <jslaby@suse.cz>
Signed-off-by: Peter Hurley <peter@hurleysoftware.com>
Signed-off-by: Jiri 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: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[bwh: Backported to 3.4: output_lock is a member of struct tty_struct]
Merge "tenderloin:  Fix up 4g wifi" into kitkat
Merge "tenderloin:  Fix up rotation for the 4g Model" into kitkat
defconfig: clone for tenderloin 4G

Change-Id: If29d6fbd6f520ab13e27f97346ff922def4521c0
defconfig: initial changes for tenderloin 4G
tenderloin4g:  Fix up compile error

Change-Id: I89cf74e1c8163884b7a3d8551bc604fc8b73e74e
board-tenderloin-usb: initialize isp1763 gpios for 4G
board-tenderloin: configure uart gpios for 4G
tenderloin-usb: add debug info
pehci: turn on all debugging
pehci: fix typo in qtdptd.c
pehci: fix bad printk
pehci: fix bad printks
tenderloin4g: Fix up compile error

Change-Id: I2634af4957d2a563fca4d06cd69e0593bc2fdd3c
tenderloing:  add in and init. ebi2 only for 4g model

Change-Id: I779d6b8e6843375c0700287a4d453bd3c5b7d0a4
Revert "pehci: turn on all debugging"

This reverts commit 4a1d6dbd36a9038aa168a5178f1efd7716a9b2f1.

Change-Id: I10bfe7df8040aca7ecd6e26053656d3500eb498d
Revert "tenderloin-usb: add debug info"

This reverts commit 96b3866372f1454ffa839d6b8ba1a2c74c79a665.
driver: add in SERIAL_SIERRAWIRELESS_SWI driver

Change-Id: I1b710659c5cecd979f76d81daa5192ca7780ec63
drivers:  Add a few to quirks list

Along with setting up USB_QUIRK_NO_AUTOSUSPEND

Change-Id: I08906c4f851b98661593e7230905d6ba1d0fb58c
gpio:  add in 92 to ebi2

Was in the 2.6 kernel didn't notice anything yet that requires
it but figured it in the 2.6 should add it in here.

Change-Id: Ided650e2e7ba46b25c00533f7488d8f12e3f4b3e