21 #include <linux/module.h>
22 #include <linux/sched.h>
26 #include <linux/slab.h>
34 #include <linux/kernel.h>
36 #include <linux/resource.h>
40 #include <linux/ptrace.h>
41 #include <asm/uaccess.h>
54 static const struct task_struct *kmod_thread_locker;
56 #define CAP_BSET (void *)1
57 #define CAP_PI (void *)2
60 static kernel_cap_t usermodehelper_inheritable = CAP_FULL_SET;
79 static char *envp[] = {
82 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
94 argv[0] = modprobe_path;
123 int __request_module(
bool wait,
const char *
fmt, ...)
127 unsigned int max_modprobes;
130 #define MAX_KMOD_CONCURRENT 50
131 static int kmod_loop_msg;
157 if (
atomic_read(&kmod_concurrent) > max_modprobes) {
159 if (kmod_loop_msg < 5) {
161 "request_module: runaway loop modprobe %s\n",
169 trace_module_request(module_name, wait,
_RET_IP_);
182 static int ____call_usermodehelper(
void *
data)
188 spin_lock_irq(&
current->sighand->siglock);
190 spin_unlock_irq(&
current->sighand->siglock);
206 spin_lock(&umh_sysctl_lock);
207 new->cap_bset = cap_intersect(usermodehelper_bset, new->cap_bset);
208 new->cap_inheritable = cap_intersect(usermodehelper_inheritable,
209 new->cap_inheritable);
210 spin_unlock(&umh_sysctl_lock);
212 if (sub_info->
init) {
213 retval = sub_info->
init(sub_info,
new);
223 (
const char *
const *)sub_info->
argv,
224 (
const char *
const *)sub_info->
envp);
234 static int call_helper(
void *data)
238 return ____call_usermodehelper(data);
258 call_usermodehelper_freeinfo(sub_info);
262 static int wait_for_helper(
void *data)
268 spin_lock_irq(&
current->sighand->siglock);
270 spin_unlock_irq(&
current->sighand->siglock);
297 umh_complete(sub_info);
319 kmod_thread_locker =
NULL;
324 call_usermodehelper_freeinfo(sub_info);
334 umh_complete(sub_info);
365 #define RUNNING_HELPERS_TIMEOUT (5 * HZ)
376 if (!usermodehelper_disabled)
392 finish_wait(&usermodehelper_disabled_waitq, &wait);
408 if (!usermodehelper_disabled)
419 finish_wait(&usermodehelper_disabled_waitq, &wait);
440 usermodehelper_disabled =
depth;
441 wake_up(&usermodehelper_disabled_waitq);
459 usermodehelper_disabled =
depth;
478 static void helper_lock(
void)
484 static void helper_unlock(
void)
487 wake_up(&running_helpers_waitq);
558 int call_usermodehelper_exec(
struct subprocess_info *sub_info,
int wait)
564 if (sub_info->
path[0] ==
'\0')
567 if (!khelper_wq || usermodehelper_disabled) {
602 retval = sub_info->
retval;
604 call_usermodehelper_freeinfo(sub_info);
617 char *path,
char **argv,
char **envp,
int wait,
624 info = call_usermodehelper_setup(path, argv, envp, gfp_mask);
629 call_usermodehelper_setfns(info,
init,
cleanup, data);
631 return call_usermodehelper_exec(info, wait);
636 void __user *
buffer,
size_t *lenp, loff_t *ppos)
651 spin_lock(&umh_sysctl_lock);
654 cap_array[
i] = usermodehelper_bset.
cap[
i];
656 cap_array[
i] = usermodehelper_inheritable.
cap[
i];
660 spin_unlock(&umh_sysctl_lock);
678 new_cap.
cap[i] = cap_array[i];
683 spin_lock(&umh_sysctl_lock);
686 usermodehelper_bset = cap_intersect(usermodehelper_bset, new_cap);
688 usermodehelper_inheritable = cap_intersect(usermodehelper_inheritable, new_cap);
690 spin_unlock(&umh_sysctl_lock);
699 .maxlen = _KERNEL_CAPABILITY_U32S *
sizeof(
unsigned long),
704 .procname =
"inheritable",
706 .maxlen = _KERNEL_CAPABILITY_U32S *
sizeof(
unsigned long),