sandbox.c 43 KB

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