Release 4.15 kernel/kmod.c
/*
* kmod - the kernel module loader
*/
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/sched/task.h>
#include <linux/binfmts.h>
#include <linux/syscalls.h>
#include <linux/unistd.h>
#include <linux/kmod.h>
#include <linux/slab.h>
#include <linux/completion.h>
#include <linux/cred.h>
#include <linux/file.h>
#include <linux/fdtable.h>
#include <linux/workqueue.h>
#include <linux/security.h>
#include <linux/mount.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/resource.h>
#include <linux/notifier.h>
#include <linux/suspend.h>
#include <linux/rwsem.h>
#include <linux/ptrace.h>
#include <linux/async.h>
#include <linux/uaccess.h>
#include <trace/events/module.h>
/*
* Assuming:
*
* threads = div64_u64((u64) totalram_pages * (u64) PAGE_SIZE,
* (u64) THREAD_SIZE * 8UL);
*
* If you need less than 50 threads would mean we're dealing with systems
* smaller than 3200 pages. This assuems you are capable of having ~13M memory,
* and this would only be an be an upper limit, after which the OOM killer
* would take effect. Systems like these are very unlikely if modules are
* enabled.
*/
#define MAX_KMOD_CONCURRENT 50
static atomic_t kmod_concurrent_max = ATOMIC_INIT(MAX_KMOD_CONCURRENT);
static DECLARE_WAIT_QUEUE_HEAD(kmod_wq);
/*
* This is a restriction on having *all* MAX_KMOD_CONCURRENT threads
* running at the same time without returning. When this happens we
* believe you've somehow ended up with a recursive module dependency
* creating a loop.
*
* We have no option but to fail.
*
* Userspace should proactively try to detect and prevent these.
*/
#define MAX_KMOD_ALL_BUSY_TIMEOUT 5
/*
modprobe_path is set via /proc/sys.
*/
char modprobe_path[KMOD_PATH_LEN] = "/sbin/modprobe";
static void free_modprobe_argv(struct subprocess_info *info)
{
kfree(info->argv[3]); /* check call_modprobe() */
kfree(info->argv);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Oleg Nesterov | 29 | 100.00% | 1 | 100.00% |
Total | 29 | 100.00% | 1 | 100.00% |
static int call_modprobe(char *module_name, int wait)
{
struct subprocess_info *info;
static char *envp[] = {
"HOME=/",
"TERM=linux",
"PATH=/sbin:/usr/sbin:/bin:/usr/bin",
NULL
};
char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
if (!argv)
goto out;
module_name = kstrdup(module_name, GFP_KERNEL);
if (!module_name)
goto free_argv;
argv[0] = modprobe_path;
argv[1] = "-q";
argv[2] = "--";
argv[3] = module_name; /* check free_modprobe_argv() */
argv[4] = NULL;
info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
NULL, free_modprobe_argv, NULL);
if (!info)
goto free_module_name;
return call_usermodehelper_exec(info, wait | UMH_KILLABLE);
free_module_name:
kfree(module_name);
free_argv:
kfree(argv);
out:
return -ENOMEM;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Oleg Nesterov | 137 | 80.12% | 2 | 66.67% |
Lucas De Marchi | 34 | 19.88% | 1 | 33.33% |
Total | 171 | 100.00% | 3 | 100.00% |
/**
* __request_module - try to load a kernel module
* @wait: wait (or not) for the operation to complete
* @fmt: printf style format string for the name of the module
* @...: arguments as specified in the format string
*
* Load a module using the user mode module loader. The function returns
* zero on success or a negative errno code or positive exit code from
* "modprobe" on failure. Note that a successful module load does not mean
* the module did not then unload and exit on an error of its own. Callers
* must check that the service they requested is now available not blindly
* invoke it.
*
* If module auto-loading support is disabled then this function
* becomes a no-operation.
*/
int __request_module(bool wait, const char *fmt, ...)
{
va_list args;
char module_name[MODULE_NAME_LEN];
int ret;
/*
* We don't allow synchronous module loading from async. Module
* init may invoke async_synchronize_full() which will end up
* waiting for this task which already is waiting for the module
* loading to complete, leading to a deadlock.
*/
WARN_ON_ONCE(wait && current_is_async());
if (!modprobe_path[0])
return 0;
va_start(args, fmt);
ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
va_end(args);
if (ret >= MODULE_NAME_LEN)
return -ENAMETOOLONG;
ret = security_kernel_module_request(module_name);
if (ret)
return ret;
if (atomic_dec_if_positive(&kmod_concurrent_max) < 0) {
pr_warn_ratelimited("request_module: kmod_concurrent_max (%u) close to 0 (max_modprobes: %u), for module %s, throttling...",
atomic_read(&kmod_concurrent_max),
MAX_KMOD_CONCURRENT, module_name);
ret = wait_event_killable_timeout(kmod_wq,
atomic_dec_if_positive(&kmod_concurrent_max) >= 0,
MAX_KMOD_ALL_BUSY_TIMEOUT * HZ);
if (!ret) {
pr_warn_ratelimited("request_module: modprobe %s cannot be processed, kmod busy with %d threads for more than %d seconds now",
module_name, MAX_KMOD_CONCURRENT, MAX_KMOD_ALL_BUSY_TIMEOUT);
return -ETIME;
} else if (ret == -ERESTARTSYS) {
pr_warn_ratelimited("request_module: sigkill sent for modprobe %s, giving up", module_name);
return ret;
}
}
trace_module_request(module_name, wait, _RET_IP_);
ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
atomic_inc(&kmod_concurrent_max);
wake_up(&kmod_wq);
return ret;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Luis R. Rodriguez | 82 | 37.10% | 3 | 16.67% |
Linus Torvalds | 44 | 19.91% | 1 | 5.56% |
Rusty Russell | 20 | 9.05% | 2 | 11.11% |
Linus Torvalds (pre-git) | 16 | 7.24% | 4 | 22.22% |
Eric Paris | 14 | 6.33% | 1 | 5.56% |
Oleg Nesterov | 13 | 5.88% | 2 | 11.11% |
Li Zefan | 9 | 4.07% | 1 | 5.56% |
Arjan van de Ven | 9 | 4.07% | 1 | 5.56% |
Tejun Heo | 9 | 4.07% | 1 | 5.56% |
Ingo Molnar | 3 | 1.36% | 1 | 5.56% |
Jiri Kosina | 2 | 0.90% | 1 | 5.56% |
Total | 221 | 100.00% | 18 | 100.00% |
EXPORT_SYMBOL(__request_module);
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Oleg Nesterov | 179 | 33.33% | 3 | 6.98% |
Luis R. Rodriguez | 108 | 20.11% | 4 | 9.30% |
Linus Torvalds | 54 | 10.06% | 5 | 11.63% |
Linus Torvalds (pre-git) | 38 | 7.08% | 6 | 13.95% |
Lucas De Marchi | 34 | 6.33% | 1 | 2.33% |
Rusty Russell | 23 | 4.28% | 2 | 4.65% |
Eric Paris | 17 | 3.17% | 2 | 4.65% |
Tejun Heo | 12 | 2.23% | 1 | 2.33% |
Li Zefan | 12 | 2.23% | 1 | 2.33% |
Andrew Morton | 11 | 2.05% | 3 | 6.98% |
Arjan van de Ven | 10 | 1.86% | 1 | 2.33% |
Ingo Molnar | 10 | 1.86% | 4 | 9.30% |
Al Viro | 6 | 1.12% | 2 | 4.65% |
Rafael J. Wysocki | 6 | 1.12% | 1 | 2.33% |
Greg Kroah-Hartman | 3 | 0.56% | 1 | 2.33% |
Christoph Hellwig | 3 | 0.56% | 1 | 2.33% |
Srivatsa S. Bhat | 3 | 0.56% | 1 | 2.33% |
Andi Kleen | 3 | 0.56% | 1 | 2.33% |
Jiri Kosina | 2 | 0.37% | 1 | 2.33% |
Matthew Wilcox | 2 | 0.37% | 1 | 2.33% |
Neil Brown | 1 | 0.19% | 1 | 2.33% |
Total | 537 | 100.00% | 43 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.