summaryrefslogtreecommitdiff
path: root/drivers/pci
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2018-05-18 19:56:24 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-08-09 13:20:26 +0300
commit0bedc117bab4a0ac92de0e856e896e1f708f1c57 (patch)
treeb588105902487e433f41e8b804e9df7c5e31ad9d /drivers/pci
parent8362d3e90c1105380b4b2b1bd232a638e3f3f807 (diff)
downloadlinux-0bedc117bab4a0ac92de0e856e896e1f708f1c57.tar.xz
PCI: Prevent sysfs disable of device while driver is attached
[ Upstream commit 6f5cdfa802733dcb561bf664cc89d203f2fd958f ] Manipulating the enable_cnt behind the back of the driver will wreak complete havoc with the kernel state, so disallow it. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de> Acked-by: Keith Busch <keith.busch@intel.com> Signed-off-by: Sasha Levin <alexander.levin@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/pci')
-rw-r--r--drivers/pci/pci-sysfs.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index 318707870cb2..6b66f9950b57 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -199,13 +199,16 @@ static ssize_t enable_store(struct device *dev, struct device_attribute *attr,
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
- if (!val) {
- if (pci_is_enabled(pdev))
- pci_disable_device(pdev);
- else
- result = -EIO;
- } else
+ device_lock(dev);
+ if (dev->driver)
+ result = -EBUSY;
+ else if (val)
result = pci_enable_device(pdev);
+ else if (pci_is_enabled(pdev))
+ pci_disable_device(pdev);
+ else
+ result = -EIO;
+ device_unlock(dev);
return result < 0 ? result : count;
}