]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
PCI: Prevent sysfs disable of device while driver is attached
authorChristoph Hellwig <hch@lst.de>
Fri, 18 May 2018 16:56:24 +0000 (18:56 +0200)
committerStefan Bader <stefan.bader@canonical.com>
Fri, 1 Mar 2019 13:20:37 +0000 (14:20 +0100)
BugLink: http://bugs.launchpad.net/bugs/1815234
[ 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>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
drivers/pci/pci-sysfs.c

index 612e523551f890eba1ca0a04c5f6d07d5aac2421..83b6174174c9bc680204f0edf148b3ee3bb26855 100644 (file)
@@ -311,13 +311,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;
 }