Skip to content

Commit f72264e

Browse files
AlanSterngregkh
authored andcommitted
USB: gadgetfs: fix copy_to_user while holding spinlock
commit 6e76c01e71551cb221c1f3deacb9dcd9a7346784 upstream. The gadgetfs driver as a long-outstanding FIXME, regarding a call of copy_to_user() made while holding a spinlock. This patch fixes the issue by dropping the spinlock and using the dev->udc_usage mechanism introduced by another recent patch to guard against status changes while the lock isn't held. Signed-off-by: Alan Stern <stern@rowland.harvard.edu> Reported-by: Andrey Konovalov <andreyknvl@google.com> Acked-by: Felipe Balbi <felipe.balbi@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent d20fff0 commit f72264e

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

drivers/usb/gadget/legacy/inode.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -985,11 +985,14 @@ ep0_read (struct file *fd, char __user *buf, size_t len, loff_t *ptr)
985985
retval = -EIO;
986986
else {
987987
len = min (len, (size_t)dev->req->actual);
988-
// FIXME don't call this with the spinlock held ...
988+
++dev->udc_usage;
989+
spin_unlock_irq(&dev->lock);
989990
if (copy_to_user (buf, dev->req->buf, len))
990991
retval = -EFAULT;
991992
else
992993
retval = len;
994+
spin_lock_irq(&dev->lock);
995+
--dev->udc_usage;
993996
clean_req (dev->gadget->ep0, dev->req);
994997
/* NOTE userspace can't yet choose to stall */
995998
}

0 commit comments

Comments
 (0)