public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] USB: inode.c: fix unbalanced spin_lock in ep0_write
@ 2015-12-11 19:56 David Eccher
  2015-12-11 20:11 ` Al Viro
  2015-12-11 20:57 ` Sergei Shtylyov
  0 siblings, 2 replies; 4+ messages in thread
From: David Eccher @ 2015-12-11 19:56 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: Greg Kroah-Hartman, Al Viro, linux-usb, linux-kernel,
	David Eccher

Fix bad unlock balance: ep0_write enter with the locks locked from inode.c:1769,
hence it must exit with spinlock held to avoid double unlock in dev_config.

Signed-off-by: David Eccher <d.eccher@gmail.com>
---
 drivers/usb/gadget/legacy/inode.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/usb/gadget/legacy/inode.c b/drivers/usb/gadget/legacy/inode.c
index f454c7a..b968c25 100644
--- a/drivers/usb/gadget/legacy/inode.c
+++ b/drivers/usb/gadget/legacy/inode.c
@@ -1144,6 +1144,7 @@ ep0_write (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
 				} else
 					retval = len;
 
+				spin_lock_irq (&dev->lock);
 				return retval;
 			}
 
-- 
1.8.1.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/1] USB: inode.c: fix unbalanced spin_lock in ep0_write
  2015-12-11 19:56 [PATCH 1/1] USB: inode.c: fix unbalanced spin_lock in ep0_write David Eccher
@ 2015-12-11 20:11 ` Al Viro
  2015-12-11 21:12   ` David Eccher
  2015-12-11 20:57 ` Sergei Shtylyov
  1 sibling, 1 reply; 4+ messages in thread
From: Al Viro @ 2015-12-11 20:11 UTC (permalink / raw)
  To: David Eccher; +Cc: Felipe Balbi, Greg Kroah-Hartman, linux-usb, linux-kernel

On Fri, Dec 11, 2015 at 08:56:26PM +0100, David Eccher wrote:
> Fix bad unlock balance: ep0_write enter with the locks locked from inode.c:1769,
> hence it must exit with spinlock held to avoid double unlock in dev_config.

*Ugh*

Just take that spinlock before the if (retval < 0) and don't drop it after
clear_req(), then...

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/1] USB: inode.c: fix unbalanced spin_lock in ep0_write
  2015-12-11 19:56 [PATCH 1/1] USB: inode.c: fix unbalanced spin_lock in ep0_write David Eccher
  2015-12-11 20:11 ` Al Viro
@ 2015-12-11 20:57 ` Sergei Shtylyov
  1 sibling, 0 replies; 4+ messages in thread
From: Sergei Shtylyov @ 2015-12-11 20:57 UTC (permalink / raw)
  To: David Eccher, Felipe Balbi
  Cc: Greg Kroah-Hartman, Al Viro, linux-usb, linux-kernel

Hello.

On 12/11/2015 10:56 PM, David Eccher wrote:

> Fix bad unlock balance: ep0_write enter with the locks locked from inode.c:1769,
> hence it must exit with spinlock held to avoid double unlock in dev_config.
>
> Signed-off-by: David Eccher <d.eccher@gmail.com>
> ---
>   drivers/usb/gadget/legacy/inode.c | 1 +
>   1 file changed, 1 insertion(+)
>
> diff --git a/drivers/usb/gadget/legacy/inode.c b/drivers/usb/gadget/legacy/inode.c
> index f454c7a..b968c25 100644
> --- a/drivers/usb/gadget/legacy/inode.c
> +++ b/drivers/usb/gadget/legacy/inode.c
> @@ -1144,6 +1144,7 @@ ep0_write (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
>   				} else
>   					retval = len;
>
> +				spin_lock_irq (&dev->lock);

    I guess you hadn't run the patch thru scripts/checkpatch.pl?

MBR, Sergei


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/1] USB: inode.c: fix unbalanced spin_lock in ep0_write
  2015-12-11 20:11 ` Al Viro
@ 2015-12-11 21:12   ` David Eccher
  0 siblings, 0 replies; 4+ messages in thread
From: David Eccher @ 2015-12-11 21:12 UTC (permalink / raw)
  To: Al Viro; +Cc: Felipe Balbi, Greg Kroah-Hartman, linux-usb, linux-kernel

On Fri, Dec 11, 2015 at 9:11 PM, Al Viro <viro@zeniv.linux.org.uk> wrote:
>
> On Fri, Dec 11, 2015 at 08:56:26PM +0100, David Eccher wrote:
> > Fix bad unlock balance: ep0_write enter with the locks locked from inode.c:1769,
> > hence it must exit with spinlock held to avoid double unlock in dev_config.
>
> *Ugh*
>
> Just take that spinlock before the if (retval < 0) and don't drop it after
> clear_req(), then...

Oh, yeah good point, I'll send a v2...and test the patch thru
checkpatch.pl, sorry



-- 
David Eccher

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-12-11 21:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-11 19:56 [PATCH 1/1] USB: inode.c: fix unbalanced spin_lock in ep0_write David Eccher
2015-12-11 20:11 ` Al Viro
2015-12-11 21:12   ` David Eccher
2015-12-11 20:57 ` Sergei Shtylyov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox