All of lore.kernel.org
 help / color / mirror / Atom feed
* Patch "USB: devio: Don't corrupt user memory" has been added to the 4.4-stable tree
@ 2017-10-09 11:31 gregkh
  2017-10-17 14:36 ` Ben Hutchings
  0 siblings, 1 reply; 4+ messages in thread
From: gregkh @ 2017-10-09 11:31 UTC (permalink / raw)
  To: dan.carpenter, gregkh, stern; +Cc: stable, stable-commits


This is a note to let you know that I've just added the patch titled

    USB: devio: Don't corrupt user memory

to the 4.4-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     usb-devio-don-t-corrupt-user-memory.patch
and it can be found in the queue-4.4 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@vger.kernel.org> know about it.


>From fa1ed74eb1c233be6131ec92df21ab46499a15b6 Mon Sep 17 00:00:00 2001
From: Dan Carpenter <dan.carpenter@oracle.com>
Date: Fri, 22 Sep 2017 23:43:46 +0300
Subject: USB: devio: Don't corrupt user memory

From: Dan Carpenter <dan.carpenter@oracle.com>

commit fa1ed74eb1c233be6131ec92df21ab46499a15b6 upstream.

The user buffer has "uurb->buffer_length" bytes.  If the kernel has more
information than that, we should truncate it instead of writing past
the end of the user's buffer.  I added a WARN_ONCE() to help the user
debug the issue.

Reported-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 drivers/usb/core/devio.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -1417,7 +1417,11 @@ static int proc_do_submiturb(struct usb_
 			totlen += isopkt[u].length;
 		}
 		u *= sizeof(struct usb_iso_packet_descriptor);
-		uurb->buffer_length = totlen;
+		if (totlen <= uurb->buffer_length)
+			uurb->buffer_length = totlen;
+		else
+			WARN_ONCE(1, "uurb->buffer_length is too short %d vs %d",
+				  totlen, uurb->buffer_length);
 		break;
 
 	default:


Patches currently in stable-queue which might be from dan.carpenter@oracle.com are

queue-4.4/usb-devio-don-t-corrupt-user-memory.patch

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

* Re: Patch "USB: devio: Don't corrupt user memory" has been added to the 4.4-stable tree
  2017-10-09 11:31 Patch "USB: devio: Don't corrupt user memory" has been added to the 4.4-stable tree gregkh
@ 2017-10-17 14:36 ` Ben Hutchings
  2017-10-17 14:48   ` Dan Carpenter
  2017-10-17 14:58   ` Greg Kroah-Hartman
  0 siblings, 2 replies; 4+ messages in thread
From: Ben Hutchings @ 2017-10-17 14:36 UTC (permalink / raw)
  To: dan.carpenter, stern; +Cc: stable, stable-commits, Greg Kroah-Hartman

On Mon, 2017-10-09 at 13:31 +0200, gregkh@linuxfoundation.org wrote:
[...]
> From: Dan Carpenter <dan.carpenter@oracle.com>
> 
> commit fa1ed74eb1c233be6131ec92df21ab46499a15b6 upstream.
> 
> The user buffer has "uurb->buffer_length" bytes.  If the kernel has more
> information than that, we should truncate it instead of writing past
> the end of the user's buffer.  I added a WARN_ONCE() to help the user
> debug the issue.
[...]

Users should not be able to provoke a WARN_ON at will, that's a DoS
(log spam, possible panic).

And this truncated user buffer length is also used for allocation of
the kernel buffer.  Are you totally sure that this can't result in a
kernel buffer overrun (or leak)?

This fix seems worse than continuing to allow userspace to shoot itself
in the foot.

Ben.

-- 
Ben Hutchings
Software Developer, Codethink Ltd.

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

* Re: Patch "USB: devio: Don't corrupt user memory" has been added to the 4.4-stable tree
  2017-10-17 14:36 ` Ben Hutchings
@ 2017-10-17 14:48   ` Dan Carpenter
  2017-10-17 14:58   ` Greg Kroah-Hartman
  1 sibling, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2017-10-17 14:48 UTC (permalink / raw)
  To: Ben Hutchings; +Cc: stern, stable, stable-commits, Greg Kroah-Hartman

On Tue, Oct 17, 2017 at 03:36:10PM +0100, Ben Hutchings wrote:
> On Mon, 2017-10-09 at 13:31 +0200, gregkh@linuxfoundation.org wrote:
> [...]
> > From: Dan Carpenter <dan.carpenter@oracle.com>
> > 
> > commit fa1ed74eb1c233be6131ec92df21ab46499a15b6 upstream.
> > 
> > The user buffer has "uurb->buffer_length" bytes.��If the kernel has more
> > information than that, we should truncate it instead of writing past
> > the end of the user's buffer.��I added a WARN_ONCE() to help the user
> > debug the issue.
> [...]
> 
> Users should not be able to provoke a WARN_ON at will, that's a DoS
> (log spam, possible panic).
> 
> And this truncated user buffer length is also used for allocation of
> the kernel buffer.  Are you totally sure that this can't result in a
> kernel buffer overrun (or leak)?
> 
> This fix seems worse than continuing to allow userspace to shoot itself
> in the foot.
> 

We don't want to add this because it breaks API and does actually lead
to a leak.  But it was a WARN_ONCE() not, a WARN_ON() so that part was
ok.  Probably it helped find the bug in my code.

regards,
dan carpenter

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

* Re: Patch "USB: devio: Don't corrupt user memory" has been added to the 4.4-stable tree
  2017-10-17 14:36 ` Ben Hutchings
  2017-10-17 14:48   ` Dan Carpenter
@ 2017-10-17 14:58   ` Greg Kroah-Hartman
  1 sibling, 0 replies; 4+ messages in thread
From: Greg Kroah-Hartman @ 2017-10-17 14:58 UTC (permalink / raw)
  To: Ben Hutchings; +Cc: dan.carpenter, stern, stable, stable-commits

On Tue, Oct 17, 2017 at 03:36:10PM +0100, Ben Hutchings wrote:
> On Mon, 2017-10-09 at 13:31 +0200, gregkh@linuxfoundation.org wrote:
> [...]
> > From: Dan Carpenter <dan.carpenter@oracle.com>
> > 
> > commit fa1ed74eb1c233be6131ec92df21ab46499a15b6 upstream.
> > 
> > The user buffer has "uurb->buffer_length" bytes.��If the kernel has more
> > information than that, we should truncate it instead of writing past
> > the end of the user's buffer.��I added a WARN_ONCE() to help the user
> > debug the issue.
> [...]
> 
> Users should not be able to provoke a WARN_ON at will, that's a DoS
> (log spam, possible panic).
> 
> And this truncated user buffer length is also used for allocation of
> the kernel buffer.  Are you totally sure that this can't result in a
> kernel buffer overrun (or leak)?
> 
> This fix seems worse than continuing to allow userspace to shoot itself
> in the foot.

A fix reverting this has gone into my tree right now, and will get to
Linus real-soon, to fix this issue.

thanks,

greg k-h

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

end of thread, other threads:[~2017-10-17 14:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-09 11:31 Patch "USB: devio: Don't corrupt user memory" has been added to the 4.4-stable tree gregkh
2017-10-17 14:36 ` Ben Hutchings
2017-10-17 14:48   ` Dan Carpenter
2017-10-17 14:58   ` Greg Kroah-Hartman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.