module blacklist
生活随笔
收集整理的這篇文章主要介紹了
module blacklist
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
對內(nèi)核模塊來說,黑名單是指禁止某個模塊裝入的機制
使用 /etc/modprobe.d/ 中的文件
在 /etc/modprobe.d/ 中創(chuàng)建 .conf 文件,使用 blacklist 關(guān)鍵字屏蔽不需要的模塊,例如如果不想裝入 pcspkr 模塊:/etc/modprobe.d/nobeep.conf
# Do not load the pcspkr module on boot
blacklist pcspkr
或者通過命令行的模式
modprobe.blacklist=modname1,modname2
從這里可以看出blacklist是一個模塊參數(shù),其實現(xiàn)在linux/module.c中
其源碼如下:
static bool blacklisted(const char *module_name)
{const char *p;size_t len;#可以看到module_blacklist 這個list 為null,則直接返回falseif (!module_blacklist)return false;#這里通過查詢這個list 來比較模塊的name 是否在module_blacklist中,如果在的話,返回true,就不在加載#layout_and_allocate 這個函數(shù)中加載這個模塊for (p = module_blacklist; *p; p += len) {len = strcspn(p, ",");if (strlen(module_name) == len && !memcmp(module_name, p, len))return true;if (p[len] == ',')len++;}return false;
}
core_param(module_blacklist, module_blacklist, charp, 0400);
blacklisted 這個函數(shù)是在layout_and_allocate 中加載的
static struct module *layout_and_allocate(struct load_info *info, int flags)
{/* Module within temporary copy. */struct module *mod;unsigned int ndx;int err;mod = setup_load_info(info, flags);if (IS_ERR(mod))return mod;#可以看到如果blacklisted 返回true,則layout_and_allocate 就返回-EPERM,表示不加載這個模塊if (blacklisted(info->name))return ERR_PTR(-EPERM);
}
總結(jié)
以上是生活随笔為你收集整理的module blacklist的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 计算机科学领域sci杂志,【分享】计算机
- 下一篇: wpf 骚搞 新浪微博