Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4831776ybl; Wed, 22 Jan 2020 05:33:31 -0800 (PST) X-Google-Smtp-Source: APXvYqxDBXDn2Rhdhli9H1acQBWkPK1K/o/ui7g7nJZKMeo5Lh6BEx2GyTpH0bQoOeh2iCmKTcIQ X-Received: by 2002:aca:1b19:: with SMTP id b25mr4804990oib.24.1579700010834; Wed, 22 Jan 2020 05:33:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579700010; cv=none; d=google.com; s=arc-20160816; b=Djy5WnvtUU6CU1gDTZarF5IQW4oFehHMwrG7QlYKb+hflAAf/kqEIDTn3j5Wo7TVw0 j5QDr/vI5sYohGtItdQ04wvrfGTOhUBksBPLFEsdUTkeSpMQ7mNutL58aXJ+OQtBColH NFhEQclTzVrrTUTSKvXRYrRsjAkuUEy3wSR94Enf0ksYqGkvDohZ+EuQh9nl3BOJrzZj VyIOA7dylX9NxbpcpRrLQvsVXN59npfh1mH6Oyg9xe8gp7oJP1ZKq1t8G64y2y0hRNpA VAlJirO1N+cFMqnAM2yyeBwBfYLoY+Rm8v0mwjpcSg3lBMIl8mMGJ9cLWHr8so/BxLIM wHMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=SsMN3ZZA2oQass2yvPhNi5E+3NWZLLlzdWQ4erR2bOI=; b=geyttUMJ25zBlf/CPRZk4APZYjedlELSa76CeZo7e1pZ6ptX25u/0F/8zMe4RxGHWN UE41gWIl4roKD/d6KucKlrZjoDFLS2bc6RpiUWmeCG/gZ76Vjod3yQ6u//VDFDx6atiH D0iZ4aDIQrug69LcNETJyitHdKfIbdJYcMIPp3wRkQWtTA+Hz49+gpjFXCEHAenWsmHG P/iFEdvt7jCxB+QnfR6+xe/TANPWET0BmcgPE/r2SLle4qi+6V7Vrz84BvpHWvi45Kyo fx3bT45eH4S5mjh+Zm5cnAAHoPllEOW++9woTtljxN62Vw5mNeiVdkDyf9Vol7EJhCGC uysA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Y8tXoLbj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t2si23484558otq.196.2020.01.22.05.33.16; Wed, 22 Jan 2020 05:33:30 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Y8tXoLbj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728901AbgAVNaO (ORCPT + 99 others); Wed, 22 Jan 2020 08:30:14 -0500 Received: from mail.kernel.org ([198.145.29.99]:41886 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730770AbgAVNXf (ORCPT ); Wed, 22 Jan 2020 08:23:35 -0500 Received: from localhost (unknown [84.241.205.26]) (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 DC94C205F4; Wed, 22 Jan 2020 13:23:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579699414; bh=2of5CTXKjjGti1kbcPgJ/LjlfCW/6qH5PUVAquhJEno=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y8tXoLbjZbBzowbhyOWMhbK9vI+WlYa8v1d5hgO74hC7QJROxX/sbVl7uMxkHbyos 6mvOFp+MHFpUpm8zLdSx6Ke1dph/bKpnfGfbSzpDcNHR+oO7s9TF+YOrHVJZ/izm3B jfsQSXXp0UHMwYBcc8OvPmCX3s1fEcWlMq8toGXk= 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 5.4 137/222] hv_netvsc: Fix memory leak when removing rndis device Date: Wed, 22 Jan 2020 10:28:43 +0100 Message-Id: <20200122092843.549078478@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200122092833.339495161@linuxfoundation.org> References: <20200122092833.339495161@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 @@ -1436,8 +1436,6 @@ void rndis_filter_device_remove(struct h /* Halt and release the rndis device */ rndis_filter_halt_device(net_dev, rndis_dev); - net_dev->extension = NULL; - netvsc_device_remove(dev); }