seccomp.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * linux/kernel/seccomp.c
  4. *
  5. * Copyright 2004-2005 Andrea Arcangeli <andrea@cpushare.com>
  6. *
  7. * Copyright (C) 2012 Google, Inc.
  8. * Will Drewry <wad@chromium.org>
  9. *
  10. * This defines a simple but solid secure-computing facility.
  11. *
  12. * Mode 1 uses a fixed list of allowed system calls.
  13. * Mode 2 allows user-defined system call filters in the form
  14. * of Berkeley Packet Filters/Linux Socket Filters.
  15. */
  16. #include <linux/refcount.h>
  17. #include <linux/audit.h>
  18. #include <linux/compat.h>
  19. #include <linux/coredump.h>
  20. #include <linux/kmemleak.h>
  21. #include <linux/nospec.h>
  22. #include <linux/prctl.h>
  23. #include <linux/sched.h>
  24. #include <linux/sched/task_stack.h>
  25. #include <linux/seccomp.h>
  26. #include <linux/slab.h>
  27. #include <linux/syscalls.h>
  28. #include <linux/sysctl.h>
  29. #ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER
  30. #include <asm/syscall.h>
  31. #endif
  32. #ifdef CONFIG_SECCOMP_FILTER
  33. #include <linux/filter.h>
  34. #include <linux/pid.h>
  35. #include <linux/ptrace.h>
  36. #include <linux/security.h>
  37. #include <linux/tracehook.h>
  38. #include <linux/uaccess.h>
  39. /**
  40. * struct seccomp_filter - container for seccomp BPF programs
  41. *
  42. * @usage: reference count to manage the object lifetime.
  43. * get/put helpers should be used when accessing an instance
  44. * outside of a lifetime-guarded section. In general, this
  45. * is only needed for handling filters shared across tasks.
  46. * @log: true if all actions except for SECCOMP_RET_ALLOW should be logged
  47. * @prev: points to a previously installed, or inherited, filter
  48. * @prog: the BPF program to evaluate
  49. *
  50. * seccomp_filter objects are organized in a tree linked via the @prev
  51. * pointer. For any task, it appears to be a singly-linked list starting
  52. * with current->seccomp.filter, the most recently attached or inherited filter.
  53. * However, multiple filters may share a @prev node, by way of fork(), which
  54. * results in a unidirectional tree existing in memory. This is similar to
  55. * how namespaces work.
  56. *
  57. * seccomp_filter objects should never be modified after being attached
  58. * to a task_struct (other than @usage).
  59. */
  60. struct seccomp_filter {
  61. refcount_t usage;
  62. bool log;
  63. struct seccomp_filter *prev;
  64. struct bpf_prog *prog;
  65. };
  66. /* Limit any path through the tree to 256KB worth of instructions. */
  67. #define MAX_INSNS_PER_PATH ((1 << 18) / sizeof(struct sock_filter))
  68. /*
  69. * Endianness is explicitly ignored and left for BPF program authors to manage
  70. * as per the specific architecture.
  71. */
  72. static void populate_seccomp_data(struct seccomp_data *sd)
  73. {
  74. struct task_struct *task = current;
  75. struct pt_regs *regs = task_pt_regs(task);
  76. unsigned long args[6];
  77. sd->nr = syscall_get_nr(task, regs);
  78. sd->arch = syscall_get_arch();
  79. syscall_get_arguments(task, regs, 0, 6, args);
  80. sd->args[0] = args[0];
  81. sd->args[1] = args[1];
  82. sd->args[2] = args[2];
  83. sd->args[3] = args[3];
  84. sd->args[4] = args[4];
  85. sd->args[5] = args[5];
  86. sd->instruction_pointer = KSTK_EIP(task);
  87. }
  88. /**
  89. * seccomp_check_filter - verify seccomp filter code
  90. * @filter: filter to verify
  91. * @flen: length of filter
  92. *
  93. * Takes a previously checked filter (by bpf_check_classic) and
  94. * redirects all filter code that loads struct sk_buff data
  95. * and related data through seccomp_bpf_load. It also
  96. * enforces length and alignment checking of those loads.
  97. *
  98. * Returns 0 if the rule set is legal or -EINVAL if not.
  99. */
  100. static int seccomp_check_filter(struct sock_filter *filter, unsigned int flen)
  101. {
  102. int pc;
  103. for (pc = 0; pc < flen; pc++) {
  104. struct sock_filter *ftest = &filter[pc];
  105. u16 code = ftest->code;
  106. u32 k = ftest->k;
  107. switch (code) {
  108. case BPF_LD | BPF_W | BPF_ABS:
  109. ftest->code = BPF_LDX | BPF_W | BPF_ABS;
  110. /* 32-bit aligned and not out of bounds. */
  111. if (k >= sizeof(struct seccomp_data) || k & 3)
  112. return -EINVAL;
  113. continue;
  114. case BPF_LD | BPF_W | BPF_LEN:
  115. ftest->code = BPF_LD | BPF_IMM;
  116. ftest->k = sizeof(struct seccomp_data);
  117. continue;
  118. case BPF_LDX | BPF_W | BPF_LEN:
  119. ftest->code = BPF_LDX | BPF_IMM;
  120. ftest->k = sizeof(struct seccomp_data);
  121. continue;
  122. /* Explicitly include allowed calls. */
  123. case BPF_RET | BPF_K:
  124. case BPF_RET | BPF_A:
  125. case BPF_ALU | BPF_ADD | BPF_K:
  126. case BPF_ALU | BPF_ADD | BPF_X:
  127. case BPF_ALU | BPF_SUB | BPF_K:
  128. case BPF_ALU | BPF_SUB | BPF_X:
  129. case BPF_ALU | BPF_MUL | BPF_K:
  130. case BPF_ALU | BPF_MUL | BPF_X:
  131. case BPF_ALU | BPF_DIV | BPF_K:
  132. case BPF_ALU | BPF_DIV | BPF_X:
  133. case BPF_ALU | BPF_AND | BPF_K:
  134. case BPF_ALU | BPF_AND | BPF_X:
  135. case BPF_ALU | BPF_OR | BPF_K:
  136. case BPF_ALU | BPF_OR | BPF_X:
  137. case BPF_ALU | BPF_XOR | BPF_K:
  138. case BPF_ALU | BPF_XOR | BPF_X:
  139. case BPF_ALU | BPF_LSH | BPF_K:
  140. case BPF_ALU | BPF_LSH | BPF_X:
  141. case BPF_ALU | BPF_RSH | BPF_K:
  142. case BPF_ALU | BPF_RSH | BPF_X:
  143. case BPF_ALU | BPF_NEG:
  144. case BPF_LD | BPF_IMM:
  145. case BPF_LDX | BPF_IMM:
  146. case BPF_MISC | BPF_TAX:
  147. case BPF_MISC | BPF_TXA:
  148. case BPF_LD | BPF_MEM:
  149. case BPF_LDX | BPF_MEM:
  150. case BPF_ST:
  151. case BPF_STX:
  152. case BPF_JMP | BPF_JA:
  153. case BPF_JMP | BPF_JEQ | BPF_K:
  154. case BPF_JMP | BPF_JEQ | BPF_X:
  155. case BPF_JMP | BPF_JGE | BPF_K:
  156. case BPF_JMP | BPF_JGE | BPF_X:
  157. case BPF_JMP | BPF_JGT | BPF_K:
  158. case BPF_JMP | BPF_JGT | BPF_X:
  159. case BPF_JMP | BPF_JSET | BPF_K:
  160. case BPF_JMP | BPF_JSET | BPF_X:
  161. continue;
  162. default:
  163. return -EINVAL;
  164. }
  165. }
  166. return 0;
  167. }
  168. /**
  169. * seccomp_run_filters - evaluates all seccomp filters against @sd
  170. * @sd: optional seccomp data to be passed to filters
  171. * @match: stores struct seccomp_filter that resulted in the return value,
  172. * unless filter returned SECCOMP_RET_ALLOW, in which case it will
  173. * be unchanged.
  174. *
  175. * Returns valid seccomp BPF response codes.
  176. */
  177. #define ACTION_ONLY(ret) ((s32)((ret) & (SECCOMP_RET_ACTION_FULL)))
  178. static u32 seccomp_run_filters(const struct seccomp_data *sd,
  179. struct seccomp_filter **match)
  180. {
  181. struct seccomp_data sd_local;
  182. u32 ret = SECCOMP_RET_ALLOW;
  183. /* Make sure cross-thread synced filter points somewhere sane. */
  184. struct seccomp_filter *f =
  185. READ_ONCE(current->seccomp.filter);
  186. /* Ensure unexpected behavior doesn't result in failing open. */
  187. if (unlikely(WARN_ON(f == NULL)))
  188. return SECCOMP_RET_KILL_PROCESS;
  189. if (!sd) {
  190. populate_seccomp_data(&sd_local);
  191. sd = &sd_local;
  192. }
  193. /*
  194. * All filters in the list are evaluated and the lowest BPF return
  195. * value always takes priority (ignoring the DATA).
  196. */
  197. for (; f; f = f->prev) {
  198. u32 cur_ret = BPF_PROG_RUN(f->prog, sd);
  199. if (ACTION_ONLY(cur_ret) < ACTION_ONLY(ret)) {
  200. ret = cur_ret;
  201. *match = f;
  202. }
  203. }
  204. return ret;
  205. }
  206. #endif /* CONFIG_SECCOMP_FILTER */
  207. static inline bool seccomp_may_assign_mode(unsigned long seccomp_mode)
  208. {
  209. assert_spin_locked(&current->sighand->siglock);
  210. if (current->seccomp.mode && current->seccomp.mode != seccomp_mode)
  211. return false;
  212. return true;
  213. }
  214. /*
  215. * If a given speculation mitigation is opt-in (prctl()-controlled),
  216. * select it, by disabling speculation (enabling mitigation).
  217. */
  218. static inline void spec_mitigate(struct task_struct *task,
  219. unsigned long which)
  220. {
  221. int state = arch_prctl_spec_ctrl_get(task, which);
  222. if (state > 0 && (state & PR_SPEC_PRCTL))
  223. arch_prctl_spec_ctrl_set(task, which, PR_SPEC_FORCE_DISABLE);
  224. }
  225. static inline void seccomp_assign_mode(struct task_struct *task,
  226. unsigned long seccomp_mode,
  227. unsigned long flags)
  228. {
  229. assert_spin_locked(&task->sighand->siglock);
  230. task->seccomp.mode = seccomp_mode;
  231. /*
  232. * Make sure TIF_SECCOMP cannot be set before the mode (and
  233. * filter) is set.
  234. */
  235. smp_mb__before_atomic();
  236. /* Assume default seccomp processes want spec flaw mitigation. */
  237. if ((flags & SECCOMP_FILTER_FLAG_SPEC_ALLOW) == 0)
  238. spec_mitigate(task, PR_SPEC_STORE_BYPASS);
  239. set_tsk_thread_flag(task, TIF_SECCOMP);
  240. }
  241. #ifdef CONFIG_SECCOMP_FILTER
  242. /* Returns 1 if the parent is an ancestor of the child. */
  243. static int is_ancestor(struct seccomp_filter *parent,
  244. struct seccomp_filter *child)
  245. {
  246. /* NULL is the root ancestor. */
  247. if (parent == NULL)
  248. return 1;
  249. for (; child; child = child->prev)
  250. if (child == parent)
  251. return 1;
  252. return 0;
  253. }
  254. /**
  255. * seccomp_can_sync_threads: checks if all threads can be synchronized
  256. *
  257. * Expects sighand and cred_guard_mutex locks to be held.
  258. *
  259. * Returns 0 on success, -ve on error, or the pid of a thread which was
  260. * either not in the correct seccomp mode or it did not have an ancestral
  261. * seccomp filter.
  262. */
  263. static inline pid_t seccomp_can_sync_threads(void)
  264. {
  265. struct task_struct *thread, *caller;
  266. BUG_ON(!mutex_is_locked(&current->signal->cred_guard_mutex));
  267. assert_spin_locked(&current->sighand->siglock);
  268. /* Validate all threads being eligible for synchronization. */
  269. caller = current;
  270. for_each_thread(caller, thread) {
  271. pid_t failed;
  272. /* Skip current, since it is initiating the sync. */
  273. if (thread == caller)
  274. continue;
  275. if (thread->seccomp.mode == SECCOMP_MODE_DISABLED ||
  276. (thread->seccomp.mode == SECCOMP_MODE_FILTER &&
  277. is_ancestor(thread->seccomp.filter,
  278. caller->seccomp.filter)))
  279. continue;
  280. /* Return the first thread that cannot be synchronized. */
  281. failed = task_pid_vnr(thread);
  282. /* If the pid cannot be resolved, then return -ESRCH */
  283. if (unlikely(WARN_ON(failed == 0)))
  284. failed = -ESRCH;
  285. return failed;
  286. }
  287. return 0;
  288. }
  289. /**
  290. * seccomp_sync_threads: sets all threads to use current's filter
  291. *
  292. * Expects sighand and cred_guard_mutex locks to be held, and for
  293. * seccomp_can_sync_threads() to have returned success already
  294. * without dropping the locks.
  295. *
  296. */
  297. static inline void seccomp_sync_threads(unsigned long flags)
  298. {
  299. struct task_struct *thread, *caller;
  300. BUG_ON(!mutex_is_locked(&current->signal->cred_guard_mutex));
  301. assert_spin_locked(&current->sighand->siglock);
  302. /* Synchronize all threads. */
  303. caller = current;
  304. for_each_thread(caller, thread) {
  305. /* Skip current, since it needs no changes. */
  306. if (thread == caller)
  307. continue;
  308. /* Get a task reference for the new leaf node. */
  309. get_seccomp_filter(caller);
  310. /*
  311. * Drop the task reference to the shared ancestor since
  312. * current's path will hold a reference. (This also
  313. * allows a put before the assignment.)
  314. */
  315. put_seccomp_filter(thread);
  316. smp_store_release(&thread->seccomp.filter,
  317. caller->seccomp.filter);
  318. /*
  319. * Don't let an unprivileged task work around
  320. * the no_new_privs restriction by creating
  321. * a thread that sets it up, enters seccomp,
  322. * then dies.
  323. */
  324. if (task_no_new_privs(caller))
  325. task_set_no_new_privs(thread);
  326. /*
  327. * Opt the other thread into seccomp if needed.
  328. * As threads are considered to be trust-realm
  329. * equivalent (see ptrace_may_access), it is safe to
  330. * allow one thread to transition the other.
  331. */
  332. if (thread->seccomp.mode == SECCOMP_MODE_DISABLED)
  333. seccomp_assign_mode(thread, SECCOMP_MODE_FILTER,
  334. flags);
  335. }
  336. }
  337. /**
  338. * seccomp_prepare_filter: Prepares a seccomp filter for use.
  339. * @fprog: BPF program to install
  340. *
  341. * Returns filter on success or an ERR_PTR on failure.
  342. */
  343. static struct seccomp_filter *seccomp_prepare_filter(struct sock_fprog *fprog)
  344. {
  345. struct seccomp_filter *sfilter;
  346. int ret;
  347. const bool save_orig = IS_ENABLED(CONFIG_CHECKPOINT_RESTORE);
  348. if (fprog->len == 0 || fprog->len > BPF_MAXINSNS)
  349. return ERR_PTR(-EINVAL);
  350. BUG_ON(INT_MAX / fprog->len < sizeof(struct sock_filter));
  351. /*
  352. * Installing a seccomp filter requires that the task has
  353. * CAP_SYS_ADMIN in its namespace or be running with no_new_privs.
  354. * This avoids scenarios where unprivileged tasks can affect the
  355. * behavior of privileged children.
  356. */
  357. if (!task_no_new_privs(current) &&
  358. security_capable_noaudit(current_cred(), current_user_ns(),
  359. CAP_SYS_ADMIN) != 0)
  360. return ERR_PTR(-EACCES);
  361. /* Allocate a new seccomp_filter */
  362. sfilter = kzalloc(sizeof(*sfilter), GFP_KERNEL | __GFP_NOWARN);
  363. if (!sfilter)
  364. return ERR_PTR(-ENOMEM);
  365. ret = bpf_prog_create_from_user(&sfilter->prog, fprog,
  366. seccomp_check_filter, save_orig);
  367. if (ret < 0) {
  368. kfree(sfilter);
  369. return ERR_PTR(ret);
  370. }
  371. refcount_set(&sfilter->usage, 1);
  372. return sfilter;
  373. }
  374. /**
  375. * seccomp_prepare_user_filter - prepares a user-supplied sock_fprog
  376. * @user_filter: pointer to the user data containing a sock_fprog.
  377. *
  378. * Returns 0 on success and non-zero otherwise.
  379. */
  380. static struct seccomp_filter *
  381. seccomp_prepare_user_filter(const char __user *user_filter)
  382. {
  383. struct sock_fprog fprog;
  384. struct seccomp_filter *filter = ERR_PTR(-EFAULT);
  385. #ifdef CONFIG_COMPAT
  386. if (in_compat_syscall()) {
  387. struct compat_sock_fprog fprog32;
  388. if (copy_from_user(&fprog32, user_filter, sizeof(fprog32)))
  389. goto out;
  390. fprog.len = fprog32.len;
  391. fprog.filter = compat_ptr(fprog32.filter);
  392. } else /* falls through to the if below. */
  393. #endif
  394. if (copy_from_user(&fprog, user_filter, sizeof(fprog)))
  395. goto out;
  396. filter = seccomp_prepare_filter(&fprog);
  397. out:
  398. return filter;
  399. }
  400. /**
  401. * seccomp_attach_filter: validate and attach filter
  402. * @flags: flags to change filter behavior
  403. * @filter: seccomp filter to add to the current process
  404. *
  405. * Caller must be holding current->sighand->siglock lock.
  406. *
  407. * Returns 0 on success, -ve on error.
  408. */
  409. static long seccomp_attach_filter(unsigned int flags,
  410. struct seccomp_filter *filter)
  411. {
  412. unsigned long total_insns;
  413. struct seccomp_filter *walker;
  414. assert_spin_locked(&current->sighand->siglock);
  415. /* Validate resulting filter length. */
  416. total_insns = filter->prog->len;
  417. for (walker = current->seccomp.filter; walker; walker = walker->prev)
  418. total_insns += walker->prog->len + 4; /* 4 instr penalty */
  419. if (total_insns > MAX_INSNS_PER_PATH)
  420. return -ENOMEM;
  421. /* If thread sync has been requested, check that it is possible. */
  422. if (flags & SECCOMP_FILTER_FLAG_TSYNC) {
  423. int ret;
  424. ret = seccomp_can_sync_threads();
  425. if (ret)
  426. return ret;
  427. }
  428. /* Set log flag, if present. */
  429. if (flags & SECCOMP_FILTER_FLAG_LOG)
  430. filter->log = true;
  431. /*
  432. * If there is an existing filter, make it the prev and don't drop its
  433. * task reference.
  434. */
  435. filter->prev = current->seccomp.filter;
  436. current->seccomp.filter = filter;
  437. /* Now that the new filter is in place, synchronize to all threads. */
  438. if (flags & SECCOMP_FILTER_FLAG_TSYNC)
  439. seccomp_sync_threads(flags);
  440. return 0;
  441. }
  442. static void __get_seccomp_filter(struct seccomp_filter *filter)
  443. {
  444. /* Reference count is bounded by the number of total processes. */
  445. refcount_inc(&filter->usage);
  446. }
  447. /* get_seccomp_filter - increments the reference count of the filter on @tsk */
  448. void get_seccomp_filter(struct task_struct *tsk)
  449. {
  450. struct seccomp_filter *orig = tsk->seccomp.filter;
  451. if (!orig)
  452. return;
  453. __get_seccomp_filter(orig);
  454. }
  455. static inline void seccomp_filter_free(struct seccomp_filter *filter)
  456. {
  457. if (filter) {
  458. bpf_prog_destroy(filter->prog);
  459. kfree(filter);
  460. }
  461. }
  462. static void __put_seccomp_filter(struct seccomp_filter *orig)
  463. {
  464. /* Clean up single-reference branches iteratively. */
  465. while (orig && refcount_dec_and_test(&orig->usage)) {
  466. struct seccomp_filter *freeme = orig;
  467. orig = orig->prev;
  468. seccomp_filter_free(freeme);
  469. }
  470. }
  471. /* put_seccomp_filter - decrements the ref count of tsk->seccomp.filter */
  472. void put_seccomp_filter(struct task_struct *tsk)
  473. {
  474. __put_seccomp_filter(tsk->seccomp.filter);
  475. }
  476. static void seccomp_init_siginfo(siginfo_t *info, int syscall, int reason)
  477. {
  478. clear_siginfo(info);
  479. info->si_signo = SIGSYS;
  480. info->si_code = SYS_SECCOMP;
  481. info->si_call_addr = (void __user *)KSTK_EIP(current);
  482. info->si_errno = reason;
  483. info->si_arch = syscall_get_arch();
  484. info->si_syscall = syscall;
  485. }
  486. /**
  487. * seccomp_send_sigsys - signals the task to allow in-process syscall emulation
  488. * @syscall: syscall number to send to userland
  489. * @reason: filter-supplied reason code to send to userland (via si_errno)
  490. *
  491. * Forces a SIGSYS with a code of SYS_SECCOMP and related sigsys info.
  492. */
  493. static void seccomp_send_sigsys(int syscall, int reason)
  494. {
  495. struct siginfo info;
  496. seccomp_init_siginfo(&info, syscall, reason);
  497. force_sig_info(SIGSYS, &info, current);
  498. }
  499. #endif /* CONFIG_SECCOMP_FILTER */
  500. /* For use with seccomp_actions_logged */
  501. #define SECCOMP_LOG_KILL_PROCESS (1 << 0)
  502. #define SECCOMP_LOG_KILL_THREAD (1 << 1)
  503. #define SECCOMP_LOG_TRAP (1 << 2)
  504. #define SECCOMP_LOG_ERRNO (1 << 3)
  505. #define SECCOMP_LOG_TRACE (1 << 4)
  506. #define SECCOMP_LOG_LOG (1 << 5)
  507. #define SECCOMP_LOG_ALLOW (1 << 6)
  508. static u32 seccomp_actions_logged = SECCOMP_LOG_KILL_PROCESS |
  509. SECCOMP_LOG_KILL_THREAD |
  510. SECCOMP_LOG_TRAP |
  511. SECCOMP_LOG_ERRNO |
  512. SECCOMP_LOG_TRACE |
  513. SECCOMP_LOG_LOG;
  514. static inline void seccomp_log(unsigned long syscall, long signr, u32 action,
  515. bool requested)
  516. {
  517. bool log = false;
  518. switch (action) {
  519. case SECCOMP_RET_ALLOW:
  520. break;
  521. case SECCOMP_RET_TRAP:
  522. log = requested && seccomp_actions_logged & SECCOMP_LOG_TRAP;
  523. break;
  524. case SECCOMP_RET_ERRNO:
  525. log = requested && seccomp_actions_logged & SECCOMP_LOG_ERRNO;
  526. break;
  527. case SECCOMP_RET_TRACE:
  528. log = requested && seccomp_actions_logged & SECCOMP_LOG_TRACE;
  529. break;
  530. case SECCOMP_RET_LOG:
  531. log = seccomp_actions_logged & SECCOMP_LOG_LOG;
  532. break;
  533. case SECCOMP_RET_KILL_THREAD:
  534. log = seccomp_actions_logged & SECCOMP_LOG_KILL_THREAD;
  535. break;
  536. case SECCOMP_RET_KILL_PROCESS:
  537. default:
  538. log = seccomp_actions_logged & SECCOMP_LOG_KILL_PROCESS;
  539. }
  540. /*
  541. * Force an audit message to be emitted when the action is RET_KILL_*,
  542. * RET_LOG, or the FILTER_FLAG_LOG bit was set and the action is
  543. * allowed to be logged by the admin.
  544. */
  545. if (log)
  546. return __audit_seccomp(syscall, signr, action);
  547. /*
  548. * Let the audit subsystem decide if the action should be audited based
  549. * on whether the current task itself is being audited.
  550. */
  551. return audit_seccomp(syscall, signr, action);
  552. }
  553. /*
  554. * Secure computing mode 1 allows only read/write/exit/sigreturn.
  555. * To be fully secure this must be combined with rlimit
  556. * to limit the stack allocations too.
  557. */
  558. static const int mode1_syscalls[] = {
  559. __NR_seccomp_read, __NR_seccomp_write, __NR_seccomp_exit, __NR_seccomp_sigreturn,
  560. 0, /* null terminated */
  561. };
  562. static void __secure_computing_strict(int this_syscall)
  563. {
  564. const int *syscall_whitelist = mode1_syscalls;
  565. #ifdef CONFIG_COMPAT
  566. if (in_compat_syscall())
  567. syscall_whitelist = get_compat_mode1_syscalls();
  568. #endif
  569. do {
  570. if (*syscall_whitelist == this_syscall)
  571. return;
  572. } while (*++syscall_whitelist);
  573. #ifdef SECCOMP_DEBUG
  574. dump_stack();
  575. #endif
  576. seccomp_log(this_syscall, SIGKILL, SECCOMP_RET_KILL_THREAD, true);
  577. do_exit(SIGKILL);
  578. }
  579. #ifndef CONFIG_HAVE_ARCH_SECCOMP_FILTER
  580. void secure_computing_strict(int this_syscall)
  581. {
  582. int mode = current->seccomp.mode;
  583. if (IS_ENABLED(CONFIG_CHECKPOINT_RESTORE) &&
  584. unlikely(current->ptrace & PT_SUSPEND_SECCOMP))
  585. return;
  586. if (mode == SECCOMP_MODE_DISABLED)
  587. return;
  588. else if (mode == SECCOMP_MODE_STRICT)
  589. __secure_computing_strict(this_syscall);
  590. else
  591. BUG();
  592. }
  593. #else
  594. #ifdef CONFIG_SECCOMP_FILTER
  595. static int __seccomp_filter(int this_syscall, const struct seccomp_data *sd,
  596. const bool recheck_after_trace)
  597. {
  598. u32 filter_ret, action;
  599. struct seccomp_filter *match = NULL;
  600. int data;
  601. /*
  602. * Make sure that any changes to mode from another thread have
  603. * been seen after TIF_SECCOMP was seen.
  604. */
  605. rmb();
  606. filter_ret = seccomp_run_filters(sd, &match);
  607. data = filter_ret & SECCOMP_RET_DATA;
  608. action = filter_ret & SECCOMP_RET_ACTION_FULL;
  609. switch (action) {
  610. case SECCOMP_RET_ERRNO:
  611. /* Set low-order bits as an errno, capped at MAX_ERRNO. */
  612. if (data > MAX_ERRNO)
  613. data = MAX_ERRNO;
  614. syscall_set_return_value(current, task_pt_regs(current),
  615. -data, 0);
  616. goto skip;
  617. case SECCOMP_RET_TRAP:
  618. /* Show the handler the original registers. */
  619. syscall_rollback(current, task_pt_regs(current));
  620. /* Let the filter pass back 16 bits of data. */
  621. seccomp_send_sigsys(this_syscall, data);
  622. goto skip;
  623. case SECCOMP_RET_TRACE:
  624. /* We've been put in this state by the ptracer already. */
  625. if (recheck_after_trace)
  626. return 0;
  627. /* ENOSYS these calls if there is no tracer attached. */
  628. if (!ptrace_event_enabled(current, PTRACE_EVENT_SECCOMP)) {
  629. syscall_set_return_value(current,
  630. task_pt_regs(current),
  631. -ENOSYS, 0);
  632. goto skip;
  633. }
  634. /* Allow the BPF to provide the event message */
  635. ptrace_event(PTRACE_EVENT_SECCOMP, data);
  636. /*
  637. * The delivery of a fatal signal during event
  638. * notification may silently skip tracer notification,
  639. * which could leave us with a potentially unmodified
  640. * syscall that the tracer would have liked to have
  641. * changed. Since the process is about to die, we just
  642. * force the syscall to be skipped and let the signal
  643. * kill the process and correctly handle any tracer exit
  644. * notifications.
  645. */
  646. if (fatal_signal_pending(current))
  647. goto skip;
  648. /* Check if the tracer forced the syscall to be skipped. */
  649. this_syscall = syscall_get_nr(current, task_pt_regs(current));
  650. if (this_syscall < 0)
  651. goto skip;
  652. /*
  653. * Recheck the syscall, since it may have changed. This
  654. * intentionally uses a NULL struct seccomp_data to force
  655. * a reload of all registers. This does not goto skip since
  656. * a skip would have already been reported.
  657. */
  658. if (__seccomp_filter(this_syscall, NULL, true))
  659. return -1;
  660. return 0;
  661. case SECCOMP_RET_LOG:
  662. seccomp_log(this_syscall, 0, action, true);
  663. return 0;
  664. case SECCOMP_RET_ALLOW:
  665. /*
  666. * Note that the "match" filter will always be NULL for
  667. * this action since SECCOMP_RET_ALLOW is the starting
  668. * state in seccomp_run_filters().
  669. */
  670. return 0;
  671. case SECCOMP_RET_KILL_THREAD:
  672. case SECCOMP_RET_KILL_PROCESS:
  673. default:
  674. seccomp_log(this_syscall, SIGSYS, action, true);
  675. /* Dump core only if this is the last remaining thread. */
  676. if (action == SECCOMP_RET_KILL_PROCESS ||
  677. get_nr_threads(current) == 1) {
  678. siginfo_t info;
  679. /* Show the original registers in the dump. */
  680. syscall_rollback(current, task_pt_regs(current));
  681. /* Trigger a manual coredump since do_exit skips it. */
  682. seccomp_init_siginfo(&info, this_syscall, data);
  683. do_coredump(&info);
  684. }
  685. if (action == SECCOMP_RET_KILL_PROCESS)
  686. do_group_exit(SIGSYS);
  687. else
  688. do_exit(SIGSYS);
  689. }
  690. unreachable();
  691. skip:
  692. seccomp_log(this_syscall, 0, action, match ? match->log : false);
  693. return -1;
  694. }
  695. #else
  696. static int __seccomp_filter(int this_syscall, const struct seccomp_data *sd,
  697. const bool recheck_after_trace)
  698. {
  699. BUG();
  700. }
  701. #endif
  702. int __secure_computing(const struct seccomp_data *sd)
  703. {
  704. int mode = current->seccomp.mode;
  705. int this_syscall;
  706. if (IS_ENABLED(CONFIG_CHECKPOINT_RESTORE) &&
  707. unlikely(current->ptrace & PT_SUSPEND_SECCOMP))
  708. return 0;
  709. this_syscall = sd ? sd->nr :
  710. syscall_get_nr(current, task_pt_regs(current));
  711. switch (mode) {
  712. case SECCOMP_MODE_STRICT:
  713. __secure_computing_strict(this_syscall); /* may call do_exit */
  714. return 0;
  715. case SECCOMP_MODE_FILTER:
  716. return __seccomp_filter(this_syscall, sd, false);
  717. default:
  718. BUG();
  719. }
  720. }
  721. #endif /* CONFIG_HAVE_ARCH_SECCOMP_FILTER */
  722. long prctl_get_seccomp(void)
  723. {
  724. return current->seccomp.mode;
  725. }
  726. /**
  727. * seccomp_set_mode_strict: internal function for setting strict seccomp
  728. *
  729. * Once current->seccomp.mode is non-zero, it may not be changed.
  730. *
  731. * Returns 0 on success or -EINVAL on failure.
  732. */
  733. static long seccomp_set_mode_strict(void)
  734. {
  735. const unsigned long seccomp_mode = SECCOMP_MODE_STRICT;
  736. long ret = -EINVAL;
  737. spin_lock_irq(&current->sighand->siglock);
  738. if (!seccomp_may_assign_mode(seccomp_mode))
  739. goto out;
  740. #ifdef TIF_NOTSC
  741. disable_TSC();
  742. #endif
  743. seccomp_assign_mode(current, seccomp_mode, 0);
  744. ret = 0;
  745. out:
  746. spin_unlock_irq(&current->sighand->siglock);
  747. return ret;
  748. }
  749. #ifdef CONFIG_SECCOMP_FILTER
  750. /**
  751. * seccomp_set_mode_filter: internal function for setting seccomp filter
  752. * @flags: flags to change filter behavior
  753. * @filter: struct sock_fprog containing filter
  754. *
  755. * This function may be called repeatedly to install additional filters.
  756. * Every filter successfully installed will be evaluated (in reverse order)
  757. * for each system call the task makes.
  758. *
  759. * Once current->seccomp.mode is non-zero, it may not be changed.
  760. *
  761. * Returns 0 on success or -EINVAL on failure.
  762. */
  763. static long seccomp_set_mode_filter(unsigned int flags,
  764. const char __user *filter)
  765. {
  766. const unsigned long seccomp_mode = SECCOMP_MODE_FILTER;
  767. struct seccomp_filter *prepared = NULL;
  768. long ret = -EINVAL;
  769. /* Validate flags. */
  770. if (flags & ~SECCOMP_FILTER_FLAG_MASK)
  771. return -EINVAL;
  772. /* Prepare the new filter before holding any locks. */
  773. prepared = seccomp_prepare_user_filter(filter);
  774. if (IS_ERR(prepared))
  775. return PTR_ERR(prepared);
  776. /*
  777. * Make sure we cannot change seccomp or nnp state via TSYNC
  778. * while another thread is in the middle of calling exec.
  779. */
  780. if (flags & SECCOMP_FILTER_FLAG_TSYNC &&
  781. mutex_lock_killable(&current->signal->cred_guard_mutex))
  782. goto out_free;
  783. spin_lock_irq(&current->sighand->siglock);
  784. if (!seccomp_may_assign_mode(seccomp_mode))
  785. goto out;
  786. ret = seccomp_attach_filter(flags, prepared);
  787. if (ret)
  788. goto out;
  789. /* Do not free the successfully attached filter. */
  790. prepared = NULL;
  791. seccomp_assign_mode(current, seccomp_mode, flags);
  792. out:
  793. spin_unlock_irq(&current->sighand->siglock);
  794. if (flags & SECCOMP_FILTER_FLAG_TSYNC)
  795. mutex_unlock(&current->signal->cred_guard_mutex);
  796. out_free:
  797. seccomp_filter_free(prepared);
  798. return ret;
  799. }
  800. #else
  801. static inline long seccomp_set_mode_filter(unsigned int flags,
  802. const char __user *filter)
  803. {
  804. return -EINVAL;
  805. }
  806. #endif
  807. static long seccomp_get_action_avail(const char __user *uaction)
  808. {
  809. u32 action;
  810. if (copy_from_user(&action, uaction, sizeof(action)))
  811. return -EFAULT;
  812. switch (action) {
  813. case SECCOMP_RET_KILL_PROCESS:
  814. case SECCOMP_RET_KILL_THREAD:
  815. case SECCOMP_RET_TRAP:
  816. case SECCOMP_RET_ERRNO:
  817. case SECCOMP_RET_TRACE:
  818. case SECCOMP_RET_LOG:
  819. case SECCOMP_RET_ALLOW:
  820. break;
  821. default:
  822. return -EOPNOTSUPP;
  823. }
  824. return 0;
  825. }
  826. /* Common entry point for both prctl and syscall. */
  827. static long do_seccomp(unsigned int op, unsigned int flags,
  828. const char __user *uargs)
  829. {
  830. switch (op) {
  831. case SECCOMP_SET_MODE_STRICT:
  832. if (flags != 0 || uargs != NULL)
  833. return -EINVAL;
  834. return seccomp_set_mode_strict();
  835. case SECCOMP_SET_MODE_FILTER:
  836. return seccomp_set_mode_filter(flags, uargs);
  837. case SECCOMP_GET_ACTION_AVAIL:
  838. if (flags != 0)
  839. return -EINVAL;
  840. return seccomp_get_action_avail(uargs);
  841. default:
  842. return -EINVAL;
  843. }
  844. }
  845. SYSCALL_DEFINE3(seccomp, unsigned int, op, unsigned int, flags,
  846. const char __user *, uargs)
  847. {
  848. return do_seccomp(op, flags, uargs);
  849. }
  850. /**
  851. * prctl_set_seccomp: configures current->seccomp.mode
  852. * @seccomp_mode: requested mode to use
  853. * @filter: optional struct sock_fprog for use with SECCOMP_MODE_FILTER
  854. *
  855. * Returns 0 on success or -EINVAL on failure.
  856. */
  857. long prctl_set_seccomp(unsigned long seccomp_mode, char __user *filter)
  858. {
  859. unsigned int op;
  860. char __user *uargs;
  861. switch (seccomp_mode) {
  862. case SECCOMP_MODE_STRICT:
  863. op = SECCOMP_SET_MODE_STRICT;
  864. /*
  865. * Setting strict mode through prctl always ignored filter,
  866. * so make sure it is always NULL here to pass the internal
  867. * check in do_seccomp().
  868. */
  869. uargs = NULL;
  870. break;
  871. case SECCOMP_MODE_FILTER:
  872. op = SECCOMP_SET_MODE_FILTER;
  873. uargs = filter;
  874. break;
  875. default:
  876. return -EINVAL;
  877. }
  878. /* prctl interface doesn't have flags, so they are always zero. */
  879. return do_seccomp(op, 0, uargs);
  880. }
  881. #if defined(CONFIG_SECCOMP_FILTER) && defined(CONFIG_CHECKPOINT_RESTORE)
  882. static struct seccomp_filter *get_nth_filter(struct task_struct *task,
  883. unsigned long filter_off)
  884. {
  885. struct seccomp_filter *orig, *filter;
  886. unsigned long count;
  887. /*
  888. * Note: this is only correct because the caller should be the (ptrace)
  889. * tracer of the task, otherwise lock_task_sighand is needed.
  890. */
  891. spin_lock_irq(&task->sighand->siglock);
  892. if (task->seccomp.mode != SECCOMP_MODE_FILTER) {
  893. spin_unlock_irq(&task->sighand->siglock);
  894. return ERR_PTR(-EINVAL);
  895. }
  896. orig = task->seccomp.filter;
  897. __get_seccomp_filter(orig);
  898. spin_unlock_irq(&task->sighand->siglock);
  899. count = 0;
  900. for (filter = orig; filter; filter = filter->prev)
  901. count++;
  902. if (filter_off >= count) {
  903. filter = ERR_PTR(-ENOENT);
  904. goto out;
  905. }
  906. count -= filter_off;
  907. for (filter = orig; filter && count > 1; filter = filter->prev)
  908. count--;
  909. if (WARN_ON(count != 1 || !filter)) {
  910. filter = ERR_PTR(-ENOENT);
  911. goto out;
  912. }
  913. __get_seccomp_filter(filter);
  914. out:
  915. __put_seccomp_filter(orig);
  916. return filter;
  917. }
  918. long seccomp_get_filter(struct task_struct *task, unsigned long filter_off,
  919. void __user *data)
  920. {
  921. struct seccomp_filter *filter;
  922. struct sock_fprog_kern *fprog;
  923. long ret;
  924. if (!capable(CAP_SYS_ADMIN) ||
  925. current->seccomp.mode != SECCOMP_MODE_DISABLED) {
  926. return -EACCES;
  927. }
  928. filter = get_nth_filter(task, filter_off);
  929. if (IS_ERR(filter))
  930. return PTR_ERR(filter);
  931. fprog = filter->prog->orig_prog;
  932. if (!fprog) {
  933. /* This must be a new non-cBPF filter, since we save
  934. * every cBPF filter's orig_prog above when
  935. * CONFIG_CHECKPOINT_RESTORE is enabled.
  936. */
  937. ret = -EMEDIUMTYPE;
  938. goto out;
  939. }
  940. ret = fprog->len;
  941. if (!data)
  942. goto out;
  943. if (copy_to_user(data, fprog->filter, bpf_classic_proglen(fprog)))
  944. ret = -EFAULT;
  945. out:
  946. __put_seccomp_filter(filter);
  947. return ret;
  948. }
  949. long seccomp_get_metadata(struct task_struct *task,
  950. unsigned long size, void __user *data)
  951. {
  952. long ret;
  953. struct seccomp_filter *filter;
  954. struct seccomp_metadata kmd = {};
  955. if (!capable(CAP_SYS_ADMIN) ||
  956. current->seccomp.mode != SECCOMP_MODE_DISABLED) {
  957. return -EACCES;
  958. }
  959. size = min_t(unsigned long, size, sizeof(kmd));
  960. if (size < sizeof(kmd.filter_off))
  961. return -EINVAL;
  962. if (copy_from_user(&kmd.filter_off, data, sizeof(kmd.filter_off)))
  963. return -EFAULT;
  964. filter = get_nth_filter(task, kmd.filter_off);
  965. if (IS_ERR(filter))
  966. return PTR_ERR(filter);
  967. if (filter->log)
  968. kmd.flags |= SECCOMP_FILTER_FLAG_LOG;
  969. ret = size;
  970. if (copy_to_user(data, &kmd, size))
  971. ret = -EFAULT;
  972. __put_seccomp_filter(filter);
  973. return ret;
  974. }
  975. #endif
  976. #ifdef CONFIG_SYSCTL
  977. /* Human readable action names for friendly sysctl interaction */
  978. #define SECCOMP_RET_KILL_PROCESS_NAME "kill_process"
  979. #define SECCOMP_RET_KILL_THREAD_NAME "kill_thread"
  980. #define SECCOMP_RET_TRAP_NAME "trap"
  981. #define SECCOMP_RET_ERRNO_NAME "errno"
  982. #define SECCOMP_RET_TRACE_NAME "trace"
  983. #define SECCOMP_RET_LOG_NAME "log"
  984. #define SECCOMP_RET_ALLOW_NAME "allow"
  985. static const char seccomp_actions_avail[] =
  986. SECCOMP_RET_KILL_PROCESS_NAME " "
  987. SECCOMP_RET_KILL_THREAD_NAME " "
  988. SECCOMP_RET_TRAP_NAME " "
  989. SECCOMP_RET_ERRNO_NAME " "
  990. SECCOMP_RET_TRACE_NAME " "
  991. SECCOMP_RET_LOG_NAME " "
  992. SECCOMP_RET_ALLOW_NAME;
  993. struct seccomp_log_name {
  994. u32 log;
  995. const char *name;
  996. };
  997. static const struct seccomp_log_name seccomp_log_names[] = {
  998. { SECCOMP_LOG_KILL_PROCESS, SECCOMP_RET_KILL_PROCESS_NAME },
  999. { SECCOMP_LOG_KILL_THREAD, SECCOMP_RET_KILL_THREAD_NAME },
  1000. { SECCOMP_LOG_TRAP, SECCOMP_RET_TRAP_NAME },
  1001. { SECCOMP_LOG_ERRNO, SECCOMP_RET_ERRNO_NAME },
  1002. { SECCOMP_LOG_TRACE, SECCOMP_RET_TRACE_NAME },
  1003. { SECCOMP_LOG_LOG, SECCOMP_RET_LOG_NAME },
  1004. { SECCOMP_LOG_ALLOW, SECCOMP_RET_ALLOW_NAME },
  1005. { }
  1006. };
  1007. static bool seccomp_names_from_actions_logged(char *names, size_t size,
  1008. u32 actions_logged)
  1009. {
  1010. const struct seccomp_log_name *cur;
  1011. bool append_space = false;
  1012. for (cur = seccomp_log_names; cur->name && size; cur++) {
  1013. ssize_t ret;
  1014. if (!(actions_logged & cur->log))
  1015. continue;
  1016. if (append_space) {
  1017. ret = strscpy(names, " ", size);
  1018. if (ret < 0)
  1019. return false;
  1020. names += ret;
  1021. size -= ret;
  1022. } else
  1023. append_space = true;
  1024. ret = strscpy(names, cur->name, size);
  1025. if (ret < 0)
  1026. return false;
  1027. names += ret;
  1028. size -= ret;
  1029. }
  1030. return true;
  1031. }
  1032. static bool seccomp_action_logged_from_name(u32 *action_logged,
  1033. const char *name)
  1034. {
  1035. const struct seccomp_log_name *cur;
  1036. for (cur = seccomp_log_names; cur->name; cur++) {
  1037. if (!strcmp(cur->name, name)) {
  1038. *action_logged = cur->log;
  1039. return true;
  1040. }
  1041. }
  1042. return false;
  1043. }
  1044. static bool seccomp_actions_logged_from_names(u32 *actions_logged, char *names)
  1045. {
  1046. char *name;
  1047. *actions_logged = 0;
  1048. while ((name = strsep(&names, " ")) && *name) {
  1049. u32 action_logged = 0;
  1050. if (!seccomp_action_logged_from_name(&action_logged, name))
  1051. return false;
  1052. *actions_logged |= action_logged;
  1053. }
  1054. return true;
  1055. }
  1056. static int seccomp_actions_logged_handler(struct ctl_table *ro_table, int write,
  1057. void __user *buffer, size_t *lenp,
  1058. loff_t *ppos)
  1059. {
  1060. char names[sizeof(seccomp_actions_avail)];
  1061. struct ctl_table table;
  1062. int ret;
  1063. if (write && !capable(CAP_SYS_ADMIN))
  1064. return -EPERM;
  1065. memset(names, 0, sizeof(names));
  1066. if (!write) {
  1067. if (!seccomp_names_from_actions_logged(names, sizeof(names),
  1068. seccomp_actions_logged))
  1069. return -EINVAL;
  1070. }
  1071. table = *ro_table;
  1072. table.data = names;
  1073. table.maxlen = sizeof(names);
  1074. ret = proc_dostring(&table, write, buffer, lenp, ppos);
  1075. if (ret)
  1076. return ret;
  1077. if (write) {
  1078. u32 actions_logged;
  1079. if (!seccomp_actions_logged_from_names(&actions_logged,
  1080. table.data))
  1081. return -EINVAL;
  1082. if (actions_logged & SECCOMP_LOG_ALLOW)
  1083. return -EINVAL;
  1084. seccomp_actions_logged = actions_logged;
  1085. }
  1086. return 0;
  1087. }
  1088. static struct ctl_path seccomp_sysctl_path[] = {
  1089. { .procname = "kernel", },
  1090. { .procname = "seccomp", },
  1091. { }
  1092. };
  1093. static struct ctl_table seccomp_sysctl_table[] = {
  1094. {
  1095. .procname = "actions_avail",
  1096. .data = (void *) &seccomp_actions_avail,
  1097. .maxlen = sizeof(seccomp_actions_avail),
  1098. .mode = 0444,
  1099. .proc_handler = proc_dostring,
  1100. },
  1101. {
  1102. .procname = "actions_logged",
  1103. .mode = 0644,
  1104. .proc_handler = seccomp_actions_logged_handler,
  1105. },
  1106. { }
  1107. };
  1108. static int __init seccomp_sysctl_init(void)
  1109. {
  1110. struct ctl_table_header *hdr;
  1111. hdr = register_sysctl_paths(seccomp_sysctl_path, seccomp_sysctl_table);
  1112. if (!hdr)
  1113. pr_warn("seccomp: sysctl registration failed\n");
  1114. else
  1115. kmemleak_not_leak(hdr);
  1116. return 0;
  1117. }
  1118. device_initcall(seccomp_sysctl_init)
  1119. #endif /* CONFIG_SYSCTL */