USBAUTH(8)
π‘οΈ USBAUTH(8) β the usbauth page from the System Manager's Manual, section 8, bestie
okay so first things first: this whole page is about usbauth, and it's a USB firewall against BadUSB attacks π
that's the whole vibe, let's get into it.
β¨ SYNOPSIS β¨
Three modes, three moods. Pick your fighter:
udev mode β called by udev:
usbauth udev-add
manual mode β called by the notifier:
usbauth allow DEVNUM PATH
usbauth deny DEVNUM PATH
where:
PATHis the path of the USB interface, example/sys/bus/usb/devices/3-2/3-2:1.0/DEVNUMis the value of the attribute, example16(from/sys/bus/usb/devices/3-2/devnum)
init mode β does apply rules for all available devices:
usbauth init
πΈ DESCRIPTION πΈ
It's a firewall against BadUSB attacks, periodt. π₯
A config file describes in which way USB interfaces would be accepted or denied. To the kernel, an interface authorization was developed with this firewall β and the firewall sets the authorization mask according to the rules. That's literally it. That's the whole job. π
π RULES π
The Attribute
[parameter operator value]
An attribute consists of a parameter, an operator and a value. Three little pieces, one iconic trio. β¨
The allow/deny rule
allow|deny Attribute+
A allow/deny rule have at minimum one attribute. For a allow/deny rule to be enforced, an USB interface must match all attributes β no cherry-picking, bestie, all of them or nothing. π«Ά
Example: a rule describes all interfaces with the HID class 0x03.
The condition
condition Attribute+ case Attribute+
The first section describes the condition that must be fulfilled. The second section, with the keyword case, defines for what interfaces the condition should apply.
Example: all rules that describe HID interfaces should apply for two devices at maximum. Then the device counter must be fulfilled. The second section describes the interface class 0x03.
Default rules
allow|deny all
These rules are for the generic case. If no other rule matches an interface, these are the ones that catch it. π§
Order matters, ngl
Rules will be checked top down. A rule at top could be overwritten by a rule at down. So yeah β position your faves wisely. π
π Parameters π
The following parameters are defined at device section
busnumβ number of the USB busdevpathβ number of the USB portidVendorβ vendor ID, defines the vendor of the USB deviceidProductβ product ID, defines the product from a vendorbDeviceClassβ USB device classbDeviceSubClassβ USB device sub classbDeviceProtocolβ USB device protocolbConfigurationValueβ current USB configurationserialβ serial number of the devicemanufacturerβ manufacturer of deviceproductβ product name stringconnect_typeβhotplug: external USB device,direct: internal USB devicebcdDeviceβ USB protocol versionspeedβ USB speed valuebNumConfigurationsβ the number of available USB configurations
The following parameters are defined at configuration section
bNumInterfacesβ number of available interfaces in the active configurationbInterfaceNumberβ interface numberbInterfaceClassβ interface classbInterfaceSubClassβ current sub class of interfacebInterfaceProtocolβ in case of HID devices, with this value keyboards (1) and mouses (2) could be distinctbNumEndpointsβ number of endpoints for the interface
The special internals π
The following parameters are specific and calculated internally by the firewall. They are not available in the SysFS. They count how many devices or interfaces match a rule.
intfcountβ number of interfaces for a ruledevcountβ number of devices for a rule
anyChild
The keyword anyChild could be used for a parameter to check not only the own interface's attribute, but also check the siblings' attribute. If one sibling matches, the rule is valid. π
π¦ Operators π¦
The following operators are defined: ==, !=, <=, >=, <, >
With operators two values are compared. One from the data structure of a rule, the other from an USB interface. Simple as that, no cap. π
β Values β
The configured value will be compared with the default value type from sysfs. If not specified, the type of the configured value is assumed to be in sysfs value type.
- Using
\xas value prefix will set the configured value type as hexadecimal. - Using
\das value prefix will set the configured value type as decimal. - With an explicit integer value, a type conversion will be done if the value type does not match the sysfs value type.
- Using double quotes for the configured value forces a string comparisation. It allows you to specify strings containing spaces, too. π
- Point separated integer values like
1.2.3(e.g. fordevpath) are possible, and they also allow explicit type prefixing like\x1.2.3.
π Rule examples π
these are examples from the page, copy them exactly, do not freestyle π
Default rule to allow everything:
allow all
Default rule to deny everything:
deny all
Every configuration file should allow hubs β only special cases should limit these:
allow bDeviceClass==09 bInterfaceClass==09
Interfaces with device class 0 and interface class 08 (storage) will be accepted:
allow bDeviceClass==00 bInterfaceClass==08
allow bInterfaceClass==08
β the device class is irrelevant in this case.
Two USB storage devices will be accepted at specific USB ports. Not more than one storage device is allowed during a condition:
allow idVendor==0781 idProduct==5406 bInterfaceClass==08 busnum==3 devpath==6
allow idVendor==8564 idProduct==1000 bInterfaceClass==08 busnum==3 devpath==4
condition devcount<=1 case bInterfaceClass==08
β the condition is valid for all interfaces from class 08. Interfaces must comply with the condition for enforcing the two belonging allow rules.
Allow two HID (example keyboard and mouse) devices at maximum:
allow bInterfaceClass==03 devcount<=2
Allow only one keyboard:
allow bInterfaceClass==03 anyChild bInterfaceProtocol==01 devcount<=1
Allow only one mouse:
allow bInterfaceClass==03 bInterfaceProtocol==02 devcount<=1
β The parent device children of the interface would be enumerated to check for the attribute. If one matches the attribute, then the rule will be enforced.
A keyboard should have two interfaces. The bInterfaceProtocol of the first interface is "1", from the second "0". (the original page has a stray br here β that's a formatting thing, not a rule π) With anyChild it is possible to allow a rule matching for both interfaces. (another stray br in the original β iconic of it, honestly π)
Allow only certain interfaces:
Example: a multi function device have three interfaces (0xFF, 0x07, 0x08). 0xFF is to scan, 0x07 is to print, and 0x08 is for storage devices connected to the multi function device.
With the following rules only the 0xFF and 0x07 interfaces are allowed. The device class must be 0.
allow idVendor==04b8 idProduct==089e bDeviceClass==00 bInterfaceClass==ff
allow idVendor==04b8 idProduct==089e bDeviceClass==00 bInterfaceClass==07
okay that's genuinely the whole page, you ate that π go forth and firewall your USB ports like the main character you are.
sign-off time: this was USBAUTH(8), page 8 of the System Manager's Manual β mwah, take care of your hubs π«Άβ¨
π¦ where this page comes from
- fedora 43: usbauth 1.0.5-8.fc43 Β· GPL-2.0-only
- fedora 44: usbauth 1.0.5-9.fc44 Β· GPL-2.0-only
- opensuse-leap 16.0: usbauth 1.0.5-bp160.1.12 Β· GPL-2.0-only
- opensuse-leap 16.0: usbauth 1.0.5-bp160.1.12 Β· GPL-2.0-only
- opensuse-leap 16.0: usbauth 1.0.5-bp160.1.12 Β· GPL-2.0-only
- opensuse-leap 16.0: usbauth 1.0.5-bp160.1.12 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms