seccomp.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298
  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. {
  228. assert_spin_locked(&task->sighand->siglock);
  229. task->seccomp.mode = seccomp_mode;
  230. /*
  231. * Make sure TIF_SECCOMP cannot be set before the mode (and
  232. * filter) is set.
  233. */
  234. smp_mb__before_atomic();
  235. /* Assume seccomp processes want speculation flaw mitigation. */
  236. spec_mitigate(task, PR_SPEC_STORE_BYPASS);
  237. set_tsk_thread_flag(task, TIF_SECCOMP);
  238. }
  239. #ifdef CONFIG_SECCOMP_FILTER
  240. /* Returns 1 if the parent is an ancestor of the child. */
  241. static int is_ancestor(struct seccomp_filter *parent,
  242. struct seccomp_filter *child)
  243. {
  244. /* NULL is the root ancestor. */
  245. if (parent == NULL)
  246. return 1;
  247. for (; child; child = child->prev)
  248. if (child == parent)
  249. return 1;
  250. return 0;
  251. }
  252. /**
  253. * seccomp_can_sync_threads: checks if all threads can be synchronized
  254. *
  255. * Expects sighand and cred_guard_mutex locks to be held.
  256. *
  257. * Returns 0 on success, -ve on error, or the pid of a thread which was
  258. * either not in the correct seccomp mode or it did not have an ancestral
  259. * seccomp filter.
  260. */
  261. static inline pid_t seccomp_can_sync_threads(void)
  262. {
  263. struct task_struct *thread, *caller;
  264. BUG_ON(!mutex_is_locked(&current->signal->cred_guard_mutex));
  265. assert_spin_locked(&current->sighand->siglock);
  266. /* Validate all threads being eligible for synchronization. */
  267. caller = current;
  268. for_each_thread(caller, thread) {
  269. pid_t failed;
  270. /* Skip current, since it is initiating the sync. */
  271. if (thread == caller)
  272. continue;
  273. if (thread->seccomp.mode == SECCOMP_MODE_DISABLED ||
  274. (thread->seccomp.mode == SECCOMP_MODE_FILTER &&
  275. is_ancestor(thread->seccomp.filter,
  276. caller->seccomp.filter)))
  277. continue;
  278. /* Return the first thread that cannot be synchronized. */
  279. failed = task_pid_vnr(thread);
  280. /* If the pid cannot be resolved, then return -ESRCH */
  281. if (unlikely(WARN_ON(failed == 0)))
  282. failed = -ESRCH;
  283. return failed;
  284. }
  285. return 0;
  286. }
  287. /**
  288. * seccomp_sync_threads: sets all threads to use current's filter
  289. *
  290. * Expects sighand and cred_guard_mutex locks to be held, and for
  291. * seccomp_can_sync_threads() to have returned success already
  292. * without dropping the locks.
  293. *
  294. */
  295. static inline void seccomp_sync_threads(void)
  296. {
  297. struct task_struct *thread, *caller;
  298. BUG_ON(!mutex_is_locked(&current->signal->cred_guard_mutex));
  299. assert_spin_locked(&current->sighand->siglock);
  300. /* Synchronize all threads. */
  301. caller = current;
  302. for_each_thread(caller, thread) {
  303. /* Skip current, since it needs no changes. */
  304. if (thread == caller)
  305. continue;
  306. /* Get a task reference for the new leaf node. */
  307. get_seccomp_filter(caller);
  308. /*
  309. * Drop the task reference to the shared ancestor since
  310. * current's path will hold a reference. (This also
  311. * allows a put before the assignment.)
  312. */
  313. put_seccomp_filter(thread);
  314. smp_store_release(&thread->seccomp.filter,
  315. caller->seccomp.filter);
  316. /*
  317. * Don't let an unprivileged task work around
  318. * the no_new_privs restriction by creating
  319. * a thread that sets it up, enters seccomp,
  320. * then dies.
  321. */
  322. if (task_no_new_privs(caller))
  323. task_set_no_new_privs(thread);
  324. /*
  325. * Opt the other thread into seccomp if needed.
  326. * As threads are considered to be trust-realm
  327. * equivalent (see ptrace_may_access), it is safe to
  328. * allow one thread to transition the other.
  329. */
  330. if (thread->seccomp.mode == SECCOMP_MODE_DISABLED)
  331. seccomp_assign_mode(thread, SECCOMP_MODE_FILTER);
  332. }
  333. }
  334. /**
  335. * seccomp_prepare_filter: Prepares a seccomp filter for use.
  336. * @fprog: BPF program to install
  337. *
  338. * Returns filter on success or an ERR_PTR on failure.
  339. */
  340. static struct seccomp_filter *seccomp_prepare_filter(struct sock_fprog *fprog)
  341. {
  342. struct seccomp_filter *sfilter;
  343. int ret;
  344. const bool save_orig = IS_ENABLED(CONFIG_CHECKPOINT_RESTORE);
  345. if (fprog->len == 0 || fprog->len > BPF_MAXINSNS)
  346. return ERR_PTR(-EINVAL);
  347. BUG_ON(INT_MAX / fprog->len < sizeof(struct sock_filter));
  348. /*
  349. * Installing a seccomp filter requires that the task has
  350. * CAP_SYS_ADMIN in its namespace or be running with no_new_privs.
  351. * This avoids scenarios where unprivileged tasks can affect the
  352. * behavior of privileged children.
  353. */
  354. if (!task_no_new_privs(current) &&
  355. security_capable_noaudit(current_cred(), current_user_ns(),
  356. CAP_SYS_ADMIN) != 0)
  357. return ERR_PTR(-EACCES);
  358. /* Allocate a new seccomp_filter */
  359. sfilter = kzalloc(sizeof(*sfilter), GFP_KERNEL | __GFP_NOWARN);
  360. if (!sfilter)
  361. return ERR_PTR(-ENOMEM);
  362. ret = bpf_prog_create_from_user(&sfilter->prog, fprog,
  363. seccomp_check_filter, save_orig);
  364. if (ret < 0) {
  365. kfree(sfilter);
  366. return ERR_PTR(ret);
  367. }
  368. refcount_set(&sfilter->usage, 1);
  369. return sfilter;
  370. }
  371. /**
  372. * seccomp_prepare_user_filter - prepares a user-supplied sock_fprog
  373. * @user_filter: pointer to the user data containing a sock_fprog.
  374. *
  375. * Returns 0 on success and non-zero otherwise.
  376. */
  377. static struct seccomp_filter *
  378. seccomp_prepare_user_filter(const char __user *user_filter)
  379. {
  380. struct sock_fprog fprog;
  381. struct seccomp_filter *filter = ERR_PTR(-EFAULT);
  382. #ifdef CONFIG_COMPAT
  383. if (in_compat_syscall()) {
  384. struct compat_sock_fprog fprog32;
  385. if (copy_from_user(&fprog32, user_filter, sizeof(fprog32)))
  386. goto out;
  387. fprog.len = fprog32.len;
  388. fprog.filter = compat_ptr(fprog32.filter);
  389. } else /* falls through to the if below. */
  390. #endif
  391. if (copy_from_user(&fprog, user_filter, sizeof(fprog)))
  392. goto out;
  393. filter = seccomp_prepare_filter(&fprog);
  394. out:
  395. return filter;
  396. }
  397. /**
  398. * seccomp_attach_filter: validate and attach filter
  399. * @flags: flags to change filter behavior
  400. * @filter: seccomp filter to add to the current process
  401. *
  402. * Caller must be holding current->sighand->siglock lock.
  403. *
  404. * Returns 0 on success, -ve on error.
  405. */
  406. static long seccomp_attach_filter(unsigned int flags,
  407. struct seccomp_filter *filter)
  408. {
  409. unsigned long total_insns;
  410. struct seccomp_filter *walker;
  411. assert_spin_locked(&current->sighand->siglock);
  412. /* Validate resulting filter length. */
  413. total_insns = filter->prog->len;
  414. for (walker = current->seccomp.filter; walker; walker = walker->prev)
  415. total_insns += walker->prog->len + 4; /* 4 instr penalty */
  416. if (total_insns > MAX_INSNS_PER_PATH)
  417. return -ENOMEM;
  418. /* If thread sync has been requested, check that it is possible. */
  419. if (flags & SECCOMP_FILTER_FLAG_TSYNC) {
  420. int ret;
  421. ret = seccomp_can_sync_threads();
  422. if (ret)
  423. return ret;
  424. }
  425. /* Set log flag, if present. */
  426. if (flags & SECCOMP_FILTER_FLAG_LOG)
  427. filter->log = true;
  428. /*
  429. * If there is an existing filter, make it the prev and don't drop its
  430. * task reference.
  431. */
  432. filter->prev = current->seccomp.filter;
  433. current->seccomp.filter = filter;
  434. /* Now that the new filter is in place, synchronize to all threads. */
  435. if (flags & SECCOMP_FILTER_FLAG_TSYNC)
  436. seccomp_sync_threads();
  437. return 0;
  438. }
  439. static void __get_seccomp_filter(struct seccomp_filter *filter)
  440. {
  441. /* Reference count is bounded by the number of total processes. */
  442. refcount_inc(&filter->usage);
  443. }
  444. /* get_seccomp_filter - increments the reference count of the filter on @tsk */
  445. void get_seccomp_filter(struct task_struct *tsk)
  446. {
  447. struct seccomp_filter *orig = tsk->seccomp.filter;
  448. if (!orig)
  449. return;
  450. __get_seccomp_filter(orig);
  451. }
  452. static inline void seccomp_filter_free(struct seccomp_filter *filter)
  453. {
  454. if (filter) {
  455. bpf_prog_destroy(filter->prog);
  456. kfree(filter);
  457. }
  458. }
  459. static void __put_seccomp_filter(struct seccomp_filter *orig)
  460. {
  461. /* Clean up single-reference branches iteratively. */
  462. while (orig && refcount_dec_and_test(&orig->usage)) {
  463. struct seccomp_filter *freeme = orig;
  464. orig = orig->prev;
  465. seccomp_filter_free(freeme);
  466. }
  467. }
  468. /* put_seccomp_filter - decrements the ref count of tsk->seccomp.filter */
  469. void put_seccomp_filter(struct task_struct *tsk)
  470. {
  471. __put_seccomp_filter(tsk->seccomp.filter);
  472. }
  473. static void seccomp_init_siginfo(siginfo_t *info, int syscall, int reason)
  474. {
  475. clear_siginfo(info);
  476. info->si_signo = SIGSYS;
  477. info->si_code = SYS_SECCOMP;
  478. info->si_call_addr = (void __user *)KSTK_EIP(current);
  479. info->si_errno = reason;
  480. info->si_arch = syscall_get_arch();
  481. info->si_syscall = syscall;
  482. }
  483. /**
  484. * seccomp_send_sigsys - signals the task to allow in-process syscall emulation
  485. * @syscall: syscall number to send to userland
  486. * @reason: filter-supplied reason code to send to userland (via si_errno)
  487. *
  488. * Forces a SIGSYS with a code of SYS_SECCOMP and related sigsys info.
  489. */
  490. static void seccomp_send_sigsys(int syscall, int reason)
  491. {
  492. struct siginfo info;
  493. seccomp_init_siginfo(&info, syscall, reason);
  494. force_sig_info(SIGSYS, &info, current);
  495. }
  496. #endif /* CONFIG_SECCOMP_FILTER */
  497. /* For use with seccomp_actions_logged */
  498. #define SECCOMP_LOG_KILL_PROCESS (1 << 0)
  499. #define SECCOMP_LOG_KILL_THREAD (1 << 1)
  500. #define SECCOMP_LOG_TRAP (1 << 2)
  501. #define SECCOMP_LOG_ERRNO (1 << 3)
  502. #define SECCOMP_LOG_TRACE (1 << 4)
  503. #define SECCOMP_LOG_LOG (1 << 5)
  504. #define SECCOMP_LOG_ALLOW (1 << 6)
  505. static u32 seccomp_actions_logged = SECCOMP_LOG_KILL_PROCESS |
  506. SECCOMP_LOG_KILL_THREAD |
  507. SECCOMP_LOG_TRAP |
  508. SECCOMP_LOG_ERRNO |
  509. SECCOMP_LOG_TRACE |
  510. SECCOMP_LOG_LOG;
  511. static inline void seccomp_log(unsigned long syscall, long signr, u32 action,
  512. bool requested)
  513. {
  514. bool log = false;
  515. switch (action) {
  516. case SECCOMP_RET_ALLOW:
  517. break;
  518. case SECCOMP_RET_TRAP:
  519. log = requested && seccomp_actions_logged & SECCOMP_LOG_TRAP;
  520. break;
  521. case SECCOMP_RET_ERRNO:
  522. log = requested && seccomp_actions_logged & SECCOMP_LOG_ERRNO;
  523. break;
  524. case SECCOMP_RET_TRACE:
  525. log = requested && seccomp_actions_logged & SECCOMP_LOG_TRACE;
  526. break;
  527. case SECCOMP_RET_LOG:
  528. log = seccomp_actions_logged & SECCOMP_LOG_LOG;
  529. break;
  530. case SECCOMP_RET_KILL_THREAD:
  531. log = seccomp_actions_logged & SECCOMP_LOG_KILL_THREAD;
  532. break;
  533. case SECCOMP_RET_KILL_PROCESS:
  534. default:
  535. log = seccomp_actions_logged & SECCOMP_LOG_KILL_PROCESS;
  536. }
  537. /*
  538. * Force an audit message to be emitted when the action is RET_KILL_*,
  539. * RET_LOG, or the FILTER_FLAG_LOG bit was set and the action is
  540. * allowed to be logged by the admin.
  541. */
  542. if (log)
  543. return __audit_seccomp(syscall, signr, action);
  544. /*
  545. * Let the audit subsystem decide if the action should be audited based
  546. * on whether the current task itself is being audited.
  547. */
  548. return audit_seccomp(syscall, signr, action);
  549. }
  550. /*
  551. * Secure computing mode 1 allows only read/write/exit/sigreturn.
  552. * To be fully secure this must be combined with rlimit
  553. * to limit the stack allocations too.
  554. */
  555. static const int mode1_syscalls[] = {
  556. __NR_seccomp_read, __NR_seccomp_write, __NR_seccomp_exit, __NR_seccomp_sigreturn,
  557. 0, /* null terminated */
  558. };
  559. static void __secure_computing_strict(int this_syscall)
  560. {
  561. const int *syscall_whitelist = mode1_syscalls;
  562. #ifdef CONFIG_COMPAT
  563. if (in_compat_syscall())
  564. syscall_whitelist = get_compat_mode1_syscalls();
  565. #endif
  566. do {
  567. if (*syscall_whitelist == this_syscall)
  568. return;
  569. } while (*++syscall_whitelist);
  570. #ifdef SECCOMP_DEBUG
  571. dump_stack();
  572. #endif
  573. seccomp_log(this_syscall, SIGKILL, SECCOMP_RET_KILL_THREAD, true);
  574. do_exit(SIGKILL);
  575. }
  576. #ifndef CONFIG_HAVE_ARCH_SECCOMP_FILTER
  577. void secure_computing_strict(int this_syscall)
  578. {
  579. int mode = current->seccomp.mode;
  580. if (IS_ENABLED(CONFIG_CHECKPOINT_RESTORE) &&
  581. unlikely(current->ptrace & PT_SUSPEND_SECCOMP))
  582. return;
  583. if (mode == SECCOMP_MODE_DISABLED)
  584. return;
  585. else if (mode == SECCOMP_MODE_STRICT)
  586. __secure_computing_strict(this_syscall);
  587. else
  588. BUG();
  589. }
  590. #else
  591. #ifdef CONFIG_SECCOMP_FILTER
  592. static int __seccomp_filter(int this_syscall, const struct seccomp_data *sd,
  593. const bool recheck_after_trace)
  594. {
  595. u32 filter_ret, action;
  596. struct seccomp_filter *match = NULL;
  597. int data;
  598. /*
  599. * Make sure that any changes to mode from another thread have
  600. * been seen after TIF_SECCOMP was seen.
  601. */
  602. rmb();
  603. filter_ret = seccomp_run_filters(sd, &match);
  604. data = filter_ret & SECCOMP_RET_DATA;
  605. action = filter_ret & SECCOMP_RET_ACTION_FULL;
  606. switch (action) {
  607. case SECCOMP_RET_ERRNO:
  608. /* Set low-order bits as an errno, capped at MAX_ERRNO. */
  609. if (data > MAX_ERRNO)
  610. data = MAX_ERRNO;
  611. syscall_set_return_value(current, task_pt_regs(current),
  612. -data, 0);
  613. goto skip;
  614. case SECCOMP_RET_TRAP:
  615. /* Show the handler the original registers. */
  616. syscall_rollback(current, task_pt_regs(current));
  617. /* Let the filter pass back 16 bits of data. */
  618. seccomp_send_sigsys(this_syscall, data);
  619. goto skip;
  620. case SECCOMP_RET_TRACE:
  621. /* We've been put in this state by the ptracer already. */
  622. if (recheck_after_trace)
  623. return 0;
  624. /* ENOSYS these calls if there is no tracer attached. */
  625. if (!ptrace_event_enabled(current, PTRACE_EVENT_SECCOMP)) {
  626. syscall_set_return_value(current,
  627. task_pt_regs(current),
  628. -ENOSYS, 0);
  629. goto skip;
  630. }
  631. /* Allow the BPF to provide the event message */
  632. ptrace_event(PTRACE_EVENT_SECCOMP, data);
  633. /*
  634. * The delivery of a fatal signal during event
  635. * notification may silently skip tracer notification,
  636. * which could leave us with a potentially unmodified
  637. * syscall that the tracer would have liked to have
  638. * changed. Since the process is about to die, we just
  639. * force the syscall to be skipped and let the signal
  640. * kill the process and correctly handle any tracer exit
  641. * notifications.
  642. */
  643. if (fatal_signal_pending(current))
  644. goto skip;
  645. /* Check if the tracer forced the syscall to be skipped. */
  646. this_syscall = syscall_get_nr(current, task_pt_regs(current));
  647. if (this_syscall < 0)
  648. goto skip;
  649. /*
  650. * Recheck the syscall, since it may have changed. This
  651. * intentionally uses a NULL struct seccomp_data to force
  652. * a reload of all registers. This does not goto skip since
  653. * a skip would have already been reported.
  654. */
  655. if (__seccomp_filter(this_syscall, NULL, true))
  656. return -1;
  657. return 0;
  658. case SECCOMP_RET_LOG:
  659. seccomp_log(this_syscall, 0, action, true);
  660. return 0;
  661. case SECCOMP_RET_ALLOW:
  662. /*
  663. * Note that the "match" filter will always be NULL for
  664. * this action since SECCOMP_RET_ALLOW is the starting
  665. * state in seccomp_run_filters().
  666. */
  667. return 0;
  668. case SECCOMP_RET_KILL_THREAD:
  669. case SECCOMP_RET_KILL_PROCESS:
  670. default:
  671. seccomp_log(this_syscall, SIGSYS, action, true);
  672. /* Dump core only if this is the last remaining thread. */
  673. if (action == SECCOMP_RET_KILL_PROCESS ||
  674. get_nr_threads(current) == 1) {
  675. siginfo_t info;
  676. /* Show the original registers in the dump. */
  677. syscall_rollback(current, task_pt_regs(current));
  678. /* Trigger a manual coredump since do_exit skips it. */
  679. seccomp_init_siginfo(&info, this_syscall, data);
  680. do_coredump(&info);
  681. }
  682. if (action == SECCOMP_RET_KILL_PROCESS)
  683. do_group_exit(SIGSYS);
  684. else
  685. do_exit(SIGSYS);
  686. }
  687. unreachable();
  688. skip:
  689. seccomp_log(this_syscall, 0, action, match ? match->log : false);
  690. return -1;
  691. }
  692. #else
  693. static int __seccomp_filter(int this_syscall, const struct seccomp_data *sd,
  694. const bool recheck_after_trace)
  695. {
  696. BUG();
  697. }
  698. #endif
  699. int __secure_computing(const struct seccomp_data *sd)
  700. {
  701. int mode = current->seccomp.mode;
  702. int this_syscall;
  703. if (IS_ENABLED(CONFIG_CHECKPOINT_RESTORE) &&
  704. unlikely(current->ptrace & PT_SUSPEND_SECCOMP))
  705. return 0;
  706. this_syscall = sd ? sd->nr :
  707. syscall_get_nr(current, task_pt_regs(current));
  708. switch (mode) {
  709. case SECCOMP_MODE_STRICT:
  710. __secure_computing_strict(this_syscall); /* may call do_exit */
  711. return 0;
  712. case SECCOMP_MODE_FILTER:
  713. return __seccomp_filter(this_syscall, sd, false);
  714. default:
  715. BUG();
  716. }
  717. }
  718. #endif /* CONFIG_HAVE_ARCH_SECCOMP_FILTER */
  719. long prctl_get_seccomp(void)
  720. {
  721. return current->seccomp.mode;
  722. }
  723. /**
  724. * seccomp_set_mode_strict: internal function for setting strict seccomp
  725. *
  726. * Once current->seccomp.mode is non-zero, it may not be changed.
  727. *
  728. * Returns 0 on success or -EINVAL on failure.
  729. */
  730. static long seccomp_set_mode_strict(void)
  731. {
  732. const unsigned long seccomp_mode = SECCOMP_MODE_STRICT;
  733. long ret = -EINVAL;
  734. spin_lock_irq(&current->sighand->siglock);
  735. if (!seccomp_may_assign_mode(seccomp_mode))
  736. goto out;
  737. #ifdef TIF_NOTSC
  738. disable_TSC();
  739. #endif
  740. seccomp_assign_mode(current, seccomp_mode);
  741. ret = 0;
  742. out:
  743. spin_unlock_irq(&current->sighand->siglock);
  744. return ret;
  745. }
  746. #ifdef CONFIG_SECCOMP_FILTER
  747. /**
  748. * seccomp_set_mode_filter: internal function for setting seccomp filter
  749. * @flags: flags to change filter behavior
  750. * @filter: struct sock_fprog containing filter
  751. *
  752. * This function may be called repeatedly to install additional filters.
  753. * Every filter successfully installed will be evaluated (in reverse order)
  754. * for each system call the task makes.
  755. *
  756. * Once current->seccomp.mode is non-zero, it may not be changed.
  757. *
  758. * Returns 0 on success or -EINVAL on failure.
  759. */
  760. static long seccomp_set_mode_filter(unsigned int flags,
  761. const char __user *filter)
  762. {
  763. const unsigned long seccomp_mode = SECCOMP_MODE_FILTER;
  764. struct seccomp_filter *prepared = NULL;
  765. long ret = -EINVAL;
  766. /* Validate flags. */
  767. if (flags & ~SECCOMP_FILTER_FLAG_MASK)
  768. return -EINVAL;
  769. /* Prepare the new filter before holding any locks. */
  770. prepared = seccomp_prepare_user_filter(filter);
  771. if (IS_ERR(prepared))
  772. return PTR_ERR(prepared);
  773. /*
  774. * Make sure we cannot change seccomp or nnp state via TSYNC
  775. * while another thread is in the middle of calling exec.
  776. */
  777. if (flags & SECCOMP_FILTER_FLAG_TSYNC &&
  778. mutex_lock_killable(&current->signal->cred_guard_mutex))
  779. goto out_free;
  780. spin_lock_irq(&current->sighand->siglock);
  781. if (!seccomp_may_assign_mode(seccomp_mode))
  782. goto out;
  783. ret = seccomp_attach_filter(flags, prepared);
  784. if (ret)
  785. goto out;
  786. /* Do not free the successfully attached filter. */
  787. prepared = NULL;
  788. seccomp_assign_mode(current, seccomp_mode);
  789. out:
  790. spin_unlock_irq(&current->sighand->siglock);
  791. if (flags & SECCOMP_FILTER_FLAG_TSYNC)
  792. mutex_unlock(&current->signal->cred_guard_mutex);
  793. out_free:
  794. seccomp_filter_free(prepared);
  795. return ret;
  796. }
  797. #else
  798. static inline long seccomp_set_mode_filter(unsigned int flags,
  799. const char __user *filter)
  800. {
  801. return -EINVAL;
  802. }
  803. #endif
  804. static long seccomp_get_action_avail(const char __user *uaction)
  805. {
  806. u32 action;
  807. if (copy_from_user(&action, uaction, sizeof(action)))
  808. return -EFAULT;
  809. switch (action) {
  810. case SECCOMP_RET_KILL_PROCESS:
  811. case SECCOMP_RET_KILL_THREAD:
  812. case SECCOMP_RET_TRAP:
  813. case SECCOMP_RET_ERRNO:
  814. case SECCOMP_RET_TRACE:
  815. case SECCOMP_RET_LOG:
  816. case SECCOMP_RET_ALLOW:
  817. break;
  818. default:
  819. return -EOPNOTSUPP;
  820. }
  821. return 0;
  822. }
  823. /* Common entry point for both prctl and syscall. */
  824. static long do_seccomp(unsigned int op, unsigned int flags,
  825. const char __user *uargs)
  826. {
  827. switch (op) {
  828. case SECCOMP_SET_MODE_STRICT:
  829. if (flags != 0 || uargs != NULL)
  830. return -EINVAL;
  831. return seccomp_set_mode_strict();
  832. case SECCOMP_SET_MODE_FILTER:
  833. return seccomp_set_mode_filter(flags, uargs);
  834. case SECCOMP_GET_ACTION_AVAIL:
  835. if (flags != 0)
  836. return -EINVAL;
  837. return seccomp_get_action_avail(uargs);
  838. default:
  839. return -EINVAL;
  840. }
  841. }
  842. SYSCALL_DEFINE3(seccomp, unsigned int, op, unsigned int, flags,
  843. const char __user *, uargs)
  844. {
  845. return do_seccomp(op, flags, uargs);
  846. }
  847. /**
  848. * prctl_set_seccomp: configures current->seccomp.mode
  849. * @seccomp_mode: requested mode to use
  850. * @filter: optional struct sock_fprog for use with SECCOMP_MODE_FILTER
  851. *
  852. * Returns 0 on success or -EINVAL on failure.
  853. */
  854. long prctl_set_seccomp(unsigned long seccomp_mode, char __user *filter)
  855. {
  856. unsigned int op;
  857. char __user *uargs;
  858. switch (seccomp_mode) {
  859. case SECCOMP_MODE_STRICT:
  860. op = SECCOMP_SET_MODE_STRICT;
  861. /*
  862. * Setting strict mode through prctl always ignored filter,
  863. * so make sure it is always NULL here to pass the internal
  864. * check in do_seccomp().
  865. */
  866. uargs = NULL;
  867. break;
  868. case SECCOMP_MODE_FILTER:
  869. op = SECCOMP_SET_MODE_FILTER;
  870. uargs = filter;
  871. break;
  872. default:
  873. return -EINVAL;
  874. }
  875. /* prctl interface doesn't have flags, so they are always zero. */
  876. return do_seccomp(op, 0, uargs);
  877. }
  878. #if defined(CONFIG_SECCOMP_FILTER) && defined(CONFIG_CHECKPOINT_RESTORE)
  879. static struct seccomp_filter *get_nth_filter(struct task_struct *task,
  880. unsigned long filter_off)
  881. {
  882. struct seccomp_filter *orig, *filter;
  883. unsigned long count;
  884. /*
  885. * Note: this is only correct because the caller should be the (ptrace)
  886. * tracer of the task, otherwise lock_task_sighand is needed.
  887. */
  888. spin_lock_irq(&task->sighand->siglock);
  889. if (task->seccomp.mode != SECCOMP_MODE_FILTER) {
  890. spin_unlock_irq(&task->sighand->siglock);
  891. return ERR_PTR(-EINVAL);
  892. }
  893. orig = task->seccomp.filter;
  894. __get_seccomp_filter(orig);
  895. spin_unlock_irq(&task->sighand->siglock);
  896. count = 0;
  897. for (filter = orig; filter; filter = filter->prev)
  898. count++;
  899. if (filter_off >= count) {
  900. filter = ERR_PTR(-ENOENT);
  901. goto out;
  902. }
  903. count -= filter_off;
  904. for (filter = orig; filter && count > 1; filter = filter->prev)
  905. count--;
  906. if (WARN_ON(count != 1 || !filter)) {
  907. filter = ERR_PTR(-ENOENT);
  908. goto out;
  909. }
  910. __get_seccomp_filter(filter);
  911. out:
  912. __put_seccomp_filter(orig);
  913. return filter;
  914. }
  915. long seccomp_get_filter(struct task_struct *task, unsigned long filter_off,
  916. void __user *data)
  917. {
  918. struct seccomp_filter *filter;
  919. struct sock_fprog_kern *fprog;
  920. long ret;
  921. if (!capable(CAP_SYS_ADMIN) ||
  922. current->seccomp.mode != SECCOMP_MODE_DISABLED) {
  923. return -EACCES;
  924. }
  925. filter = get_nth_filter(task, filter_off);
  926. if (IS_ERR(filter))
  927. return PTR_ERR(filter);
  928. fprog = filter->prog->orig_prog;
  929. if (!fprog) {
  930. /* This must be a new non-cBPF filter, since we save
  931. * every cBPF filter's orig_prog above when
  932. * CONFIG_CHECKPOINT_RESTORE is enabled.
  933. */
  934. ret = -EMEDIUMTYPE;
  935. goto out;
  936. }
  937. ret = fprog->len;
  938. if (!data)
  939. goto out;
  940. if (copy_to_user(data, fprog->filter, bpf_classic_proglen(fprog)))
  941. ret = -EFAULT;
  942. out:
  943. __put_seccomp_filter(filter);
  944. return ret;
  945. }
  946. long seccomp_get_metadata(struct task_struct *task,
  947. unsigned long size, void __user *data)
  948. {
  949. long ret;
  950. struct seccomp_filter *filter;
  951. struct seccomp_metadata kmd = {};
  952. if (!capable(CAP_SYS_ADMIN) ||
  953. current->seccomp.mode != SECCOMP_MODE_DISABLED) {
  954. return -EACCES;
  955. }
  956. size = min_t(unsigned long, size, sizeof(kmd));
  957. if (size < sizeof(kmd.filter_off))
  958. return -EINVAL;
  959. if (copy_from_user(&kmd.filter_off, data, sizeof(kmd.filter_off)))
  960. return -EFAULT;
  961. filter = get_nth_filter(task, kmd.filter_off);
  962. if (IS_ERR(filter))
  963. return PTR_ERR(filter);
  964. if (filter->log)
  965. kmd.flags |= SECCOMP_FILTER_FLAG_LOG;
  966. ret = size;
  967. if (copy_to_user(data, &kmd, size))
  968. ret = -EFAULT;
  969. __put_seccomp_filter(filter);
  970. return ret;
  971. }
  972. #endif
  973. #ifdef CONFIG_SYSCTL
  974. /* Human readable action names for friendly sysctl interaction */
  975. #define SECCOMP_RET_KILL_PROCESS_NAME "kill_process"
  976. #define SECCOMP_RET_KILL_THREAD_NAME "kill_thread"
  977. #define SECCOMP_RET_TRAP_NAME "trap"
  978. #define SECCOMP_RET_ERRNO_NAME "errno"
  979. #define SECCOMP_RET_TRACE_NAME "trace"
  980. #define SECCOMP_RET_LOG_NAME "log"
  981. #define SECCOMP_RET_ALLOW_NAME "allow"
  982. static const char seccomp_actions_avail[] =
  983. SECCOMP_RET_KILL_PROCESS_NAME " "
  984. SECCOMP_RET_KILL_THREAD_NAME " "
  985. SECCOMP_RET_TRAP_NAME " "
  986. SECCOMP_RET_ERRNO_NAME " "
  987. SECCOMP_RET_TRACE_NAME " "
  988. SECCOMP_RET_LOG_NAME " "
  989. SECCOMP_RET_ALLOW_NAME;
  990. struct seccomp_log_name {
  991. u32 log;
  992. const char *name;
  993. };
  994. static const struct seccomp_log_name seccomp_log_names[] = {
  995. { SECCOMP_LOG_KILL_PROCESS, SECCOMP_RET_KILL_PROCESS_NAME },
  996. { SECCOMP_LOG_KILL_THREAD, SECCOMP_RET_KILL_THREAD_NAME },
  997. { SECCOMP_LOG_TRAP, SECCOMP_RET_TRAP_NAME },
  998. { SECCOMP_LOG_ERRNO, SECCOMP_RET_ERRNO_NAME },
  999. { SECCOMP_LOG_TRACE, SECCOMP_RET_TRACE_NAME },
  1000. { SECCOMP_LOG_LOG, SECCOMP_RET_LOG_NAME },
  1001. { SECCOMP_LOG_ALLOW, SECCOMP_RET_ALLOW_NAME },
  1002. { }
  1003. };
  1004. static bool seccomp_names_from_actions_logged(char *names, size_t size,
  1005. u32 actions_logged)
  1006. {
  1007. const struct seccomp_log_name *cur;
  1008. bool append_space = false;
  1009. for (cur = seccomp_log_names; cur->name && size; cur++) {
  1010. ssize_t ret;
  1011. if (!(actions_logged & cur->log))
  1012. continue;
  1013. if (append_space) {
  1014. ret = strscpy(names, " ", size);
  1015. if (ret < 0)
  1016. return false;
  1017. names += ret;
  1018. size -= ret;
  1019. } else
  1020. append_space = true;
  1021. ret = strscpy(names, cur->name, size);
  1022. if (ret < 0)
  1023. return false;
  1024. names += ret;
  1025. size -= ret;
  1026. }
  1027. return true;
  1028. }
  1029. static bool seccomp_action_logged_from_name(u32 *action_logged,
  1030. const char *name)
  1031. {
  1032. const struct seccomp_log_name *cur;
  1033. for (cur = seccomp_log_names; cur->name; cur++) {
  1034. if (!strcmp(cur->name, name)) {
  1035. *action_logged = cur->log;
  1036. return true;
  1037. }
  1038. }
  1039. return false;
  1040. }
  1041. static bool seccomp_actions_logged_from_names(u32 *actions_logged, char *names)
  1042. {
  1043. char *name;
  1044. *actions_logged = 0;
  1045. while ((name = strsep(&names, " ")) && *name) {
  1046. u32 action_logged = 0;
  1047. if (!seccomp_action_logged_from_name(&action_logged, name))
  1048. return false;
  1049. *actions_logged |= action_logged;
  1050. }
  1051. return true;
  1052. }
  1053. static int seccomp_actions_logged_handler(struct ctl_table *ro_table, int write,
  1054. void __user *buffer, size_t *lenp,
  1055. loff_t *ppos)
  1056. {
  1057. char names[sizeof(seccomp_actions_avail)];
  1058. struct ctl_table table;
  1059. int ret;
  1060. if (write && !capable(CAP_SYS_ADMIN))
  1061. return -EPERM;
  1062. memset(names, 0, sizeof(names));
  1063. if (!write) {
  1064. if (!seccomp_names_from_actions_logged(names, sizeof(names),
  1065. seccomp_actions_logged))
  1066. return -EINVAL;
  1067. }
  1068. table = *ro_table;
  1069. table.data = names;
  1070. table.maxlen = sizeof(names);
  1071. ret = proc_dostring(&table, write, buffer, lenp, ppos);
  1072. if (ret)
  1073. return ret;
  1074. if (write) {
  1075. u32 actions_logged;
  1076. if (!seccomp_actions_logged_from_names(&actions_logged,
  1077. table.data))
  1078. return -EINVAL;
  1079. if (actions_logged & SECCOMP_LOG_ALLOW)
  1080. return -EINVAL;
  1081. seccomp_actions_logged = actions_logged;
  1082. }
  1083. return 0;
  1084. }
  1085. static struct ctl_path seccomp_sysctl_path[] = {
  1086. { .procname = "kernel", },
  1087. { .procname = "seccomp", },
  1088. { }
  1089. };
  1090. static struct ctl_table seccomp_sysctl_table[] = {
  1091. {
  1092. .procname = "actions_avail",
  1093. .data = (void *) &seccomp_actions_avail,
  1094. .maxlen = sizeof(seccomp_actions_avail),
  1095. .mode = 0444,
  1096. .proc_handler = proc_dostring,
  1097. },
  1098. {
  1099. .procname = "actions_logged",
  1100. .mode = 0644,
  1101. .proc_handler = seccomp_actions_logged_handler,
  1102. },
  1103. { }
  1104. };
  1105. static int __init seccomp_sysctl_init(void)
  1106. {
  1107. struct ctl_table_header *hdr;
  1108. hdr = register_sysctl_paths(seccomp_sysctl_path, seccomp_sysctl_table);
  1109. if (!hdr)
  1110. pr_warn("seccomp: sysctl registration failed\n");
  1111. else
  1112. kmemleak_not_leak(hdr);
  1113. return 0;
  1114. }
  1115. device_initcall(seccomp_sysctl_init)
  1116. #endif /* CONFIG_SYSCTL */