sandbox.c 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806
  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/torlog.h"
  34. #include "lib/cc/torint.h"
  35. #include "lib/net/resolve.h"
  36. #include "lib/malloc/util_malloc.h"
  37. #include "lib/string/scanf.h"
  38. #include "tor_queue.h"
  39. #include "ht.h"
  40. #include "siphash.h"
  41. #define DEBUGGING_CLOSE
  42. #if defined(USE_LIBSECCOMP)
  43. #include <sys/mman.h>
  44. #include <sys/syscall.h>
  45. #include <sys/types.h>
  46. #include <sys/stat.h>
  47. #include <sys/epoll.h>
  48. #include <sys/prctl.h>
  49. #include <linux/futex.h>
  50. #include <sys/file.h>
  51. #include <stdarg.h>
  52. #include <seccomp.h>
  53. #include <signal.h>
  54. #include <unistd.h>
  55. #include <fcntl.h>
  56. #include <time.h>
  57. #include <poll.h>
  58. #ifdef HAVE_GNU_LIBC_VERSION_H
  59. #include <gnu/libc-version.h>
  60. #endif
  61. #ifdef HAVE_LINUX_NETFILTER_IPV4_H
  62. #include <linux/netfilter_ipv4.h>
  63. #endif
  64. #ifdef HAVE_LINUX_IF_H
  65. #include <linux/if.h>
  66. #endif
  67. #ifdef HAVE_LINUX_NETFILTER_IPV6_IP6_TABLES_H
  68. #include <linux/netfilter_ipv6/ip6_tables.h>
  69. #endif
  70. #if defined(HAVE_EXECINFO_H) && defined(HAVE_BACKTRACE) && \
  71. defined(HAVE_BACKTRACE_SYMBOLS_FD) && defined(HAVE_SIGACTION)
  72. #define USE_BACKTRACE
  73. #define EXPOSE_CLEAN_BACKTRACE
  74. #include "lib/err/backtrace.h"
  75. #endif /* defined(HAVE_EXECINFO_H) && defined(HAVE_BACKTRACE) && ... */
  76. #ifdef USE_BACKTRACE
  77. #include <execinfo.h>
  78. #endif
  79. /**
  80. * Linux 32 bit definitions
  81. */
  82. #if defined(__i386__)
  83. #define REG_SYSCALL REG_EAX
  84. #define M_SYSCALL gregs[REG_SYSCALL]
  85. /**
  86. * Linux 64 bit definitions
  87. */
  88. #elif defined(__x86_64__)
  89. #define REG_SYSCALL REG_RAX
  90. #define M_SYSCALL gregs[REG_SYSCALL]
  91. #elif defined(__arm__)
  92. #define M_SYSCALL arm_r7
  93. #elif defined(__aarch64__) && defined(__LP64__)
  94. #define REG_SYSCALL 8
  95. #define M_SYSCALL regs[REG_SYSCALL]
  96. #endif /* defined(__i386__) || ... */
  97. /**Determines if at least one sandbox is active.*/
  98. static int sandbox_active = 0;
  99. /** Holds the parameter list configuration for the sandbox.*/
  100. static sandbox_cfg_t *filter_dynamic = NULL;
  101. #undef SCMP_CMP
  102. #define SCMP_CMP(a,b,c) ((struct scmp_arg_cmp){(a),(b),(c),0})
  103. #define SCMP_CMP_STR(a,b,c) \
  104. ((struct scmp_arg_cmp) {(a),(b),(intptr_t)(void*)(c),0})
  105. #define SCMP_CMP4(a,b,c,d) ((struct scmp_arg_cmp){(a),(b),(c),(d)})
  106. /* We use a wrapper here because these masked comparisons seem to be pretty
  107. * verbose. Also, it's important to cast to scmp_datum_t before negating the
  108. * mask, since otherwise the negation might get applied to a 32 bit value, and
  109. * the high bits of the value might get masked out improperly. */
  110. #define SCMP_CMP_MASKED(a,b,c) \
  111. SCMP_CMP4((a), SCMP_CMP_MASKED_EQ, ~(scmp_datum_t)(b), (c))
  112. /** Variable used for storing all syscall numbers that will be allowed with the
  113. * stage 1 general Tor sandbox.
  114. */
  115. static int filter_nopar_gen[] = {
  116. SCMP_SYS(access),
  117. SCMP_SYS(brk),
  118. SCMP_SYS(clock_gettime),
  119. SCMP_SYS(close),
  120. SCMP_SYS(clone),
  121. SCMP_SYS(epoll_create),
  122. SCMP_SYS(epoll_wait),
  123. #ifdef __NR_epoll_pwait
  124. SCMP_SYS(epoll_pwait),
  125. #endif
  126. #ifdef HAVE_EVENTFD
  127. SCMP_SYS(eventfd2),
  128. #endif
  129. #ifdef HAVE_PIPE2
  130. SCMP_SYS(pipe2),
  131. #endif
  132. #ifdef HAVE_PIPE
  133. SCMP_SYS(pipe),
  134. #endif
  135. #ifdef __NR_fchmod
  136. SCMP_SYS(fchmod),
  137. #endif
  138. SCMP_SYS(fcntl),
  139. SCMP_SYS(fstat),
  140. #ifdef __NR_fstat64
  141. SCMP_SYS(fstat64),
  142. #endif
  143. SCMP_SYS(futex),
  144. SCMP_SYS(getdents),
  145. SCMP_SYS(getdents64),
  146. SCMP_SYS(getegid),
  147. #ifdef __NR_getegid32
  148. SCMP_SYS(getegid32),
  149. #endif
  150. SCMP_SYS(geteuid),
  151. #ifdef __NR_geteuid32
  152. SCMP_SYS(geteuid32),
  153. #endif
  154. SCMP_SYS(getgid),
  155. #ifdef __NR_getgid32
  156. SCMP_SYS(getgid32),
  157. #endif
  158. SCMP_SYS(getpid),
  159. #ifdef __NR_getrlimit
  160. SCMP_SYS(getrlimit),
  161. #endif
  162. SCMP_SYS(gettimeofday),
  163. SCMP_SYS(gettid),
  164. SCMP_SYS(getuid),
  165. #ifdef __NR_getuid32
  166. SCMP_SYS(getuid32),
  167. #endif
  168. SCMP_SYS(lseek),
  169. #ifdef __NR__llseek
  170. SCMP_SYS(_llseek),
  171. #endif
  172. SCMP_SYS(mkdir),
  173. SCMP_SYS(mlockall),
  174. #ifdef __NR_mmap
  175. /* XXXX restrict this in the same ways as mmap2 */
  176. SCMP_SYS(mmap),
  177. #endif
  178. SCMP_SYS(munmap),
  179. #ifdef __NR_nanosleep
  180. SCMP_SYS(nanosleep),
  181. #endif
  182. #ifdef __NR_prlimit
  183. SCMP_SYS(prlimit),
  184. #endif
  185. #ifdef __NR_prlimit64
  186. SCMP_SYS(prlimit64),
  187. #endif
  188. SCMP_SYS(read),
  189. SCMP_SYS(rt_sigreturn),
  190. SCMP_SYS(sched_getaffinity),
  191. #ifdef __NR_sched_yield
  192. SCMP_SYS(sched_yield),
  193. #endif
  194. SCMP_SYS(sendmsg),
  195. SCMP_SYS(set_robust_list),
  196. #ifdef __NR_setrlimit
  197. SCMP_SYS(setrlimit),
  198. #endif
  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_STR(0, SCMP_CMP_EQ, 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. sandbox_make_getaddrinfo_cache_active();
  1334. end:
  1335. seccomp_release(ctx);
  1336. return (rc < 0 ? -rc : rc);
  1337. }
  1338. #include "lib/sandbox/linux_syscalls.inc"
  1339. static const char *
  1340. get_syscall_name(int syscall_num)
  1341. {
  1342. int i;
  1343. for (i = 0; SYSCALLS_BY_NUMBER[i].syscall_name; ++i) {
  1344. if (SYSCALLS_BY_NUMBER[i].syscall_num == syscall_num)
  1345. return SYSCALLS_BY_NUMBER[i].syscall_name;
  1346. }
  1347. {
  1348. static char syscall_name_buf[64];
  1349. format_dec_number_sigsafe(syscall_num,
  1350. syscall_name_buf, sizeof(syscall_name_buf));
  1351. return syscall_name_buf;
  1352. }
  1353. }
  1354. #ifdef USE_BACKTRACE
  1355. #define MAX_DEPTH 256
  1356. static void *syscall_cb_buf[MAX_DEPTH];
  1357. #endif
  1358. /**
  1359. * Function called when a SIGSYS is caught by the application. It notifies the
  1360. * user that an error has occurred and either terminates or allows the
  1361. * application to continue execution, based on the DEBUGGING_CLOSE symbol.
  1362. */
  1363. static void
  1364. sigsys_debugging(int nr, siginfo_t *info, void *void_context)
  1365. {
  1366. ucontext_t *ctx = (ucontext_t *) (void_context);
  1367. const char *syscall_name;
  1368. int syscall;
  1369. #ifdef USE_BACKTRACE
  1370. size_t depth;
  1371. int n_fds, i;
  1372. const int *fds = NULL;
  1373. #endif
  1374. (void) nr;
  1375. if (info->si_code != SYS_SECCOMP)
  1376. return;
  1377. if (!ctx)
  1378. return;
  1379. syscall = (int) ctx->uc_mcontext.M_SYSCALL;
  1380. #ifdef USE_BACKTRACE
  1381. depth = backtrace(syscall_cb_buf, MAX_DEPTH);
  1382. /* Clean up the top stack frame so we get the real function
  1383. * name for the most recently failing function. */
  1384. clean_backtrace(syscall_cb_buf, depth, ctx);
  1385. #endif /* defined(USE_BACKTRACE) */
  1386. syscall_name = get_syscall_name(syscall);
  1387. tor_log_err_sigsafe("(Sandbox) Caught a bad syscall attempt (syscall ",
  1388. syscall_name,
  1389. ")\n",
  1390. NULL);
  1391. #ifdef USE_BACKTRACE
  1392. n_fds = tor_log_get_sigsafe_err_fds(&fds);
  1393. for (i=0; i < n_fds; ++i)
  1394. backtrace_symbols_fd(syscall_cb_buf, (int)depth, fds[i]);
  1395. #endif
  1396. #if defined(DEBUGGING_CLOSE)
  1397. _exit(1); // exit ok: programming error has led to sandbox failure.
  1398. #endif // DEBUGGING_CLOSE
  1399. }
  1400. /**
  1401. * Function that adds a handler for SIGSYS, which is the signal thrown
  1402. * when the application is issuing a syscall which is not allowed. The
  1403. * main purpose of this function is to help with debugging by identifying
  1404. * filtered syscalls.
  1405. */
  1406. static int
  1407. install_sigsys_debugging(void)
  1408. {
  1409. struct sigaction act;
  1410. sigset_t mask;
  1411. memset(&act, 0, sizeof(act));
  1412. sigemptyset(&mask);
  1413. sigaddset(&mask, SIGSYS);
  1414. act.sa_sigaction = &sigsys_debugging;
  1415. act.sa_flags = SA_SIGINFO;
  1416. if (sigaction(SIGSYS, &act, NULL) < 0) {
  1417. log_err(LD_BUG,"(Sandbox) Failed to register SIGSYS signal handler");
  1418. return -1;
  1419. }
  1420. if (sigprocmask(SIG_UNBLOCK, &mask, NULL)) {
  1421. log_err(LD_BUG,"(Sandbox) Failed call to sigprocmask()");
  1422. return -2;
  1423. }
  1424. return 0;
  1425. }
  1426. /**
  1427. * Function responsible of registering the sandbox_cfg_t list of parameter
  1428. * syscall filters to the existing parameter list. This is used for incipient
  1429. * multiple-sandbox support.
  1430. */
  1431. static int
  1432. register_cfg(sandbox_cfg_t* cfg)
  1433. {
  1434. sandbox_cfg_t *elem = NULL;
  1435. if (filter_dynamic == NULL) {
  1436. filter_dynamic = cfg;
  1437. return 0;
  1438. }
  1439. for (elem = filter_dynamic; elem->next != NULL; elem = elem->next)
  1440. ;
  1441. elem->next = cfg;
  1442. return 0;
  1443. }
  1444. #endif /* defined(USE_LIBSECCOMP) */
  1445. #ifdef USE_LIBSECCOMP
  1446. /**
  1447. * Initialises the syscall sandbox filter for any linux architecture, taking
  1448. * into account various available features for different linux flavours.
  1449. */
  1450. static int
  1451. initialise_libseccomp_sandbox(sandbox_cfg_t* cfg)
  1452. {
  1453. /* Prevent glibc from trying to open /dev/tty on fatal error */
  1454. setenv("LIBC_FATAL_STDERR_", "1", 1);
  1455. if (install_sigsys_debugging())
  1456. return -1;
  1457. if (install_syscall_filter(cfg))
  1458. return -2;
  1459. if (register_cfg(cfg))
  1460. return -3;
  1461. return 0;
  1462. }
  1463. int
  1464. sandbox_is_active(void)
  1465. {
  1466. return sandbox_active != 0;
  1467. }
  1468. #endif /* defined(USE_LIBSECCOMP) */
  1469. sandbox_cfg_t*
  1470. sandbox_cfg_new(void)
  1471. {
  1472. return NULL;
  1473. }
  1474. int
  1475. sandbox_init(sandbox_cfg_t *cfg)
  1476. {
  1477. #if defined(USE_LIBSECCOMP)
  1478. return initialise_libseccomp_sandbox(cfg);
  1479. #elif defined(__linux__)
  1480. (void)cfg;
  1481. log_warn(LD_GENERAL,
  1482. "This version of Tor was built without support for sandboxing. To "
  1483. "build with support for sandboxing on Linux, you must have "
  1484. "libseccomp and its necessary header files (e.g. seccomp.h).");
  1485. return 0;
  1486. #else
  1487. (void)cfg;
  1488. log_warn(LD_GENERAL,
  1489. "Currently, sandboxing is only implemented on Linux. The feature "
  1490. "is disabled on your platform.");
  1491. return 0;
  1492. #endif /* defined(USE_LIBSECCOMP) || ... */
  1493. }
  1494. #ifndef USE_LIBSECCOMP
  1495. int
  1496. sandbox_cfg_allow_open_filename(sandbox_cfg_t **cfg, char *file)
  1497. {
  1498. (void)cfg; (void)file;
  1499. return 0;
  1500. }
  1501. int
  1502. sandbox_cfg_allow_openat_filename(sandbox_cfg_t **cfg, char *file)
  1503. {
  1504. (void)cfg; (void)file;
  1505. return 0;
  1506. }
  1507. int
  1508. sandbox_cfg_allow_stat_filename(sandbox_cfg_t **cfg, char *file)
  1509. {
  1510. (void)cfg; (void)file;
  1511. return 0;
  1512. }
  1513. int
  1514. sandbox_cfg_allow_chown_filename(sandbox_cfg_t **cfg, char *file)
  1515. {
  1516. (void)cfg; (void)file;
  1517. return 0;
  1518. }
  1519. int
  1520. sandbox_cfg_allow_chmod_filename(sandbox_cfg_t **cfg, char *file)
  1521. {
  1522. (void)cfg; (void)file;
  1523. return 0;
  1524. }
  1525. int
  1526. sandbox_cfg_allow_rename(sandbox_cfg_t **cfg, char *file1, char *file2)
  1527. {
  1528. (void)cfg; (void)file1; (void)file2;
  1529. return 0;
  1530. }
  1531. int
  1532. sandbox_is_active(void)
  1533. {
  1534. return 0;
  1535. }
  1536. void
  1537. sandbox_disable_getaddrinfo_cache(void)
  1538. {
  1539. }
  1540. #endif /* !defined(USE_LIBSECCOMP) */