PCI/sysfs: do not allow enabling/disabling a device with a driver
Christoph Hellwig
maintainerPATCH 1/1 PCI/sysfs: do not allow enabling/disabling a device with a driver
Manpulating the enable_cnt behind the back of the driver will wreck complete havok with the kernel state, so disallow it.
--- drivers/pci/pci-sysfs.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
drivers/pci/pci-sysfs.c +9 -6
@@ -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; }
Signature · 1 line
2.17.0
PATCH 1/1 PCI/sysfs: do not allow enabling/disabling a device with a driver
Quoted 4 lines · Christoph Hellwig
Manpulating the
enable_cntbehind the back of the driver will wreck complete havok with the kernel state, so disallow it.Signed-off-by Christoph Hellwig <[email protected]>
Nice, looks like you beat me to it, and used device locking that I missed.
Bjorn,
Please disregard https://marc.info/?l=linux-pci&m=152666267830742&w=2
PATCH 1/1 PCI/sysfs: do not allow enabling/disabling a device with a driver
In reply to Christoph HellwigLooks good,
Reviewed-by: Johannes Thumshirn <jthumshirn at suse.de>
Signature · 6 lines
Johannes Thumshirn Storage jthumshirn at suse.de +49 911 74053 689 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N?rnberg GF: Felix Imend?rffer, Jane Smithard, Graham Norton HRB 21284 (AG N?rnberg) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
Bjorn Helgaas
AppliedPATCH 1/1 PCI/sysfs: do not allow enabling/disabling a device with a driver
In reply to Christoph HellwigQuoted 4 lines · Christoph Hellwig
Manpulating the
enable_cntbehind the back of the driver will wreck complete havok with the kernel state, so disallow it.Signed-off-by Christoph Hellwig <hch at lst.de>
Applied to pci/enumeration for v4.18, thanks!
Quoted 34 lines
--- drivers/pci/pci-sysfs.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)drivers/pci/pci-sysfs.c +9
-6@@ -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; }Signature · 1 line
2.17.0