Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp464196yba; Wed, 15 May 2019 04:34:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqwD1KmWBUOVltiarYqb/cglFZyrSj4+rzuagjFolRthPJXXksZjlAqPUDNKnTtXmYnvIDoS X-Received: by 2002:a17:902:4101:: with SMTP id e1mr44367456pld.25.1557920072931; Wed, 15 May 2019 04:34:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557920072; cv=none; d=google.com; s=arc-20160816; b=Fs1K9ktjIes2/pmVnQlOozoY68jujh92o663xIDuIa6w8Q5Ukre3x+Aa9R27yaW5dS OalGqnASrES49OS5DdNyzg/seSJhMRNArg77FdnTLsC8w6+8tFp9D5q3jo98f8jHx/IP zDwfcwNtGRrPRProjThTdo2XrwOlOq/5zM+SAa1Keu3mdbLB8A3f5TQ2F5BhyR9TLy+f wA6wvrJU083z874RN3fSt8fOcHW1j2pih5RJDXUygpF0/fuyRgQNUD/P+desOjwfnuHz fmd/55YcTDKkaj7fSMexKQOD80ntKbsDGbz19jFairf8uzeSpwteX9VnuCVbmyZexHb/ 94eg== 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=tHxbcECDLTWLG98p+8A5kfw4Wai7VxK9kRIGdxPo+Zs=; b=NwsEeEl7TtlowXfiHvjVliY81NnYcoB6FBaZ4ALm3yNYcrlhCiu1L76/l3qYIMblys Rdi5Iu0YWM6r0lO3CIkoG/OxBM67rZjqwIeNBbmzxn43HpwWI08W1FfTiMcRbSjFLJ/G iUzsDT25fCfUrpTLczuv1JC1AB5olXRKtQUgEbdkvTd3u4ttqiIoMuOavbolZci4ikB+ pfOxAfU8lxBnBLA8Y9Hyy9shmXE46D3wzIF9OGOB8ccf0vu+ULITU6g0bICQUurrzPOD AdVUHOR413DCpE72ZWdekOXuzUt4ts7q3ET+04vouD5EO97maJDHGUWcSoSRJPBwt/ps toZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ybvuPSvL; 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 d16si1784363pfr.229.2019.05.15.04.34.18; Wed, 15 May 2019 04:34:32 -0700 (PDT) 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=ybvuPSvL; 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 S1732901AbfEOLbe (ORCPT + 99 others); Wed, 15 May 2019 07:31:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:43290 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726964AbfEOLbc (ORCPT ); Wed, 15 May 2019 07:31:32 -0400 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 75DB3206BF; Wed, 15 May 2019 11:31:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557919891; bh=GtcRU5ZM3n54XN/gJfZc+nyZGktY5oRZUcZIHhUpe/I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ybvuPSvLRTCdwFv37PFCliD7qsfDQ+UHiWhu+YXKstqcGXIvUtzzokV6yvdK9cwqp 1Q6fSNw1dFxTrazu/jNCKE63HEY7Fra9kRSa6zCXQy2v0cfVDCsfg7IXzHNPIpLGie Uzl5Cd4TMuytLpbVlHhIiVZFAChjgY2Q2o4yc+ak= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dexuan Cui , Lorenzo Pieralisi , Stephen Hemminger , Michael Kelley Subject: [PATCH 5.0 134/137] PCI: hv: Fix a memory leak in hv_eject_device_work() Date: Wed, 15 May 2019 12:56:55 +0200 Message-Id: <20190515090703.600457250@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190515090651.633556783@linuxfoundation.org> References: <20190515090651.633556783@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: Dexuan Cui commit 05f151a73ec2b23ffbff706e5203e729a995cdc2 upstream. When a device is created in new_pcichild_device(), hpdev->refs is set to 2 (i.e. the initial value of 1 plus the get_pcichild()). When we hot remove the device from the host, in a Linux VM we first call hv_pci_eject_device(), which increases hpdev->refs by get_pcichild() and then schedules a work of hv_eject_device_work(), so hpdev->refs becomes 3 (let's ignore the paired get/put_pcichild() in other places). But in hv_eject_device_work(), currently we only call put_pcichild() twice, meaning the 'hpdev' struct can't be freed in put_pcichild(). Add one put_pcichild() to fix the memory leak. The device can also be removed when we run "rmmod pci-hyperv". On this path (hv_pci_remove() -> hv_pci_bus_exit() -> hv_pci_devices_present()), hpdev->refs is 2, and we do correctly call put_pcichild() twice in pci_devices_present_work(). Fixes: 4daace0d8ce8 ("PCI: hv: Add paravirtual PCI front-end for Microsoft Hyper-V VMs") Signed-off-by: Dexuan Cui [lorenzo.pieralisi@arm.com: commit log rework] Signed-off-by: Lorenzo Pieralisi Reviewed-by: Stephen Hemminger Reviewed-by: Michael Kelley Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/pci/controller/pci-hyperv.c | 3 +++ 1 file changed, 3 insertions(+) --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -1905,6 +1905,9 @@ static void hv_eject_device_work(struct sizeof(*ejct_pkt), (unsigned long)&ctxt.pkt, VM_PKT_DATA_INBAND, 0); + /* For the get_pcichild() in hv_pci_eject_device() */ + put_pcichild(hpdev); + /* For the two refs got in new_pcichild_device() */ put_pcichild(hpdev); put_pcichild(hpdev); put_hvpcibus(hpdev->hbus);