插入 USB HID 设备时防止 usbhid 自动加载

Prevent usbhid from autoloading when USB HID device is plugged in

我正在尝试(可逆地)在 Raspbian Jessie 安装、内核版本 4.4.16-v7+ 上禁用 USB HID 支持。我们需要在半 public space 中安装 Raspberry Pi 并在电视上显示内容,我们想让它至少在一定程度上难以扰乱它。

到目前为止,我已经设法通过 rmmod 使 usbhid 模块从内核中移除。在 rmmod'ing 模块之后,tt 似乎每次我插入 USB 键盘或鼠标时,设备驱动程序都会加载回内核。

有什么办法可以避免吗?

我能想到两个方案:

更简单:

将/etc/modprobe.d/blacklist.conf中的内核模块加入黑名单:

blacklist usbhid

确保您使用 sudo 或以 root 身份登录以 root 身份执行此操作,否则此文件为只读。

更难:

如果您有能力重新编译您正在使用的内核,那么您可以在内核配置文件中设置 CONFIG_USB_HID=n 以完全禁用 usbhid。

您可以关注 Raspberry Pi 的 kernel building steps, and once you have everything all set to build, you can modify the configuration file so that CONFIG_USB_HID=n. You could do this during a menuconfig or the way I usually do it, which is by editing the hidden .config file after running a make defconfig. See linux kernel in a nutshell 以获得有关配置和构建 linux 内核的更多信息。

由于 Raspberry Pi 是 ARM,我假设您的计算机是 x86,您将需要设置一个交叉编译器工具链。该信息也应该在 RasPi 的内核构建步骤中找到。

然后继续按照 RasPi 的内核构建步骤将内核安装到您的 Raspberry Pi 上。这应该可以解决出现 usbhid 的问题。它不会首先被烘焙到内核中。

udev 是最好和最简单的方法,添加一个新规则,例如: /etc/udev/rules.d/99-disable-usb-hid.规则:

SUBSYSTEMS=="usb", DRIVERS=="usbhid", ACTION=="add", ATTR{authorized}="0"

并重新启动 udev。 我刚刚在 Debian Jessie ARM 4.4.16 中对其进行了测试。