kmod.c 18 KB

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