[PATCH 3.2 17/94] USB: gadgetfs: fix copy_to_user while holding spinlock
From: Ben Hutchings
Date: Thu Dec 28 2017 - 13:29:10 EST
3.2.97-rc1 review patch. If anyone has any objections, please let me know.
From: Alan Stern <stern@xxxxxxxxxxxxxxxxxxx>
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@xxxxxxxxxxxxxxxxxxx>
Reported-by: Andrey Konovalov <andreyknvl@xxxxxxxxxx>
Acked-by: Felipe Balbi <felipe.balbi@xxxxxxxxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
[bwh: Backported to 3.2: adjust filename]
Signed-off-by: Ben Hutchings <ben@xxxxxxxxxxxxxxx>
drivers/usb/gadget/inode.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
@@ -1054,11 +1054,14 @@ ep0_read (struct file *fd, char __user *
retval = -EIO;
len = min (len, (size_t)dev->req->actual);
-// FIXME don't call this with the spinlock held ...
if (copy_to_user (buf, dev->req->buf, len))
retval = -EFAULT;
retval = len;
clean_req (dev->gadget->ep0, dev->req);
/* NOTE userspace can't yet choose to stall */