sandbox.c 43 KB

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