linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jack Pham <jackp@codeaurora.org>
To: Wenwen Wang <wenwen@cs.uga.edu>
Cc: Oliver Neukum <oneukum@suse.com>,
	"David S. Miller" <davem@davemloft.net>,
	"open list:USB \"USBNET\" DRIVER FRAMEWORK"
	<netdev@vger.kernel.org>,
	"open list:USB NETWORKING DRIVERS" <linux-usb@vger.kernel.org>,
	open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] net: usbnet: fix a memory leak bug
Date: Wed, 14 Aug 2019 14:32:03 -0700	[thread overview]
Message-ID: <20190814213203.GA9754@jackp-linux.qualcomm.com> (raw)
In-Reply-To: <1565804493-7758-1-git-send-email-wenwen@cs.uga.edu>

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

  reply	other threads:[~2019-08-14 21:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-14 17:41 [PATCH] net: usbnet: fix a memory leak bug Wenwen Wang
2019-08-14 21:32 ` Jack Pham [this message]
2019-08-15 10:42 ` Oliver Neukum

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=20190814213203.GA9754@jackp-linux.qualcomm.com \
    --to=jackp@codeaurora.org \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=oneukum@suse.com \
    --cc=wenwen@cs.uga.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;
as well as URLs for NNTP newsgroup(s).