Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1736973

Re: usb/gadget: copy_to_user called with spinlock held

From Alan Stern <stern@rowland.harvard.edu>
Newsgroups linux.kernel
Subject Re: usb/gadget: copy_to_user called with spinlock held
Date 2017-09-21 19:40 +0200
Message-ID <usdCa-3YA-21@gated-at.bofh.it> (permalink)
References <uscPM-3sF-13@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Thu, 21 Sep 2017, Andrey Konovalov wrote:

> Hi!
> 
> I've got the following report while fuzzing the kernel with syzkaller.
> 
> On commit ebb2c2437d8008d46796902ff390653822af6cc4 (Sep 18).
> 
> Line numbers might be a little off, due to some local changes to
> gadgetfs code but the issue is AFAIU with calling copy_to_user() with
> spinlock held in ep0_read(). I see that there's a FIXME exactly about
> that and I was wondering if there's any chance of getting this fixed?
> 
> Thanks!

The patch below, which goes on top of the gadgetfs patch from a few
days ago, should eliminate this problem.

Alan Stern



Index: usb-4.x/drivers/usb/gadget/legacy/inode.c
===================================================================
--- usb-4.x.orig/drivers/usb/gadget/legacy/inode.c
+++ usb-4.x/drivers/usb/gadget/legacy/inode.c
@@ -986,11 +986,14 @@ ep0_read (struct file *fd, char __user *
 				retval = -EIO;
 			else {
 				len = min (len, (size_t)dev->req->actual);
-// FIXME don't call this with the spinlock held ...
+				++dev->udc_usage;
+				spin_unlock_irq(&dev->lock);
 				if (copy_to_user (buf, dev->req->buf, len))
 					retval = -EFAULT;
 				else
 					retval = len;
+				spin_lock_irq(&dev->lock);
+				--dev->udc_usage;
 				clean_req (dev->gadget->ep0, dev->req);
 				/* NOTE userspace can't yet choose to stall */
 			}

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

usb/gadget: copy_to_user called with spinlock held Andrey Konovalov <andreyknvl@google.com> - 2017-09-21 18:50 +0200
  Re: usb/gadget: copy_to_user called with spinlock held Alan Stern <stern@rowland.harvard.edu> - 2017-09-21 19:40 +0200
    Re: usb/gadget: copy_to_user called with spinlock held Andrey Konovalov <andreyknvl@google.com> - 2017-09-21 20:30 +0200

csiph-web