Linux-USB Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] net: usbnet: fix a memory leak bug
@ 2019-08-14 17:41 Wenwen Wang
  2019-08-14 21:32 ` Jack Pham
  2019-08-15 10:42 ` Oliver Neukum
  0 siblings, 2 replies; 3+ messages in thread
From: Wenwen Wang @ 2019-08-14 17:41 UTC (permalink / raw)
  To: Wenwen Wang
  Cc: Oliver Neukum, David S. Miller, netdev, linux-usb, linux-kernel

In usbnet_start_xmit(), 'urb->sg' is allocated through kmalloc_array() by
invoking build_dma_sg(). Later on, if 'CONFIG_PM' is defined and the if
branch is taken, the execution will go to the label 'deferred'. However,
'urb->sg' is not deallocated on this execution path, leading to a memory
leak bug.

Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu>
---
 drivers/net/usb/usbnet.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
index 72514c4..f17fafa 100644
--- a/drivers/net/usb/usbnet.c
+++ b/drivers/net/usb/usbnet.c
@@ -1433,6 +1433,7 @@ netdev_tx_t usbnet_start_xmit (struct sk_buff *skb,
 		usb_anchor_urb(urb, &dev->deferred);
 		/* no use to process more packets */
 		netif_stop_queue(net);
+		kfree(urb->sg);
 		usb_put_urb(urb);
 		spin_unlock_irqrestore(&dev->txq.lock, flags);
 		netdev_dbg(dev->net, "Delaying transmission for resumption\n");
-- 
2.7.4


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

* Re: [PATCH] net: usbnet: fix a memory leak bug
  2019-08-14 17:41 [PATCH] net: usbnet: fix a memory leak bug Wenwen Wang
@ 2019-08-14 21:32 ` Jack Pham
  2019-08-15 10:42 ` Oliver Neukum
  1 sibling, 0 replies; 3+ messages in thread
From: Jack Pham @ 2019-08-14 21:32 UTC (permalink / raw)
  To: Wenwen Wang
  Cc: Oliver Neukum, David S. Miller,
	open list:USB \"USBNET\" DRIVER FRAMEWORK,
	open list:USB NETWORKING DRIVERS, open list

On Wed, Aug 14, 2019 at 12:41:33PM -0500, Wenwen Wang wrote:
> In usbnet_start_xmit(), 'urb->sg' is allocated through kmalloc_array() by
> invoking build_dma_sg(). Later on, if 'CONFIG_PM' is defined and the if
> branch is taken, the execution will go to the label 'deferred'. However,
> 'urb->sg' is not deallocated on this execution path, leading to a memory
> leak bug.
> 
> Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu>
> ---
>  drivers/net/usb/usbnet.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
> index 72514c4..f17fafa 100644
> --- a/drivers/net/usb/usbnet.c
> +++ b/drivers/net/usb/usbnet.c
> @@ -1433,6 +1433,7 @@ netdev_tx_t usbnet_start_xmit (struct sk_buff *skb,
>  		usb_anchor_urb(urb, &dev->deferred);
>  		/* no use to process more packets */
>  		netif_stop_queue(net);
> +		kfree(urb->sg);
>  		usb_put_urb(urb);

The URB itself is not getting freed here; it is merely added to the
anchor list and will be submitted later upon usbnet_resume(). Therefore
freeing the SG list is premature and incorrect, as it will get freed in
either the tx_complete/tx_done path or upon URB submission failure.

>  		spin_unlock_irqrestore(&dev->txq.lock, flags);
>  		netdev_dbg(dev->net, "Delaying transmission for resumption\n");

Jack
-- 
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

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

* Re: [PATCH] net: usbnet: fix a memory leak bug
  2019-08-14 17:41 [PATCH] net: usbnet: fix a memory leak bug Wenwen Wang
  2019-08-14 21:32 ` Jack Pham
@ 2019-08-15 10:42 ` Oliver Neukum
  1 sibling, 0 replies; 3+ messages in thread
From: Oliver Neukum @ 2019-08-15 10:42 UTC (permalink / raw)
  To: Wenwen Wang
  Cc: David S. Miller, open list, open list:USB NETWORKING DRIVERS,
	open list:USB USBNET DRIVER FRAMEWORK

Am Mittwoch, den 14.08.2019, 12:41 -0500 schrieb Wenwen Wang:
> In usbnet_start_xmit(), 'urb->sg' is allocated through kmalloc_array() by
> invoking build_dma_sg(). Later on, if 'CONFIG_PM' is defined and the if
> branch is taken, the execution will go to the label 'deferred'. However,
> 'urb->sg' is not deallocated on this execution path, leading to a memory
> leak bug.

Just to make this clear:

> Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu>
NACK

For the reason Jack explained. Deferral is not a failure.

	Regards
		Oliver


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

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-14 17:41 [PATCH] net: usbnet: fix a memory leak bug Wenwen Wang
2019-08-14 21:32 ` Jack Pham
2019-08-15 10:42 ` Oliver Neukum

Linux-USB Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-usb/0 linux-usb/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-usb linux-usb/ https://lore.kernel.org/linux-usb \
		linux-usb@vger.kernel.org linux-usb@archiver.kernel.org
	public-inbox-index linux-usb


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-usb


AGPL code for this site: git clone https://public-inbox.org/ public-inbox