Update to version p5.9.20211031.0 of ctags
[geany-mirror.git] / ctags / main / seccomp.c
blobf87b35351301886a1aa3fc22b96b5c773d2ba097
1 /*
2 * Copyright (c) 2017, Google, Inc.
4 * Author: Han-Wen Nienhuys <hanwen@google.com>
6 * This source code is released for free distribution under the terms of the
7 * GNU General Public License version 2 or (at your option) any later version.
9 */
11 #include "general.h"
12 #include "debug.h"
13 #include "interactive_p.h"
14 #include "routines.h"
16 #ifdef HAVE_SECCOMP
17 #include <seccomp.h>
20 int installSyscallFilter (void)
22 // Use SCMP_ACT_TRAP to get a core dump.
23 scmp_filter_ctx ctx = seccomp_init (SCMP_ACT_KILL);
24 if (ctx == NULL)
26 return 1;
29 // Memory allocation.
30 seccomp_rule_add (ctx, SCMP_ACT_ALLOW, SCMP_SYS (mmap), 0);
31 seccomp_rule_add (ctx, SCMP_ACT_ALLOW, SCMP_SYS (munmap), 0);
32 seccomp_rule_add (ctx, SCMP_ACT_ALLOW, SCMP_SYS (mremap), 0);
33 seccomp_rule_add (ctx, SCMP_ACT_ALLOW, SCMP_SYS (brk), 0);
35 // I/O
36 seccomp_rule_add (ctx, SCMP_ACT_ALLOW, SCMP_SYS (read), 0);
37 seccomp_rule_add (ctx, SCMP_ACT_ALLOW, SCMP_SYS (write), 0);
39 // Clean exit
40 seccomp_rule_add (ctx, SCMP_ACT_ALLOW, SCMP_SYS (exit), 0);
41 seccomp_rule_add (ctx, SCMP_ACT_ALLOW, SCMP_SYS (exit_group), 0);
43 // The bowels of stdio want to know the size of a file, even for stdout.
44 seccomp_rule_add (ctx, SCMP_ACT_ALLOW, SCMP_SYS (fstat), 0);
45 seccomp_rule_add (ctx, SCMP_ACT_ALLOW, SCMP_SYS (fstat64), 0);
46 #ifdef __SNR_newfstatat
47 seccomp_rule_add (ctx, SCMP_ACT_ALLOW, SCMP_SYS (newfstatat), 0);
48 #endif
49 #ifdef __SNR_statx
50 // armhf fallback
51 seccomp_rule_add (ctx, SCMP_ACT_ALLOW, SCMP_SYS (statx), 0);
52 #endif
54 // seems unnecessary, but this comes from
55 // main/parse.c:2764 : tagFilePosition (&tagfpos);
56 seccomp_rule_add (ctx, SCMP_ACT_ALLOW, SCMP_SYS (lseek), 0);
57 seccomp_rule_add (ctx, SCMP_ACT_ALLOW, SCMP_SYS (_llseek), 0);
59 // libxml2 uses pthread_once, which in turn uses a futex
60 seccomp_rule_add (ctx, SCMP_ACT_ALLOW, SCMP_SYS (futex), 0);
62 verbose ("Entering sandbox\n");
63 int err = seccomp_load (ctx);
64 if (err < 0)
66 error (WARNING, "Failed to install syscall filter");
67 /* Error handling is done in upper layer. */
70 seccomp_release (ctx);
72 return err;
76 TODO: on OSX, Seatbelt
77 (https://dev.chromium.org/developers/design-documents/sandbox/osx-sandboxing-design)
78 should be used for equivalent functionality.
81 #else
82 int installSyscallFilter (void)
84 AssertNotReached ();
85 return -1;
87 #endif