Skip to content

Commit be7de5f

Browse files
praritrustyrussell
authored andcommitted
modules: Add kernel parameter to blacklist modules
Blacklisting a module in linux has long been a problem. The current procedure is to use rd.blacklist=module_name, however, that doesn't cover the case after the initramfs and before a boot prompt (where one is supposed to use /etc/modprobe.d/blacklist.conf to blacklist runtime loading). Using rd.shell to get an early prompt is hit-or-miss, and doesn't cover all situations AFAICT. This patch adds this functionality of permanently blacklisting a module by its name via the kernel parameter module_blacklist=module_name. [v2]: Rusty, use core_param() instead of __setup() which simplifies things. [v3]: Rusty, undo wreckage from strsep() [v4]: Rusty, simpler version of blacklisted() Signed-off-by: Prarit Bhargava <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: Rusty Russell <[email protected]> Cc: [email protected] Signed-off-by: Rusty Russell <[email protected]>
1 parent 9502514 commit be7de5f

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

Documentation/kernel-parameters.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2301,6 +2301,9 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
23012301
Note that if CONFIG_MODULE_SIG_FORCE is set, that
23022302
is always true, so this option does nothing.
23032303

2304+
module_blacklist= [KNL] Do not load a comma-separated list of
2305+
modules. Useful for debugging problem modules.
2306+
23042307
mousedev.tap_time=
23052308
[MOUSE] Maximum time between finger touching and
23062309
leaving touchpad surface for touch to be considered

kernel/module.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3168,6 +3168,27 @@ int __weak module_frob_arch_sections(Elf_Ehdr *hdr,
31683168
return 0;
31693169
}
31703170

3171+
/* module_blacklist is a comma-separated list of module names */
3172+
static char *module_blacklist;
3173+
static bool blacklisted(char *module_name)
3174+
{
3175+
const char *p;
3176+
size_t len;
3177+
3178+
if (!module_blacklist)
3179+
return false;
3180+
3181+
for (p = module_blacklist; *p; p += len) {
3182+
len = strcspn(p, ",");
3183+
if (strlen(module_name) == len && !memcmp(module_name, p, len))
3184+
return true;
3185+
if (p[len] == ',')
3186+
len++;
3187+
}
3188+
return false;
3189+
}
3190+
core_param(module_blacklist, module_blacklist, charp, 0400);
3191+
31713192
static struct module *layout_and_allocate(struct load_info *info, int flags)
31723193
{
31733194
/* Module within temporary copy. */
@@ -3178,6 +3199,9 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
31783199
if (IS_ERR(mod))
31793200
return mod;
31803201

3202+
if (blacklisted(mod->name))
3203+
return ERR_PTR(-EPERM);
3204+
31813205
err = check_modinfo(mod, info, flags);
31823206
if (err)
31833207
return ERR_PTR(err);

0 commit comments

Comments
 (0)