On monolythic kernel /sys/modules/*/drivers may not exist (ENOENT)
On kernels with enhanced security (e.g. grsecurity), it might not be
accessible: EACCESS or EPERM.

Directly try to open if it fails with any of those errors, we fallback
on the module name.

Signed-off-by: Baptiste Daroussin <[email protected]>
Reviewed-by: Peter Krempa <[email protected]>
---
 src/util/virpci.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/util/virpci.c b/src/util/virpci.c
index fa04264a95..ec22eac7c9 100644
--- a/src/util/virpci.c
+++ b/src/util/virpci.c
@@ -1287,8 +1287,21 @@ virPCIDeviceFindDriver(virPCIDevice *dev)
 
     moduleDriversDir = g_strdup_printf("/sys/module/%s/drivers", moduleName);
 
-    if (virDirOpen(&dir, moduleDriversDir) < 0)
+    if (virDirOpenQuiet(&dir, moduleDriversDir) < 0) {
+        /* with monolithic kernels this directory will not exist: ENOENT
+         * with hardened system like grsecurity or any MAC frameowrk it might 
be be accessible:
+         * EACCESS or EPERM.
+         */
+        if (errno == ENOENT || errno == EACCES || errno == EPERM) {
+            VIR_DEBUG("driver directory not available (%s), using module name 
as driver name",
+                     moduleDriversDir);
+            g_free(dev->stubDriverName);
+            dev->stubDriverName = g_steal_pointer(&moduleName);
+            return 0;
+        }
+        virReportSystemError(errno, _("cannot open directory '%1$s'"), 
moduleDriversDir);
         return -1;
+    }
 
     while (virDirRead(dir, &ent, moduleDriversDir) > 0) {
 
-- 
2.43.0

Reply via email to