From: Anton Vasilyev <vasilyev@ispras.ru>
To: Felipe Balbi <balbi@kernel.org>
Cc: Anton Vasilyev <vasilyev@ispras.ru>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Alan Stern <stern@rowland.harvard.edu>,
Jussi Kivilinna <jussi.kivilinna@haltian.com>,
Peter Senna Tschudin <peter.senna@collabora.com>,
Raz Manor <Raz.Manor@valens.com>,
Romain Perier <romain.perier@collabora.com>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
ldv-project@linuxtesting.org
Subject: [PATCH] udc: Memory leak on error path and use after free
Date: Wed, 16 Aug 2017 16:47:28 +0300 [thread overview]
Message-ID: <1502891248-7827-1-git-send-email-vasilyev@ispras.ru> (raw)
gadget_release() is responsible for cleanup dev memory.
But if net2280_probe() fails after dev allocation, then
gadget_release() become unregistered and dev memory leaks.
Also net2280_remove() calls usb_del_gadget_udc() which
perform schedule_delayed_work() with gadget_release(), so
it is possible that dev will be deallocated exactly after
this call and leads to use after free.
The patch moves deallocation from gadget_release() to
net2280_remove().
Found by Linux Driver Verififcation project (linuxtesting.org).
Signed-off-by: Anton Vasilyev <vasilyev@ispras.ru>
---
drivers/usb/gadget/udc/net2280.c | 14 +++-----------
1 file changed, 3 insertions(+), 11 deletions(-)
diff --git a/drivers/usb/gadget/udc/net2280.c b/drivers/usb/gadget/udc/net2280.c
index f608c1f..62ac876 100644
--- a/drivers/usb/gadget/udc/net2280.c
+++ b/drivers/usb/gadget/udc/net2280.c
@@ -3546,15 +3546,6 @@ static irqreturn_t net2280_irq(int irq, void *_dev)
return IRQ_HANDLED;
}
-/*-------------------------------------------------------------------------*/
-
-static void gadget_release(struct device *_dev)
-{
- struct net2280 *dev = dev_get_drvdata(_dev);
-
- kfree(dev);
-}
-
/* tear down the binding between this driver and the pci device */
static void net2280_remove(struct pci_dev *pdev)
@@ -3592,6 +3583,8 @@ static void net2280_remove(struct pci_dev *pdev)
device_remove_file(&pdev->dev, &dev_attr_registers);
ep_info(dev, "unbind\n");
+
+ kfree(dev);
}
/* wrap this driver around the specified device, but
@@ -3769,8 +3762,7 @@ static int net2280_probe(struct pci_dev *pdev, const struct pci_device_id *id)
if (retval)
goto done;
- retval = usb_add_gadget_udc_release(&pdev->dev, &dev->gadget,
- gadget_release);
+ retval = usb_add_gadget_udc(&pdev->dev, &dev->gadget);
if (retval)
goto done;
return 0;
--
2.7.4
next reply other threads:[~2017-08-16 13:47 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-16 13:47 Anton Vasilyev [this message]
2017-08-16 15:29 ` Alan Stern
2017-08-16 16:00 ` Anton Vasilyev
2017-08-16 16:35 ` Alan Stern
2017-08-22 15:45 ` Anton Vasilyev
2017-08-22 18:37 ` Alan Stern
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=1502891248-7827-1-git-send-email-vasilyev@ispras.ru \
--to=vasilyev@ispras.ru \
--cc=Raz.Manor@valens.com \
--cc=balbi@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=jussi.kivilinna@haltian.com \
--cc=ldv-project@linuxtesting.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=peter.senna@collabora.com \
--cc=romain.perier@collabora.com \
--cc=stern@rowland.harvard.edu \
/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®