All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: bhelgaas@google.com
Cc: arjan@linux.intel.com, keith.busch@linux.intel.com,
	jthumshirn@suse.de, ming.lei@redhat.com,
	linux-pci@vger.kernel.org, linux-nvme@lists.infradead.org
Subject: [PATCH] PCI/sysfs: do not allow enabling/disabling a device with a driver
Date: Fri, 18 May 2018 18:56:24 +0200	[thread overview]
Message-ID: <20180518165624.13993-1-hch@lst.de> (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@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

WARNING: multiple messages have this Message-ID (diff)
From: hch@lst.de (Christoph Hellwig)
Subject: [PATCH] PCI/sysfs: do not allow enabling/disabling a device with a driver
Date: Fri, 18 May 2018 18:56:24 +0200	[thread overview]
Message-ID: <20180518165624.13993-1-hch@lst.de> (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

             reply	other threads:[~2018-05-18 16:56 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-18 16:56 Christoph Hellwig [this message]
2018-05-18 16:56 ` [PATCH] PCI/sysfs: do not allow enabling/disabling a device with a driver 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180518165624.13993-1-hch@lst.de \
    --to=hch@lst.de \
    --cc=arjan@linux.intel.com \
    --cc=bhelgaas@google.com \
    --cc=jthumshirn@suse.de \
    --cc=keith.busch@linux.intel.com \
    --cc=linux-nvme@lists.infradead.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=ming.lei@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.