sandbox.c 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801
  1. /* Copyright (c) 2001 Matej Pfajfar.
  2. * Copyright (c) 2001-2004, Roger Dingledine.
  3. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  4. * Copyright (c) 2007-2018, The Tor Project, Inc. */
  5. /* See LICENSE for licensing information */
  6. /**
  7. * \file sandbox.c
  8. * \brief Code to enable sandboxing.
  9. **/
  10. #include "orconfig.h"
  11. #ifndef _LARGEFILE64_SOURCE
  12. /**
  13. * Temporarily required for O_LARGEFILE flag. Needs to be removed
  14. * with the libevent fix.
  15. */
  16. #define _LARGEFILE64_SOURCE
  17. #endif /* !defined(_LARGEFILE64_SOURCE) */
  18. /** Malloc mprotect limit in bytes.
  19. *
  20. * 28/06/2017: This value was increased from 16 MB to 20 MB after we introduced
  21. * LZMA support in Tor (0.3.1.1-alpha). We limit our LZMA coder to 16 MB, but
  22. * liblzma have a small overhead that we need to compensate for to avoid being
  23. * killed by the sandbox.
  24. */
  25. #define MALLOC_MP_LIM (20*1024*1024)
  26. #include <stdio.h>
  27. #include <string.h>
  28. #include <stdlib.h>
  29. #include <errno.h>
  30. #include "lib/sandbox/sandbox.h"
  31. #include "lib/container/map.h"
  32. #include "lib/err/torerr.h"
  33. #include "lib/log/log.h"
  34. #include "lib/cc/torint.h"
  35. #include "lib/malloc/malloc.h"
  36. #include "lib/string/scanf.h"
  37. #include "ext/tor_queue.h"
  38. #include "ext/ht.h"
  39. #include "ext/siphash.h"
  40. #define DEBUGGING_CLOSE
  41. #if defined(USE_LIBSECCOMP)
  42. #include <sys/mman.h>
  43. #include <sys/syscall.h>
  44. #include <sys/types.h>
  45. #include <sys/stat.h>
  46. #include <sys/epoll.h>
  47. #include <sys/prctl.h>
  48. #include <linux/futex.h>
  49. #include <sys/file.h>
  50. #include <stdarg.h>
  51. #include <seccomp.h>
  52. #include <signal.h>
  53. #include <unistd.h>
  54. #include <fcntl.h>
  55. #include <time.h>
  56. #include <poll.h>
  57. #ifdef HAVE_GNU_LIBC_VERSION_H
  58. #include <gnu/libc-version.h>
  59. #endif
  60. #ifdef HAVE_LINUX_NETFILTER_IPV4_H
  61. #include <linux/netfilter_ipv4.h>
  62. #endif
  63. #ifdef HAVE_LINUX_IF_H
  64. #include <linux/if.h>
  65. #endif
  66. #ifdef HAVE_LINUX_NETFILTER_IPV6_IP6_TABLES_H
  67. #include <linux/netfilter_ipv6/ip6_tables.h>
  68. #endif
  69. #if defined(HAVE_EXECINFO_H) && defined(HAVE_BACKTRACE) && \
  70. defined(HAVE_BACKTRACE_SYMBOLS_FD) && defined(HAVE_SIGACTION)
  71. #define USE_BACKTRACE
  72. #define EXPOSE_CLEAN_BACKTRACE
  73. #include "lib/err/backtrace.h"
  74. #endif /* defined(HAVE_EXECINFO_H) && defined(HAVE_BACKTRACE) && ... */
  75. #ifdef USE_BACKTRACE
  76. #include <execinfo.h>
  77. #endif
  78. /**
  79. * Linux 32 bit definitions
  80. */
  81. #if defined(__i386__)
  82. #define REG_SYSCALL REG_EAX
  83. #define M_SYSCALL gregs[REG_SYSCALL]
  84. /**
  85. * Linux 64 bit definitions
  86. */
  87. #elif defined(__x86_64__)
  88. #define REG_SYSCALL REG_RAX
  89. #define M_SYSCALL gregs[REG_SYSCALL]
  90. #elif defined(__arm__)
  91. #define M_SYSCALL arm_r7
  92. #elif defined(__aarch64__) && defined(__LP64__)
  93. #define REG_SYSCALL 8
  94. #define M_SYSCALL regs[REG_SYSCALL]
  95. #endif /* defined(__i386__) || ... */
  96. /**Determines if at least one sandbox is active.*/
  97. static int sandbox_active = 0;
  98. /** Holds the parameter list configuration for the sandbox.*/
  99. static sandbox_cfg_t *filter_dynamic = NULL;
  100. #undef SCMP_CMP
  101. #define SCMP_CMP(a,b,c) ((struct scmp_arg_cmp){(a),(b),(c),0})
  102. #define SCMP_CMP_STR(a,b,c) \
  103. ((struct scmp_arg_cmp) {(a),(b),(intptr_t)(void*)(c),0})
  104. #define SCMP_CMP4(a,b,c,d) ((struct scmp_arg_cmp){(a),(b),(c),(d)})
  105. /* We use a wrapper here because these masked comparisons seem to be pretty
  106. * verbose. Also, it's important to cast to scmp_datum_t before negating the
  107. * mask, since otherwise the negation might get applied to a 32 bit value, and
  108. * the high bits of the value might get masked out improperly. */
  109. #define SCMP_CMP_MASKED(a,b,c) \
  110. SCMP_CMP4((a), SCMP_CMP_MASKED_EQ, ~(scmp_datum_t)(b), (c))
  111. /** Variable used for storing all syscall numbers that will be allowed with the
  112. * stage 1 general Tor sandbox.
  113. */
  114. static int filter_nopar_gen[] = {
  115. SCMP_SYS(access),
  116. SCMP_SYS(brk),
  117. SCMP_SYS(clock_gettime),
  118. SCMP_SYS(close),
  119. SCMP_SYS(clone),
  120. SCMP_SYS(epoll_create),
  121. SCMP_SYS(epoll_wait),
  122. #ifdef __NR_epoll_pwait
  123. SCMP_SYS(epoll_pwait),
  124. #endif
  125. #ifdef HAVE_EVENTFD
  126. SCMP_SYS(eventfd2),
  127. #endif
  128. #ifdef HAVE_PIPE2
  129. SCMP_SYS(pipe2),
  130. #endif
  131. #ifdef HAVE_PIPE
  132. SCMP_SYS(pipe),
  133. #endif
  134. #ifdef __NR_fchmod
  135. SCMP_SYS(fchmod),
  136. #endif
  137. SCMP_SYS(fcntl),
  138. SCMP_SYS(fstat),
  139. #ifdef __NR_fstat64
  140. SCMP_SYS(fstat64),
  141. #endif
  142. SCMP_SYS(futex),
  143. SCMP_SYS(getdents),
  144. SCMP_SYS(getdents64),
  145. SCMP_SYS(getegid),
  146. #ifdef __NR_getegid32
  147. SCMP_SYS(getegid32),
  148. #endif
  149. SCMP_SYS(geteuid),
  150. #ifdef __NR_geteuid32
  151. SCMP_SYS(geteuid32),
  152. #endif
  153. SCMP_SYS(getgid),
  154. #ifdef __NR_getgid32
  155. SCMP_SYS(getgid32),
  156. #endif
  157. SCMP_SYS(getpid),
  158. #ifdef __NR_getrlimit
  159. SCMP_SYS(getrlimit),
  160. #endif
  161. SCMP_SYS(gettimeofday),
  162. SCMP_SYS(gettid),
  163. SCMP_SYS(getuid),
  164. #ifdef __NR_getuid32
  165. SCMP_SYS(getuid32),
  166. #endif
  167. SCMP_SYS(lseek),
  168. #ifdef __NR__llseek
  169. SCMP_SYS(_llseek),
  170. #endif
  171. SCMP_SYS(mkdir),
  172. SCMP_SYS(mlockall),
  173. #ifdef __NR_mmap
  174. /* XXXX restrict this in the same ways as mmap2 */
  175. SCMP_SYS(mmap),
  176. #endif
  177. SCMP_SYS(munmap),
  178. #ifdef __NR_nanosleep
  179. SCMP_SYS(nanosleep),
  180. #endif
  181. #ifdef __NR_prlimit
  182. SCMP_SYS(prlimit),
  183. #endif
  184. #ifdef __NR_prlimit64
  185. SCMP_SYS(prlimit64),
  186. #endif
  187. SCMP_SYS(read),
  188. SCMP_SYS(rt_sigreturn),
  189. SCMP_SYS(sched_getaffinity),
  190. #ifdef __NR_sched_yield
  191. SCMP_SYS(sched_yield),
  192. #endif
  193. SCMP_SYS(sendmsg),
  194. SCMP_SYS(set_robust_list),
  195. #ifdef __NR_setrlimit
  196. SCMP_SYS(setrlimit),
  197. #endif
  198. SCMP_SYS(shutdown),
  199. #ifdef __NR_sigaltstack
  200. SCMP_SYS(sigaltstack),
  201. #endif
  202. #ifdef __NR_sigreturn
  203. SCMP_SYS(sigreturn),
  204. #endif
  205. SCMP_SYS(stat),
  206. SCMP_SYS(uname),
  207. SCMP_SYS(wait4),
  208. SCMP_SYS(write),
  209. SCMP_SYS(writev),
  210. SCMP_SYS(exit_group),
  211. SCMP_SYS(exit),
  212. SCMP_SYS(madvise),
  213. #ifdef __NR_stat64
  214. // getaddrinfo uses this..
  215. SCMP_SYS(stat64),
  216. #endif
  217. #ifdef __NR_getrandom
  218. SCMP_SYS(getrandom),
  219. #endif
  220. #ifdef __NR_sysinfo
  221. // qsort uses this..
  222. SCMP_SYS(sysinfo),
  223. #endif
  224. /*
  225. * These socket syscalls are not required on x86_64 and not supported with
  226. * some libseccomp versions (eg: 1.0.1)
  227. */
  228. #if defined(__i386)
  229. SCMP_SYS(recv),
  230. SCMP_SYS(send),
  231. #endif
  232. // socket syscalls
  233. SCMP_SYS(bind),
  234. SCMP_SYS(listen),
  235. SCMP_SYS(connect),
  236. SCMP_SYS(getsockname),
  237. SCMP_SYS(recvmsg),
  238. SCMP_SYS(recvfrom),
  239. SCMP_SYS(sendto),
  240. SCMP_SYS(unlink),
  241. SCMP_SYS(poll)
  242. };
  243. /* These macros help avoid the error where the number of filters we add on a
  244. * single rule don't match the arg_cnt param. */
  245. #define seccomp_rule_add_0(ctx,act,call) \
  246. seccomp_rule_add((ctx),(act),(call),0)
  247. #define seccomp_rule_add_1(ctx,act,call,f1) \
  248. seccomp_rule_add((ctx),(act),(call),1,(f1))
  249. #define seccomp_rule_add_2(ctx,act,call,f1,f2) \
  250. seccomp_rule_add((ctx),(act),(call),2,(f1),(f2))
  251. #define seccomp_rule_add_3(ctx,act,call,f1,f2,f3) \
  252. seccomp_rule_add((ctx),(act),(call),3,(f1),(f2),(f3))
  253. #define seccomp_rule_add_4(ctx,act,call,f1,f2,f3,f4) \
  254. seccomp_rule_add((ctx),(act),(call),4,(f1),(f2),(f3),(f4))
  255. /**
  256. * Function responsible for setting up the rt_sigaction syscall for
  257. * the seccomp filter sandbox.
  258. */
  259. static int
  260. sb_rt_sigaction(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
  261. {
  262. unsigned i;
  263. int rc;
  264. int param[] = { SIGINT, SIGTERM, SIGPIPE, SIGUSR1, SIGUSR2, SIGHUP, SIGCHLD,
  265. #ifdef SIGXFSZ
  266. SIGXFSZ
  267. #endif
  268. };
  269. (void) filter;
  270. for (i = 0; i < ARRAY_LENGTH(param); i++) {
  271. rc = seccomp_rule_add_1(ctx, SCMP_ACT_ALLOW, SCMP_SYS(rt_sigaction),
  272. SCMP_CMP(0, SCMP_CMP_EQ, param[i]));
  273. if (rc)
  274. break;
  275. }
  276. return rc;
  277. }
  278. /**
  279. * Function responsible for setting up the time syscall for
  280. * the seccomp filter sandbox.
  281. */
  282. static int
  283. sb_time(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
  284. {
  285. (void) filter;
  286. #ifdef __NR_time
  287. return seccomp_rule_add_1(ctx, SCMP_ACT_ALLOW, SCMP_SYS(time),
  288. SCMP_CMP(0, SCMP_CMP_EQ, 0));
  289. #else
  290. return 0;
  291. #endif /* defined(__NR_time) */
  292. }
  293. /**
  294. * Function responsible for setting up the accept4 syscall for
  295. * the seccomp filter sandbox.
  296. */
  297. static int
  298. sb_accept4(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
  299. {
  300. int rc = 0;
  301. (void)filter;
  302. #ifdef __i386__
  303. rc = seccomp_rule_add_1(ctx, SCMP_ACT_ALLOW, SCMP_SYS(socketcall),
  304. SCMP_CMP(0, SCMP_CMP_EQ, 18));
  305. if (rc) {
  306. return rc;
  307. }
  308. #endif /* defined(__i386__) */
  309. rc = seccomp_rule_add_1(ctx, SCMP_ACT_ALLOW, SCMP_SYS(accept4),
  310. SCMP_CMP_MASKED(3, SOCK_CLOEXEC|SOCK_NONBLOCK, 0));
  311. if (rc) {
  312. return rc;
  313. }
  314. return 0;
  315. }
  316. #ifdef __NR_mmap2
  317. /**
  318. * Function responsible for setting up the mmap2 syscall for
  319. * the seccomp filter sandbox.
  320. */
  321. static int
  322. sb_mmap2(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
  323. {
  324. int rc = 0;
  325. (void)filter;
  326. rc = seccomp_rule_add_2(ctx, SCMP_ACT_ALLOW, SCMP_SYS(mmap2),
  327. SCMP_CMP(2, SCMP_CMP_EQ, PROT_READ),
  328. SCMP_CMP(3, SCMP_CMP_EQ, MAP_PRIVATE));
  329. if (rc) {
  330. return rc;
  331. }
  332. rc = seccomp_rule_add_2(ctx, SCMP_ACT_ALLOW, SCMP_SYS(mmap2),
  333. SCMP_CMP(2, SCMP_CMP_EQ, PROT_NONE),
  334. SCMP_CMP(3, SCMP_CMP_EQ, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE));
  335. if (rc) {
  336. return rc;
  337. }
  338. rc = seccomp_rule_add_2(ctx, SCMP_ACT_ALLOW, SCMP_SYS(mmap2),
  339. SCMP_CMP(2, SCMP_CMP_EQ, PROT_READ|PROT_WRITE),
  340. SCMP_CMP(3, SCMP_CMP_EQ, MAP_PRIVATE|MAP_ANONYMOUS));
  341. if (rc) {
  342. return rc;
  343. }
  344. rc = seccomp_rule_add_2(ctx, SCMP_ACT_ALLOW, SCMP_SYS(mmap2),
  345. SCMP_CMP(2, SCMP_CMP_EQ, PROT_READ|PROT_WRITE),
  346. SCMP_CMP(3, SCMP_CMP_EQ,MAP_PRIVATE|MAP_ANONYMOUS|MAP_STACK));
  347. if (rc) {
  348. return rc;
  349. }
  350. rc = seccomp_rule_add_2(ctx, SCMP_ACT_ALLOW, SCMP_SYS(mmap2),
  351. SCMP_CMP(2, SCMP_CMP_EQ, PROT_READ|PROT_WRITE),
  352. SCMP_CMP(3, SCMP_CMP_EQ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE));
  353. if (rc) {
  354. return rc;
  355. }
  356. rc = seccomp_rule_add_2(ctx, SCMP_ACT_ALLOW, SCMP_SYS(mmap2),
  357. SCMP_CMP(2, SCMP_CMP_EQ, PROT_READ|PROT_WRITE),
  358. SCMP_CMP(3, SCMP_CMP_EQ, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS));
  359. if (rc) {
  360. return rc;
  361. }
  362. rc = seccomp_rule_add_2(ctx, SCMP_ACT_ALLOW, SCMP_SYS(mmap2),
  363. SCMP_CMP(2, SCMP_CMP_EQ, PROT_READ|PROT_EXEC),
  364. SCMP_CMP(3, SCMP_CMP_EQ, MAP_PRIVATE|MAP_DENYWRITE));
  365. if (rc) {
  366. return rc;
  367. }
  368. return 0;
  369. }
  370. #endif /* defined(__NR_mmap2) */
  371. #ifdef HAVE_GNU_LIBC_VERSION_H
  372. #ifdef HAVE_GNU_GET_LIBC_VERSION
  373. #define CHECK_LIBC_VERSION
  374. #endif
  375. #endif
  376. /* Return true if we think we're running with a libc that always uses
  377. * openat on linux. */
  378. static int
  379. libc_uses_openat_for_everything(void)
  380. {
  381. #ifdef CHECK_LIBC_VERSION
  382. const char *version = gnu_get_libc_version();
  383. if (version == NULL)
  384. return 0;
  385. int major = -1;
  386. int minor = -1;
  387. tor_sscanf(version, "%d.%d", &major, &minor);
  388. if (major >= 3)
  389. return 1;
  390. else if (major == 2 && minor >= 26)
  391. return 1;
  392. else
  393. return 0;
  394. #else /* !(defined(CHECK_LIBC_VERSION)) */
  395. return 0;
  396. #endif /* defined(CHECK_LIBC_VERSION) */
  397. }
  398. /** Allow a single file to be opened. If <b>use_openat</b> is true,
  399. * we're using a libc that remaps all the opens into openats. */
  400. static int
  401. allow_file_open(scmp_filter_ctx ctx, int use_openat, const char *file)
  402. {
  403. if (use_openat) {
  404. return seccomp_rule_add_2(ctx, SCMP_ACT_ALLOW, SCMP_SYS(openat),
  405. SCMP_CMP(0, SCMP_CMP_EQ, (unsigned int)AT_FDCWD),
  406. SCMP_CMP_STR(1, SCMP_CMP_EQ, file));
  407. } else {
  408. return seccomp_rule_add_1(ctx, SCMP_ACT_ALLOW, SCMP_SYS(open),
  409. SCMP_CMP_STR(0, SCMP_CMP_EQ, file));
  410. }
  411. }
  412. /**
  413. * Function responsible for setting up the open syscall for
  414. * the seccomp filter sandbox.
  415. */
  416. static int
  417. sb_open(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
  418. {
  419. int rc;
  420. sandbox_cfg_t *elem = NULL;
  421. int use_openat = libc_uses_openat_for_everything();
  422. // for each dynamic parameter filters
  423. for (elem = filter; elem != NULL; elem = elem->next) {
  424. smp_param_t *param = elem->param;
  425. if (param != NULL && param->prot == 1 && param->syscall
  426. == SCMP_SYS(open)) {
  427. rc = allow_file_open(ctx, use_openat, param->value);
  428. if (rc != 0) {
  429. log_err(LD_BUG,"(Sandbox) failed to add open syscall, received "
  430. "libseccomp error %d", rc);
  431. return rc;
  432. }
  433. }
  434. }
  435. rc = seccomp_rule_add_1(ctx, SCMP_ACT_ERRNO(EACCES), SCMP_SYS(open),
  436. SCMP_CMP_MASKED(1, O_CLOEXEC|O_NONBLOCK|O_NOCTTY|O_NOFOLLOW,
  437. O_RDONLY));
  438. if (rc != 0) {
  439. log_err(LD_BUG,"(Sandbox) failed to add open syscall, received libseccomp "
  440. "error %d", rc);
  441. return rc;
  442. }
  443. rc = seccomp_rule_add_1(ctx, SCMP_ACT_ERRNO(EACCES), SCMP_SYS(openat),
  444. SCMP_CMP_MASKED(2, O_CLOEXEC|O_NONBLOCK|O_NOCTTY|O_NOFOLLOW,
  445. O_RDONLY));
  446. if (rc != 0) {
  447. log_err(LD_BUG,"(Sandbox) failed to add openat syscall, received "
  448. "libseccomp error %d", rc);
  449. return rc;
  450. }
  451. return 0;
  452. }
  453. static int
  454. sb_chmod(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
  455. {
  456. int rc;
  457. sandbox_cfg_t *elem = NULL;
  458. // for each dynamic parameter filters
  459. for (elem = filter; elem != NULL; elem = elem->next) {
  460. smp_param_t *param = elem->param;
  461. if (param != NULL && param->prot == 1 && param->syscall
  462. == SCMP_SYS(chmod)) {
  463. rc = seccomp_rule_add_1(ctx, SCMP_ACT_ALLOW, SCMP_SYS(chmod),
  464. SCMP_CMP_STR(0, SCMP_CMP_EQ, param->value));
  465. if (rc != 0) {
  466. log_err(LD_BUG,"(Sandbox) failed to add chmod syscall, received "
  467. "libseccomp error %d", rc);
  468. return rc;
  469. }
  470. }
  471. }
  472. return 0;
  473. }
  474. static int
  475. sb_chown(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
  476. {
  477. int rc;
  478. sandbox_cfg_t *elem = NULL;
  479. // for each dynamic parameter filters
  480. for (elem = filter; elem != NULL; elem = elem->next) {
  481. smp_param_t *param = elem->param;
  482. if (param != NULL && param->prot == 1 && param->syscall
  483. == SCMP_SYS(chown)) {
  484. rc = seccomp_rule_add_1(ctx, SCMP_ACT_ALLOW, SCMP_SYS(chown),
  485. SCMP_CMP_STR(0, SCMP_CMP_EQ, param->value));
  486. if (rc != 0) {
  487. log_err(LD_BUG,"(Sandbox) failed to add chown syscall, received "
  488. "libseccomp error %d", rc);
  489. return rc;
  490. }
  491. }
  492. }
  493. return 0;
  494. }
  495. static int
  496. sb__sysctl(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
  497. {
  498. int rc;
  499. (void) filter;
  500. (void) ctx;
  501. rc = seccomp_rule_add_0(ctx, SCMP_ACT_ERRNO(EPERM), SCMP_SYS(_sysctl));
  502. if (rc != 0) {
  503. log_err(LD_BUG,"(Sandbox) failed to add _sysctl syscall, "
  504. "received libseccomp error %d", rc);
  505. return rc;
  506. }
  507. return 0;
  508. }
  509. /**
  510. * Function responsible for setting up the rename syscall for
  511. * the seccomp filter sandbox.
  512. */
  513. static int
  514. sb_rename(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
  515. {
  516. int rc;
  517. sandbox_cfg_t *elem = NULL;
  518. // for each dynamic parameter filters
  519. for (elem = filter; elem != NULL; elem = elem->next) {
  520. smp_param_t *param = elem->param;
  521. if (param != NULL && param->prot == 1 &&
  522. param->syscall == SCMP_SYS(rename)) {
  523. rc = seccomp_rule_add_2(ctx, SCMP_ACT_ALLOW, SCMP_SYS(rename),
  524. SCMP_CMP_STR(0, SCMP_CMP_EQ, param->value),
  525. SCMP_CMP_STR(1, SCMP_CMP_EQ, param->value2));
  526. if (rc != 0) {
  527. log_err(LD_BUG,"(Sandbox) failed to add rename syscall, received "
  528. "libseccomp error %d", rc);
  529. return rc;
  530. }
  531. }
  532. }
  533. return 0;
  534. }
  535. /**
  536. * Function responsible for setting up the openat syscall for
  537. * the seccomp filter sandbox.
  538. */
  539. static int
  540. sb_openat(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
  541. {
  542. int rc;
  543. sandbox_cfg_t *elem = NULL;
  544. // for each dynamic parameter filters
  545. for (elem = filter; elem != NULL; elem = elem->next) {
  546. smp_param_t *param = elem->param;
  547. if (param != NULL && param->prot == 1 && param->syscall
  548. == SCMP_SYS(openat)) {
  549. rc = seccomp_rule_add_3(ctx, SCMP_ACT_ALLOW, SCMP_SYS(openat),
  550. SCMP_CMP(0, SCMP_CMP_EQ, AT_FDCWD),
  551. SCMP_CMP_STR(1, SCMP_CMP_EQ, param->value),
  552. SCMP_CMP(2, SCMP_CMP_EQ, O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|
  553. O_CLOEXEC));
  554. if (rc != 0) {
  555. log_err(LD_BUG,"(Sandbox) failed to add openat syscall, received "
  556. "libseccomp error %d", rc);
  557. return rc;
  558. }
  559. }
  560. }
  561. return 0;
  562. }
  563. /**
  564. * Function responsible for setting up the socket syscall for
  565. * the seccomp filter sandbox.
  566. */
  567. static int
  568. sb_socket(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
  569. {
  570. int rc = 0;
  571. int i, j;
  572. (void) filter;
  573. #ifdef __i386__
  574. rc = seccomp_rule_add_0(ctx, SCMP_ACT_ALLOW, SCMP_SYS(socket));
  575. if (rc)
  576. return rc;
  577. #endif
  578. rc = seccomp_rule_add_2(ctx, SCMP_ACT_ALLOW, SCMP_SYS(socket),
  579. SCMP_CMP(0, SCMP_CMP_EQ, PF_FILE),
  580. SCMP_CMP_MASKED(1, SOCK_CLOEXEC|SOCK_NONBLOCK, SOCK_STREAM));
  581. if (rc)
  582. return rc;
  583. for (i = 0; i < 2; ++i) {
  584. const int pf = i ? PF_INET : PF_INET6;
  585. for (j=0; j < 3; ++j) {
  586. const int type = (j == 0) ? SOCK_STREAM :
  587. SOCK_DGRAM;
  588. const int protocol = (j == 0) ? IPPROTO_TCP :
  589. (j == 1) ? IPPROTO_IP :
  590. IPPROTO_UDP;
  591. rc = seccomp_rule_add_3(ctx, SCMP_ACT_ALLOW, SCMP_SYS(socket),
  592. SCMP_CMP(0, SCMP_CMP_EQ, pf),
  593. SCMP_CMP_MASKED(1, SOCK_CLOEXEC|SOCK_NONBLOCK, type),
  594. SCMP_CMP(2, SCMP_CMP_EQ, protocol));
  595. if (rc)
  596. return rc;
  597. }
  598. }
  599. rc = seccomp_rule_add_3(ctx, SCMP_ACT_ALLOW, SCMP_SYS(socket),
  600. SCMP_CMP(0, SCMP_CMP_EQ, PF_UNIX),
  601. SCMP_CMP_MASKED(1, SOCK_CLOEXEC|SOCK_NONBLOCK, SOCK_STREAM),
  602. SCMP_CMP(2, SCMP_CMP_EQ, 0));
  603. if (rc)
  604. return rc;
  605. rc = seccomp_rule_add_3(ctx, SCMP_ACT_ALLOW, SCMP_SYS(socket),
  606. SCMP_CMP(0, SCMP_CMP_EQ, PF_UNIX),
  607. SCMP_CMP_MASKED(1, SOCK_CLOEXEC|SOCK_NONBLOCK, SOCK_DGRAM),
  608. SCMP_CMP(2, SCMP_CMP_EQ, 0));
  609. if (rc)
  610. return rc;
  611. rc = seccomp_rule_add_3(ctx, SCMP_ACT_ALLOW, SCMP_SYS(socket),
  612. SCMP_CMP(0, SCMP_CMP_EQ, PF_NETLINK),
  613. SCMP_CMP_MASKED(1, SOCK_CLOEXEC, SOCK_RAW),
  614. SCMP_CMP(2, SCMP_CMP_EQ, 0));
  615. if (rc)
  616. return rc;
  617. return 0;
  618. }
  619. /**
  620. * Function responsible for setting up the socketpair syscall for
  621. * the seccomp filter sandbox.
  622. */
  623. static int
  624. sb_socketpair(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
  625. {
  626. int rc = 0;
  627. (void) filter;
  628. #ifdef __i386__
  629. rc = seccomp_rule_add_0(ctx, SCMP_ACT_ALLOW, SCMP_SYS(socketpair));
  630. if (rc)
  631. return rc;
  632. #endif
  633. rc = seccomp_rule_add_2(ctx, SCMP_ACT_ALLOW, SCMP_SYS(socketpair),
  634. SCMP_CMP(0, SCMP_CMP_EQ, PF_FILE),
  635. SCMP_CMP(1, SCMP_CMP_EQ, SOCK_STREAM|SOCK_CLOEXEC));
  636. if (rc)
  637. return rc;
  638. return 0;
  639. }
  640. #ifdef HAVE_KIST_SUPPORT
  641. #include <linux/sockios.h>
  642. static int
  643. sb_ioctl(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
  644. {
  645. int rc;
  646. (void) filter;
  647. rc = seccomp_rule_add_1(ctx, SCMP_ACT_ALLOW, SCMP_SYS(ioctl),
  648. SCMP_CMP(1, SCMP_CMP_EQ, SIOCOUTQNSD));
  649. if (rc)
  650. return rc;
  651. return 0;
  652. }
  653. #endif /* defined(HAVE_KIST_SUPPORT) */
  654. /**
  655. * Function responsible for setting up the setsockopt syscall for
  656. * the seccomp filter sandbox.
  657. */
  658. static int
  659. sb_setsockopt(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
  660. {
  661. int rc = 0;
  662. (void) filter;
  663. #ifdef __i386__
  664. rc = seccomp_rule_add_0(ctx, SCMP_ACT_ALLOW, SCMP_SYS(setsockopt));
  665. if (rc)
  666. return rc;
  667. #endif
  668. rc = seccomp_rule_add_2(ctx, SCMP_ACT_ALLOW, SCMP_SYS(setsockopt),
  669. SCMP_CMP(1, SCMP_CMP_EQ, SOL_SOCKET),
  670. SCMP_CMP(2, SCMP_CMP_EQ, SO_REUSEADDR));
  671. if (rc)
  672. return rc;
  673. rc = seccomp_rule_add_2(ctx, SCMP_ACT_ALLOW, SCMP_SYS(setsockopt),
  674. SCMP_CMP(1, SCMP_CMP_EQ, SOL_SOCKET),
  675. SCMP_CMP(2, SCMP_CMP_EQ, SO_SNDBUF));
  676. if (rc)
  677. return rc;
  678. rc = seccomp_rule_add_2(ctx, SCMP_ACT_ALLOW, SCMP_SYS(setsockopt),
  679. SCMP_CMP(1, SCMP_CMP_EQ, SOL_SOCKET),
  680. SCMP_CMP(2, SCMP_CMP_EQ, SO_RCVBUF));
  681. if (rc)
  682. return rc;
  683. #ifdef HAVE_SYSTEMD
  684. rc = seccomp_rule_add_2(ctx, SCMP_ACT_ALLOW, SCMP_SYS(setsockopt),
  685. SCMP_CMP(1, SCMP_CMP_EQ, SOL_SOCKET),
  686. SCMP_CMP(2, SCMP_CMP_EQ, SO_SNDBUFFORCE));
  687. if (rc)
  688. return rc;
  689. #endif /* defined(HAVE_SYSTEMD) */
  690. #ifdef IP_TRANSPARENT
  691. rc = seccomp_rule_add_2(ctx, SCMP_ACT_ALLOW, SCMP_SYS(setsockopt),
  692. SCMP_CMP(1, SCMP_CMP_EQ, SOL_IP),
  693. SCMP_CMP(2, SCMP_CMP_EQ, IP_TRANSPARENT));
  694. if (rc)
  695. return rc;
  696. #endif /* defined(IP_TRANSPARENT) */
  697. #ifdef IPV6_V6ONLY
  698. rc = seccomp_rule_add_2(ctx, SCMP_ACT_ALLOW, SCMP_SYS(setsockopt),
  699. SCMP_CMP(1, SCMP_CMP_EQ, IPPROTO_IPV6),
  700. SCMP_CMP(2, SCMP_CMP_EQ, IPV6_V6ONLY));
  701. if (rc)
  702. return rc;
  703. #endif /* defined(IPV6_V6ONLY) */
  704. return 0;
  705. }
  706. /**
  707. * Function responsible for setting up the getsockopt syscall for
  708. * the seccomp filter sandbox.
  709. */
  710. static int
  711. sb_getsockopt(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
  712. {
  713. int rc = 0;
  714. (void) filter;
  715. #ifdef __i386__
  716. rc = seccomp_rule_add_0(ctx, SCMP_ACT_ALLOW, SCMP_SYS(getsockopt));
  717. if (rc)
  718. return rc;
  719. #endif
  720. rc = seccomp_rule_add_2(ctx, SCMP_ACT_ALLOW, SCMP_SYS(getsockopt),
  721. SCMP_CMP(1, SCMP_CMP_EQ, SOL_SOCKET),
  722. SCMP_CMP(2, SCMP_CMP_EQ, SO_ERROR));
  723. if (rc)
  724. return rc;
  725. #ifdef HAVE_SYSTEMD
  726. rc = seccomp_rule_add_2(ctx, SCMP_ACT_ALLOW, SCMP_SYS(getsockopt),
  727. SCMP_CMP(1, SCMP_CMP_EQ, SOL_SOCKET),
  728. SCMP_CMP(2, SCMP_CMP_EQ, SO_SNDBUF));
  729. if (rc)
  730. return rc;
  731. #endif /* defined(HAVE_SYSTEMD) */
  732. #ifdef HAVE_LINUX_NETFILTER_IPV4_H
  733. rc = seccomp_rule_add_2(ctx, SCMP_ACT_ALLOW, SCMP_SYS(getsockopt),
  734. SCMP_CMP(1, SCMP_CMP_EQ, SOL_IP),
  735. SCMP_CMP(2, SCMP_CMP_EQ, SO_ORIGINAL_DST));
  736. if (rc)
  737. return rc;
  738. #endif /* defined(HAVE_LINUX_NETFILTER_IPV4_H) */
  739. #ifdef HAVE_LINUX_NETFILTER_IPV6_IP6_TABLES_H
  740. rc = seccomp_rule_add_2(ctx, SCMP_ACT_ALLOW, SCMP_SYS(getsockopt),
  741. SCMP_CMP(1, SCMP_CMP_EQ, SOL_IPV6),
  742. SCMP_CMP(2, SCMP_CMP_EQ, IP6T_SO_ORIGINAL_DST));
  743. if (rc)
  744. return rc;
  745. #endif /* defined(HAVE_LINUX_NETFILTER_IPV6_IP6_TABLES_H) */
  746. #ifdef HAVE_KIST_SUPPORT
  747. #include <netinet/tcp.h>
  748. rc = seccomp_rule_add_2(ctx, SCMP_ACT_ALLOW, SCMP_SYS(getsockopt),
  749. SCMP_CMP(1, SCMP_CMP_EQ, SOL_TCP),
  750. SCMP_CMP(2, SCMP_CMP_EQ, TCP_INFO));
  751. if (rc)
  752. return rc;
  753. #endif /* defined(HAVE_KIST_SUPPORT) */
  754. return 0;
  755. }
  756. #ifdef __NR_fcntl64
  757. /**
  758. * Function responsible for setting up the fcntl64 syscall for
  759. * the seccomp filter sandbox.
  760. */
  761. static int
  762. sb_fcntl64(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
  763. {
  764. int rc = 0;
  765. (void) filter;
  766. rc = seccomp_rule_add_1(ctx, SCMP_ACT_ALLOW, SCMP_SYS(fcntl64),
  767. SCMP_CMP(1, SCMP_CMP_EQ, F_GETFL));
  768. if (rc)
  769. return rc;
  770. rc = seccomp_rule_add_2(ctx, SCMP_ACT_ALLOW, SCMP_SYS(fcntl64),
  771. SCMP_CMP(1, SCMP_CMP_EQ, F_SETFL),
  772. SCMP_CMP(2, SCMP_CMP_EQ, O_RDWR|O_NONBLOCK));
  773. if (rc)
  774. return rc;
  775. rc = seccomp_rule_add_1(ctx, SCMP_ACT_ALLOW, SCMP_SYS(fcntl64),
  776. SCMP_CMP(1, SCMP_CMP_EQ, F_GETFD));
  777. if (rc)
  778. return rc;
  779. rc = seccomp_rule_add_2(ctx, SCMP_ACT_ALLOW, SCMP_SYS(fcntl64),
  780. SCMP_CMP(1, SCMP_CMP_EQ, F_SETFD),
  781. SCMP_CMP(2, SCMP_CMP_EQ, FD_CLOEXEC));
  782. if (rc)
  783. return rc;
  784. return 0;
  785. }
  786. #endif /* defined(__NR_fcntl64) */
  787. /**
  788. * Function responsible for setting up the epoll_ctl syscall for
  789. * the seccomp filter sandbox.
  790. *
  791. * Note: basically allows everything but will keep for now..
  792. */
  793. static int
  794. sb_epoll_ctl(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
  795. {
  796. int rc = 0;
  797. (void) filter;
  798. rc = seccomp_rule_add_1(ctx, SCMP_ACT_ALLOW, SCMP_SYS(epoll_ctl),
  799. SCMP_CMP(1, SCMP_CMP_EQ, EPOLL_CTL_ADD));
  800. if (rc)
  801. return rc;
  802. rc = seccomp_rule_add_1(ctx, SCMP_ACT_ALLOW, SCMP_SYS(epoll_ctl),
  803. SCMP_CMP(1, SCMP_CMP_EQ, EPOLL_CTL_MOD));
  804. if (rc)
  805. return rc;
  806. rc = seccomp_rule_add_1(ctx, SCMP_ACT_ALLOW, SCMP_SYS(epoll_ctl),
  807. SCMP_CMP(1, SCMP_CMP_EQ, EPOLL_CTL_DEL));
  808. if (rc)
  809. return rc;
  810. return 0;
  811. }
  812. /**
  813. * Function responsible for setting up the prctl syscall for
  814. * the seccomp filter sandbox.
  815. *
  816. * NOTE: if multiple filters need to be added, the PR_SECCOMP parameter needs
  817. * to be whitelisted in this function.
  818. */
  819. static int
  820. sb_prctl(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
  821. {
  822. int rc = 0;
  823. (void) filter;
  824. rc = seccomp_rule_add_1(ctx, SCMP_ACT_ALLOW, SCMP_SYS(prctl),
  825. SCMP_CMP(0, SCMP_CMP_EQ, PR_SET_DUMPABLE));
  826. if (rc)
  827. return rc;
  828. return 0;
  829. }
  830. /**
  831. * Function responsible for setting up the mprotect syscall for
  832. * the seccomp filter sandbox.
  833. *
  834. * NOTE: does not NEED to be here.. currently only occurs before filter; will
  835. * keep just in case for the future.
  836. */
  837. static int
  838. sb_mprotect(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
  839. {
  840. int rc = 0;
  841. (void) filter;
  842. rc = seccomp_rule_add_1(ctx, SCMP_ACT_ALLOW, SCMP_SYS(mprotect),
  843. SCMP_CMP(2, SCMP_CMP_EQ, PROT_READ));
  844. if (rc)
  845. return rc;
  846. rc = seccomp_rule_add_1(ctx, SCMP_ACT_ALLOW, SCMP_SYS(mprotect),
  847. SCMP_CMP(2, SCMP_CMP_EQ, PROT_NONE));
  848. if (rc)
  849. return rc;
  850. return 0;
  851. }
  852. /**
  853. * Function responsible for setting up the rt_sigprocmask syscall for
  854. * the seccomp filter sandbox.
  855. */
  856. static int
  857. sb_rt_sigprocmask(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
  858. {
  859. int rc = 0;
  860. (void) filter;
  861. rc = seccomp_rule_add_1(ctx, SCMP_ACT_ALLOW, SCMP_SYS(rt_sigprocmask),
  862. SCMP_CMP(0, SCMP_CMP_EQ, SIG_UNBLOCK));
  863. if (rc)
  864. return rc;
  865. rc = seccomp_rule_add_1(ctx, SCMP_ACT_ALLOW, SCMP_SYS(rt_sigprocmask),
  866. SCMP_CMP(0, SCMP_CMP_EQ, SIG_SETMASK));
  867. if (rc)
  868. return rc;
  869. return 0;
  870. }
  871. /**
  872. * Function responsible for setting up the flock syscall for
  873. * the seccomp filter sandbox.
  874. *
  875. * NOTE: does not need to be here, occurs before filter is applied.
  876. */
  877. static int
  878. sb_flock(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
  879. {
  880. int rc = 0;
  881. (void) filter;
  882. rc = seccomp_rule_add_1(ctx, SCMP_ACT_ALLOW, SCMP_SYS(flock),
  883. SCMP_CMP(1, SCMP_CMP_EQ, LOCK_EX|LOCK_NB));
  884. if (rc)
  885. return rc;
  886. rc = seccomp_rule_add_1(ctx, SCMP_ACT_ALLOW, SCMP_SYS(flock),
  887. SCMP_CMP(1, SCMP_CMP_EQ, LOCK_UN));
  888. if (rc)
  889. return rc;
  890. return 0;
  891. }
  892. /**
  893. * Function responsible for setting up the futex syscall for
  894. * the seccomp filter sandbox.
  895. */
  896. static int
  897. sb_futex(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
  898. {
  899. int rc = 0;
  900. (void) filter;
  901. // can remove
  902. rc = seccomp_rule_add_1(ctx, SCMP_ACT_ALLOW, SCMP_SYS(futex),
  903. SCMP_CMP(1, SCMP_CMP_EQ,
  904. FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME));
  905. if (rc)
  906. return rc;
  907. rc = seccomp_rule_add_1(ctx, SCMP_ACT_ALLOW, SCMP_SYS(futex),
  908. SCMP_CMP(1, SCMP_CMP_EQ, FUTEX_WAKE_PRIVATE));
  909. if (rc)
  910. return rc;
  911. rc = seccomp_rule_add_1(ctx, SCMP_ACT_ALLOW, SCMP_SYS(futex),
  912. SCMP_CMP(1, SCMP_CMP_EQ, FUTEX_WAIT_PRIVATE));
  913. if (rc)
  914. return rc;
  915. return 0;
  916. }
  917. /**
  918. * Function responsible for setting up the mremap syscall for
  919. * the seccomp filter sandbox.
  920. *
  921. * NOTE: so far only occurs before filter is applied.
  922. */
  923. static int
  924. sb_mremap(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
  925. {
  926. int rc = 0;
  927. (void) filter;
  928. rc = seccomp_rule_add_1(ctx, SCMP_ACT_ALLOW, SCMP_SYS(mremap),
  929. SCMP_CMP(3, SCMP_CMP_EQ, MREMAP_MAYMOVE));
  930. if (rc)
  931. return rc;
  932. return 0;
  933. }
  934. #ifdef __NR_stat64
  935. /**
  936. * Function responsible for setting up the stat64 syscall for
  937. * the seccomp filter sandbox.
  938. */
  939. static int
  940. sb_stat64(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
  941. {
  942. int rc = 0;
  943. sandbox_cfg_t *elem = NULL;
  944. // for each dynamic parameter filters
  945. for (elem = filter; elem != NULL; elem = elem->next) {
  946. smp_param_t *param = elem->param;
  947. if (param != NULL && param->prot == 1 && (param->syscall == SCMP_SYS(open)
  948. || param->syscall == SCMP_SYS(stat64))) {
  949. rc = seccomp_rule_add_1(ctx, SCMP_ACT_ALLOW, SCMP_SYS(stat64),
  950. SCMP_CMP_STR(0, SCMP_CMP_EQ, param->value));
  951. if (rc != 0) {
  952. log_err(LD_BUG,"(Sandbox) failed to add stat64 syscall, received "
  953. "libseccomp error %d", rc);
  954. return rc;
  955. }
  956. }
  957. }
  958. return 0;
  959. }
  960. #endif /* defined(__NR_stat64) */
  961. static int
  962. sb_kill(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
  963. {
  964. (void) filter;
  965. #ifdef __NR_kill
  966. /* Allow killing anything with signal 0 -- it isn't really a kill. */
  967. return seccomp_rule_add_1(ctx, SCMP_ACT_ALLOW, SCMP_SYS(kill),
  968. SCMP_CMP(1, SCMP_CMP_EQ, 0));
  969. #else
  970. return 0;
  971. #endif /* defined(__NR_kill) */
  972. }
  973. /**
  974. * Array of function pointers responsible for filtering different syscalls at
  975. * a parameter level.
  976. */
  977. static sandbox_filter_func_t filter_func[] = {
  978. sb_rt_sigaction,
  979. sb_rt_sigprocmask,
  980. sb_time,
  981. sb_accept4,
  982. #ifdef __NR_mmap2
  983. sb_mmap2,
  984. #endif
  985. sb_chown,
  986. sb_chmod,
  987. sb_open,
  988. sb_openat,
  989. sb__sysctl,
  990. sb_rename,
  991. #ifdef __NR_fcntl64
  992. sb_fcntl64,
  993. #endif
  994. sb_epoll_ctl,
  995. sb_prctl,
  996. sb_mprotect,
  997. sb_flock,
  998. sb_futex,
  999. sb_mremap,
  1000. #ifdef __NR_stat64
  1001. sb_stat64,
  1002. #endif
  1003. sb_socket,
  1004. sb_setsockopt,
  1005. sb_getsockopt,
  1006. sb_socketpair,
  1007. #ifdef HAVE_KIST_SUPPORT
  1008. sb_ioctl,
  1009. #endif
  1010. sb_kill
  1011. };
  1012. const char *
  1013. sandbox_intern_string(const char *str)
  1014. {
  1015. sandbox_cfg_t *elem;
  1016. if (str == NULL)
  1017. return NULL;
  1018. for (elem = filter_dynamic; elem != NULL; elem = elem->next) {
  1019. smp_param_t *param = elem->param;
  1020. if (param->prot) {
  1021. if (!strcmp(str, (char*)(param->value))) {
  1022. return (char*)param->value;
  1023. }
  1024. if (param->value2 && !strcmp(str, (char*)param->value2)) {
  1025. return (char*)param->value2;
  1026. }
  1027. }
  1028. }
  1029. if (sandbox_active)
  1030. log_warn(LD_BUG, "No interned sandbox parameter found for %s", str);
  1031. return str;
  1032. }
  1033. /* DOCDOC */
  1034. static int
  1035. prot_strings_helper(strmap_t *locations,
  1036. char **pr_mem_next_p,
  1037. size_t *pr_mem_left_p,
  1038. char **value_p)
  1039. {
  1040. char *param_val;
  1041. size_t param_size;
  1042. void *location;
  1043. if (*value_p == 0)
  1044. return 0;
  1045. param_val = (char*) *value_p;
  1046. param_size = strlen(param_val) + 1;
  1047. location = strmap_get(locations, param_val);
  1048. if (location) {
  1049. // We already interned this string.
  1050. tor_free(param_val);
  1051. *value_p = location;
  1052. return 0;
  1053. } else if (*pr_mem_left_p >= param_size) {
  1054. // copy to protected
  1055. location = *pr_mem_next_p;
  1056. memcpy(location, param_val, param_size);
  1057. // re-point el parameter to protected
  1058. tor_free(param_val);
  1059. *value_p = location;
  1060. strmap_set(locations, location, location); /* good real estate advice */
  1061. // move next available protected memory
  1062. *pr_mem_next_p += param_size;
  1063. *pr_mem_left_p -= param_size;
  1064. return 0;
  1065. } else {
  1066. log_err(LD_BUG,"(Sandbox) insufficient protected memory!");
  1067. return -1;
  1068. }
  1069. }
  1070. /**
  1071. * Protects all the strings in the sandbox's parameter list configuration. It
  1072. * works by calculating the total amount of memory required by the parameter
  1073. * list, allocating the memory using mmap, and protecting it from writes with
  1074. * mprotect().
  1075. */
  1076. static int
  1077. prot_strings(scmp_filter_ctx ctx, sandbox_cfg_t* cfg)
  1078. {
  1079. int ret = 0;
  1080. size_t pr_mem_size = 0, pr_mem_left = 0;
  1081. char *pr_mem_next = NULL, *pr_mem_base;
  1082. sandbox_cfg_t *el = NULL;
  1083. strmap_t *locations = NULL;
  1084. // get total number of bytes required to mmap. (Overestimate.)
  1085. for (el = cfg; el != NULL; el = el->next) {
  1086. pr_mem_size += strlen((char*) el->param->value) + 1;
  1087. if (el->param->value2)
  1088. pr_mem_size += strlen((char*) el->param->value2) + 1;
  1089. }
  1090. // allocate protected memory with MALLOC_MP_LIM canary
  1091. pr_mem_base = (char*) mmap(NULL, MALLOC_MP_LIM + pr_mem_size,
  1092. PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
  1093. if (pr_mem_base == MAP_FAILED) {
  1094. log_err(LD_BUG,"(Sandbox) failed allocate protected memory! mmap: %s",
  1095. strerror(errno));
  1096. ret = -1;
  1097. goto out;
  1098. }
  1099. pr_mem_next = pr_mem_base + MALLOC_MP_LIM;
  1100. pr_mem_left = pr_mem_size;
  1101. locations = strmap_new();
  1102. // change el value pointer to protected
  1103. for (el = cfg; el != NULL; el = el->next) {
  1104. if (prot_strings_helper(locations, &pr_mem_next, &pr_mem_left,
  1105. &el->param->value) < 0) {
  1106. ret = -2;
  1107. goto out;
  1108. }
  1109. if (prot_strings_helper(locations, &pr_mem_next, &pr_mem_left,
  1110. &el->param->value2) < 0) {
  1111. ret = -2;
  1112. goto out;
  1113. }
  1114. el->param->prot = 1;
  1115. }
  1116. // protecting from writes
  1117. if (mprotect(pr_mem_base, MALLOC_MP_LIM + pr_mem_size, PROT_READ)) {
  1118. log_err(LD_BUG,"(Sandbox) failed to protect memory! mprotect: %s",
  1119. strerror(errno));
  1120. ret = -3;
  1121. goto out;
  1122. }
  1123. /*
  1124. * Setting sandbox restrictions so the string memory cannot be tampered with
  1125. */
  1126. // no mremap of the protected base address
  1127. ret = seccomp_rule_add_1(ctx, SCMP_ACT_KILL, SCMP_SYS(mremap),
  1128. SCMP_CMP(0, SCMP_CMP_EQ, (intptr_t) pr_mem_base));
  1129. if (ret) {
  1130. log_err(LD_BUG,"(Sandbox) mremap protected memory filter fail!");
  1131. goto out;
  1132. }
  1133. // no munmap of the protected base address
  1134. ret = seccomp_rule_add_1(ctx, SCMP_ACT_KILL, SCMP_SYS(munmap),
  1135. SCMP_CMP(0, SCMP_CMP_EQ, (intptr_t) pr_mem_base));
  1136. if (ret) {
  1137. log_err(LD_BUG,"(Sandbox) munmap protected memory filter fail!");
  1138. goto out;
  1139. }
  1140. /*
  1141. * Allow mprotect with PROT_READ|PROT_WRITE because openssl uses it, but
  1142. * never over the memory region used by the protected strings.
  1143. *
  1144. * PROT_READ|PROT_WRITE was originally fully allowed in sb_mprotect(), but
  1145. * had to be removed due to limitation of libseccomp regarding intervals.
  1146. *
  1147. * There is a restriction on how much you can mprotect with R|W up to the
  1148. * size of the canary.
  1149. */
  1150. ret = seccomp_rule_add_3(ctx, SCMP_ACT_ALLOW, SCMP_SYS(mprotect),
  1151. SCMP_CMP(0, SCMP_CMP_LT, (intptr_t) pr_mem_base),
  1152. SCMP_CMP(1, SCMP_CMP_LE, MALLOC_MP_LIM),
  1153. SCMP_CMP(2, SCMP_CMP_EQ, PROT_READ|PROT_WRITE));
  1154. if (ret) {
  1155. log_err(LD_BUG,"(Sandbox) mprotect protected memory filter fail (LT)!");
  1156. goto out;
  1157. }
  1158. ret = seccomp_rule_add_3(ctx, SCMP_ACT_ALLOW, SCMP_SYS(mprotect),
  1159. SCMP_CMP(0, SCMP_CMP_GT, (intptr_t) pr_mem_base + pr_mem_size +
  1160. MALLOC_MP_LIM),
  1161. SCMP_CMP(1, SCMP_CMP_LE, MALLOC_MP_LIM),
  1162. SCMP_CMP(2, SCMP_CMP_EQ, PROT_READ|PROT_WRITE));
  1163. if (ret) {
  1164. log_err(LD_BUG,"(Sandbox) mprotect protected memory filter fail (GT)!");
  1165. goto out;
  1166. }
  1167. out:
  1168. strmap_free(locations, NULL);
  1169. return ret;
  1170. }
  1171. /**
  1172. * Auxiliary function used in order to allocate a sandbox_cfg_t element and set
  1173. * its values according the parameter list. All elements are initialised
  1174. * with the 'prot' field set to false, as the pointer is not protected at this
  1175. * point.
  1176. */
  1177. static sandbox_cfg_t*
  1178. new_element2(int syscall, char *value, char *value2)
  1179. {
  1180. smp_param_t *param = NULL;
  1181. sandbox_cfg_t *elem = tor_malloc_zero(sizeof(sandbox_cfg_t));
  1182. param = elem->param = tor_malloc_zero(sizeof(smp_param_t));
  1183. param->syscall = syscall;
  1184. param->value = value;
  1185. param->value2 = value2;
  1186. param->prot = 0;
  1187. return elem;
  1188. }
  1189. static sandbox_cfg_t*
  1190. new_element(int syscall, char *value)
  1191. {
  1192. return new_element2(syscall, value, NULL);
  1193. }
  1194. #ifdef __NR_stat64
  1195. #define SCMP_stat SCMP_SYS(stat64)
  1196. #else
  1197. #define SCMP_stat SCMP_SYS(stat)
  1198. #endif
  1199. int
  1200. sandbox_cfg_allow_stat_filename(sandbox_cfg_t **cfg, char *file)
  1201. {
  1202. sandbox_cfg_t *elem = NULL;
  1203. elem = new_element(SCMP_stat, file);
  1204. elem->next = *cfg;
  1205. *cfg = elem;
  1206. return 0;
  1207. }
  1208. int
  1209. sandbox_cfg_allow_open_filename(sandbox_cfg_t **cfg, char *file)
  1210. {
  1211. sandbox_cfg_t *elem = NULL;
  1212. elem = new_element(SCMP_SYS(open), file);
  1213. elem->next = *cfg;
  1214. *cfg = elem;
  1215. return 0;
  1216. }
  1217. int
  1218. sandbox_cfg_allow_chmod_filename(sandbox_cfg_t **cfg, char *file)
  1219. {
  1220. sandbox_cfg_t *elem = NULL;
  1221. elem = new_element(SCMP_SYS(chmod), file);
  1222. elem->next = *cfg;
  1223. *cfg = elem;
  1224. return 0;
  1225. }
  1226. int
  1227. sandbox_cfg_allow_chown_filename(sandbox_cfg_t **cfg, char *file)
  1228. {
  1229. sandbox_cfg_t *elem = NULL;
  1230. elem = new_element(SCMP_SYS(chown), file);
  1231. elem->next = *cfg;
  1232. *cfg = elem;
  1233. return 0;
  1234. }
  1235. int
  1236. sandbox_cfg_allow_rename(sandbox_cfg_t **cfg, char *file1, char *file2)
  1237. {
  1238. sandbox_cfg_t *elem = NULL;
  1239. elem = new_element2(SCMP_SYS(rename), file1, file2);
  1240. elem->next = *cfg;
  1241. *cfg = elem;
  1242. return 0;
  1243. }
  1244. int
  1245. sandbox_cfg_allow_openat_filename(sandbox_cfg_t **cfg, char *file)
  1246. {
  1247. sandbox_cfg_t *elem = NULL;
  1248. elem = new_element(SCMP_SYS(openat), file);
  1249. elem->next = *cfg;
  1250. *cfg = elem;
  1251. return 0;
  1252. }
  1253. /**
  1254. * Function responsible for going through the parameter syscall filters and
  1255. * call each function pointer in the list.
  1256. */
  1257. static int
  1258. add_param_filter(scmp_filter_ctx ctx, sandbox_cfg_t* cfg)
  1259. {
  1260. unsigned i;
  1261. int rc = 0;
  1262. // function pointer
  1263. for (i = 0; i < ARRAY_LENGTH(filter_func); i++) {
  1264. rc = filter_func[i](ctx, cfg);
  1265. if (rc) {
  1266. log_err(LD_BUG,"(Sandbox) failed to add syscall %d, received libseccomp "
  1267. "error %d", i, rc);
  1268. return rc;
  1269. }
  1270. }
  1271. return 0;
  1272. }
  1273. /**
  1274. * Function responsible of loading the libseccomp syscall filters which do not
  1275. * have parameter filtering.
  1276. */
  1277. static int
  1278. add_noparam_filter(scmp_filter_ctx ctx)
  1279. {
  1280. unsigned i;
  1281. int rc = 0;
  1282. // add general filters
  1283. for (i = 0; i < ARRAY_LENGTH(filter_nopar_gen); i++) {
  1284. rc = seccomp_rule_add_0(ctx, SCMP_ACT_ALLOW, filter_nopar_gen[i]);
  1285. if (rc != 0) {
  1286. log_err(LD_BUG,"(Sandbox) failed to add syscall index %d (NR=%d), "
  1287. "received libseccomp error %d", i, filter_nopar_gen[i], rc);
  1288. return rc;
  1289. }
  1290. }
  1291. return 0;
  1292. }
  1293. /**
  1294. * Function responsible for setting up and enabling a global syscall filter.
  1295. * The function is a prototype developed for stage 1 of sandboxing Tor.
  1296. * Returns 0 on success.
  1297. */
  1298. static int
  1299. install_syscall_filter(sandbox_cfg_t* cfg)
  1300. {
  1301. int rc = 0;
  1302. scmp_filter_ctx ctx;
  1303. ctx = seccomp_init(SCMP_ACT_TRAP);
  1304. if (ctx == NULL) {
  1305. log_err(LD_BUG,"(Sandbox) failed to initialise libseccomp context");
  1306. rc = -1;
  1307. goto end;
  1308. }
  1309. // protectign sandbox parameter strings
  1310. if ((rc = prot_strings(ctx, cfg))) {
  1311. goto end;
  1312. }
  1313. // add parameter filters
  1314. if ((rc = add_param_filter(ctx, cfg))) {
  1315. log_err(LD_BUG, "(Sandbox) failed to add param filters!");
  1316. goto end;
  1317. }
  1318. // adding filters with no parameters
  1319. if ((rc = add_noparam_filter(ctx))) {
  1320. log_err(LD_BUG, "(Sandbox) failed to add param filters!");
  1321. goto end;
  1322. }
  1323. // loading the seccomp2 filter
  1324. if ((rc = seccomp_load(ctx))) {
  1325. log_err(LD_BUG, "(Sandbox) failed to load: %d (%s)! "
  1326. "Are you sure that your kernel has seccomp2 support? The "
  1327. "sandbox won't work without it.", rc,
  1328. strerror(-rc));
  1329. goto end;
  1330. }
  1331. // marking the sandbox as active
  1332. sandbox_active = 1;
  1333. end:
  1334. seccomp_release(ctx);
  1335. return (rc < 0 ? -rc : rc);
  1336. }
  1337. #include "lib/sandbox/linux_syscalls.inc"
  1338. static const char *
  1339. get_syscall_name(int syscall_num)
  1340. {
  1341. int i;
  1342. for (i = 0; SYSCALLS_BY_NUMBER[i].syscall_name; ++i) {
  1343. if (SYSCALLS_BY_NUMBER[i].syscall_num == syscall_num)
  1344. return SYSCALLS_BY_NUMBER[i].syscall_name;
  1345. }
  1346. {
  1347. static char syscall_name_buf[64];
  1348. format_dec_number_sigsafe(syscall_num,
  1349. syscall_name_buf, sizeof(syscall_name_buf));
  1350. return syscall_name_buf;
  1351. }
  1352. }
  1353. #ifdef USE_BACKTRACE
  1354. #define MAX_DEPTH 256
  1355. static void *syscall_cb_buf[MAX_DEPTH];
  1356. #endif
  1357. /**
  1358. * Function called when a SIGSYS is caught by the application. It notifies the
  1359. * user that an error has occurred and either terminates or allows the
  1360. * application to continue execution, based on the DEBUGGING_CLOSE symbol.
  1361. */
  1362. static void
  1363. sigsys_debugging(int nr, siginfo_t *info, void *void_context)
  1364. {
  1365. ucontext_t *ctx = (ucontext_t *) (void_context);
  1366. const char *syscall_name;
  1367. int syscall;
  1368. #ifdef USE_BACKTRACE
  1369. size_t depth;
  1370. int n_fds, i;
  1371. const int *fds = NULL;
  1372. #endif
  1373. (void) nr;
  1374. if (info->si_code != SYS_SECCOMP)
  1375. return;
  1376. if (!ctx)
  1377. return;
  1378. syscall = (int) ctx->uc_mcontext.M_SYSCALL;
  1379. #ifdef USE_BACKTRACE
  1380. depth = backtrace(syscall_cb_buf, MAX_DEPTH);
  1381. /* Clean up the top stack frame so we get the real function
  1382. * name for the most recently failing function. */
  1383. clean_backtrace(syscall_cb_buf, depth, ctx);
  1384. #endif /* defined(USE_BACKTRACE) */
  1385. syscall_name = get_syscall_name(syscall);
  1386. tor_log_err_sigsafe("(Sandbox) Caught a bad syscall attempt (syscall ",
  1387. syscall_name,
  1388. ")\n",
  1389. NULL);
  1390. #ifdef USE_BACKTRACE
  1391. n_fds = tor_log_get_sigsafe_err_fds(&fds);
  1392. for (i=0; i < n_fds; ++i)
  1393. backtrace_symbols_fd(syscall_cb_buf, (int)depth, fds[i]);
  1394. #endif
  1395. #if defined(DEBUGGING_CLOSE)
  1396. _exit(1); // exit ok: programming error has led to sandbox failure.
  1397. #endif // DEBUGGING_CLOSE
  1398. }
  1399. /**
  1400. * Function that adds a handler for SIGSYS, which is the signal thrown
  1401. * when the application is issuing a syscall which is not allowed. The
  1402. * main purpose of this function is to help with debugging by identifying
  1403. * filtered syscalls.
  1404. */
  1405. static int
  1406. install_sigsys_debugging(void)
  1407. {
  1408. struct sigaction act;
  1409. sigset_t mask;
  1410. memset(&act, 0, sizeof(act));
  1411. sigemptyset(&mask);
  1412. sigaddset(&mask, SIGSYS);
  1413. act.sa_sigaction = &sigsys_debugging;
  1414. act.sa_flags = SA_SIGINFO;
  1415. if (sigaction(SIGSYS, &act, NULL) < 0) {
  1416. log_err(LD_BUG,"(Sandbox) Failed to register SIGSYS signal handler");
  1417. return -1;
  1418. }
  1419. if (sigprocmask(SIG_UNBLOCK, &mask, NULL)) {
  1420. log_err(LD_BUG,"(Sandbox) Failed call to sigprocmask()");
  1421. return -2;
  1422. }
  1423. return 0;
  1424. }
  1425. /**
  1426. * Function responsible of registering the sandbox_cfg_t list of parameter
  1427. * syscall filters to the existing parameter list. This is used for incipient
  1428. * multiple-sandbox support.
  1429. */
  1430. static int
  1431. register_cfg(sandbox_cfg_t* cfg)
  1432. {
  1433. sandbox_cfg_t *elem = NULL;
  1434. if (filter_dynamic == NULL) {
  1435. filter_dynamic = cfg;
  1436. return 0;
  1437. }
  1438. for (elem = filter_dynamic; elem->next != NULL; elem = elem->next)
  1439. ;
  1440. elem->next = cfg;
  1441. return 0;
  1442. }
  1443. #endif /* defined(USE_LIBSECCOMP) */
  1444. #ifdef USE_LIBSECCOMP
  1445. /**
  1446. * Initialises the syscall sandbox filter for any linux architecture, taking
  1447. * into account various available features for different linux flavours.
  1448. */
  1449. static int
  1450. initialise_libseccomp_sandbox(sandbox_cfg_t* cfg)
  1451. {
  1452. /* Prevent glibc from trying to open /dev/tty on fatal error */
  1453. setenv("LIBC_FATAL_STDERR_", "1", 1);
  1454. if (install_sigsys_debugging())
  1455. return -1;
  1456. if (install_syscall_filter(cfg))
  1457. return -2;
  1458. if (register_cfg(cfg))
  1459. return -3;
  1460. return 0;
  1461. }
  1462. int
  1463. sandbox_is_active(void)
  1464. {
  1465. return sandbox_active != 0;
  1466. }
  1467. #endif /* defined(USE_LIBSECCOMP) */
  1468. sandbox_cfg_t*
  1469. sandbox_cfg_new(void)
  1470. {
  1471. return NULL;
  1472. }
  1473. int
  1474. sandbox_init(sandbox_cfg_t *cfg)
  1475. {
  1476. #if defined(USE_LIBSECCOMP)
  1477. return initialise_libseccomp_sandbox(cfg);
  1478. #elif defined(__linux__)
  1479. (void)cfg;
  1480. log_warn(LD_GENERAL,
  1481. "This version of Tor was built without support for sandboxing. To "
  1482. "build with support for sandboxing on Linux, you must have "
  1483. "libseccomp and its necessary header files (e.g. seccomp.h).");
  1484. return 0;
  1485. #else
  1486. (void)cfg;
  1487. log_warn(LD_GENERAL,
  1488. "Currently, sandboxing is only implemented on Linux. The feature "
  1489. "is disabled on your platform.");
  1490. return 0;
  1491. #endif /* defined(USE_LIBSECCOMP) || ... */
  1492. }
  1493. #ifndef USE_LIBSECCOMP
  1494. int
  1495. sandbox_cfg_allow_open_filename(sandbox_cfg_t **cfg, char *file)
  1496. {
  1497. (void)cfg; (void)file;
  1498. return 0;
  1499. }
  1500. int
  1501. sandbox_cfg_allow_openat_filename(sandbox_cfg_t **cfg, char *file)
  1502. {
  1503. (void)cfg; (void)file;
  1504. return 0;
  1505. }
  1506. int
  1507. sandbox_cfg_allow_stat_filename(sandbox_cfg_t **cfg, char *file)
  1508. {
  1509. (void)cfg; (void)file;
  1510. return 0;
  1511. }
  1512. int
  1513. sandbox_cfg_allow_chown_filename(sandbox_cfg_t **cfg, char *file)
  1514. {
  1515. (void)cfg; (void)file;
  1516. return 0;
  1517. }
  1518. int
  1519. sandbox_cfg_allow_chmod_filename(sandbox_cfg_t **cfg, char *file)
  1520. {
  1521. (void)cfg; (void)file;
  1522. return 0;
  1523. }
  1524. int
  1525. sandbox_cfg_allow_rename(sandbox_cfg_t **cfg, char *file1, char *file2)
  1526. {
  1527. (void)cfg; (void)file1; (void)file2;
  1528. return 0;
  1529. }
  1530. int
  1531. sandbox_is_active(void)
  1532. {
  1533. return 0;
  1534. }
  1535. #endif /* !defined(USE_LIBSECCOMP) */