Home Home > GIT Browse > stable
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiri Slaby <jslaby@suse.cz>2019-05-17 06:38:43 +0200
committerJiri Slaby <jslaby@suse.cz>2019-05-17 06:38:53 +0200
commitce4e2d0a22c6da2f4342ffa39fd51280a85e94a8 (patch)
tree9f353fa7764b0a54adaeefd05654628c5c654286
parenta4ff3f0eed766da2549e0597fc46e9d30231d63a (diff)
PCI: hv: Fix a memory leak in hv_eject_device_work()
-rw-r--r--patches.kernel.org/5.1.3-040-PCI-hv-Fix-a-memory-leak-in-hv_eject_device_wor.patch56
-rw-r--r--series.conf1
2 files changed, 57 insertions, 0 deletions
diff --git a/patches.kernel.org/5.1.3-040-PCI-hv-Fix-a-memory-leak-in-hv_eject_device_wor.patch b/patches.kernel.org/5.1.3-040-PCI-hv-Fix-a-memory-leak-in-hv_eject_device_wor.patch
new file mode 100644
index 0000000000..6e0575cc24
--- /dev/null
+++ b/patches.kernel.org/5.1.3-040-PCI-hv-Fix-a-memory-leak-in-hv_eject_device_wor.patch
@@ -0,0 +1,56 @@
+From: Dexuan Cui <decui@microsoft.com>
+Date: Mon, 4 Mar 2019 21:34:48 +0000
+Subject: [PATCH] PCI: hv: Fix a memory leak in hv_eject_device_work()
+References: bnc#1012628
+Patch-mainline: 5.1.3
+Git-commit: 05f151a73ec2b23ffbff706e5203e729a995cdc2
+
+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 <decui@microsoft.com>
+[lorenzo.pieralisi@arm.com: commit log rework]
+Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
+Reviewed-by: Stephen Hemminger <stephen@networkplumber.org>
+Reviewed-by: Michael Kelley <mikelley@microsoft.com>
+Cc: stable@vger.kernel.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+Signed-off-by: Jiri Slaby <jslaby@suse.cz>
+---
+ drivers/pci/controller/pci-hyperv.c | 3 +++
+ 1 file changed, 3 insertions(+)
+
+diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c
+index 95441a35eceb..30f16b882746 100644
+--- a/drivers/pci/controller/pci-hyperv.c
++++ b/drivers/pci/controller/pci-hyperv.c
+@@ -1900,6 +1900,9 @@ static void hv_eject_device_work(struct work_struct *work)
+ 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);
+--
+2.21.0
+
diff --git a/series.conf b/series.conf
index 750da05d29..251a9391c4 100644
--- a/series.conf
+++ b/series.conf
@@ -125,6 +125,7 @@
patches.kernel.org/5.1.3-037-powerpc-powernv-idle-Restore-IAMR-after-idle.patch
patches.kernel.org/5.1.3-038-powerpc-booke64-set-RI-in-default-MSR.patch
patches.kernel.org/5.1.3-039-virtio_ring-Fix-potential-mem-leak-in-virtqueue.patch
+ patches.kernel.org/5.1.3-040-PCI-hv-Fix-a-memory-leak-in-hv_eject_device_wor.patch
########################################################
# Build fixes that apply to the vanilla kernel too.