mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [3.13.y.z extended stable] Linux 3.13.11.1 stable review (new patches)
@ 2014-05-06 20:42 Kamal Mostafa
  2014-05-06 20:42 ` [PATCH 3.13 1/3] n_tty: Fix n_tty_write crash when echoing in raw mode Kamal Mostafa
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Kamal Mostafa @ 2014-05-06 20:42 UTC (permalink / raw)
  To: linux-kernel, stable, kernel-team; +Cc: Kamal Mostafa

New patches have been added during this review cycle for the Linux 3.13.11.1
stable kernel.

The 3 new patches are summarized below.  The new patches are
posted as replies to this message and also available in this git branch:

http://kernel.ubuntu.com/git?p=ubuntu/linux.git;h=linux-3.13.y-review;a=shortlog

git://kernel.ubuntu.com/ubuntu/linux.git  linux-3.13.y-review

To report a problem, please reply to the relevant follow-up patch message.

For more information about the Linux 3.13.y.z extended stable kernel version,
see https://wiki.ubuntu.com/Kernel/Dev/ExtendedStable .

 -Kamal

--
 drivers/block/floppy.c | 11 +++++++----
 drivers/tty/n_tty.c    |  4 ++++
 2 files changed, 11 insertions(+), 4 deletions(-)

Matthew Daley (2):
      floppy: ignore kernel-only members in FDRAWCMD ioctl input
      floppy: don't write kernel-only members to FDRAWCMD ioctl output

Peter Hurley (1):
      n_tty: Fix n_tty_write crash when echoing in raw mode

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

* [PATCH 3.13 1/3] n_tty: Fix n_tty_write crash when echoing in raw mode
  2014-05-06 20:42 [3.13.y.z extended stable] Linux 3.13.11.1 stable review (new patches) Kamal Mostafa
@ 2014-05-06 20:42 ` Kamal Mostafa
  2014-05-06 20:42 ` [PATCH 3.13 2/3] floppy: ignore kernel-only members in FDRAWCMD ioctl input Kamal Mostafa
  2014-05-06 20:42 ` [PATCH 3.13 3/3] floppy: don't write kernel-only members to FDRAWCMD ioctl output Kamal Mostafa
  2 siblings, 0 replies; 4+ messages in thread
From: Kamal Mostafa @ 2014-05-06 20:42 UTC (permalink / raw)
  To: linux-kernel, stable, kernel-team
  Cc: Peter Hurley, Jiri Slaby, Linus Torvalds, Alan Cox,
	Greg Kroah-Hartman, Kamal Mostafa

3.13.11.1 -stable review patch.  If anyone has any objections, please let me know.

------------------

From: Peter Hurley <peter@hurleysoftware.com>

commit 4291086b1f081b869c6d79e5b7441633dc3ace00 upstream.

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

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
---
 drivers/tty/n_tty.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index 4c10837..86093e2 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -2345,8 +2345,12 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file,
 			if (tty->ops->flush_chars)
 				tty->ops->flush_chars(tty);
 		} else {
+			struct n_tty_data *ldata = tty->disc_data;
+
 			while (nr > 0) {
+				mutex_lock(&ldata->output_lock);
 				c = tty->ops->write(tty, b, nr);
+				mutex_unlock(&ldata->output_lock);
 				if (c < 0) {
 					retval = c;
 					goto break_out;
-- 
1.9.1


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

* [PATCH 3.13 2/3] floppy: ignore kernel-only members in FDRAWCMD ioctl input
  2014-05-06 20:42 [3.13.y.z extended stable] Linux 3.13.11.1 stable review (new patches) Kamal Mostafa
  2014-05-06 20:42 ` [PATCH 3.13 1/3] n_tty: Fix n_tty_write crash when echoing in raw mode Kamal Mostafa
@ 2014-05-06 20:42 ` Kamal Mostafa
  2014-05-06 20:42 ` [PATCH 3.13 3/3] floppy: don't write kernel-only members to FDRAWCMD ioctl output Kamal Mostafa
  2 siblings, 0 replies; 4+ messages in thread
From: Kamal Mostafa @ 2014-05-06 20:42 UTC (permalink / raw)
  To: linux-kernel, stable, kernel-team
  Cc: Matthew Daley, Linus Torvalds, Kamal Mostafa

3.13.11.1 -stable review patch.  If anyone has any objections, please let me know.

------------------

From: Matthew Daley <mattd@bugfuzz.com>

commit ef87dbe7614341c2e7bfe8d32fcb7028cc97442c upstream.

Always clear out these floppy_raw_cmd struct members after copying the
entire structure from userspace so that the in-kernel version is always
valid and never left in an interdeterminate state.

Signed-off-by: Matthew Daley <mattd@bugfuzz.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
References: CVE-2014-1737
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
---
 drivers/block/floppy.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index 000abe2..10fbd3f 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -3107,10 +3107,11 @@ loop:
 		return -ENOMEM;
 	*rcmd = ptr;
 	ret = copy_from_user(ptr, param, sizeof(*ptr));
-	if (ret)
-		return -EFAULT;
 	ptr->next = NULL;
 	ptr->buffer_length = 0;
+	ptr->kernel_data = NULL;
+	if (ret)
+		return -EFAULT;
 	param += sizeof(struct floppy_raw_cmd);
 	if (ptr->cmd_count > 33)
 			/* the command may now also take up the space
@@ -3126,7 +3127,6 @@ loop:
 	for (i = 0; i < 16; i++)
 		ptr->reply[i] = 0;
 	ptr->resultcode = 0;
-	ptr->kernel_data = NULL;
 
 	if (ptr->flags & (FD_RAW_READ | FD_RAW_WRITE)) {
 		if (ptr->length <= 0)
-- 
1.9.1


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

* [PATCH 3.13 3/3] floppy: don't write kernel-only members to FDRAWCMD ioctl output
  2014-05-06 20:42 [3.13.y.z extended stable] Linux 3.13.11.1 stable review (new patches) Kamal Mostafa
  2014-05-06 20:42 ` [PATCH 3.13 1/3] n_tty: Fix n_tty_write crash when echoing in raw mode Kamal Mostafa
  2014-05-06 20:42 ` [PATCH 3.13 2/3] floppy: ignore kernel-only members in FDRAWCMD ioctl input Kamal Mostafa
@ 2014-05-06 20:42 ` Kamal Mostafa
  2 siblings, 0 replies; 4+ messages in thread
From: Kamal Mostafa @ 2014-05-06 20:42 UTC (permalink / raw)
  To: linux-kernel, stable, kernel-team
  Cc: Matthew Daley, Linus Torvalds, Kamal Mostafa

3.13.11.1 -stable review patch.  If anyone has any objections, please let me know.

------------------

From: Matthew Daley <mattd@bugfuzz.com>

commit 2145e15e0557a01b9195d1c7199a1b92cb9be81f upstream.

Do not leak kernel-only floppy_raw_cmd structure members to userspace.
This includes the linked-list pointer and the pointer to the allocated
DMA space.

Signed-off-by: Matthew Daley <mattd@bugfuzz.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
References: CVE-2014-1738
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
---
 drivers/block/floppy.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index 10fbd3f..738af94 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -3053,7 +3053,10 @@ static int raw_cmd_copyout(int cmd, void __user *param,
 	int ret;
 
 	while (ptr) {
-		ret = copy_to_user(param, ptr, sizeof(*ptr));
+		struct floppy_raw_cmd cmd = *ptr;
+		cmd.next = NULL;
+		cmd.kernel_data = NULL;
+		ret = copy_to_user(param, &cmd, sizeof(cmd));
 		if (ret)
 			return -EFAULT;
 		param += sizeof(struct floppy_raw_cmd);
-- 
1.9.1


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

end of thread, other threads:[~2014-05-06 20:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-06 20:42 [3.13.y.z extended stable] Linux 3.13.11.1 stable review (new patches) Kamal Mostafa
2014-05-06 20:42 ` [PATCH 3.13 1/3] n_tty: Fix n_tty_write crash when echoing in raw mode Kamal Mostafa
2014-05-06 20:42 ` [PATCH 3.13 2/3] floppy: ignore kernel-only members in FDRAWCMD ioctl input Kamal Mostafa
2014-05-06 20:42 ` [PATCH 3.13 3/3] floppy: don't write kernel-only members to FDRAWCMD ioctl output Kamal Mostafa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®