Skip to content

Commit 5dcf8cd

Browse files
committed
main: make the set of system calls allowed in sandbox tunable
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
1 parent c7c9014 commit 5dcf8cd

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

main/interactive_p.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ bool jsonErrorPrinter (const errorSelection selection, const char *const format,
3131
#endif
3232

3333
void interactiveOneshot (cookedArgs *args, void *user);
34-
int installSyscallFilter (void);
34+
35+
enum syscallSet {
36+
syscall_coreset = 1 << 0,
37+
};
38+
39+
int installSyscallFilter (unsigned int set);
3540

3641
#endif /* CTAGS_MAIN_INTERACTIVE_H */
3742

main/main.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,9 @@ static void batchMakeTags (cookedArgs *args, void *user CTAGS_ATTR_UNUSED)
391391
#undef timeStamp
392392
}
393393

394-
static void prepareSandbox (void)
394+
static void prepareSandbox (unsigned int set)
395395
{
396-
if (installSyscallFilter ()) {
396+
if (installSyscallFilter (set)) {
397397
error (FATAL, "install_syscall_filter failed");
398398
/* The explicit exit call is needed because
399399
"error (FATAL,..." just prints a message in
@@ -408,7 +408,7 @@ void interactiveLoop (cookedArgs *args CTAGS_ATTR_UNUSED, void *user)
408408
struct interactiveModeArgs *iargs = user;
409409

410410
if (iargs->sandbox)
411-
prepareSandbox ();
411+
prepareSandbox (syscall_coreset);
412412

413413
char buffer[1024];
414414
json_t *request;
@@ -521,7 +521,7 @@ extern void interactiveOneshot (cookedArgs *args CTAGS_ATTR_UNUSED, void *user)
521521
Assert (iargs->fname);
522522

523523
if (iargs->sandbox)
524-
prepareSandbox ();
524+
prepareSandbox (syscall_coreset);
525525

526526
oneshotCommon (iargs->fname, iargs->limit, iargs->sandbox);
527527
}

main/seccomp.c

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,8 @@
1717
#include <seccomp.h>
1818

1919

20-
int installSyscallFilter (void)
20+
static void installSyscallCoresetFilter(scmp_filter_ctx ctx)
2121
{
22-
// Use SCMP_ACT_TRAP to get a core dump.
23-
scmp_filter_ctx ctx = seccomp_init (SCMP_ACT_KILL);
24-
if (ctx == NULL)
25-
{
26-
return 1;
27-
}
28-
2922
// Memory allocation.
3023
seccomp_rule_add (ctx, SCMP_ACT_ALLOW, SCMP_SYS (mmap), 0);
3124
seccomp_rule_add (ctx, SCMP_ACT_ALLOW, SCMP_SYS (munmap), 0);
@@ -61,7 +54,23 @@ int installSyscallFilter (void)
6154
// libxml2 uses pthread_once, which in turn uses a futex
6255
seccomp_rule_add (ctx, SCMP_ACT_ALLOW, SCMP_SYS (futex), 0);
6356

64-
verbose ("Entering sandbox\n");
57+
verbose ("coreset ");
58+
}
59+
60+
int installSyscallFilter (unsigned int set)
61+
{
62+
// Use SCMP_ACT_TRAP to get a core dump.
63+
scmp_filter_ctx ctx = seccomp_init (SCMP_ACT_KILL);
64+
if (ctx == NULL)
65+
{
66+
return 1;
67+
}
68+
69+
verbose ("Entering sandbox (");
70+
if (set & syscall_coreset)
71+
installSyscallCoresetFilter (ctx);
72+
verbose (")\n");
73+
6574
int err = seccomp_load (ctx);
6675
if (err < 0)
6776
{
@@ -81,7 +90,7 @@ int installSyscallFilter (void)
8190
*/
8291

8392
#else
84-
int installSyscallFilter (void)
93+
int installSyscallFilter (unsigned int set)
8594
{
8695
AssertNotReached ();
8796
return -1;

0 commit comments

Comments
 (0)