]> git.ipfire.org Git - people/ms/linux.git/blob - kernel/kmod.c
Importing "grsecurity-3.1-3.19.2-201503201903.patch"
[people/ms/linux.git] / kernel / kmod.c
1 /*
2 kmod, the new module loader (replaces kerneld)
3 Kirk Petersen
4
5 Reorganized not to be a daemon by Adam Richter, with guidance
6 from Greg Zornetzer.
7
8 Modified to avoid chroot and file sharing problems.
9 Mikael Pettersson
10
11 Limit the concurrent number of kmod modprobes to catch loops from
12 "modprobe needs a service that is in a module".
13 Keith Owens <kaos@ocs.com.au> December 1999
14
15 Unblock all signals when we exec a usermode process.
16 Shuu Yamaguchi <shuu@wondernetworkresources.com> December 2000
17
18 call_usermodehelper wait flag, and remove exec_usermodehelper.
19 Rusty Russell <rusty@rustcorp.com.au> Jan 2003
20 */
21 #include <linux/module.h>
22 #include <linux/sched.h>
23 #include <linux/syscalls.h>
24 #include <linux/unistd.h>
25 #include <linux/kmod.h>
26 #include <linux/slab.h>
27 #include <linux/completion.h>
28 #include <linux/cred.h>
29 #include <linux/file.h>
30 #include <linux/fdtable.h>
31 #include <linux/workqueue.h>
32 #include <linux/security.h>
33 #include <linux/mount.h>
34 #include <linux/kernel.h>
35 #include <linux/init.h>
36 #include <linux/resource.h>
37 #include <linux/notifier.h>
38 #include <linux/suspend.h>
39 #include <linux/rwsem.h>
40 #include <linux/ptrace.h>
41 #include <linux/async.h>
42 #include <asm/uaccess.h>
43
44 #include <trace/events/module.h>
45
46 extern int max_threads;
47
48 static struct workqueue_struct *khelper_wq;
49
50 #define CAP_BSET (void *)1
51 #define CAP_PI (void *)2
52
53 static kernel_cap_t usermodehelper_bset = CAP_FULL_SET;
54 static kernel_cap_t usermodehelper_inheritable = CAP_FULL_SET;
55 static DEFINE_SPINLOCK(umh_sysctl_lock);
56 static DECLARE_RWSEM(umhelper_sem);
57
58 #ifdef CONFIG_MODULES
59
60 /*
61 modprobe_path is set via /proc/sys.
62 */
63 char modprobe_path[KMOD_PATH_LEN] = "/sbin/modprobe";
64
65 static void free_modprobe_argv(struct subprocess_info *info)
66 {
67 kfree(info->argv[3]); /* check call_modprobe() */
68 kfree(info->argv);
69 }
70
71 static int call_modprobe(char *module_name, char *module_param, int wait)
72 {
73 struct subprocess_info *info;
74 static char *envp[] = {
75 "HOME=/",
76 "TERM=linux",
77 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
78 NULL
79 };
80
81 char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
82 if (!argv)
83 goto out;
84
85 module_name = kstrdup(module_name, GFP_KERNEL);
86 if (!module_name)
87 goto free_argv;
88
89 argv[0] = modprobe_path;
90 argv[1] = "-q";
91 argv[2] = "--";
92 argv[3] = module_name; /* check free_modprobe_argv() */
93 argv[4] = module_param;
94 argv[5] = NULL;
95
96 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
97 NULL, free_modprobe_argv, NULL);
98 if (!info)
99 goto free_module_name;
100
101 return call_usermodehelper_exec(info, wait | UMH_KILLABLE);
102
103 free_module_name:
104 kfree(module_name);
105 free_argv:
106 kfree(argv);
107 out:
108 return -ENOMEM;
109 }
110
111 /**
112 * __request_module - try to load a kernel module
113 * @wait: wait (or not) for the operation to complete
114 * @fmt: printf style format string for the name of the module
115 * @...: arguments as specified in the format string
116 *
117 * Load a module using the user mode module loader. The function returns
118 * zero on success or a negative errno code on failure. Note that a
119 * successful module load does not mean the module did not then unload
120 * and exit on an error of its own. Callers must check that the service
121 * they requested is now available not blindly invoke it.
122 *
123 * If module auto-loading support is disabled then this function
124 * becomes a no-operation.
125 */
126 static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
127 {
128 char module_name[MODULE_NAME_LEN];
129 unsigned int max_modprobes;
130 int ret;
131 static atomic_t kmod_concurrent = ATOMIC_INIT(0);
132 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
133 static int kmod_loop_msg;
134
135 /*
136 * We don't allow synchronous module loading from async. Module
137 * init may invoke async_synchronize_full() which will end up
138 * waiting for this task which already is waiting for the module
139 * loading to complete, leading to a deadlock.
140 */
141 WARN_ON_ONCE(wait && current_is_async());
142
143 if (!modprobe_path[0])
144 return 0;
145
146 ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
147 if (ret >= MODULE_NAME_LEN)
148 return -ENAMETOOLONG;
149
150 ret = security_kernel_module_request(module_name);
151 if (ret)
152 return ret;
153
154 #ifdef CONFIG_GRKERNSEC_MODHARDEN
155 if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
156 /* hack to workaround consolekit/udisks stupidity */
157 read_lock(&tasklist_lock);
158 if (!strcmp(current->comm, "mount") &&
159 current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
160 read_unlock(&tasklist_lock);
161 printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
162 return -EPERM;
163 }
164 read_unlock(&tasklist_lock);
165 }
166 #endif
167
168 /* If modprobe needs a service that is in a module, we get a recursive
169 * loop. Limit the number of running kmod threads to max_threads/2 or
170 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
171 * would be to run the parents of this process, counting how many times
172 * kmod was invoked. That would mean accessing the internals of the
173 * process tables to get the command line, proc_pid_cmdline is static
174 * and it is not worth changing the proc code just to handle this case.
175 * KAO.
176 *
177 * "trace the ppid" is simple, but will fail if someone's
178 * parent exits. I think this is as good as it gets. --RR
179 */
180 max_modprobes = min(max_threads/2, MAX_KMOD_CONCURRENT);
181 atomic_inc(&kmod_concurrent);
182 if (atomic_read(&kmod_concurrent) > max_modprobes) {
183 /* We may be blaming an innocent here, but unlikely */
184 if (kmod_loop_msg < 5) {
185 printk(KERN_ERR
186 "request_module: runaway loop modprobe %s\n",
187 module_name);
188 kmod_loop_msg++;
189 }
190 atomic_dec(&kmod_concurrent);
191 return -ENOMEM;
192 }
193
194 trace_module_request(module_name, wait, _RET_IP_);
195
196 ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
197
198 atomic_dec(&kmod_concurrent);
199 return ret;
200 }
201
202 int ___request_module(bool wait, char *module_param, const char *fmt, ...)
203 {
204 va_list args;
205 int ret;
206
207 va_start(args, fmt);
208 ret = ____request_module(wait, module_param, fmt, args);
209 va_end(args);
210
211 return ret;
212 }
213
214 int __request_module(bool wait, const char *fmt, ...)
215 {
216 va_list args;
217 int ret;
218
219 #ifdef CONFIG_GRKERNSEC_MODHARDEN
220 if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
221 char module_param[MODULE_NAME_LEN];
222
223 memset(module_param, 0, sizeof(module_param));
224
225 snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
226
227 va_start(args, fmt);
228 ret = ____request_module(wait, module_param, fmt, args);
229 va_end(args);
230
231 return ret;
232 }
233 #endif
234
235 va_start(args, fmt);
236 ret = ____request_module(wait, NULL, fmt, args);
237 va_end(args);
238
239 return ret;
240 }
241
242 EXPORT_SYMBOL(__request_module);
243 #endif /* CONFIG_MODULES */
244
245 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
246 {
247 #ifdef CONFIG_GRKERNSEC
248 kfree(info->path);
249 info->path = info->origpath;
250 #endif
251 if (info->cleanup)
252 (*info->cleanup)(info);
253 kfree(info);
254 }
255
256 static void umh_complete(struct subprocess_info *sub_info)
257 {
258 struct completion *comp = xchg(&sub_info->complete, NULL);
259 /*
260 * See call_usermodehelper_exec(). If xchg() returns NULL
261 * we own sub_info, the UMH_KILLABLE caller has gone away
262 * or the caller used UMH_NO_WAIT.
263 */
264 if (comp)
265 complete(comp);
266 else
267 call_usermodehelper_freeinfo(sub_info);
268 }
269
270 /*
271 * This is the task which runs the usermode application
272 */
273 static int ____call_usermodehelper(void *data)
274 {
275 struct subprocess_info *sub_info = data;
276 struct cred *new;
277 int retval;
278
279 spin_lock_irq(&current->sighand->siglock);
280 flush_signal_handlers(current, 1);
281 spin_unlock_irq(&current->sighand->siglock);
282
283 /* We can run anywhere, unlike our parent keventd(). */
284 set_cpus_allowed_ptr(current, cpu_all_mask);
285
286 /*
287 * Our parent is keventd, which runs with elevated scheduling priority.
288 * Avoid propagating that into the userspace child.
289 */
290 set_user_nice(current, 0);
291
292 #ifdef CONFIG_GRKERNSEC
293 /* this is race-free as far as userland is concerned as we copied
294 out the path to be used prior to this point and are now operating
295 on that copy
296 */
297 if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
298 strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
299 strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
300 printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
301 retval = -EPERM;
302 goto out;
303 }
304 #endif
305
306 retval = -ENOMEM;
307 new = prepare_kernel_cred(current);
308 if (!new)
309 goto out;
310
311 spin_lock(&umh_sysctl_lock);
312 new->cap_bset = cap_intersect(usermodehelper_bset, new->cap_bset);
313 new->cap_inheritable = cap_intersect(usermodehelper_inheritable,
314 new->cap_inheritable);
315 spin_unlock(&umh_sysctl_lock);
316
317 if (sub_info->init) {
318 retval = sub_info->init(sub_info, new);
319 if (retval) {
320 abort_creds(new);
321 goto out;
322 }
323 }
324
325 commit_creds(new);
326
327 retval = do_execve(getname_kernel(sub_info->path),
328 (const char __user *const __force_user *)sub_info->argv,
329 (const char __user *const __force_user *)sub_info->envp);
330 out:
331 sub_info->retval = retval;
332 /* wait_for_helper() will call umh_complete if UHM_WAIT_PROC. */
333 if (!(sub_info->wait & UMH_WAIT_PROC))
334 umh_complete(sub_info);
335 if (!retval)
336 return 0;
337 do_exit(0);
338 }
339
340 /* Keventd can't block, but this (a child) can. */
341 static int wait_for_helper(void *data)
342 {
343 struct subprocess_info *sub_info = data;
344 pid_t pid;
345
346 /* If SIGCLD is ignored sys_wait4 won't populate the status. */
347 kernel_sigaction(SIGCHLD, SIG_DFL);
348 pid = kernel_thread(____call_usermodehelper, sub_info, SIGCHLD);
349 if (pid < 0) {
350 sub_info->retval = pid;
351 } else {
352 int ret = -ECHILD;
353 /*
354 * Normally it is bogus to call wait4() from in-kernel because
355 * wait4() wants to write the exit code to a userspace address.
356 * But wait_for_helper() always runs as keventd, and put_user()
357 * to a kernel address works OK for kernel threads, due to their
358 * having an mm_segment_t which spans the entire address space.
359 *
360 * Thus the __user pointer cast is valid here.
361 */
362 sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
363
364 /*
365 * If ret is 0, either ____call_usermodehelper failed and the
366 * real error code is already in sub_info->retval or
367 * sub_info->retval is 0 anyway, so don't mess with it then.
368 */
369 if (ret)
370 sub_info->retval = ret;
371 }
372
373 umh_complete(sub_info);
374 do_exit(0);
375 }
376
377 /* This is run by khelper thread */
378 static void __call_usermodehelper(struct work_struct *work)
379 {
380 struct subprocess_info *sub_info =
381 container_of(work, struct subprocess_info, work);
382 pid_t pid;
383
384 if (sub_info->wait & UMH_WAIT_PROC)
385 pid = kernel_thread(wait_for_helper, sub_info,
386 CLONE_FS | CLONE_FILES | SIGCHLD);
387 else
388 pid = kernel_thread(____call_usermodehelper, sub_info,
389 SIGCHLD);
390
391 if (pid < 0) {
392 sub_info->retval = pid;
393 umh_complete(sub_info);
394 }
395 }
396
397 /*
398 * If set, call_usermodehelper_exec() will exit immediately returning -EBUSY
399 * (used for preventing user land processes from being created after the user
400 * land has been frozen during a system-wide hibernation or suspend operation).
401 * Should always be manipulated under umhelper_sem acquired for write.
402 */
403 static enum umh_disable_depth usermodehelper_disabled = UMH_DISABLED;
404
405 /* Number of helpers running */
406 static atomic_t running_helpers = ATOMIC_INIT(0);
407
408 /*
409 * Wait queue head used by usermodehelper_disable() to wait for all running
410 * helpers to finish.
411 */
412 static DECLARE_WAIT_QUEUE_HEAD(running_helpers_waitq);
413
414 /*
415 * Used by usermodehelper_read_lock_wait() to wait for usermodehelper_disabled
416 * to become 'false'.
417 */
418 static DECLARE_WAIT_QUEUE_HEAD(usermodehelper_disabled_waitq);
419
420 /*
421 * Time to wait for running_helpers to become zero before the setting of
422 * usermodehelper_disabled in usermodehelper_disable() fails
423 */
424 #define RUNNING_HELPERS_TIMEOUT (5 * HZ)
425
426 int usermodehelper_read_trylock(void)
427 {
428 DEFINE_WAIT(wait);
429 int ret = 0;
430
431 down_read(&umhelper_sem);
432 for (;;) {
433 prepare_to_wait(&usermodehelper_disabled_waitq, &wait,
434 TASK_INTERRUPTIBLE);
435 if (!usermodehelper_disabled)
436 break;
437
438 if (usermodehelper_disabled == UMH_DISABLED)
439 ret = -EAGAIN;
440
441 up_read(&umhelper_sem);
442
443 if (ret)
444 break;
445
446 schedule();
447 try_to_freeze();
448
449 down_read(&umhelper_sem);
450 }
451 finish_wait(&usermodehelper_disabled_waitq, &wait);
452 return ret;
453 }
454 EXPORT_SYMBOL_GPL(usermodehelper_read_trylock);
455
456 long usermodehelper_read_lock_wait(long timeout)
457 {
458 DEFINE_WAIT(wait);
459
460 if (timeout < 0)
461 return -EINVAL;
462
463 down_read(&umhelper_sem);
464 for (;;) {
465 prepare_to_wait(&usermodehelper_disabled_waitq, &wait,
466 TASK_UNINTERRUPTIBLE);
467 if (!usermodehelper_disabled)
468 break;
469
470 up_read(&umhelper_sem);
471
472 timeout = schedule_timeout(timeout);
473 if (!timeout)
474 break;
475
476 down_read(&umhelper_sem);
477 }
478 finish_wait(&usermodehelper_disabled_waitq, &wait);
479 return timeout;
480 }
481 EXPORT_SYMBOL_GPL(usermodehelper_read_lock_wait);
482
483 void usermodehelper_read_unlock(void)
484 {
485 up_read(&umhelper_sem);
486 }
487 EXPORT_SYMBOL_GPL(usermodehelper_read_unlock);
488
489 /**
490 * __usermodehelper_set_disable_depth - Modify usermodehelper_disabled.
491 * @depth: New value to assign to usermodehelper_disabled.
492 *
493 * Change the value of usermodehelper_disabled (under umhelper_sem locked for
494 * writing) and wakeup tasks waiting for it to change.
495 */
496 void __usermodehelper_set_disable_depth(enum umh_disable_depth depth)
497 {
498 down_write(&umhelper_sem);
499 usermodehelper_disabled = depth;
500 wake_up(&usermodehelper_disabled_waitq);
501 up_write(&umhelper_sem);
502 }
503
504 /**
505 * __usermodehelper_disable - Prevent new helpers from being started.
506 * @depth: New value to assign to usermodehelper_disabled.
507 *
508 * Set usermodehelper_disabled to @depth and wait for running helpers to exit.
509 */
510 int __usermodehelper_disable(enum umh_disable_depth depth)
511 {
512 long retval;
513
514 if (!depth)
515 return -EINVAL;
516
517 down_write(&umhelper_sem);
518 usermodehelper_disabled = depth;
519 up_write(&umhelper_sem);
520
521 /*
522 * From now on call_usermodehelper_exec() won't start any new
523 * helpers, so it is sufficient if running_helpers turns out to
524 * be zero at one point (it may be increased later, but that
525 * doesn't matter).
526 */
527 retval = wait_event_timeout(running_helpers_waitq,
528 atomic_read(&running_helpers) == 0,
529 RUNNING_HELPERS_TIMEOUT);
530 if (retval)
531 return 0;
532
533 __usermodehelper_set_disable_depth(UMH_ENABLED);
534 return -EAGAIN;
535 }
536
537 static void helper_lock(void)
538 {
539 atomic_inc(&running_helpers);
540 smp_mb__after_atomic();
541 }
542
543 static void helper_unlock(void)
544 {
545 if (atomic_dec_and_test(&running_helpers))
546 wake_up(&running_helpers_waitq);
547 }
548
549 /**
550 * call_usermodehelper_setup - prepare to call a usermode helper
551 * @path: path to usermode executable
552 * @argv: arg vector for process
553 * @envp: environment for process
554 * @gfp_mask: gfp mask for memory allocation
555 * @cleanup: a cleanup function
556 * @init: an init function
557 * @data: arbitrary context sensitive data
558 *
559 * Returns either %NULL on allocation failure, or a subprocess_info
560 * structure. This should be passed to call_usermodehelper_exec to
561 * exec the process and free the structure.
562 *
563 * The init function is used to customize the helper process prior to
564 * exec. A non-zero return code causes the process to error out, exit,
565 * and return the failure to the calling process
566 *
567 * The cleanup function is just before ethe subprocess_info is about to
568 * be freed. This can be used for freeing the argv and envp. The
569 * Function must be runnable in either a process context or the
570 * context in which call_usermodehelper_exec is called.
571 */
572 struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
573 char **envp, gfp_t gfp_mask,
574 int (*init)(struct subprocess_info *info, struct cred *new),
575 void (*cleanup)(struct subprocess_info *info),
576 void *data)
577 {
578 struct subprocess_info *sub_info;
579 sub_info = kzalloc(sizeof(struct subprocess_info), gfp_mask);
580 if (!sub_info)
581 goto out;
582
583 INIT_WORK(&sub_info->work, __call_usermodehelper);
584 #ifdef CONFIG_GRKERNSEC
585 sub_info->origpath = path;
586 sub_info->path = kstrdup(path, gfp_mask);
587 #else
588 sub_info->path = path;
589 #endif
590 sub_info->argv = argv;
591 sub_info->envp = envp;
592
593 sub_info->cleanup = cleanup;
594 sub_info->init = init;
595 sub_info->data = data;
596 out:
597 return sub_info;
598 }
599 EXPORT_SYMBOL(call_usermodehelper_setup);
600
601 /**
602 * call_usermodehelper_exec - start a usermode application
603 * @sub_info: information about the subprocessa
604 * @wait: wait for the application to finish and return status.
605 * when UMH_NO_WAIT don't wait at all, but you get no useful error back
606 * when the program couldn't be exec'ed. This makes it safe to call
607 * from interrupt context.
608 *
609 * Runs a user-space application. The application is started
610 * asynchronously if wait is not set, and runs as a child of keventd.
611 * (ie. it runs with full root capabilities).
612 */
613 int call_usermodehelper_exec(struct subprocess_info *sub_info, int wait)
614 {
615 DECLARE_COMPLETION_ONSTACK(done);
616 int retval = 0;
617
618 if (!sub_info->path) {
619 call_usermodehelper_freeinfo(sub_info);
620 return -EINVAL;
621 }
622 helper_lock();
623 if (!khelper_wq || usermodehelper_disabled) {
624 retval = -EBUSY;
625 goto out;
626 }
627 /*
628 * Set the completion pointer only if there is a waiter.
629 * This makes it possible to use umh_complete to free
630 * the data structure in case of UMH_NO_WAIT.
631 */
632 sub_info->complete = (wait == UMH_NO_WAIT) ? NULL : &done;
633 sub_info->wait = wait;
634
635 queue_work(khelper_wq, &sub_info->work);
636 if (wait == UMH_NO_WAIT) /* task has freed sub_info */
637 goto unlock;
638
639 if (wait & UMH_KILLABLE) {
640 retval = wait_for_completion_killable(&done);
641 if (!retval)
642 goto wait_done;
643
644 /* umh_complete() will see NULL and free sub_info */
645 if (xchg(&sub_info->complete, NULL))
646 goto unlock;
647 /* fallthrough, umh_complete() was already called */
648 }
649
650 wait_for_completion(&done);
651 wait_done:
652 retval = sub_info->retval;
653 out:
654 call_usermodehelper_freeinfo(sub_info);
655 unlock:
656 helper_unlock();
657 return retval;
658 }
659 EXPORT_SYMBOL(call_usermodehelper_exec);
660
661 /**
662 * call_usermodehelper() - prepare and start a usermode application
663 * @path: path to usermode executable
664 * @argv: arg vector for process
665 * @envp: environment for process
666 * @wait: wait for the application to finish and return status.
667 * when UMH_NO_WAIT don't wait at all, but you get no useful error back
668 * when the program couldn't be exec'ed. This makes it safe to call
669 * from interrupt context.
670 *
671 * This function is the equivalent to use call_usermodehelper_setup() and
672 * call_usermodehelper_exec().
673 */
674 int call_usermodehelper(char *path, char **argv, char **envp, int wait)
675 {
676 struct subprocess_info *info;
677 gfp_t gfp_mask = (wait == UMH_NO_WAIT) ? GFP_ATOMIC : GFP_KERNEL;
678
679 info = call_usermodehelper_setup(path, argv, envp, gfp_mask,
680 NULL, NULL, NULL);
681 if (info == NULL)
682 return -ENOMEM;
683
684 return call_usermodehelper_exec(info, wait);
685 }
686 EXPORT_SYMBOL(call_usermodehelper);
687
688 static int proc_cap_handler(struct ctl_table *table, int write,
689 void __user *buffer, size_t *lenp, loff_t *ppos)
690 {
691 ctl_table_no_const t;
692 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
693 kernel_cap_t new_cap;
694 int err, i;
695
696 if (write && (!capable(CAP_SETPCAP) ||
697 !capable(CAP_SYS_MODULE)))
698 return -EPERM;
699
700 /*
701 * convert from the global kernel_cap_t to the ulong array to print to
702 * userspace if this is a read.
703 */
704 spin_lock(&umh_sysctl_lock);
705 for (i = 0; i < _KERNEL_CAPABILITY_U32S; i++) {
706 if (table->data == CAP_BSET)
707 cap_array[i] = usermodehelper_bset.cap[i];
708 else if (table->data == CAP_PI)
709 cap_array[i] = usermodehelper_inheritable.cap[i];
710 else
711 BUG();
712 }
713 spin_unlock(&umh_sysctl_lock);
714
715 t = *table;
716 t.data = &cap_array;
717
718 /*
719 * actually read or write and array of ulongs from userspace. Remember
720 * these are least significant 32 bits first
721 */
722 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
723 if (err < 0)
724 return err;
725
726 /*
727 * convert from the sysctl array of ulongs to the kernel_cap_t
728 * internal representation
729 */
730 for (i = 0; i < _KERNEL_CAPABILITY_U32S; i++)
731 new_cap.cap[i] = cap_array[i];
732
733 /*
734 * Drop everything not in the new_cap (but don't add things)
735 */
736 spin_lock(&umh_sysctl_lock);
737 if (write) {
738 if (table->data == CAP_BSET)
739 usermodehelper_bset = cap_intersect(usermodehelper_bset, new_cap);
740 if (table->data == CAP_PI)
741 usermodehelper_inheritable = cap_intersect(usermodehelper_inheritable, new_cap);
742 }
743 spin_unlock(&umh_sysctl_lock);
744
745 return 0;
746 }
747
748 struct ctl_table usermodehelper_table[] = {
749 {
750 .procname = "bset",
751 .data = CAP_BSET,
752 .maxlen = _KERNEL_CAPABILITY_U32S * sizeof(unsigned long),
753 .mode = 0600,
754 .proc_handler = proc_cap_handler,
755 },
756 {
757 .procname = "inheritable",
758 .data = CAP_PI,
759 .maxlen = _KERNEL_CAPABILITY_U32S * sizeof(unsigned long),
760 .mode = 0600,
761 .proc_handler = proc_cap_handler,
762 },
763 { }
764 };
765
766 void __init usermodehelper_init(void)
767 {
768 khelper_wq = create_singlethread_workqueue("khelper");
769 BUG_ON(!khelper_wq);
770 }