Blame SOURCES/0002-Fix-lshw-crashes-with-SEGV-in-privileged-containers.patch

1c14b3
From 7b99d35064230f908551ba65c29264d90f49f246 Mon Sep 17 00:00:00 2001
1c14b3
From: Eric Desrochers <eric.desrochers@canonical.com>
1c14b3
Date: Wed, 11 Oct 2017 15:06:51 -0400
1c14b3
Subject: [PATCH] Fix lshw crashes with SEGV in privileged containers
1c14b3
1c14b3
lshw cmd segfault, when ran inside a privileged container.
1c14b3
All debugfs access is denied as it should be in privileged containers.
1c14b3
1c14b3
[strace of lshw]
1c14b3
open("/usr/share/hwdata/usb.ids", O_RDONLY) = -1 ENOENT (No such file or directory)
1c14b3
open("/etc/usb.ids", O_RDONLY) = -1 ENOENT (No such file or directory)
1c14b3
open("/usr/share/usb.ids", O_RDONLY) = -1 ENOENT (No such file or directory)
1c14b3
open("/usr/local/share/usb.ids", O_RDONLY) = -1 ENOENT (No such file or directory)
1c14b3
open("/usr/share/lshw-common/usb.ids", O_RDONLY) = -1 ENOENT (No such file or directory)
1c14b3
open("/usr/share/usb.ids", O_RDONLY) = -1 ENOENT (No such file or directory)
1c14b3
open("/sys/kernel/debug/usb/devices", O_RDONLY) = -1 EACCES (Permission denied)
1c14b3
open("/proc/bus/usb/devices", O_RDONLY) = -1 ENOENT (No such file or directory)
1c14b3
1c14b3
Signed-off-by: Lianbo Jiang <lijiang@redhat.com>
1c14b3
---
1c14b3
 src/core/usb.cc | 9 +++++++--
1c14b3
 1 file changed, 7 insertions(+), 2 deletions(-)
1c14b3
1c14b3
diff --git a/src/core/usb.cc b/src/core/usb.cc
1c14b3
index ea27f2476195..da65e10df191 100644
1c14b3
--- a/src/core/usb.cc
1c14b3
+++ b/src/core/usb.cc
1c14b3
@@ -373,10 +373,15 @@ bool scan_usb(hwNode & n)
1c14b3
   }
1c14b3
   filenames.clear();
1c14b3
 
1c14b3
-  usbdevices = fopen(SYSKERNELDEBUGUSBDEVICES, "r");
1c14b3
-  if(!usbdevices)
1c14b3
+  if (exists(SYSKERNELDEBUGUSBDEVICES))
1c14b3
+    usbdevices = fopen(SYSKERNELDEBUGUSBDEVICES, "r");
1c14b3
+
1c14b3
+  if(!usbdevices && exists(PROCBUSUSBDEVICES))
1c14b3
     usbdevices = fopen(PROCBUSUSBDEVICES, "r");
1c14b3
 
1c14b3
+  if(!usbdevices)
1c14b3
+    return false;
1c14b3
+
1c14b3
   while(!feof(usbdevices))
1c14b3
   {
1c14b3
     char * buffer = NULL;
1c14b3
-- 
1c14b3
2.17.1
1c14b3