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]
Revert "pvr: more calculation on dvfs."

This reverts commit baff6d9c8bcba8baf996c93abb2b7bdb1f79def3.


Change-Id: Ieda06b27206ea2c9476decc5f31f4848b6b93d44
Signed-off-by: doc <doc.divxm@gmail.com>
Revert "gpu: Made more careful calculation on dvfs."

This reverts commit 08bcee1616bdd097fbdf47fc6ae9c6746125d8c4.

Change-Id: I99057bc0c2d2d419ec36327a88ee523623aaec38
Revert "gpu: let sec dvfs driver use lower frequencies more."

This reverts commit 0b3b73588dbf8d977dee3eeb218ab6cb55524015.


Change-Id: I86f62d867448dabdc6518e7cc4af7271e8ddb5e8
Signed-off-by: doc <doc.divxm@gmail.com>
Revert "i9500: Enable Sound Control by default."

This reverts commit 7912ac9b25bc9ccc2d4ece7633af415690f9a7d4.


Change-Id: I9af785c12d11de4efb6e91aa3152d6010ec85e9f
Signed-off-by: doc <doc.divxm@gmail.com>
Revert "sound: some fixes from AndreiLux repo"

This reverts commit a632da58e5dd03ffdae5981c6d4a046a8d8d7f6a.


Change-Id: Ic70b704a1055241f1314eb4fb5071edd4844dcfa
Signed-off-by: doc <doc.divxm@gmail.com>
Revert "sound-control: Add SP mono mode and SP privacy mode"

This reverts commit c313f8edceda92904ebff9574ae1f06126a562dc.


Change-Id: I9074b22165ea39264e279f9c49c9a634e31c454f
Signed-off-by: doc <doc.divxm@gmail.com>
Revert "sound-control: Add speaker EQ and EQ freq controls"

This reverts commit b92a9dc764b8c75341da62f521c0b0fd25642556.


Change-Id: Idba076e99372b80b7413aa963588261abd9b38f8
Signed-off-by: doc <doc.divxm@gmail.com>
Revert "sound-control: Misc fixes and HP power control for EQ and DRC"

This reverts commit 6cc2604a6fc1c5dff4be86401cbf310320c5403d.


Change-Id: Ieff3f207dd33dc0deead97ce29aa5b66d533f89c
Signed-off-by: doc <doc.divxm@gmail.com>
Revert "sound-control: Add dynamic range compression"

This reverts commit d097db425235d07324b4e04f6ceefa31ff6bbf3d.


Change-Id: If04ec1375fc49895920a6d2df3518a704d721662
Signed-off-by: doc <doc.divxm@gmail.com>
Revert "sound-control: Headphone equalizer"

This reverts commit 661b6313f35ceb04788a43a14812ff4d6b0982fc.


Change-Id: I4824c759d6f31aa220b3660925e173b2c2274c1b
Signed-off-by: doc <doc.divxm@gmail.com>
Revert "sound: SoC: WolfsonMicro WM5102 sound control"

This reverts commit 0c6801036bbed2d975e4e81ada5e3200be788043.


Change-Id: Ib039f89afafccb23f8e18bc986dc95c7c5e30fcc
Signed-off-by: doc <doc.divxm@gmail.com>
Revert "gpu: Added defconfig for perseus dvfs which has overclock."

This reverts commit 61c68e75da21ec562348424f51657d91bc177303.


Change-Id: I1d0cbf3f47026e088c9166d486e219e31390d3cc
Signed-off-by: doc <doc.divxm@gmail.com>
Revert "gpu: pvr: Add Exynos 5410 SGX 544 custom DVFS control"

This reverts commit e5c3a2202b5a7ede4637dd696660262aec34d987.


Change-Id: I959d9e8308c3b105eb6f50100d1eb42b04094469
Signed-off-by: doc <doc.divxm@gmail.com>
Linux 3.4.90

Change-Id: I3d6e58051f7254a93fa56e89103b3ae31a454ad5
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: doc <doc.divxm@gmail.com>
i9500: Linux 3.4.91

Change-Id: I66e44b51fb824866595f2d552d44f45934c5f860
Signed-off-by: Greg Kroah-Hartman<gregkh@linuxfoundation.org>
Signed-off-by: doc <doc.divxm@gmail.com>
Merge remote-tracking branch 'aicp/kitkat' into kitkat-legacy

Conflicts:
	Makefile
	arch/x86/crypto/ghash-clmulni-intel_asm.S