public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: gadgetfs: correct dev state
@ 2014-06-05 13:08 Marcus Nutzinger
  2014-06-05 14:18 ` Sergei Shtylyov
  2014-06-05 15:17 ` [PATCH v2] " Marcus Nutzinger
  0 siblings, 2 replies; 5+ messages in thread
From: Marcus Nutzinger @ 2014-06-05 13:08 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: Greg Kroah-Hartman, linux-usb, linux-kernel, Marcus Nutzinger

Commit 1826e9b1 fixes the use after free of "dev".
However if this is not the final call to dev_release()
and the state is not reset to STATE_DEV_DISABLED and
hence all further open() calls to the gadgetfs ep0
device will fail with EBUSY.

So this commit reverts 1826e9b1 and places the call
put_dev() after setting the state.

Signed-off-by: Marcus Nutzinger <marcus.nutzinger@theobroma-systems.com>
Reviewed-by: Christoph Muellner <christoph.muellner@theobroma-systems.com>
---
 drivers/usb/gadget/inode.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c
index a925d0c..6330528 100644
--- a/drivers/usb/gadget/inode.c
+++ b/drivers/usb/gadget/inode.c
@@ -1264,8 +1264,13 @@ dev_release (struct inode *inode, struct file *fd)
 
 	kfree (dev->buf);
 	dev->buf = NULL;
-	put_dev (dev);
 
+	/* other endpoints were all decoupled from this device */
+	spin_lock_irq(&dev->lock);
+	dev->state = STATE_DEV_DISABLED;
+	spin_unlock_irq(&dev->lock);
+
+	put_dev (dev);
 	return 0;
 }
 
-- 
1.9.0


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

end of thread, other threads:[~2014-06-05 16:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-05 13:08 [PATCH] usb: gadget: gadgetfs: correct dev state Marcus Nutzinger
2014-06-05 14:18 ` Sergei Shtylyov
2014-06-05 15:15   ` Marcus Nutzinger
2014-06-05 16:04     ` Alan Stern
2014-06-05 15:17 ` [PATCH v2] " Marcus Nutzinger

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