Skip to content

Commit

Permalink
PCI: Prevent sysfs disable of device while driver is attached
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Bjorn Helgaas <[email protected]>
Reviewed-by: Johannes Thumshirn <[email protected]>
Acked-by: Keith Busch <[email protected]>
  • Loading branch information
Christoph Hellwig authored and bjorn-helgaas committed May 25, 2018
1 parent 17e8f0d commit 6f5cdfa
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions drivers/pci/pci-sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,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;
}
Expand Down

0 comments on commit 6f5cdfa

Please sign in to comment.