From mboxrd@z Thu Jan 1 00:00:00 1970 From: Myron Stowe Date: Sat, 16 Mar 2013 21:35:19 +0000 Subject: [PATCH] udevadm-info: Don't access sysfs 'resource' files Message-Id: <20130316213519.2974.38954.stgit@amt.stowe> List-Id: References: <20130316213512.2974.17303.stgit@amt.stowe> In-Reply-To: <20130316213512.2974.17303.stgit@amt.stowe> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: kay@vrfy.org Cc: linux-hotplug@vger.kernel.org, greg@kroah.com, alex.williamson@redhat.com, linux-pci@vger.kernel.org, yuxiangl@marvell.com, yxlraid@gmail.com, linux-kernel@vger.kernel.org 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' entries that correspond to a PCI device's BARs. Reported-by: Xiangliang Yu Signed-off-by: Myron Stowe --- 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' 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;