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-2019, The Tor Project, Inc. */
  5. /* See LICENSE for licensing information */
  6. /**
  7. * \file sandbox.c
  8. * \brief Code to enable sandboxing.
  9. **/
  10. #include "orconfig.h"
  11. #ifndef _LARGEFILE64_SOURCE
  12. /**
  13. * Temporarily required for O_LARGEFILE flag. Needs to be removed
  14. * with the libevent fix.
  15. */
  16. #define _LARGEFILE64_SOURCE
  17. #endif /* !defined(_LARGEFILE64_SOURCE) */
  18. /** Malloc mprotect limit in bytes.
  19. *
  20. * 28/06/2017: This value was increased from 16 MB to 20 MB after we introduced
  21. * LZMA support in Tor (0.3.1.1-alpha). We limit our LZMA coder to 16 MB, but
  22. * liblzma have a small overhead that we need to compensate for to avoid being
  23. * killed by the sandbox.
  24. */
  25. #define MALLOC_MP_LIM (20*1024*1024)
  26. #include <stdio.h>
  27. #include <string.h>
  28. #include <stdlib.h>
  29. #include <errno.h>
  30. #include "lib/sandbox/sandbox.h"
  31. #include "lib/container/map.h"
  32. #include "lib/err/torerr.h"
  33. #include "lib/log/log.h"
  34. #include "lib/cc/torint.h"
  35. #include "lib/malloc/malloc.h"
  36. #include "lib/string/scanf.h"
  37. #include "ext/tor_queue.h"
  38. #include "ext/ht.h"
  39. #include "ext/siphash.h"
  40. #define DEBUGGING_CLOSE
  41. #if defined(USE_LIBSECCOMP)
  42. #include <sys/mman.h>
  43. #include <sys/syscall.h>
  44. #include <sys/types.h>
  45. #include <sys/stat.h>
  46. #include <sys/epoll.h>
  47. #include <sys/prctl.h>
  48. #include <linux/futex.h>
  49. #include <sys/file.h>
  50. #include <stdarg.h>
  51. #include <seccomp.h>
  52. #include <signal.h>
  53. #include <unistd.h>
  54. #include <fcntl.h>
  55. #include <time.h>
  56. #include <poll.h>
  57. #ifdef HAVE_GNU_LIBC_VERSION_H
  58. #include <gnu/libc-version.h>
  59. #endif
  60. #ifdef HAVE_LINUX_NETFILTER_IPV4_H
  61. #include <linux/netfilter_ipv4.h>
  62. #endif
  63. #ifdef HAVE_LINUX_IF_H
  64. #include <linux/if.h>
  65. #endif
  66. #ifdef HAVE_LINUX_NETFILTER_IPV6_IP6_TABLES_H
  67. #include <linux/netfilter_ipv6/ip6_tables.h>
  68. #endif
  69. #if defined(HAVE_EXECINFO_H) && defined(HAVE_BACKTRACE) && \
  70. defined(HAVE_BACKTRACE_SYMBOLS_FD) && defined(HAVE_SIGACTION)
  71. #define USE_BACKTRACE
  72. #define EXPOSE_CLEAN_BACKTRACE
  73. #include "lib/err/backtrace.h"
  74. #endif /* defined(HAVE_EXECINFO_H) && defined(HAVE_BACKTRACE) && ... */
  75. #ifdef USE_BACKTRACE
  76. #include <execinfo.h>
  77. #endif
  78. /**
  79. * Linux 32 bit definitions
  80. */
  81. #if defined(__i386__)
  82. #define REG_SYSCALL REG_EAX
  83. #define M_SYSCALL gregs[REG_SYSCALL]
  84. /**
  85. * Linux 64 bit definitions
  86. */
  87. #elif defined(__x86_64__)
  88. #define REG_SYSCALL REG_RAX
  89. #define M_SYSCALL gregs[REG_SYSCALL]
  90. #elif defined(__arm__)
  91. #define M_SYSCALL arm_r7
  92. #elif defined(__aarch64__) && defined(__LP64__)
  93. #define REG_SYSCALL 8
  94. #define M_SYSCALL regs[REG_SYSCALL]
  95. #endif /* defined(__i386__) || ... */
  96. /**Determines if at least one sandbox is active.*/
  97. static int sandbox_active = 0;
  98. /** Holds the parameter list configuration for the sandbox.*/
  99. static sandbox_cfg_t *filter_dynamic = NULL;
  100. #undef SCMP_CMP
  101. #define SCMP_CMP(a,b,c) ((struct scmp_arg_cmp){(a),(b),(c),0})
  102. #define SCMP_CMP_STR(a,b,c) \
  103. ((struct scmp_arg_cmp) {(a),(b),(intptr_t)(void*)(c),0})
  104. #define SCMP_CMP4(a,b,c,d) ((struct scmp_arg_cmp){(a),(b),(c),(d)})
  105. /* We use a wrapper here because these masked comparisons seem to be pretty
  106. * verbose. Also, it's important to cast to scmp_datum_t before negating the
  107. * mask, since otherwise the negation might get applied to a 32 bit value, and
  108. * the high bits of the value might get masked out improperly. */
  109. #define SCMP_CMP_MASKED(a,b,c) \
  110. SCMP_CMP4((a), SCMP_CMP_MASKED_EQ, ~(scmp_datum_t)(b), (c))
  111. /** Variable used for storing all syscall numbers that will be allowed with the
  112. * stage 1 general Tor sandbox.
  113. */
  114. static int filter_nopar_gen[] = {
  115. SCMP_SYS(access),
  116. SCMP_SYS(brk),
  117. SCMP_SYS(clock_gettime),
  118. SCMP_SYS(close),
  119. SCMP_SYS(clone),
  120. SCMP_SYS(epoll_create),
  121. SCMP_SYS(epoll_wait),
  122. #ifdef __NR_epoll_pwait
  123. SCMP_SYS(epoll_pwait),
  124. #endif
  125. #ifdef HAVE_EVENTFD
  126. SCMP_SYS(eventfd2),
  127. #endif
  128. #ifdef HAVE_PIPE2
  129. SCMP_SYS(pipe2),
  130. #endif
  131. #ifdef HAVE_PIPE
  132. SCMP_SYS(pipe),
  133. #endif
  134. #ifdef __NR_fchmod
  135. SCMP_SYS(fchmod),
  136. #endif
  137. SCMP_SYS(fcntl),
  138. SCMP_SYS(fstat),
  139. #ifdef __NR_fstat64
  140. SCMP_SYS(fstat64),
  141. #endif
  142. SCMP_SYS(futex),
  143. SCMP_SYS(getdents),
  144. SCMP_SYS(getdents64),
  145. SCMP_SYS(getegid),
  146. #ifdef __NR_getegid32
  147. SCMP_SYS(getegid32),
  148. #endif
  149. SCMP_SYS(geteuid),
  150. #ifdef __NR_geteuid32
  151. SCMP_SYS(geteuid32),
  152. #endif
  153. SCMP_SYS(getgid),
  154. #ifdef __NR_getgid32
  155. SCMP_SYS(getgid32),
  156. #endif
  157. SCMP_SYS(getpid),
  158. #ifdef __NR_getrlimit
  159. SCMP_SYS(getrlimit),
  160. #endif
  161. SCMP_SYS(gettimeofday),
  162. SCMP_SYS(gettid),
  163. SCMP_SYS(getuid),
  164. #ifdef __NR_getuid32
  165. SCMP_SYS(getuid32),
  166. #endif
  167. SCMP_SYS(lseek),
  168. #ifdef __NR__llseek
  169. SCMP_SYS(_llseek),
  170. #endif
  171. SCMP_SYS(mkdir),
  172. SCMP_SYS(mlockall),
  173. #ifdef __NR_mmap
  174. /* XXXX restrict this in the same ways as mmap2 */
  175. SCMP_SYS(mmap),
  176. #endif
  177. SCMP_SYS(munmap),
  178. #ifdef __NR_nanosleep
  179. SCMP_SYS(nanosleep),
  180. #endif
  181. #ifdef __NR_prlimit
  182. SCMP_SYS(prlimit),
  183. #endif
  184. #ifdef __NR_prlimit64
  185. SCMP_SYS(prlimit64),
  186. #endif
  187. SCMP_SYS(read),
  188. SCMP_SYS(rt_sigreturn),
  189. SCMP_SYS(sched_getaffinity),
  190. #ifdef __NR_sched_yield
  191. SCMP_SYS(sched_yield),
  192. #endif
  193. SCMP_SYS(sendmsg),
  194. SCMP_SYS(set_robust_list),
  195. #ifdef __NR_setrlimit
  196. SCMP_SYS(setrlimit),
  197. #endif
  198. SCMP_SYS(shutdown),
  199. #ifdef __NR_sigaltstack
  200. SCMP_SYS(sigaltstack),
  201. #endif
  202. #ifdef __NR_sigreturn
  203. SCMP_SYS(sigreturn),
  204. #endif
  205. SCMP_SYS(stat),
  206. SCMP_SYS(uname),
  207. SCMP_SYS(wait4),
  208. SCMP_SYS(write),
  209. SCMP_SYS(writev),
  210. SCMP_SYS(exit_group),
  211. SCMP_SYS(exit),
  212. SCMP_SYS(madvise),
  213. #ifdef __NR_stat64
  214. // getaddrinfo uses this..
  215. SCMP_SYS(stat64),
  216. #endif
  217. #ifdef __NR_getrandom
  218. SCMP_SYS(getrandom),
  219. #endif
  220. #ifdef __NR_sysinfo
  221. // qsort uses this..
  222. SCMP_SYS(sysinfo),
  223. #endif
  224. /*
  225. * These socket syscalls are not required on x86_64 and not supported with
  226. * some libseccomp versions (eg: 1.0.1)
  227. */
  228. #if defined(__i386)
  229. SCMP_SYS(recv),
  230. SCMP_SYS(send),
  231. #endif
  232. // socket syscalls
  233. SCMP_SYS(bind),
  234. SCMP_SYS(listen),
  235. SCMP_SYS(connect),
  236. SCMP_SYS(getsockname),
  237. SCMP_SYS(recvmsg),
  238. SCMP_SYS(recvfrom),
  239. SCMP_SYS(sendto),
  240. SCMP_SYS(unlink),
  241. SCMP_SYS(poll)
  242. };
  243. /* These macros help avoid the error where the number of filters we add on a
  244. * single rule don't match the arg_cnt param. */
  245. #define seccomp_rule_add_0(ctx,act,call) \
  246. seccomp_rule_add((ctx),(act),(call),0)
  247. #define seccomp_rule_add_1(ctx,act,call,f1) \
  248. seccomp_rule_add((ctx),(act),(call),1,(f1))
  249. #define seccomp_rule_add_2(ctx,act,call,f1,f2) \
  250. seccomp_rule_add((ctx),(act),(call),2,(f1),(f2))
  251. #define seccomp_rule_add_3(ctx,act,call,f1,f2,f3) \
  252. seccomp_rule_add((ctx),(act),(call),3,(f1),(f2),(f3))
  253. #define seccomp_rule_add_4(ctx,act,call,f1,f2,f3,f4) \
  254. seccomp_rule_add((ctx),(act),(call),4,(f1),(f2),(f3),(f4))
  255. /**
  256. * Function responsible for setting up the rt_sigaction syscall for
  257. * the seccomp filter sandbox.
  258. */
  259. static int
  260. sb_rt_sigaction(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
  261. {
  262. unsigned i;
  263. int rc;
  264. int param[] = { SIGINT, SIGTERM, SIGPIPE, SIGUSR1, SIGUSR2, SIGHUP, SIGCHLD,
  265. SIGSEGV, SIGILL, SIGFPE, SIGBUS, SIGSYS, SIGIO,
  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. rc = seccomp_rule_add_2(ctx, SCMP_ACT_ALLOW, SCMP_SYS(getsockopt),
  727. SCMP_CMP(1, SCMP_CMP_EQ, SOL_SOCKET),
  728. SCMP_CMP(2, SCMP_CMP_EQ, SO_ACCEPTCONN));
  729. if (rc)
  730. return rc;
  731. #ifdef HAVE_SYSTEMD
  732. rc = seccomp_rule_add_2(ctx, SCMP_ACT_ALLOW, SCMP_SYS(getsockopt),
  733. SCMP_CMP(1, SCMP_CMP_EQ, SOL_SOCKET),
  734. SCMP_CMP(2, SCMP_CMP_EQ, SO_SNDBUF));
  735. if (rc)
  736. return rc;
  737. #endif /* defined(HAVE_SYSTEMD) */
  738. #ifdef HAVE_LINUX_NETFILTER_IPV4_H
  739. rc = seccomp_rule_add_2(ctx, SCMP_ACT_ALLOW, SCMP_SYS(getsockopt),
  740. SCMP_CMP(1, SCMP_CMP_EQ, SOL_IP),
  741. SCMP_CMP(2, SCMP_CMP_EQ, SO_ORIGINAL_DST));
  742. if (rc)
  743. return rc;
  744. #endif /* defined(HAVE_LINUX_NETFILTER_IPV4_H) */
  745. #ifdef HAVE_LINUX_NETFILTER_IPV6_IP6_TABLES_H
  746. rc = seccomp_rule_add_2(ctx, SCMP_ACT_ALLOW, SCMP_SYS(getsockopt),
  747. SCMP_CMP(1, SCMP_CMP_EQ, SOL_IPV6),
  748. SCMP_CMP(2, SCMP_CMP_EQ, IP6T_SO_ORIGINAL_DST));
  749. if (rc)
  750. return rc;
  751. #endif /* defined(HAVE_LINUX_NETFILTER_IPV6_IP6_TABLES_H) */
  752. #ifdef HAVE_KIST_SUPPORT
  753. #include <netinet/tcp.h>
  754. rc = seccomp_rule_add_2(ctx, SCMP_ACT_ALLOW, SCMP_SYS(getsockopt),
  755. SCMP_CMP(1, SCMP_CMP_EQ, SOL_TCP),
  756. SCMP_CMP(2, SCMP_CMP_EQ, TCP_INFO));
  757. if (rc)
  758. return rc;
  759. #endif /* defined(HAVE_KIST_SUPPORT) */
  760. return 0;
  761. }
  762. #ifdef __NR_fcntl64
  763. /**
  764. * Function responsible for setting up the fcntl64 syscall for
  765. * the seccomp filter sandbox.
  766. */
  767. static int
  768. sb_fcntl64(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
  769. {
  770. int rc = 0;
  771. (void) filter;
  772. rc = seccomp_rule_add_1(ctx, SCMP_ACT_ALLOW, SCMP_SYS(fcntl64),
  773. SCMP_CMP(1, SCMP_CMP_EQ, F_GETFL));
  774. if (rc)
  775. return rc;
  776. rc = seccomp_rule_add_2(ctx, SCMP_ACT_ALLOW, SCMP_SYS(fcntl64),
  777. SCMP_CMP(1, SCMP_CMP_EQ, F_SETFL),
  778. SCMP_CMP(2, SCMP_CMP_EQ, O_RDWR|O_NONBLOCK));
  779. if (rc)
  780. return rc;
  781. rc = seccomp_rule_add_1(ctx, SCMP_ACT_ALLOW, SCMP_SYS(fcntl64),
  782. SCMP_CMP(1, SCMP_CMP_EQ, F_GETFD));
  783. if (rc)
  784. return rc;
  785. rc = seccomp_rule_add_2(ctx, SCMP_ACT_ALLOW, SCMP_SYS(fcntl64),
  786. SCMP_CMP(1, SCMP_CMP_EQ, F_SETFD),
  787. SCMP_CMP(2, SCMP_CMP_EQ, FD_CLOEXEC));
  788. if (rc)
  789. return rc;
  790. return 0;
  791. }
  792. #endif /* defined(__NR_fcntl64) */
  793. /**
  794. * Function responsible for setting up the epoll_ctl syscall for
  795. * the seccomp filter sandbox.
  796. *
  797. * Note: basically allows everything but will keep for now..
  798. */
  799. static int
  800. sb_epoll_ctl(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
  801. {
  802. int rc = 0;
  803. (void) filter;
  804. rc = seccomp_rule_add_1(ctx, SCMP_ACT_ALLOW, SCMP_SYS(epoll_ctl),
  805. SCMP_CMP(1, SCMP_CMP_EQ, EPOLL_CTL_ADD));
  806. if (rc)
  807. return rc;
  808. rc = seccomp_rule_add_1(ctx, SCMP_ACT_ALLOW, SCMP_SYS(epoll_ctl),
  809. SCMP_CMP(1, SCMP_CMP_EQ, EPOLL_CTL_MOD));
  810. if (rc)
  811. return rc;
  812. rc = seccomp_rule_add_1(ctx, SCMP_ACT_ALLOW, SCMP_SYS(epoll_ctl),
  813. SCMP_CMP(1, SCMP_CMP_EQ, EPOLL_CTL_DEL));
  814. if (rc)
  815. return rc;
  816. return 0;
  817. }
  818. /**
  819. * Function responsible for setting up the prctl syscall for
  820. * the seccomp filter sandbox.
  821. *
  822. * NOTE: if multiple filters need to be added, the PR_SECCOMP parameter needs
  823. * to be whitelisted in this function.
  824. */
  825. static int
  826. sb_prctl(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
  827. {
  828. int rc = 0;
  829. (void) filter;
  830. rc = seccomp_rule_add_1(ctx, SCMP_ACT_ALLOW, SCMP_SYS(prctl),
  831. SCMP_CMP(0, SCMP_CMP_EQ, PR_SET_DUMPABLE));
  832. if (rc)
  833. return rc;
  834. return 0;
  835. }
  836. /**
  837. * Function responsible for setting up the mprotect syscall for
  838. * the seccomp filter sandbox.
  839. *
  840. * NOTE: does not NEED to be here.. currently only occurs before filter; will
  841. * keep just in case for the future.
  842. */
  843. static int
  844. sb_mprotect(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
  845. {
  846. int rc = 0;
  847. (void) filter;
  848. rc = seccomp_rule_add_1(ctx, SCMP_ACT_ALLOW, SCMP_SYS(mprotect),
  849. SCMP_CMP(2, SCMP_CMP_EQ, PROT_READ));
  850. if (rc)
  851. return rc;
  852. rc = seccomp_rule_add_1(ctx, SCMP_ACT_ALLOW, SCMP_SYS(mprotect),
  853. SCMP_CMP(2, SCMP_CMP_EQ, PROT_NONE));
  854. if (rc)
  855. return rc;
  856. return 0;
  857. }
  858. /**
  859. * Function responsible for setting up the rt_sigprocmask syscall for
  860. * the seccomp filter sandbox.
  861. */
  862. static int
  863. sb_rt_sigprocmask(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
  864. {
  865. int rc = 0;
  866. (void) filter;
  867. rc = seccomp_rule_add_1(ctx, SCMP_ACT_ALLOW, SCMP_SYS(rt_sigprocmask),
  868. SCMP_CMP(0, SCMP_CMP_EQ, SIG_UNBLOCK));
  869. if (rc)
  870. return rc;
  871. rc = seccomp_rule_add_1(ctx, SCMP_ACT_ALLOW, SCMP_SYS(rt_sigprocmask),
  872. SCMP_CMP(0, SCMP_CMP_EQ, SIG_SETMASK));
  873. if (rc)
  874. return rc;
  875. return 0;
  876. }
  877. /**
  878. * Function responsible for setting up the flock syscall for
  879. * the seccomp filter sandbox.
  880. *
  881. * NOTE: does not need to be here, occurs before filter is applied.
  882. */
  883. static int
  884. sb_flock(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
  885. {
  886. int rc = 0;
  887. (void) filter;
  888. rc = seccomp_rule_add_1(ctx, SCMP_ACT_ALLOW, SCMP_SYS(flock),
  889. SCMP_CMP(1, SCMP_CMP_EQ, LOCK_EX|LOCK_NB));
  890. if (rc)
  891. return rc;
  892. rc = seccomp_rule_add_1(ctx, SCMP_ACT_ALLOW, SCMP_SYS(flock),
  893. SCMP_CMP(1, SCMP_CMP_EQ, LOCK_UN));
  894. if (rc)
  895. return rc;
  896. return 0;
  897. }
  898. /**
  899. * Function responsible for setting up the futex syscall for
  900. * the seccomp filter sandbox.
  901. */
  902. static int
  903. sb_futex(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
  904. {
  905. int rc = 0;
  906. (void) filter;
  907. // can remove
  908. rc = seccomp_rule_add_1(ctx, SCMP_ACT_ALLOW, SCMP_SYS(futex),
  909. SCMP_CMP(1, SCMP_CMP_EQ,
  910. FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME));
  911. if (rc)
  912. return rc;
  913. rc = seccomp_rule_add_1(ctx, SCMP_ACT_ALLOW, SCMP_SYS(futex),
  914. SCMP_CMP(1, SCMP_CMP_EQ, FUTEX_WAKE_PRIVATE));
  915. if (rc)
  916. return rc;
  917. rc = seccomp_rule_add_1(ctx, SCMP_ACT_ALLOW, SCMP_SYS(futex),
  918. SCMP_CMP(1, SCMP_CMP_EQ, FUTEX_WAIT_PRIVATE));
  919. if (rc)
  920. return rc;
  921. return 0;
  922. }
  923. /**
  924. * Function responsible for setting up the mremap syscall for
  925. * the seccomp filter sandbox.
  926. *
  927. * NOTE: so far only occurs before filter is applied.
  928. */
  929. static int
  930. sb_mremap(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
  931. {
  932. int rc = 0;
  933. (void) filter;
  934. rc = seccomp_rule_add_1(ctx, SCMP_ACT_ALLOW, SCMP_SYS(mremap),
  935. SCMP_CMP(3, SCMP_CMP_EQ, MREMAP_MAYMOVE));
  936. if (rc)
  937. return rc;
  938. return 0;
  939. }
  940. #ifdef __NR_stat64
  941. /**
  942. * Function responsible for setting up the stat64 syscall for
  943. * the seccomp filter sandbox.
  944. */
  945. static int
  946. sb_stat64(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
  947. {
  948. int rc = 0;
  949. sandbox_cfg_t *elem = NULL;
  950. // for each dynamic parameter filters
  951. for (elem = filter; elem != NULL; elem = elem->next) {
  952. smp_param_t *param = elem->param;
  953. if (param != NULL && param->prot == 1 && (param->syscall == SCMP_SYS(open)
  954. || param->syscall == SCMP_SYS(stat64))) {
  955. rc = seccomp_rule_add_1(ctx, SCMP_ACT_ALLOW, SCMP_SYS(stat64),
  956. SCMP_CMP_STR(0, SCMP_CMP_EQ, param->value));
  957. if (rc != 0) {
  958. log_err(LD_BUG,"(Sandbox) failed to add stat64 syscall, received "
  959. "libseccomp error %d", rc);
  960. return rc;
  961. }
  962. }
  963. }
  964. return 0;
  965. }
  966. #endif /* defined(__NR_stat64) */
  967. static int
  968. sb_kill(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
  969. {
  970. (void) filter;
  971. #ifdef __NR_kill
  972. /* Allow killing anything with signal 0 -- it isn't really a kill. */
  973. return seccomp_rule_add_1(ctx, SCMP_ACT_ALLOW, SCMP_SYS(kill),
  974. SCMP_CMP(1, SCMP_CMP_EQ, 0));
  975. #else
  976. return 0;
  977. #endif /* defined(__NR_kill) */
  978. }
  979. /**
  980. * Array of function pointers responsible for filtering different syscalls at
  981. * a parameter level.
  982. */
  983. static sandbox_filter_func_t filter_func[] = {
  984. sb_rt_sigaction,
  985. sb_rt_sigprocmask,
  986. sb_time,
  987. sb_accept4,
  988. #ifdef __NR_mmap2
  989. sb_mmap2,
  990. #endif
  991. sb_chown,
  992. sb_chmod,
  993. sb_open,
  994. sb_openat,
  995. sb__sysctl,
  996. sb_rename,
  997. #ifdef __NR_fcntl64
  998. sb_fcntl64,
  999. #endif
  1000. sb_epoll_ctl,
  1001. sb_prctl,
  1002. sb_mprotect,
  1003. sb_flock,
  1004. sb_futex,
  1005. sb_mremap,
  1006. #ifdef __NR_stat64
  1007. sb_stat64,
  1008. #endif
  1009. sb_socket,
  1010. sb_setsockopt,
  1011. sb_getsockopt,
  1012. sb_socketpair,
  1013. #ifdef HAVE_KIST_SUPPORT
  1014. sb_ioctl,
  1015. #endif
  1016. sb_kill
  1017. };
  1018. const char *
  1019. sandbox_intern_string(const char *str)
  1020. {
  1021. sandbox_cfg_t *elem;
  1022. if (str == NULL)
  1023. return NULL;
  1024. for (elem = filter_dynamic; elem != NULL; elem = elem->next) {
  1025. smp_param_t *param = elem->param;
  1026. if (param->prot) {
  1027. if (!strcmp(str, (char*)(param->value))) {
  1028. return (char*)param->value;
  1029. }
  1030. if (param->value2 && !strcmp(str, (char*)param->value2)) {
  1031. return (char*)param->value2;
  1032. }
  1033. }
  1034. }
  1035. if (sandbox_active)
  1036. log_warn(LD_BUG, "No interned sandbox parameter found for %s", str);
  1037. return str;
  1038. }
  1039. /* DOCDOC */
  1040. static int
  1041. prot_strings_helper(strmap_t *locations,
  1042. char **pr_mem_next_p,
  1043. size_t *pr_mem_left_p,
  1044. char **value_p)
  1045. {
  1046. char *param_val;
  1047. size_t param_size;
  1048. void *location;
  1049. if (*value_p == 0)
  1050. return 0;
  1051. param_val = (char*) *value_p;
  1052. param_size = strlen(param_val) + 1;
  1053. location = strmap_get(locations, param_val);
  1054. if (location) {
  1055. // We already interned this string.
  1056. tor_free(param_val);
  1057. *value_p = location;
  1058. return 0;
  1059. } else if (*pr_mem_left_p >= param_size) {
  1060. // copy to protected
  1061. location = *pr_mem_next_p;
  1062. memcpy(location, param_val, param_size);
  1063. // re-point el parameter to protected
  1064. tor_free(param_val);
  1065. *value_p = location;
  1066. strmap_set(locations, location, location); /* good real estate advice */
  1067. // move next available protected memory
  1068. *pr_mem_next_p += param_size;
  1069. *pr_mem_left_p -= param_size;
  1070. return 0;
  1071. } else {
  1072. log_err(LD_BUG,"(Sandbox) insufficient protected memory!");
  1073. return -1;
  1074. }
  1075. }
  1076. /**
  1077. * Protects all the strings in the sandbox's parameter list configuration. It
  1078. * works by calculating the total amount of memory required by the parameter
  1079. * list, allocating the memory using mmap, and protecting it from writes with
  1080. * mprotect().
  1081. */
  1082. static int
  1083. prot_strings(scmp_filter_ctx ctx, sandbox_cfg_t* cfg)
  1084. {
  1085. int ret = 0;
  1086. size_t pr_mem_size = 0, pr_mem_left = 0;
  1087. char *pr_mem_next = NULL, *pr_mem_base;
  1088. sandbox_cfg_t *el = NULL;
  1089. strmap_t *locations = NULL;
  1090. // get total number of bytes required to mmap. (Overestimate.)
  1091. for (el = cfg; el != NULL; el = el->next) {
  1092. pr_mem_size += strlen((char*) el->param->value) + 1;
  1093. if (el->param->value2)
  1094. pr_mem_size += strlen((char*) el->param->value2) + 1;
  1095. }
  1096. // allocate protected memory with MALLOC_MP_LIM canary
  1097. pr_mem_base = (char*) mmap(NULL, MALLOC_MP_LIM + pr_mem_size,
  1098. PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
  1099. if (pr_mem_base == MAP_FAILED) {
  1100. log_err(LD_BUG,"(Sandbox) failed allocate protected memory! mmap: %s",
  1101. strerror(errno));
  1102. ret = -1;
  1103. goto out;
  1104. }
  1105. pr_mem_next = pr_mem_base + MALLOC_MP_LIM;
  1106. pr_mem_left = pr_mem_size;
  1107. locations = strmap_new();
  1108. // change el value pointer to protected
  1109. for (el = cfg; el != NULL; el = el->next) {
  1110. if (prot_strings_helper(locations, &pr_mem_next, &pr_mem_left,
  1111. &el->param->value) < 0) {
  1112. ret = -2;
  1113. goto out;
  1114. }
  1115. if (prot_strings_helper(locations, &pr_mem_next, &pr_mem_left,
  1116. &el->param->value2) < 0) {
  1117. ret = -2;
  1118. goto out;
  1119. }
  1120. el->param->prot = 1;
  1121. }
  1122. // protecting from writes
  1123. if (mprotect(pr_mem_base, MALLOC_MP_LIM + pr_mem_size, PROT_READ)) {
  1124. log_err(LD_BUG,"(Sandbox) failed to protect memory! mprotect: %s",
  1125. strerror(errno));
  1126. ret = -3;
  1127. goto out;
  1128. }
  1129. /*
  1130. * Setting sandbox restrictions so the string memory cannot be tampered with
  1131. */
  1132. // no mremap of the protected base address
  1133. ret = seccomp_rule_add_1(ctx, SCMP_ACT_KILL, SCMP_SYS(mremap),
  1134. SCMP_CMP(0, SCMP_CMP_EQ, (intptr_t) pr_mem_base));
  1135. if (ret) {
  1136. log_err(LD_BUG,"(Sandbox) mremap protected memory filter fail!");
  1137. goto out;
  1138. }
  1139. // no munmap of the protected base address
  1140. ret = seccomp_rule_add_1(ctx, SCMP_ACT_KILL, SCMP_SYS(munmap),
  1141. SCMP_CMP(0, SCMP_CMP_EQ, (intptr_t) pr_mem_base));
  1142. if (ret) {
  1143. log_err(LD_BUG,"(Sandbox) munmap protected memory filter fail!");
  1144. goto out;
  1145. }
  1146. /*
  1147. * Allow mprotect with PROT_READ|PROT_WRITE because openssl uses it, but
  1148. * never over the memory region used by the protected strings.
  1149. *
  1150. * PROT_READ|PROT_WRITE was originally fully allowed in sb_mprotect(), but
  1151. * had to be removed due to limitation of libseccomp regarding intervals.
  1152. *
  1153. * There is a restriction on how much you can mprotect with R|W up to the
  1154. * size of the canary.
  1155. */
  1156. ret = seccomp_rule_add_3(ctx, SCMP_ACT_ALLOW, SCMP_SYS(mprotect),
  1157. SCMP_CMP(0, SCMP_CMP_LT, (intptr_t) pr_mem_base),
  1158. SCMP_CMP(1, SCMP_CMP_LE, MALLOC_MP_LIM),
  1159. SCMP_CMP(2, SCMP_CMP_EQ, PROT_READ|PROT_WRITE));
  1160. if (ret) {
  1161. log_err(LD_BUG,"(Sandbox) mprotect protected memory filter fail (LT)!");
  1162. goto out;
  1163. }
  1164. ret = seccomp_rule_add_3(ctx, SCMP_ACT_ALLOW, SCMP_SYS(mprotect),
  1165. SCMP_CMP(0, SCMP_CMP_GT, (intptr_t) pr_mem_base + pr_mem_size +
  1166. MALLOC_MP_LIM),
  1167. SCMP_CMP(1, SCMP_CMP_LE, MALLOC_MP_LIM),
  1168. SCMP_CMP(2, SCMP_CMP_EQ, PROT_READ|PROT_WRITE));
  1169. if (ret) {
  1170. log_err(LD_BUG,"(Sandbox) mprotect protected memory filter fail (GT)!");
  1171. goto out;
  1172. }
  1173. out:
  1174. strmap_free(locations, NULL);
  1175. return ret;
  1176. }
  1177. /**
  1178. * Auxiliary function used in order to allocate a sandbox_cfg_t element and set
  1179. * its values according the parameter list. All elements are initialised
  1180. * with the 'prot' field set to false, as the pointer is not protected at this
  1181. * point.
  1182. */
  1183. static sandbox_cfg_t*
  1184. new_element2(int syscall, char *value, char *value2)
  1185. {
  1186. smp_param_t *param = NULL;
  1187. sandbox_cfg_t *elem = tor_malloc_zero(sizeof(sandbox_cfg_t));
  1188. param = elem->param = tor_malloc_zero(sizeof(smp_param_t));
  1189. param->syscall = syscall;
  1190. param->value = value;
  1191. param->value2 = value2;
  1192. param->prot = 0;
  1193. return elem;
  1194. }
  1195. static sandbox_cfg_t*
  1196. new_element(int syscall, char *value)
  1197. {
  1198. return new_element2(syscall, value, NULL);
  1199. }
  1200. #ifdef __NR_stat64
  1201. #define SCMP_stat SCMP_SYS(stat64)
  1202. #else
  1203. #define SCMP_stat SCMP_SYS(stat)
  1204. #endif
  1205. int
  1206. sandbox_cfg_allow_stat_filename(sandbox_cfg_t **cfg, char *file)
  1207. {
  1208. sandbox_cfg_t *elem = NULL;
  1209. elem = new_element(SCMP_stat, file);
  1210. elem->next = *cfg;
  1211. *cfg = elem;
  1212. return 0;
  1213. }
  1214. int
  1215. sandbox_cfg_allow_open_filename(sandbox_cfg_t **cfg, char *file)
  1216. {
  1217. sandbox_cfg_t *elem = NULL;
  1218. elem = new_element(SCMP_SYS(open), file);
  1219. elem->next = *cfg;
  1220. *cfg = elem;
  1221. return 0;
  1222. }
  1223. int
  1224. sandbox_cfg_allow_chmod_filename(sandbox_cfg_t **cfg, char *file)
  1225. {
  1226. sandbox_cfg_t *elem = NULL;
  1227. elem = new_element(SCMP_SYS(chmod), file);
  1228. elem->next = *cfg;
  1229. *cfg = elem;
  1230. return 0;
  1231. }
  1232. int
  1233. sandbox_cfg_allow_chown_filename(sandbox_cfg_t **cfg, char *file)
  1234. {
  1235. sandbox_cfg_t *elem = NULL;
  1236. elem = new_element(SCMP_SYS(chown), file);
  1237. elem->next = *cfg;
  1238. *cfg = elem;
  1239. return 0;
  1240. }
  1241. int
  1242. sandbox_cfg_allow_rename(sandbox_cfg_t **cfg, char *file1, char *file2)
  1243. {
  1244. sandbox_cfg_t *elem = NULL;
  1245. elem = new_element2(SCMP_SYS(rename), file1, file2);
  1246. elem->next = *cfg;
  1247. *cfg = elem;
  1248. return 0;
  1249. }
  1250. int
  1251. sandbox_cfg_allow_openat_filename(sandbox_cfg_t **cfg, char *file)
  1252. {
  1253. sandbox_cfg_t *elem = NULL;
  1254. elem = new_element(SCMP_SYS(openat), file);
  1255. elem->next = *cfg;
  1256. *cfg = elem;
  1257. return 0;
  1258. }
  1259. /**
  1260. * Function responsible for going through the parameter syscall filters and
  1261. * call each function pointer in the list.
  1262. */
  1263. static int
  1264. add_param_filter(scmp_filter_ctx ctx, sandbox_cfg_t* cfg)
  1265. {
  1266. unsigned i;
  1267. int rc = 0;
  1268. // function pointer
  1269. for (i = 0; i < ARRAY_LENGTH(filter_func); i++) {
  1270. rc = filter_func[i](ctx, cfg);
  1271. if (rc) {
  1272. log_err(LD_BUG,"(Sandbox) failed to add syscall %d, received libseccomp "
  1273. "error %d", i, rc);
  1274. return rc;
  1275. }
  1276. }
  1277. return 0;
  1278. }
  1279. /**
  1280. * Function responsible of loading the libseccomp syscall filters which do not
  1281. * have parameter filtering.
  1282. */
  1283. static int
  1284. add_noparam_filter(scmp_filter_ctx ctx)
  1285. {
  1286. unsigned i;
  1287. int rc = 0;
  1288. // add general filters
  1289. for (i = 0; i < ARRAY_LENGTH(filter_nopar_gen); i++) {
  1290. rc = seccomp_rule_add_0(ctx, SCMP_ACT_ALLOW, filter_nopar_gen[i]);
  1291. if (rc != 0) {
  1292. log_err(LD_BUG,"(Sandbox) failed to add syscall index %d (NR=%d), "
  1293. "received libseccomp error %d", i, filter_nopar_gen[i], rc);
  1294. return rc;
  1295. }
  1296. }
  1297. return 0;
  1298. }
  1299. /**
  1300. * Function responsible for setting up and enabling a global syscall filter.
  1301. * The function is a prototype developed for stage 1 of sandboxing Tor.
  1302. * Returns 0 on success.
  1303. */
  1304. static int
  1305. install_syscall_filter(sandbox_cfg_t* cfg)
  1306. {
  1307. int rc = 0;
  1308. scmp_filter_ctx ctx;
  1309. ctx = seccomp_init(SCMP_ACT_TRAP);
  1310. if (ctx == NULL) {
  1311. log_err(LD_BUG,"(Sandbox) failed to initialise libseccomp context");
  1312. rc = -1;
  1313. goto end;
  1314. }
  1315. // protectign sandbox parameter strings
  1316. if ((rc = prot_strings(ctx, cfg))) {
  1317. goto end;
  1318. }
  1319. // add parameter filters
  1320. if ((rc = add_param_filter(ctx, cfg))) {
  1321. log_err(LD_BUG, "(Sandbox) failed to add param filters!");
  1322. goto end;
  1323. }
  1324. // adding filters with no parameters
  1325. if ((rc = add_noparam_filter(ctx))) {
  1326. log_err(LD_BUG, "(Sandbox) failed to add param filters!");
  1327. goto end;
  1328. }
  1329. // loading the seccomp2 filter
  1330. if ((rc = seccomp_load(ctx))) {
  1331. log_err(LD_BUG, "(Sandbox) failed to load: %d (%s)! "
  1332. "Are you sure that your kernel has seccomp2 support? The "
  1333. "sandbox won't work without it.", rc,
  1334. strerror(-rc));
  1335. goto end;
  1336. }
  1337. // marking the sandbox as active
  1338. sandbox_active = 1;
  1339. end:
  1340. seccomp_release(ctx);
  1341. return (rc < 0 ? -rc : rc);
  1342. }
  1343. #include "lib/sandbox/linux_syscalls.inc"
  1344. static const char *
  1345. get_syscall_name(int syscall_num)
  1346. {
  1347. int i;
  1348. for (i = 0; SYSCALLS_BY_NUMBER[i].syscall_name; ++i) {
  1349. if (SYSCALLS_BY_NUMBER[i].syscall_num == syscall_num)
  1350. return SYSCALLS_BY_NUMBER[i].syscall_name;
  1351. }
  1352. {
  1353. static char syscall_name_buf[64];
  1354. format_dec_number_sigsafe(syscall_num,
  1355. syscall_name_buf, sizeof(syscall_name_buf));
  1356. return syscall_name_buf;
  1357. }
  1358. }
  1359. #ifdef USE_BACKTRACE
  1360. #define MAX_DEPTH 256
  1361. static void *syscall_cb_buf[MAX_DEPTH];
  1362. #endif
  1363. /**
  1364. * Function called when a SIGSYS is caught by the application. It notifies the
  1365. * user that an error has occurred and either terminates or allows the
  1366. * application to continue execution, based on the DEBUGGING_CLOSE symbol.
  1367. */
  1368. static void
  1369. sigsys_debugging(int nr, siginfo_t *info, void *void_context)
  1370. {
  1371. ucontext_t *ctx = (ucontext_t *) (void_context);
  1372. const char *syscall_name;
  1373. int syscall;
  1374. #ifdef USE_BACKTRACE
  1375. size_t depth;
  1376. int n_fds, i;
  1377. const int *fds = NULL;
  1378. #endif
  1379. (void) nr;
  1380. if (info->si_code != SYS_SECCOMP)
  1381. return;
  1382. if (!ctx)
  1383. return;
  1384. syscall = (int) ctx->uc_mcontext.M_SYSCALL;
  1385. #ifdef USE_BACKTRACE
  1386. depth = backtrace(syscall_cb_buf, MAX_DEPTH);
  1387. /* Clean up the top stack frame so we get the real function
  1388. * name for the most recently failing function. */
  1389. clean_backtrace(syscall_cb_buf, depth, ctx);
  1390. #endif /* defined(USE_BACKTRACE) */
  1391. syscall_name = get_syscall_name(syscall);
  1392. tor_log_err_sigsafe("(Sandbox) Caught a bad syscall attempt (syscall ",
  1393. syscall_name,
  1394. ")\n",
  1395. NULL);
  1396. #ifdef USE_BACKTRACE
  1397. n_fds = tor_log_get_sigsafe_err_fds(&fds);
  1398. for (i=0; i < n_fds; ++i)
  1399. backtrace_symbols_fd(syscall_cb_buf, (int)depth, fds[i]);
  1400. #endif
  1401. #if defined(DEBUGGING_CLOSE)
  1402. _exit(1); // exit ok: programming error has led to sandbox failure.
  1403. #endif // DEBUGGING_CLOSE
  1404. }
  1405. /**
  1406. * Function that adds a handler for SIGSYS, which is the signal thrown
  1407. * when the application is issuing a syscall which is not allowed. The
  1408. * main purpose of this function is to help with debugging by identifying
  1409. * filtered syscalls.
  1410. */
  1411. static int
  1412. install_sigsys_debugging(void)
  1413. {
  1414. struct sigaction act;
  1415. sigset_t mask;
  1416. memset(&act, 0, sizeof(act));
  1417. sigemptyset(&mask);
  1418. sigaddset(&mask, SIGSYS);
  1419. act.sa_sigaction = &sigsys_debugging;
  1420. act.sa_flags = SA_SIGINFO;
  1421. if (sigaction(SIGSYS, &act, NULL) < 0) {
  1422. log_err(LD_BUG,"(Sandbox) Failed to register SIGSYS signal handler");
  1423. return -1;
  1424. }
  1425. if (sigprocmask(SIG_UNBLOCK, &mask, NULL)) {
  1426. log_err(LD_BUG,"(Sandbox) Failed call to sigprocmask()");
  1427. return -2;
  1428. }
  1429. return 0;
  1430. }
  1431. /**
  1432. * Function responsible of registering the sandbox_cfg_t list of parameter
  1433. * syscall filters to the existing parameter list. This is used for incipient
  1434. * multiple-sandbox support.
  1435. */
  1436. static int
  1437. register_cfg(sandbox_cfg_t* cfg)
  1438. {
  1439. sandbox_cfg_t *elem = NULL;
  1440. if (filter_dynamic == NULL) {
  1441. filter_dynamic = cfg;
  1442. return 0;
  1443. }
  1444. for (elem = filter_dynamic; elem->next != NULL; elem = elem->next)
  1445. ;
  1446. elem->next = cfg;
  1447. return 0;
  1448. }
  1449. #endif /* defined(USE_LIBSECCOMP) */
  1450. #ifdef USE_LIBSECCOMP
  1451. /**
  1452. * Initialises the syscall sandbox filter for any linux architecture, taking
  1453. * into account various available features for different linux flavours.
  1454. */
  1455. static int
  1456. initialise_libseccomp_sandbox(sandbox_cfg_t* cfg)
  1457. {
  1458. /* Prevent glibc from trying to open /dev/tty on fatal error */
  1459. setenv("LIBC_FATAL_STDERR_", "1", 1);
  1460. if (install_sigsys_debugging())
  1461. return -1;
  1462. if (install_syscall_filter(cfg))
  1463. return -2;
  1464. if (register_cfg(cfg))
  1465. return -3;
  1466. return 0;
  1467. }
  1468. int
  1469. sandbox_is_active(void)
  1470. {
  1471. return sandbox_active != 0;
  1472. }
  1473. #endif /* defined(USE_LIBSECCOMP) */
  1474. sandbox_cfg_t*
  1475. sandbox_cfg_new(void)
  1476. {
  1477. return NULL;
  1478. }
  1479. int
  1480. sandbox_init(sandbox_cfg_t *cfg)
  1481. {
  1482. #if defined(USE_LIBSECCOMP)
  1483. return initialise_libseccomp_sandbox(cfg);
  1484. #elif defined(__linux__)
  1485. (void)cfg;
  1486. log_warn(LD_GENERAL,
  1487. "This version of Tor was built without support for sandboxing. To "
  1488. "build with support for sandboxing on Linux, you must have "
  1489. "libseccomp and its necessary header files (e.g. seccomp.h).");
  1490. return 0;
  1491. #else
  1492. (void)cfg;
  1493. log_warn(LD_GENERAL,
  1494. "Currently, sandboxing is only implemented on Linux. The feature "
  1495. "is disabled on your platform.");
  1496. return 0;
  1497. #endif /* defined(USE_LIBSECCOMP) || ... */
  1498. }
  1499. #ifndef USE_LIBSECCOMP
  1500. int
  1501. sandbox_cfg_allow_open_filename(sandbox_cfg_t **cfg, char *file)
  1502. {
  1503. (void)cfg; (void)file;
  1504. return 0;
  1505. }
  1506. int
  1507. sandbox_cfg_allow_openat_filename(sandbox_cfg_t **cfg, char *file)
  1508. {
  1509. (void)cfg; (void)file;
  1510. return 0;
  1511. }
  1512. int
  1513. sandbox_cfg_allow_stat_filename(sandbox_cfg_t **cfg, char *file)
  1514. {
  1515. (void)cfg; (void)file;
  1516. return 0;
  1517. }
  1518. int
  1519. sandbox_cfg_allow_chown_filename(sandbox_cfg_t **cfg, char *file)
  1520. {
  1521. (void)cfg; (void)file;
  1522. return 0;
  1523. }
  1524. int
  1525. sandbox_cfg_allow_chmod_filename(sandbox_cfg_t **cfg, char *file)
  1526. {
  1527. (void)cfg; (void)file;
  1528. return 0;
  1529. }
  1530. int
  1531. sandbox_cfg_allow_rename(sandbox_cfg_t **cfg, char *file1, char *file2)
  1532. {
  1533. (void)cfg; (void)file1; (void)file2;
  1534. return 0;
  1535. }
  1536. int
  1537. sandbox_is_active(void)
  1538. {
  1539. return 0;
  1540. }
  1541. #endif /* !defined(USE_LIBSECCOMP) */