]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - kernel/kmod.c
UBUNTU: SAUCE: Clear Linux: bootstats: add printk's to measure boot time in more...
[mirror_ubuntu-artful-kernel.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/sched/task.h>
24 #include <linux/binfmts.h>
25 #include <linux/syscalls.h>
26 #include <linux/unistd.h>
27 #include <linux/kmod.h>
28 #include <linux/slab.h>
29 #include <linux/completion.h>
30 #include <linux/cred.h>
31 #include <linux/file.h>
32 #include <linux/fdtable.h>
33 #include <linux/workqueue.h>
34 #include <linux/security.h>
35 #include <linux/mount.h>
36 #include <linux/kernel.h>
37 #include <linux/init.h>
38 #include <linux/resource.h>
39 #include <linux/notifier.h>
40 #include <linux/suspend.h>
41 #include <linux/rwsem.h>
42 #include <linux/ptrace.h>
43 #include <linux/async.h>
44 #include <linux/uaccess.h>
45
46 #include <trace/events/module.h>
47
48 #define CAP_BSET (void *)1
49 #define CAP_PI (void *)2
50
51 static kernel_cap_t usermodehelper_bset = CAP_FULL_SET;
52 static kernel_cap_t usermodehelper_inheritable = CAP_FULL_SET;
53 static DEFINE_SPINLOCK(umh_sysctl_lock);
54 static DECLARE_RWSEM(umhelper_sem);
55
56 #ifdef CONFIG_MODULES
57 /*
58 * Assuming:
59 *
60 * threads = div64_u64((u64) totalram_pages * (u64) PAGE_SIZE,
61 * (u64) THREAD_SIZE * 8UL);
62 *
63 * If you need less than 50 threads would mean we're dealing with systems
64 * smaller than 3200 pages. This assuems you are capable of having ~13M memory,
65 * and this would only be an be an upper limit, after which the OOM killer
66 * would take effect. Systems like these are very unlikely if modules are
67 * enabled.
68 */
69 #define MAX_KMOD_CONCURRENT 50
70 static atomic_t kmod_concurrent_max = ATOMIC_INIT(MAX_KMOD_CONCURRENT);
71 static DECLARE_WAIT_QUEUE_HEAD(kmod_wq);
72
73 /*
74 * This is a restriction on having *all* MAX_KMOD_CONCURRENT threads
75 * running at the same time without returning. When this happens we
76 * believe you've somehow ended up with a recursive module dependency
77 * creating a loop.
78 *
79 * We have no option but to fail.
80 *
81 * Userspace should proactively try to detect and prevent these.
82 */
83 #define MAX_KMOD_ALL_BUSY_TIMEOUT 5
84
85 /*
86 modprobe_path is set via /proc/sys.
87 */
88 char modprobe_path[KMOD_PATH_LEN] = "/sbin/modprobe";
89
90 static void free_modprobe_argv(struct subprocess_info *info)
91 {
92 kfree(info->argv[3]); /* check call_modprobe() */
93 kfree(info->argv);
94 }
95
96 static int call_modprobe(char *module_name, int wait)
97 {
98 struct subprocess_info *info;
99 static char *envp[] = {
100 "HOME=/",
101 "TERM=linux",
102 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
103 NULL
104 };
105
106 printk("call_modprobe: %s %i \n", module_name, wait);
107
108 char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
109 if (!argv)
110 goto out;
111
112 module_name = kstrdup(module_name, GFP_KERNEL);
113 if (!module_name)
114 goto free_argv;
115
116 argv[0] = modprobe_path;
117 argv[1] = "-q";
118 argv[2] = "--";
119 argv[3] = module_name; /* check free_modprobe_argv() */
120 argv[4] = NULL;
121
122 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
123 NULL, free_modprobe_argv, NULL);
124 if (!info)
125 goto free_module_name;
126
127 return call_usermodehelper_exec(info, wait | UMH_KILLABLE);
128
129 free_module_name:
130 kfree(module_name);
131 free_argv:
132 kfree(argv);
133 out:
134 return -ENOMEM;
135 }
136
137 /**
138 * __request_module - try to load a kernel module
139 * @wait: wait (or not) for the operation to complete
140 * @fmt: printf style format string for the name of the module
141 * @...: arguments as specified in the format string
142 *
143 * Load a module using the user mode module loader. The function returns
144 * zero on success or a negative errno code or positive exit code from
145 * "modprobe" on failure. Note that a successful module load does not mean
146 * the module did not then unload and exit on an error of its own. Callers
147 * must check that the service they requested is now available not blindly
148 * invoke it.
149 *
150 * If module auto-loading support is disabled then this function
151 * becomes a no-operation.
152 */
153 int __request_module(bool wait, const char *fmt, ...)
154 {
155 va_list args;
156 char module_name[MODULE_NAME_LEN];
157 int ret;
158
159 /*
160 * We don't allow synchronous module loading from async. Module
161 * init may invoke async_synchronize_full() which will end up
162 * waiting for this task which already is waiting for the module
163 * loading to complete, leading to a deadlock.
164 */
165 WARN_ON_ONCE(wait && current_is_async());
166
167 if (!modprobe_path[0])
168 return 0;
169
170 va_start(args, fmt);
171 ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
172 va_end(args);
173 if (ret >= MODULE_NAME_LEN)
174 return -ENAMETOOLONG;
175
176 ret = security_kernel_module_request(module_name);
177 if (ret)
178 return ret;
179
180 if (atomic_dec_if_positive(&kmod_concurrent_max) < 0) {
181 pr_warn_ratelimited("request_module: kmod_concurrent_max (%u) close to 0 (max_modprobes: %u), for module %s, throttling...",
182 atomic_read(&kmod_concurrent_max),
183 MAX_KMOD_CONCURRENT, module_name);
184 ret = wait_event_killable_timeout(kmod_wq,
185 atomic_dec_if_positive(&kmod_concurrent_max) >= 0,
186 MAX_KMOD_ALL_BUSY_TIMEOUT * HZ);
187 if (!ret) {
188 pr_warn_ratelimited("request_module: modprobe %s cannot be processed, kmod busy with %d threads for more than %d seconds now",
189 module_name, MAX_KMOD_CONCURRENT, MAX_KMOD_ALL_BUSY_TIMEOUT);
190 return -ETIME;
191 } else if (ret == -ERESTARTSYS) {
192 pr_warn_ratelimited("request_module: sigkill sent for modprobe %s, giving up", module_name);
193 return ret;
194 }
195 }
196
197 trace_module_request(module_name, wait, _RET_IP_);
198
199 ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
200
201 atomic_inc(&kmod_concurrent_max);
202 wake_up(&kmod_wq);
203
204 return ret;
205 }
206 EXPORT_SYMBOL(__request_module);
207
208 #endif /* CONFIG_MODULES */
209
210 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
211 {
212 if (info->cleanup)
213 (*info->cleanup)(info);
214 kfree(info);
215 }
216
217 static void umh_complete(struct subprocess_info *sub_info)
218 {
219 struct completion *comp = xchg(&sub_info->complete, NULL);
220 /*
221 * See call_usermodehelper_exec(). If xchg() returns NULL
222 * we own sub_info, the UMH_KILLABLE caller has gone away
223 * or the caller used UMH_NO_WAIT.
224 */
225 if (comp)
226 complete(comp);
227 else
228 call_usermodehelper_freeinfo(sub_info);
229 }
230
231 /*
232 * This is the task which runs the usermode application
233 */
234 static int call_usermodehelper_exec_async(void *data)
235 {
236 struct subprocess_info *sub_info = data;
237 struct cred *new;
238 int retval;
239
240 spin_lock_irq(&current->sighand->siglock);
241 flush_signal_handlers(current, 1);
242 spin_unlock_irq(&current->sighand->siglock);
243
244 /*
245 * Our parent (unbound workqueue) runs with elevated scheduling
246 * priority. Avoid propagating that into the userspace child.
247 */
248 set_user_nice(current, 0);
249
250 retval = -ENOMEM;
251 new = prepare_kernel_cred(current);
252 if (!new)
253 goto out;
254
255 spin_lock(&umh_sysctl_lock);
256 new->cap_bset = cap_intersect(usermodehelper_bset, new->cap_bset);
257 new->cap_inheritable = cap_intersect(usermodehelper_inheritable,
258 new->cap_inheritable);
259 spin_unlock(&umh_sysctl_lock);
260
261 if (sub_info->init) {
262 retval = sub_info->init(sub_info, new);
263 if (retval) {
264 abort_creds(new);
265 goto out;
266 }
267 }
268
269 commit_creds(new);
270
271 retval = do_execve(getname_kernel(sub_info->path),
272 (const char __user *const __user *)sub_info->argv,
273 (const char __user *const __user *)sub_info->envp);
274 out:
275 sub_info->retval = retval;
276 /*
277 * call_usermodehelper_exec_sync() will call umh_complete
278 * if UHM_WAIT_PROC.
279 */
280 if (!(sub_info->wait & UMH_WAIT_PROC))
281 umh_complete(sub_info);
282 if (!retval)
283 return 0;
284 do_exit(0);
285 }
286
287 /* Handles UMH_WAIT_PROC. */
288 static void call_usermodehelper_exec_sync(struct subprocess_info *sub_info)
289 {
290 pid_t pid;
291
292 /* If SIGCLD is ignored sys_wait4 won't populate the status. */
293 kernel_sigaction(SIGCHLD, SIG_DFL);
294 pid = kernel_thread(call_usermodehelper_exec_async, sub_info, SIGCHLD);
295 if (pid < 0) {
296 sub_info->retval = pid;
297 } else {
298 int ret = -ECHILD;
299 /*
300 * Normally it is bogus to call wait4() from in-kernel because
301 * wait4() wants to write the exit code to a userspace address.
302 * But call_usermodehelper_exec_sync() always runs as kernel
303 * thread (workqueue) and put_user() to a kernel address works
304 * OK for kernel threads, due to their having an mm_segment_t
305 * which spans the entire address space.
306 *
307 * Thus the __user pointer cast is valid here.
308 */
309 sys_wait4(pid, (int __user *)&ret, 0, NULL);
310
311 /*
312 * If ret is 0, either call_usermodehelper_exec_async failed and
313 * the real error code is already in sub_info->retval or
314 * sub_info->retval is 0 anyway, so don't mess with it then.
315 */
316 if (ret)
317 sub_info->retval = ret;
318 }
319
320 /* Restore default kernel sig handler */
321 kernel_sigaction(SIGCHLD, SIG_IGN);
322
323 umh_complete(sub_info);
324 }
325
326 /*
327 * We need to create the usermodehelper kernel thread from a task that is affine
328 * to an optimized set of CPUs (or nohz housekeeping ones) such that they
329 * inherit a widest affinity irrespective of call_usermodehelper() callers with
330 * possibly reduced affinity (eg: per-cpu workqueues). We don't want
331 * usermodehelper targets to contend a busy CPU.
332 *
333 * Unbound workqueues provide such wide affinity and allow to block on
334 * UMH_WAIT_PROC requests without blocking pending request (up to some limit).
335 *
336 * Besides, workqueues provide the privilege level that caller might not have
337 * to perform the usermodehelper request.
338 *
339 */
340 static void call_usermodehelper_exec_work(struct work_struct *work)
341 {
342 struct subprocess_info *sub_info =
343 container_of(work, struct subprocess_info, work);
344
345 if (sub_info->wait & UMH_WAIT_PROC) {
346 call_usermodehelper_exec_sync(sub_info);
347 } else {
348 pid_t pid;
349 /*
350 * Use CLONE_PARENT to reparent it to kthreadd; we do not
351 * want to pollute current->children, and we need a parent
352 * that always ignores SIGCHLD to ensure auto-reaping.
353 */
354 pid = kernel_thread(call_usermodehelper_exec_async, sub_info,
355 CLONE_PARENT | SIGCHLD);
356 if (pid < 0) {
357 sub_info->retval = pid;
358 umh_complete(sub_info);
359 }
360 }
361 }
362
363 /*
364 * If set, call_usermodehelper_exec() will exit immediately returning -EBUSY
365 * (used for preventing user land processes from being created after the user
366 * land has been frozen during a system-wide hibernation or suspend operation).
367 * Should always be manipulated under umhelper_sem acquired for write.
368 */
369 static enum umh_disable_depth usermodehelper_disabled = UMH_DISABLED;
370
371 /* Number of helpers running */
372 static atomic_t running_helpers = ATOMIC_INIT(0);
373
374 /*
375 * Wait queue head used by usermodehelper_disable() to wait for all running
376 * helpers to finish.
377 */
378 static DECLARE_WAIT_QUEUE_HEAD(running_helpers_waitq);
379
380 /*
381 * Used by usermodehelper_read_lock_wait() to wait for usermodehelper_disabled
382 * to become 'false'.
383 */
384 static DECLARE_WAIT_QUEUE_HEAD(usermodehelper_disabled_waitq);
385
386 /*
387 * Time to wait for running_helpers to become zero before the setting of
388 * usermodehelper_disabled in usermodehelper_disable() fails
389 */
390 #define RUNNING_HELPERS_TIMEOUT (5 * HZ)
391
392 int usermodehelper_read_trylock(void)
393 {
394 DEFINE_WAIT(wait);
395 int ret = 0;
396
397 down_read(&umhelper_sem);
398 for (;;) {
399 prepare_to_wait(&usermodehelper_disabled_waitq, &wait,
400 TASK_INTERRUPTIBLE);
401 if (!usermodehelper_disabled)
402 break;
403
404 if (usermodehelper_disabled == UMH_DISABLED)
405 ret = -EAGAIN;
406
407 up_read(&umhelper_sem);
408
409 if (ret)
410 break;
411
412 schedule();
413 try_to_freeze();
414
415 down_read(&umhelper_sem);
416 }
417 finish_wait(&usermodehelper_disabled_waitq, &wait);
418 return ret;
419 }
420 EXPORT_SYMBOL_GPL(usermodehelper_read_trylock);
421
422 long usermodehelper_read_lock_wait(long timeout)
423 {
424 DEFINE_WAIT(wait);
425
426 if (timeout < 0)
427 return -EINVAL;
428
429 down_read(&umhelper_sem);
430 for (;;) {
431 prepare_to_wait(&usermodehelper_disabled_waitq, &wait,
432 TASK_UNINTERRUPTIBLE);
433 if (!usermodehelper_disabled)
434 break;
435
436 up_read(&umhelper_sem);
437
438 timeout = schedule_timeout(timeout);
439 if (!timeout)
440 break;
441
442 down_read(&umhelper_sem);
443 }
444 finish_wait(&usermodehelper_disabled_waitq, &wait);
445 return timeout;
446 }
447 EXPORT_SYMBOL_GPL(usermodehelper_read_lock_wait);
448
449 void usermodehelper_read_unlock(void)
450 {
451 up_read(&umhelper_sem);
452 }
453 EXPORT_SYMBOL_GPL(usermodehelper_read_unlock);
454
455 /**
456 * __usermodehelper_set_disable_depth - Modify usermodehelper_disabled.
457 * @depth: New value to assign to usermodehelper_disabled.
458 *
459 * Change the value of usermodehelper_disabled (under umhelper_sem locked for
460 * writing) and wakeup tasks waiting for it to change.
461 */
462 void __usermodehelper_set_disable_depth(enum umh_disable_depth depth)
463 {
464 down_write(&umhelper_sem);
465 usermodehelper_disabled = depth;
466 wake_up(&usermodehelper_disabled_waitq);
467 up_write(&umhelper_sem);
468 }
469
470 /**
471 * __usermodehelper_disable - Prevent new helpers from being started.
472 * @depth: New value to assign to usermodehelper_disabled.
473 *
474 * Set usermodehelper_disabled to @depth and wait for running helpers to exit.
475 */
476 int __usermodehelper_disable(enum umh_disable_depth depth)
477 {
478 long retval;
479
480 if (!depth)
481 return -EINVAL;
482
483 down_write(&umhelper_sem);
484 usermodehelper_disabled = depth;
485 up_write(&umhelper_sem);
486
487 /*
488 * From now on call_usermodehelper_exec() won't start any new
489 * helpers, so it is sufficient if running_helpers turns out to
490 * be zero at one point (it may be increased later, but that
491 * doesn't matter).
492 */
493 retval = wait_event_timeout(running_helpers_waitq,
494 atomic_read(&running_helpers) == 0,
495 RUNNING_HELPERS_TIMEOUT);
496 if (retval)
497 return 0;
498
499 __usermodehelper_set_disable_depth(UMH_ENABLED);
500 return -EAGAIN;
501 }
502
503 static void helper_lock(void)
504 {
505 atomic_inc(&running_helpers);
506 smp_mb__after_atomic();
507 }
508
509 static void helper_unlock(void)
510 {
511 if (atomic_dec_and_test(&running_helpers))
512 wake_up(&running_helpers_waitq);
513 }
514
515 /**
516 * call_usermodehelper_setup - prepare to call a usermode helper
517 * @path: path to usermode executable
518 * @argv: arg vector for process
519 * @envp: environment for process
520 * @gfp_mask: gfp mask for memory allocation
521 * @cleanup: a cleanup function
522 * @init: an init function
523 * @data: arbitrary context sensitive data
524 *
525 * Returns either %NULL on allocation failure, or a subprocess_info
526 * structure. This should be passed to call_usermodehelper_exec to
527 * exec the process and free the structure.
528 *
529 * The init function is used to customize the helper process prior to
530 * exec. A non-zero return code causes the process to error out, exit,
531 * and return the failure to the calling process
532 *
533 * The cleanup function is just before ethe subprocess_info is about to
534 * be freed. This can be used for freeing the argv and envp. The
535 * Function must be runnable in either a process context or the
536 * context in which call_usermodehelper_exec is called.
537 */
538 struct subprocess_info *call_usermodehelper_setup(const char *path, char **argv,
539 char **envp, gfp_t gfp_mask,
540 int (*init)(struct subprocess_info *info, struct cred *new),
541 void (*cleanup)(struct subprocess_info *info),
542 void *data)
543 {
544 struct subprocess_info *sub_info;
545 sub_info = kzalloc(sizeof(struct subprocess_info), gfp_mask);
546 if (!sub_info)
547 goto out;
548
549 INIT_WORK(&sub_info->work, call_usermodehelper_exec_work);
550
551 #ifdef CONFIG_STATIC_USERMODEHELPER
552 sub_info->path = CONFIG_STATIC_USERMODEHELPER_PATH;
553 #else
554 sub_info->path = path;
555 #endif
556 sub_info->argv = argv;
557 sub_info->envp = envp;
558
559 sub_info->cleanup = cleanup;
560 sub_info->init = init;
561 sub_info->data = data;
562 out:
563 return sub_info;
564 }
565 EXPORT_SYMBOL(call_usermodehelper_setup);
566
567 /**
568 * call_usermodehelper_exec - start a usermode application
569 * @sub_info: information about the subprocessa
570 * @wait: wait for the application to finish and return status.
571 * when UMH_NO_WAIT don't wait at all, but you get no useful error back
572 * when the program couldn't be exec'ed. This makes it safe to call
573 * from interrupt context.
574 *
575 * Runs a user-space application. The application is started
576 * asynchronously if wait is not set, and runs as a child of system workqueues.
577 * (ie. it runs with full root capabilities and optimized affinity).
578 */
579 int call_usermodehelper_exec(struct subprocess_info *sub_info, int wait)
580 {
581 DECLARE_COMPLETION_ONSTACK(done);
582 int retval = 0;
583
584 if (!sub_info->path) {
585 call_usermodehelper_freeinfo(sub_info);
586 return -EINVAL;
587 }
588 helper_lock();
589 if (usermodehelper_disabled) {
590 retval = -EBUSY;
591 goto out;
592 }
593
594 /*
595 * If there is no binary for us to call, then just return and get out of
596 * here. This allows us to set STATIC_USERMODEHELPER_PATH to "" and
597 * disable all call_usermodehelper() calls.
598 */
599 if (strlen(sub_info->path) == 0)
600 goto out;
601
602 /*
603 * Set the completion pointer only if there is a waiter.
604 * This makes it possible to use umh_complete to free
605 * the data structure in case of UMH_NO_WAIT.
606 */
607 sub_info->complete = (wait == UMH_NO_WAIT) ? NULL : &done;
608 sub_info->wait = wait;
609
610 queue_work(system_unbound_wq, &sub_info->work);
611 if (wait == UMH_NO_WAIT) /* task has freed sub_info */
612 goto unlock;
613
614 if (wait & UMH_KILLABLE) {
615 retval = wait_for_completion_killable(&done);
616 if (!retval)
617 goto wait_done;
618
619 /* umh_complete() will see NULL and free sub_info */
620 if (xchg(&sub_info->complete, NULL))
621 goto unlock;
622 /* fallthrough, umh_complete() was already called */
623 }
624
625 wait_for_completion(&done);
626 wait_done:
627 retval = sub_info->retval;
628 out:
629 call_usermodehelper_freeinfo(sub_info);
630 unlock:
631 helper_unlock();
632 return retval;
633 }
634 EXPORT_SYMBOL(call_usermodehelper_exec);
635
636 /**
637 * call_usermodehelper() - prepare and start a usermode application
638 * @path: path to usermode executable
639 * @argv: arg vector for process
640 * @envp: environment for process
641 * @wait: wait for the application to finish and return status.
642 * when UMH_NO_WAIT don't wait at all, but you get no useful error back
643 * when the program couldn't be exec'ed. This makes it safe to call
644 * from interrupt context.
645 *
646 * This function is the equivalent to use call_usermodehelper_setup() and
647 * call_usermodehelper_exec().
648 */
649 int call_usermodehelper(const char *path, char **argv, char **envp, int wait)
650 {
651 struct subprocess_info *info;
652 gfp_t gfp_mask = (wait == UMH_NO_WAIT) ? GFP_ATOMIC : GFP_KERNEL;
653
654 info = call_usermodehelper_setup(path, argv, envp, gfp_mask,
655 NULL, NULL, NULL);
656 if (info == NULL)
657 return -ENOMEM;
658
659 return call_usermodehelper_exec(info, wait);
660 }
661 EXPORT_SYMBOL(call_usermodehelper);
662
663 static int proc_cap_handler(struct ctl_table *table, int write,
664 void __user *buffer, size_t *lenp, loff_t *ppos)
665 {
666 struct ctl_table t;
667 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
668 kernel_cap_t new_cap;
669 int err, i;
670
671 if (write && (!capable(CAP_SETPCAP) ||
672 !capable(CAP_SYS_MODULE)))
673 return -EPERM;
674
675 /*
676 * convert from the global kernel_cap_t to the ulong array to print to
677 * userspace if this is a read.
678 */
679 spin_lock(&umh_sysctl_lock);
680 for (i = 0; i < _KERNEL_CAPABILITY_U32S; i++) {
681 if (table->data == CAP_BSET)
682 cap_array[i] = usermodehelper_bset.cap[i];
683 else if (table->data == CAP_PI)
684 cap_array[i] = usermodehelper_inheritable.cap[i];
685 else
686 BUG();
687 }
688 spin_unlock(&umh_sysctl_lock);
689
690 t = *table;
691 t.data = &cap_array;
692
693 /*
694 * actually read or write and array of ulongs from userspace. Remember
695 * these are least significant 32 bits first
696 */
697 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
698 if (err < 0)
699 return err;
700
701 /*
702 * convert from the sysctl array of ulongs to the kernel_cap_t
703 * internal representation
704 */
705 for (i = 0; i < _KERNEL_CAPABILITY_U32S; i++)
706 new_cap.cap[i] = cap_array[i];
707
708 /*
709 * Drop everything not in the new_cap (but don't add things)
710 */
711 spin_lock(&umh_sysctl_lock);
712 if (write) {
713 if (table->data == CAP_BSET)
714 usermodehelper_bset = cap_intersect(usermodehelper_bset, new_cap);
715 if (table->data == CAP_PI)
716 usermodehelper_inheritable = cap_intersect(usermodehelper_inheritable, new_cap);
717 }
718 spin_unlock(&umh_sysctl_lock);
719
720 return 0;
721 }
722
723 struct ctl_table usermodehelper_table[] = {
724 {
725 .procname = "bset",
726 .data = CAP_BSET,
727 .maxlen = _KERNEL_CAPABILITY_U32S * sizeof(unsigned long),
728 .mode = 0600,
729 .proc_handler = proc_cap_handler,
730 },
731 {
732 .procname = "inheritable",
733 .data = CAP_PI,
734 .maxlen = _KERNEL_CAPABILITY_U32S * sizeof(unsigned long),
735 .mode = 0600,
736 .proc_handler = proc_cap_handler,
737 },
738 { }
739 };