69 lines
3.3 KiB
Diff
69 lines
3.3 KiB
Diff
diff -up usbguard-0.7.0/src/Library/SysFSDevice.cpp.orig usbguard-0.7.0/src/Library/SysFSDevice.cpp
|
|
--- usbguard-0.7.0/src/Library/SysFSDevice.cpp.orig 2017-10-16 09:40:33.257969336 +0200
|
|
+++ usbguard-0.7.0/src/Library/SysFSDevice.cpp 2017-10-16 09:42:11.110603414 +0200
|
|
@@ -126,6 +126,20 @@ namespace usbguard
|
|
return fd;
|
|
}
|
|
|
|
+ bool SysFSDevice::hasAttribute(const std::string& name) const
|
|
+ {
|
|
+ struct ::stat st;
|
|
+
|
|
+ if (::fstatat(_sysfs_dirfd, name.c_str(), &st, AT_SYMLINK_NOFOLLOW) != 0) {
|
|
+ if (errno == ENOENT) {
|
|
+ return false;
|
|
+ }
|
|
+ throw ErrnoException("SysFSDevice::hasAttribute", name, errno);
|
|
+ }
|
|
+
|
|
+ return S_ISREG(st.st_mode);
|
|
+ }
|
|
+
|
|
String SysFSDevice::readAttribute(const String& name, bool strip_last_null, bool optional) const
|
|
{
|
|
USBGUARD_LOG(Trace) << "name=" << name;
|
|
diff -up usbguard-0.7.0/src/Library/SysFSDevice.hpp.orig usbguard-0.7.0/src/Library/SysFSDevice.hpp
|
|
--- usbguard-0.7.0/src/Library/SysFSDevice.hpp.orig 2017-10-16 09:40:33.258969332 +0200
|
|
+++ usbguard-0.7.0/src/Library/SysFSDevice.hpp 2017-10-16 09:42:52.346449212 +0200
|
|
@@ -36,6 +36,7 @@ namespace usbguard
|
|
const String& getName() const;
|
|
const UEvent& getUEvent() const;
|
|
const String& getParentPath() const;
|
|
+ bool hasAttribute(const std::string& name) const;
|
|
String readAttribute(const String& name, bool strip_last_null = false, bool optional = false) const;
|
|
void setAttribute(const String& name, const String& value);
|
|
int openAttribute(const String& name) const;
|
|
diff -up usbguard-0.7.0/src/Library/UEventDeviceManager.cpp.orig usbguard-0.7.0/src/Library/UEventDeviceManager.cpp
|
|
--- usbguard-0.7.0/src/Library/UEventDeviceManager.cpp.orig 2017-01-29 18:52:18.290000000 +0100
|
|
+++ usbguard-0.7.0/src/Library/UEventDeviceManager.cpp 2017-10-16 09:40:33.259969329 +0200
|
|
@@ -572,7 +572,12 @@ namespace usbguard {
|
|
const String devtype = uevent.getAttribute("DEVTYPE");
|
|
const String action = uevent.getAttribute("ACTION");
|
|
|
|
- if (subsystem != "usb" || devtype != "usb_device") {
|
|
+ /*
|
|
+ * We don't care about the event if it's not from the "usb" subsystem.
|
|
+ * The device type attribute value is checked later based on the data
|
|
+ * read from the sysfs uevent file in the device directory.
|
|
+ */
|
|
+ if (subsystem != "usb") {
|
|
USBGUARD_LOG(Debug) << "Ignoring non-USB device:"
|
|
<< " subsystem=" << subsystem
|
|
<< " devtype=" << devtype
|
|
@@ -602,8 +607,13 @@ namespace usbguard {
|
|
if (sysfs_device.getUEvent().hasAttribute("DEVTYPE")) {
|
|
const String devtype = sysfs_device.getUEvent().getAttribute("DEVTYPE");
|
|
if (devtype != "usb_device") {
|
|
- USBGUARD_LOG(Warning) << sysfs_devpath << ": UEvent DEVTYPE mismatch."
|
|
- << " Expected \"usb_device\", got \"" << devtype << "\"";
|
|
+ USBGUARD_LOG(Debug) << sysfs_devpath << ": UEvent DEVTYPE != usb_device. Ignoring event.";
|
|
+ return;
|
|
+ }
|
|
+ }
|
|
+ else {
|
|
+ if (!sysfs_device.hasAttribute("descriptors")) {
|
|
+ USBGUARD_LOG(Debug) << sysfs_devpath << ": UEvent doesn't refer to a device with a descriptors file. Ignoring event.";
|
|
return;
|
|
}
|
|
}
|