]> git.proxmox.com Git - mirror_ubuntu-disco-kernel.git/commitdiff
USB: fix usbfs regression
authorAlan Stern <stern@rowland.harvard.edu>
Sat, 6 Mar 2010 20:04:03 +0000 (15:04 -0500)
committerGreg Kroah-Hartman <gregkh@suse.de>
Fri, 19 Mar 2010 14:24:02 +0000 (07:24 -0700)
This patch (as1352) fixes a bug in the way isochronous input data is
returned to userspace for usbfs transfers.  The entire buffer must be
copied, not just the first actual_length bytes, because the individual
packets will be discontiguous if any of them are short.

Reported-by: Markus Rechberger <mrechberger@gmail.com>
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
CC: stable <stable@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/usb/core/devio.c

index e909ff7b9094051c1ea1812d1252718d96ba23cc..3466fdc5bb11e7cdc42871982c5e85cde38ae0bc 100644 (file)
@@ -1207,6 +1207,13 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
                        free_async(as);
                        return -ENOMEM;
                }
+               /* Isochronous input data may end up being discontiguous
+                * if some of the packets are short.  Clear the buffer so
+                * that the gaps don't leak kernel data to userspace.
+                */
+               if (is_in && uurb->type == USBDEVFS_URB_TYPE_ISO)
+                       memset(as->urb->transfer_buffer, 0,
+                                       uurb->buffer_length);
        }
        as->urb->dev = ps->dev;
        as->urb->pipe = (uurb->type << 30) |
@@ -1345,10 +1352,14 @@ static int processcompl(struct async *as, void __user * __user *arg)
        void __user *addr = as->userurb;
        unsigned int i;
 
-       if (as->userbuffer && urb->actual_length)
-               if (copy_to_user(as->userbuffer, urb->transfer_buffer,
-                                urb->actual_length))
+       if (as->userbuffer && urb->actual_length) {
+               if (urb->number_of_packets > 0)         /* Isochronous */
+                       i = urb->transfer_buffer_length;
+               else                                    /* Non-Isoc */
+                       i = urb->actual_length;
+               if (copy_to_user(as->userbuffer, urb->transfer_buffer, i))
                        goto err_out;
+       }
        if (put_user(as->status, &userurb->status))
                goto err_out;
        if (put_user(urb->actual_length, &userurb->actual_length))