sandbox.c 43 KB

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