From 2c7bde0cb724d7385ecf1b34669eedd79e61d80b Mon Sep 17 00:00:00 2001 From: user Date: Mon, 16 Oct 2017 09:56:02 +0200 Subject: [PATCH] Fix enumeration timeout on kernel >= 4.13 Resolves: rhbz#1499052 --- usbguard-0.7.0-kernel-4.13-fix.patch | 68 ++++++++++++++++++++++++++++ usbguard.spec | 9 +++- 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 usbguard-0.7.0-kernel-4.13-fix.patch diff --git a/usbguard-0.7.0-kernel-4.13-fix.patch b/usbguard-0.7.0-kernel-4.13-fix.patch new file mode 100644 index 0000000..09188f2 --- /dev/null +++ b/usbguard-0.7.0-kernel-4.13-fix.patch @@ -0,0 +1,68 @@ +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; + } + } diff --git a/usbguard.spec b/usbguard.spec index 3666ce9..47b35e6 100644 --- a/usbguard.spec +++ b/usbguard.spec @@ -5,7 +5,7 @@ Name: usbguard Version: 0.7.0 -Release: 6%{?dist} +Release: 7%{?dist} Summary: A tool for implementing USB device usage policy Group: System Environment/Daemons License: GPLv2+ @@ -52,6 +52,8 @@ BuildRequires: pandoc Patch0: usbguard-0.6.3-disable-cast-align-warning.patch Patch1: usbguard-0.7.0-disable-unused-parameter-warning.patch +# Bug 1499052 - usbguard-daemon fails with kernel 4.13 +Patch2: usbguard-0.7.0-kernel-4.13-fix.patch %description The USBGuard software framework helps to protect your computer against rogue USB @@ -114,6 +116,7 @@ rm -rf src/ThirdParty/{Catch,PEGTL} %patch0 -p1 %patch1 -p1 +%patch2 -p1 %build mkdir -p ./m4 @@ -225,6 +228,10 @@ find %{buildroot} \( -name '*.la' -o -name '*.a' \) -exec rm -f {} ';' %endif %changelog +* Mon Oct 16 2017 Daniel Kopeček 0.7.0-7 +- Fix enumeration timeout on kernel >= 4.13 + Resolves: rhbz#1499052 + * Thu Aug 03 2017 Fedora Release Engineering - 0.7.0-6 - Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Binutils_Mass_Rebuild