aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Stern <stern@rowland.harvard.edu>2017-09-21 16:12:01 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-09-22 12:29:00 -0400
commit6e76c01e71551cb221c1f3deacb9dcd9a7346784 (patch)
tree7d82a827794b423e0e7232a87f0656f2aa5add8a
parent786de92b3cb26012d3d0f00ee37adf14527f35c4 (diff)
USB: gadgetfs: fix copy_to_user while holding spinlock
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> CC: <stable@vger.kernel.org> Acked-by: Felipe Balbi <felipe.balbi@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/usb/gadget/legacy/inode.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/drivers/usb/gadget/legacy/inode.c b/drivers/usb/gadget/legacy/inode.c
index 684900fcfe24..956b3dc7c3a4 100644
--- a/drivers/usb/gadget/legacy/inode.c
+++ b/drivers/usb/gadget/legacy/inode.c
@@ -983,11 +983,14 @@ ep0_read (struct file *fd, char __user *buf, size_t len, loff_t *ptr)
983 retval = -EIO; 983 retval = -EIO;
984 else { 984 else {
985 len = min (len, (size_t)dev->req->actual); 985 len = min (len, (size_t)dev->req->actual);
986// FIXME don't call this with the spinlock held ... 986 ++dev->udc_usage;
987 spin_unlock_irq(&dev->lock);
987 if (copy_to_user (buf, dev->req->buf, len)) 988 if (copy_to_user (buf, dev->req->buf, len))
988 retval = -EFAULT; 989 retval = -EFAULT;
989 else 990 else
990 retval = len; 991 retval = len;
992 spin_lock_irq(&dev->lock);
993 --dev->udc_usage;
991 clean_req (dev->gadget->ep0, dev->req); 994 clean_req (dev->gadget->ep0, dev->req);
992 /* NOTE userspace can't yet choose to stall */ 995 /* NOTE userspace can't yet choose to stall */
993 } 996 }