Package: usbguard
Version: 0.7.0+ds1-1
Followup-For: Bug #875808
User: [email protected]
Usertags: origin-ubuntu artful ubuntu-patch

Dear Maintainer,

In Ubuntu, the attached patch was applied to achieve the following:

  * debian/patches/bug875808.patch: fix UEventDeviceManager to work with
    Linux Kernel >= 4.13 (Closes: #875808, LP: #1717313)

Thanks for considering the patch.


-- System Information:
Debian Release: stretch/sid
  APT prefers artful
  APT policy: (500, 'artful')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 4.13.0-11-generic (SMP w/4 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), 
LANGUAGE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)
diff -Nru usbguard-0.7.0+ds1/debian/patches/bug875808.patch 
usbguard-0.7.0+ds1/debian/patches/bug875808.patch
--- usbguard-0.7.0+ds1/debian/patches/bug875808.patch   1969-12-31 
18:00:00.000000000 -0600
+++ usbguard-0.7.0+ds1/debian/patches/bug875808.patch   2017-09-18 
10:55:58.000000000 -0500
@@ -0,0 +1,76 @@
+Origin: backport, a3cdd13c245f29523f2166dd0c49db97253e3767
+Description: Fixed UEventDeviceManager to work with Linux Kernel >= 4.13
+Bug: https://github.com/dkopecek/usbguard/issues/204
+Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=875808
+
+Index: usbguard-0.7.0+ds1/src/Library/SysFSDevice.cpp
+===================================================================
+--- usbguard-0.7.0+ds1.orig/src/Library/SysFSDevice.cpp
++++ usbguard-0.7.0+ds1/src/Library/SysFSDevice.cpp
+@@ -115,6 +115,20 @@ namespace usbguard
+     return _sysfs_parent_path;
+   }
+ 
++  bool SysFSDevice::hasAttribute(const 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);
++  }
++
+   int SysFSDevice::openAttribute(const String& name) const
+   {
+     USBGUARD_LOG(Trace) << "name=" << name;
+Index: usbguard-0.7.0+ds1/src/Library/UEventDeviceManager.cpp
+===================================================================
+--- usbguard-0.7.0+ds1.orig/src/Library/UEventDeviceManager.cpp
++++ usbguard-0.7.0+ds1/src/Library/UEventDeviceManager.cpp
+@@ -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;
+             }
+           }
+Index: usbguard-0.7.0+ds1/src/Library/SysFSDevice.hpp
+===================================================================
+--- usbguard-0.7.0+ds1.orig/src/Library/SysFSDevice.hpp
++++ usbguard-0.7.0+ds1/src/Library/SysFSDevice.hpp
+@@ -36,6 +36,7 @@ namespace usbguard
+       const String& getName() const;
+       const UEvent& getUEvent() const;
+       const String& getParentPath() const;
++      bool hasAttribute(const 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 -Nru usbguard-0.7.0+ds1/debian/patches/series 
usbguard-0.7.0+ds1/debian/patches/series
--- usbguard-0.7.0+ds1/debian/patches/series    2017-08-05 14:00:42.000000000 
-0500
+++ usbguard-0.7.0+ds1/debian/patches/series    2017-09-18 10:45:38.000000000 
-0500
@@ -1,3 +1,4 @@
 disable-002_cli_devices.patch
 change-ipc-allowedgroup.patch
 0003-disable-test-that-depends-on-binary-data.patch
+bug875808.patch

Reply via email to