mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 4.14 0/2] usb: gadget: use after free in dev_config
@ 2022-03-01  2:26 Hangyu Hua
  2022-03-01  2:26 ` [PATCH 4.14 1/2] usb: gadget: don't release an existing dev->buf Hangyu Hua
  2022-03-01  2:26 ` [PATCH 4.14 2/2] usb: gadget: clear related members when goto fail Hangyu Hua
  0 siblings, 2 replies; 3+ messages in thread
From: Hangyu Hua @ 2022-03-01  2:26 UTC (permalink / raw)
  To: gregkh
  Cc: stable, linux-usb, linux-kernel, ben, balbi, axboe, mingo,
	jj251510319013, zsm, stern, Hangyu Hua

Author: Hangyu Hua <hbh25y@gmail.com>
commit 89f3594d0de5 ("usb: gadget: don't release an existing dev->buf")

Author: Hangyu Hua <hbh25y@gmail.com>
commit 501e38a5531e ("usb: gadget: clear related members when goto fail")

Add two commits to all stable branches.

There are two bugs:
dev->buf does not need to be released if it already exists before
executing dev_config.
dev->config and dev->hs_config and dev->dev need to be cleaned if
dev_config fails to avoid UAF.

Hangyu Hua (2):
  usb: gadget: don't release an existing dev->buf
  usb: gadget: clear related members when goto fail

 drivers/usb/gadget/legacy/inode.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

-- 
2.25.1


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

* [PATCH 4.14 1/2] usb: gadget: don't release an existing dev->buf
  2022-03-01  2:26 [PATCH 4.14 0/2] usb: gadget: use after free in dev_config Hangyu Hua
@ 2022-03-01  2:26 ` Hangyu Hua
  2022-03-01  2:26 ` [PATCH 4.14 2/2] usb: gadget: clear related members when goto fail Hangyu Hua
  1 sibling, 0 replies; 3+ messages in thread
From: Hangyu Hua @ 2022-03-01  2:26 UTC (permalink / raw)
  To: gregkh
  Cc: stable, linux-usb, linux-kernel, ben, balbi, axboe, mingo,
	jj251510319013, zsm, stern, Hangyu Hua

dev->buf does not need to be released if it already exists before
executing dev_config.

Acked-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Hangyu Hua <hbh25y@gmail.com>
Link: https://lore.kernel.org/r/20211231172138.7993-2-hbh25y@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: stable@vger.kernel.org #4.4+
---
 drivers/usb/gadget/legacy/inode.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/legacy/inode.c b/drivers/usb/gadget/legacy/inode.c
index 3b58f4fc0a80..eaad03c0252f 100644
--- a/drivers/usb/gadget/legacy/inode.c
+++ b/drivers/usb/gadget/legacy/inode.c
@@ -1826,8 +1826,9 @@ dev_config (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
 	spin_lock_irq (&dev->lock);
 	value = -EINVAL;
 	if (dev->buf) {
+		spin_unlock_irq(&dev->lock);
 		kfree(kbuf);
-		goto fail;
+		return value;
 	}
 	dev->buf = kbuf;
 
-- 
2.25.1


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

* [PATCH 4.14 2/2] usb: gadget: clear related members when goto fail
  2022-03-01  2:26 [PATCH 4.14 0/2] usb: gadget: use after free in dev_config Hangyu Hua
  2022-03-01  2:26 ` [PATCH 4.14 1/2] usb: gadget: don't release an existing dev->buf Hangyu Hua
@ 2022-03-01  2:26 ` Hangyu Hua
  1 sibling, 0 replies; 3+ messages in thread
From: Hangyu Hua @ 2022-03-01  2:26 UTC (permalink / raw)
  To: gregkh
  Cc: stable, linux-usb, linux-kernel, ben, balbi, axboe, mingo,
	jj251510319013, zsm, stern, Hangyu Hua

dev->config and dev->hs_config and dev->dev need to be cleaned if
dev_config fails to avoid UAF.

Acked-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Hangyu Hua <hbh25y@gmail.com>
Link: https://lore.kernel.org/r/20211231172138.7993-2-hbh25y@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: stable@vger.kernel.org #4.4+
---
 drivers/usb/gadget/legacy/inode.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/legacy/inode.c b/drivers/usb/gadget/legacy/inode.c
index eaad03c0252f..25c8809e0a38 100644
--- a/drivers/usb/gadget/legacy/inode.c
+++ b/drivers/usb/gadget/legacy/inode.c
@@ -1875,8 +1875,8 @@ dev_config (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
 
 	value = usb_gadget_probe_driver(&gadgetfs_driver);
 	if (value != 0) {
-		kfree (dev->buf);
-		dev->buf = NULL;
+		spin_lock_irq(&dev->lock);
+		goto fail;
 	} else {
 		/* at this point "good" hardware has for the first time
 		 * let the USB the host see us.  alternatively, if users
@@ -1893,6 +1893,9 @@ dev_config (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
 	return value;
 
 fail:
+	dev->config = NULL;
+	dev->hs_config = NULL;
+	dev->dev = NULL;
 	spin_unlock_irq (&dev->lock);
 	pr_debug ("%s: %s fail %zd, %p\n", shortname, __func__, value, dev);
 	kfree (dev->buf);
-- 
2.25.1


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

end of thread, other threads:[~2022-03-01  2:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-01  2:26 [PATCH 4.14 0/2] usb: gadget: use after free in dev_config Hangyu Hua
2022-03-01  2:26 ` [PATCH 4.14 1/2] usb: gadget: don't release an existing dev->buf Hangyu Hua
2022-03-01  2:26 ` [PATCH 4.14 2/2] usb: gadget: clear related members when goto fail Hangyu Hua

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

all inboxes | Powered by JetHome®