Linux-HyperV Archive on lore.kernel.org
 help / color / Atom feed
From: Haiyang Zhang <haiyangz@microsoft.com>
To: Mohammed Gamal <mgamal@redhat.com>,
	"linux-hyperv@vger.kernel.org" <linux-hyperv@vger.kernel.org>,
	Stephen Hemminger <sthemmin@microsoft.com>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>
Cc: KY Srinivasan <kys@microsoft.com>,
	"sashal@kernel.org" <sashal@kernel.org>,
	vkuznets <vkuznets@redhat.com>, cavery <cavery@redhat.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH v2] hv_netvsc: Fix memory leak when removing rndis device
Date: Tue, 14 Jan 2020 13:20:35 +0000
Message-ID: <MN2PR21MB1375B535C440C4AEFC30827ECA340@MN2PR21MB1375.namprd21.prod.outlook.com> (raw)
In-Reply-To: <20200114130950.6962-1-mgamal@redhat.com>



> -----Original Message-----
> From: Mohammed Gamal <mgamal@redhat.com>
> Sent: Tuesday, January 14, 2020 8:10 AM
> To: linux-hyperv@vger.kernel.org; Stephen Hemminger
> <sthemmin@microsoft.com>; Haiyang Zhang <haiyangz@microsoft.com>;
> netdev@vger.kernel.org
> Cc: KY Srinivasan <kys@microsoft.com>; sashal@kernel.org; vkuznets
> <vkuznets@redhat.com>; cavery <cavery@redhat.com>; linux-
> kernel@vger.kernel.org; Mohammed Gamal <mgamal@redhat.com>
> Subject: [PATCH v2] hv_netvsc: Fix memory leak when removing rndis device
> 
> kmemleak detects the following memory leak when hot removing a network
> device:
> 
> unreferenced object 0xffff888083f63600 (size 256):
>   comm "kworker/0:1", pid 12, jiffies 4294831717 (age 1113.676s)
>   hex dump (first 32 bytes):
>     00 40 c7 33 80 88 ff ff 00 00 00 00 10 00 00 00  .@.3............
>     00 00 00 00 ad 4e ad de ff ff ff ff 00 00 00 00  .....N..........
>   backtrace:
>     [<00000000d4a8f5be>] rndis_filter_device_add+0x117/0x11c0 [hv_netvsc]
>     [<000000009c02d75b>] netvsc_probe+0x5e7/0xbf0 [hv_netvsc]
>     [<00000000ddafce23>] vmbus_probe+0x74/0x170 [hv_vmbus]
>     [<00000000046e64f1>] really_probe+0x22f/0xb50
>     [<000000005cc35eb7>] driver_probe_device+0x25e/0x370
>     [<0000000043c642b2>] bus_for_each_drv+0x11f/0x1b0
>     [<000000005e3d09f0>] __device_attach+0x1c6/0x2f0
>     [<00000000a72c362f>] bus_probe_device+0x1a6/0x260
>     [<0000000008478399>] device_add+0x10a3/0x18e0
>     [<00000000cf07b48c>] vmbus_device_register+0xe7/0x1e0 [hv_vmbus]
>     [<00000000d46cf032>] vmbus_add_channel_work+0x8ab/0x1770 [hv_vmbus]
>     [<000000002c94bb64>] process_one_work+0x919/0x17d0
>     [<0000000096de6781>] worker_thread+0x87/0xb40
>     [<00000000fbe7397e>] kthread+0x333/0x3f0
>     [<000000004f844269>] ret_from_fork+0x3a/0x50
> 
> rndis_filter_device_add() allocates an instance of struct rndis_device which
> never gets deallocated as rndis_filter_device_remove() sets net_device-
> >extension which points to the rndis_device struct to NULL, leaving the
> rndis_device dangling.
> 
> Since net_device->extension is eventually freed in free_netvsc_device(), we
> refrain from setting it to NULL inside rndis_filter_device_remove()
> 
> Signed-off-by: Mohammed Gamal <mgamal@redhat.com>
> ---
>  drivers/net/hyperv/rndis_filter.c | 2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
> index 857c4bea451c..e66d77dc28c8 100644
> --- a/drivers/net/hyperv/rndis_filter.c
> +++ b/drivers/net/hyperv/rndis_filter.c
> @@ -1443,8 +1443,6 @@ void rndis_filter_device_remove(struct hv_device
> *dev,
>  	/* Halt and release the rndis device */
>  	rndis_filter_halt_device(net_dev, rndis_dev);
> 
> -	net_dev->extension = NULL;
> -
>  	netvsc_device_remove(dev);

Reviewed-by: Haiyang Zhang <haiyangz@microsoft.com>


  reply index

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-14 13:09 Mohammed Gamal
2020-01-14 13:20 ` Haiyang Zhang [this message]
2020-01-15 21:38 ` David Miller

Reply instructions:

You may reply publically 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=MN2PR21MB1375B535C440C4AEFC30827ECA340@MN2PR21MB1375.namprd21.prod.outlook.com \
    --to=haiyangz@microsoft.com \
    --cc=cavery@redhat.com \
    --cc=kys@microsoft.com \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgamal@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=sashal@kernel.org \
    --cc=sthemmin@microsoft.com \
    --cc=vkuznets@redhat.com \
    /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

Linux-HyperV Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-hyperv/0 linux-hyperv/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-hyperv linux-hyperv/ https://lore.kernel.org/linux-hyperv \
		linux-hyperv@vger.kernel.org
	public-inbox-index linux-hyperv

Example config snippet for mirrors

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


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