diff mbox series

[v2,4/7] PCI/sysfs: Only allow supported resource type in pci_mmap_resource()

Message ID 20210910202623.2293708-5-kw@linux.com
State New
Headers show
Series [v2,1/7] PCI/sysfs: Add pci_dev_resource_attr_is_visible() helper | expand

Commit Message

Krzysztof Wilczyński Sept. 10, 2021, 8:26 p.m. UTC
Currently, when the sysfs attributes for PCI resources are added
dynamically, the mmap() callback will only ever be set when the
underlying resource (a given BAR) has either the IORESOURCE_MEM (which
currently is implied) or IORESOURCE_IO flag set and where the latter
requires that the underlying architecture supports mmap() for I/O BARs,
otherwise the callbacks are set to NULL and any attempt to read from
such sysfs attribute will inherently fail.

Following the conversion to the static sysfs objects, the mmap()
callbacks will be always set for a given binary attribute (a particular
sysfs object). Thus, a check is added to the pci_mmap_resource()
function to ensure that a read against the underlying resource is
supported and that either the IORESOURCE_MEM or IORESOURCE_IO flag is
set with the platform supporting mmap() for I/O BARs as required.

Signed-off-by: Krzysztof Wilczyński <kw@linux.com>
---
 drivers/pci/pci-sysfs.c | 4 ++++
 1 file changed, 4 insertions(+)
diff mbox series

Patch

diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index e151d635fe04..2031b5da6bcf 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -1051,6 +1051,10 @@  static int pci_mmap_resource(struct kobject *kobj, struct bin_attribute *attr,
 	if (ret)
 		return ret;
 
+	if (!(res->flags & IORESOURCE_MEM ||
+	    ((res->flags & IORESOURCE_IO) && arch_can_pci_mmap_io())))
+		return -EIO;
+
 	if (res->flags & IORESOURCE_MEM && iomem_is_exclusive(res->start))
 		return -EINVAL;