]>
Commit | Line | Data |
---|---|---|
a65d4bac GKH |
1 | From foo@baz Sat Jul 28 10:25:26 CEST 2018 |
2 | From: Christoph Hellwig <hch@lst.de> | |
3 | Date: Fri, 18 May 2018 18:56:24 +0200 | |
4 | Subject: PCI: Prevent sysfs disable of device while driver is attached | |
5 | ||
6 | From: Christoph Hellwig <hch@lst.de> | |
7 | ||
8 | [ Upstream commit 6f5cdfa802733dcb561bf664cc89d203f2fd958f ] | |
9 | ||
10 | Manipulating the enable_cnt behind the back of the driver will wreak | |
11 | complete havoc with the kernel state, so disallow it. | |
12 | ||
13 | Signed-off-by: Christoph Hellwig <hch@lst.de> | |
14 | Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> | |
15 | Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de> | |
16 | Acked-by: Keith Busch <keith.busch@intel.com> | |
17 | Signed-off-by: Sasha Levin <alexander.levin@microsoft.com> | |
18 | Signed-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 | } |