]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/4.14.60/pci-prevent-sysfs-disable-of-device-while-driver-is-attached.patch
Fixes for 4.19
[thirdparty/kernel/stable-queue.git] / releases / 4.14.60 / pci-prevent-sysfs-disable-of-device-while-driver-is-attached.patch
CommitLineData
a65d4bac
GKH
1From foo@baz Sat Jul 28 10:25:26 CEST 2018
2From: Christoph Hellwig <hch@lst.de>
3Date: Fri, 18 May 2018 18:56:24 +0200
4Subject: PCI: Prevent sysfs disable of device while driver is attached
5
6From: Christoph Hellwig <hch@lst.de>
7
8[ Upstream commit 6f5cdfa802733dcb561bf664cc89d203f2fd958f ]
9
10Manipulating the enable_cnt behind the back of the driver will wreak
11complete havoc with the kernel state, so disallow it.
12
13Signed-off-by: Christoph Hellwig <hch@lst.de>
14Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
15Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
16Acked-by: Keith Busch <keith.busch@intel.com>
17Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
18Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
19---
20 drivers/pci/pci-sysfs.c | 15 +++++++++------
21 1 file changed, 9 insertions(+), 6 deletions(-)
22
23--- a/drivers/pci/pci-sysfs.c
24+++ b/drivers/pci/pci-sysfs.c
25@@ -305,13 +305,16 @@ static ssize_t enable_store(struct devic
26 if (!capable(CAP_SYS_ADMIN))
27 return -EPERM;
28
29- if (!val) {
30- if (pci_is_enabled(pdev))
31- pci_disable_device(pdev);
32- else
33- result = -EIO;
34- } else
35+ device_lock(dev);
36+ if (dev->driver)
37+ result = -EBUSY;
38+ else if (val)
39 result = pci_enable_device(pdev);
40+ else if (pci_is_enabled(pdev))
41+ pci_disable_device(pdev);
42+ else
43+ result = -EIO;
44+ device_unlock(dev);
45
46 return result < 0 ? result : count;
47 }