sandbox.c 43 KB

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