All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] PCI/sysfs: do not allow enabling/disabling a device with a driver
@ 2018-05-18 16:56 ` Christoph Hellwig
  0 siblings, 0 replies; 8+ messages in thread
From: Christoph Hellwig @ 2018-05-18 16:56 UTC (permalink / raw)
  To: bhelgaas; +Cc: arjan, keith.busch, jthumshirn, ming.lei, linux-pci, linux-nvme

Manpulating the enable_cnt behind the back of the driver will wreck
complete havok with the kernel state, so disallow it.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/pci/pci-sysfs.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index 366d93af051d..788a200fb2dc 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -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;
 }
-- 
2.17.0

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH] PCI/sysfs: do not allow enabling/disabling a device with a driver
@ 2018-05-18 16:56 ` Christoph Hellwig
  0 siblings, 0 replies; 8+ messages in thread
From: Christoph Hellwig @ 2018-05-18 16:56 UTC (permalink / raw)


Manpulating the enable_cnt behind 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>
---
 drivers/pci/pci-sysfs.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index 366d93af051d..788a200fb2dc 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -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;
 }
-- 
2.17.0

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] PCI/sysfs: do not allow enabling/disabling a device with a driver
  2018-05-18 16:56 ` Christoph Hellwig
@ 2018-05-18 17:23   ` Keith Busch
  -1 siblings, 0 replies; 8+ messages in thread
From: Keith Busch @ 2018-05-18 17:23 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: bhelgaas, arjan, jthumshirn, ming.lei, linux-pci, linux-nvme

On Fri, May 18, 2018 at 06:56:24PM +0200, Christoph Hellwig wrote:
> Manpulating the enable_cnt behind the back of the driver will wreck
> complete havok with the kernel state, so disallow it.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Nice, looks like you beat me to it, and used device locking that I
missed.

Acked-by: Keith Busch <keith.busch@intel.com>

Bjorn,
Please disregard https://marc.info/?l=linux-pci&m=152666267830742&w=2

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH] PCI/sysfs: do not allow enabling/disabling a device with a driver
@ 2018-05-18 17:23   ` Keith Busch
  0 siblings, 0 replies; 8+ messages in thread
From: Keith Busch @ 2018-05-18 17:23 UTC (permalink / raw)


On Fri, May 18, 2018@06:56:24PM +0200, Christoph Hellwig wrote:
> Manpulating the enable_cnt behind 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>

Nice, looks like you beat me to it, and used device locking that I
missed.

Acked-by: Keith Busch <keith.busch at intel.com>

Bjorn,
Please disregard https://marc.info/?l=linux-pci&m=152666267830742&w=2

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] PCI/sysfs: do not allow enabling/disabling a device with a driver
  2018-05-18 16:56 ` Christoph Hellwig
@ 2018-05-22  7:36   ` Johannes Thumshirn
  -1 siblings, 0 replies; 8+ messages in thread
From: Johannes Thumshirn @ 2018-05-22  7:36 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: linux-pci, linux-nvme, ming.lei, keith.busch, bhelgaas, arjan

Looks good,
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
-- =

Johannes Thumshirn                                          Storage
jthumshirn@suse.de                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N=FCrnberg
GF: Felix Imend=F6rffer, Jane Smithard, Graham Norton
HRB 21284 (AG N=FCrnberg)
Key fingerprint =3D EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850

_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH] PCI/sysfs: do not allow enabling/disabling a device with a driver
@ 2018-05-22  7:36   ` Johannes Thumshirn
  0 siblings, 0 replies; 8+ messages in thread
From: Johannes Thumshirn @ 2018-05-22  7:36 UTC (permalink / raw)


Looks good,
Reviewed-by: Johannes Thumshirn <jthumshirn at suse.de>
-- 
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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] PCI/sysfs: do not allow enabling/disabling a device with a driver
  2018-05-18 16:56 ` Christoph Hellwig
@ 2018-05-25 22:30   ` Bjorn Helgaas
  -1 siblings, 0 replies; 8+ messages in thread
From: Bjorn Helgaas @ 2018-05-25 22:30 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: linux-pci, linux-nvme, ming.lei, keith.busch, jthumshirn,
	bhelgaas, arjan

On Fri, May 18, 2018 at 06:56:24PM +0200, Christoph Hellwig wrote:
> Manpulating the enable_cnt behind the back of the driver will wreck
> complete havok with the kernel state, so disallow it.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Applied to pci/enumeration for v4.18, thanks!

> ---
>  drivers/pci/pci-sysfs.c | 15 +++++++++------
>  1 file changed, 9 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
> index 366d93af051d..788a200fb2dc 100644
> --- a/drivers/pci/pci-sysfs.c
> +++ b/drivers/pci/pci-sysfs.c
> @@ -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;
>  }
> -- 
> 2.17.0
> 

_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH] PCI/sysfs: do not allow enabling/disabling a device with a driver
@ 2018-05-25 22:30   ` Bjorn Helgaas
  0 siblings, 0 replies; 8+ messages in thread
From: Bjorn Helgaas @ 2018-05-25 22:30 UTC (permalink / raw)


On Fri, May 18, 2018@06:56:24PM +0200, Christoph Hellwig wrote:
> Manpulating the enable_cnt behind 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!

> ---
>  drivers/pci/pci-sysfs.c | 15 +++++++++------
>  1 file changed, 9 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
> index 366d93af051d..788a200fb2dc 100644
> --- a/drivers/pci/pci-sysfs.c
> +++ b/drivers/pci/pci-sysfs.c
> @@ -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;
>  }
> -- 
> 2.17.0
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-05-25 22:30 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-18 16:56 [PATCH] PCI/sysfs: do not allow enabling/disabling a device with a driver Christoph Hellwig
2018-05-18 16:56 ` Christoph Hellwig
2018-05-18 17:23 ` Keith Busch
2018-05-18 17:23   ` Keith Busch
2018-05-22  7:36 ` Johannes Thumshirn
2018-05-22  7:36   ` Johannes Thumshirn
2018-05-25 22:30 ` Bjorn Helgaas
2018-05-25 22:30   ` Bjorn Helgaas

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.