sandbox.c 44 KB

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