mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hangyu Hua <hbh25y@gmail.com>
To: gregkh@linuxfoundation.org
Cc: stable@vger.kernel.org, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org, ben@decadent.org.uk,
	balbi@kernel.org, axboe@kernel.dk, mingo@kernel.org,
	jj251510319013@gmail.com, zsm@chromium.org,
	stern@rowland.harvard.edu, Hangyu Hua <hbh25y@gmail.com>
Subject: [PATCH 4.14 2/2] usb: gadget: clear related members when goto fail
Date: Tue,  1 Mar 2022 10:26:08 +0800	[thread overview]
Message-ID: <20220301022608.10950-3-hbh25y@gmail.com> (raw)
In-Reply-To: <20220301022608.10950-1-hbh25y@gmail.com>

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


      parent reply	other threads:[~2022-03-01  2:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220301022608.10950-3-hbh25y@gmail.com \
    --to=hbh25y@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=balbi@kernel.org \
    --cc=ben@decadent.org.uk \
    --cc=gregkh@linuxfoundation.org \
    --cc=jj251510319013@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=stern@rowland.harvard.edu \
    --cc=zsm@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®