From patchwork Wed Jan 22 09:29:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 233513 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D153DC33CB8 for ; Wed, 22 Jan 2020 09:50:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A85872467B for ; Wed, 22 Jan 2020 09:50:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579686612; bh=5+aN8LnHZLKcM+Ov72cMOGdccVnhGxIcDkOjPOrNlEM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=HbuPOLfD7NbiLZ5bJyAwg5giFwljekuWkWJCKAXV11Z6lAOtr0wA358SxqEYVwgHI VL4KeSOyXfPWev/6SoCwMKGZ4/qzZRtKvu4/Uc+4ytFAQgyLtVbFZBvJEYkREkgkRp c71pWBv2nzCs6r8YRX5AqbfnVHHN4cUh5HNPZNFk= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729143AbgAVJuF (ORCPT ); Wed, 22 Jan 2020 04:50:05 -0500 Received: from mail.kernel.org ([198.145.29.99]:56060 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733125AbgAVJiy (ORCPT ); Wed, 22 Jan 2020 04:38:54 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5757E2467B; Wed, 22 Jan 2020 09:38:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579685933; bh=5+aN8LnHZLKcM+Ov72cMOGdccVnhGxIcDkOjPOrNlEM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cqZsZ651kqRR2W8MAYzSryhD92xV7uNXKOegNuSmOVcvl7gejLxJvRakgyqxQK7DL UGrBZe2fiN8EHvPqEV+1XmJPVjE4kAGY284DZyC95v12H+1HAP2osuF9HtG36Kt9zx b6RdOdweJ8GAaeKChvyfTrQQ522GgTs7kwbyI83Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mohammed Gamal , Haiyang Zhang , "David S. Miller" Subject: [PATCH 4.14 42/65] hv_netvsc: Fix memory leak when removing rndis device Date: Wed, 22 Jan 2020 10:29:27 +0100 Message-Id: <20200122092757.036260646@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200122092750.976732974@linuxfoundation.org> References: <20200122092750.976732974@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Mohammed Gamal [ Upstream commit 536dc5df2808efbefc5acee334d3c4f701790ec0 ] 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 Reviewed-by: Haiyang Zhang Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/hyperv/rndis_filter.c | 2 -- 1 file changed, 2 deletions(-) --- a/drivers/net/hyperv/rndis_filter.c +++ b/drivers/net/hyperv/rndis_filter.c @@ -1331,8 +1331,6 @@ void rndis_filter_device_remove(struct h /* Halt and release the rndis device */ rndis_filter_halt_device(rndis_dev); - net_dev->extension = NULL; - netvsc_device_remove(dev); }