Linux

如何為insmod設置黑名單?

  • May 15, 2013

我想阻止某個驅動程序模組載入到 linux 核心中。所以我在 /etc/modprobe.d/cdc_acm.conf 中創建了一個文件。在這個文件中,我添加了以下行:

install cdc_acm /bin/false

這在發佈時按預期工作:

modprobe cdc-acm

libkmod: ERROR libkmod/libkmod-module.c:924
command_do: Error running install command for cdc_acm ERROR: could not
insert 'cdc_acm': Operation not permitted

問題是,當我使用 insmod 實用程序時,會載入模組:

insmod cdc-acm.ko

[ 1051.914578] cdc_acm 2-1.1:1.0:
usb_probe_interface [ 1051.919437] cdc_acm 2-1.1:1.0:
usb_probe_interface - got id [ 1051.926323] cdc_acm 2-1.1:1.0:
ttyACM0: USB ACM device [ 1051.934700] usbcore: registered new
interface driver cdc_acm [ 1051.941315] cdc_acm: USB Abstract Control
Model driver for USB modems and ISDN adapters

為什麼會發生這種情況有辦法為 insmod 創建黑名單文件嗎?

modprobe黑名單是由insmod 只是嘗試插入一個模組而不用打擾依賴項或黑名單或任何東西來讀取的。

insmod手冊頁:

insmod is a trivial program to insert a module into the kernel. Most users will want to 
use modprobe(8) instead, which is more clever and can handle module dependencies.

引用自:https://unix.stackexchange.com/questions/75917