[PATCH] udevadm-info: Don't access sysfs 'resource<N>' files

Myron Stowe <[email protected]>
Newsgroups gmane.linux.hotplug.devel,gmane.linux.kernel.pci,gmane.linux.kernel
Message-ID <[email protected]>
Sysfs includes entries to memory that backs a PCI device's BARs, both I/O
Port space and MMIO.  This memory regions correspond to the device's
internal status and control registers used to drive the device.

Accessing these registers from userspace such as "udevadm info
--attribute-walk --path=/sys/devices/..." does can not be allowed as
such accesses outside of the driver, even just reading, can yield
catastrophic consequences.

Udevadm-info skips parsing a specific set of sysfs entries including
'resource'.  This patch extends the set to include the additional
'resource<N>' entries that correspond to a PCI device's BARs.

Reported-by: Xiangliang Yu <[email protected]>
Signed-off-by: Myron Stowe <[email protected]>
---

 src/udevadm-info.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/src/udevadm-info.c b/src/udevadm-info.c
index ee9b59f..298acb5 100644
--- a/src/udevadm-info.c
+++ b/src/udevadm-info.c
@@ -37,13 +37,18 @@ static bool skip_attribute(const char *name)
                 "uevent",
                 "dev",
                 "modalias",
-                "resource",
                 "driver",
                 "subsystem",
                 "module",
         };
         unsigned int i;
 
+        /*
+         * Skip any sysfs 'resource' entries, including 'resource<N>' entries
+         * that correspond to a device's I/O Port or MMIO space backed BARs.
+         */
+        if (strncmp((const char *)name, "resource", sizeof("resource")-1) == 0)
+                return true;
         for (i = 0; i < ARRAY_SIZE(skip); i++)
                 if (strcmp(name, skip[i]) == 0)
                         return true;

--
To unsubscribe from this list: send the line "unsubscribe linux-hotplug" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.