-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cdd3dc2
commit 57ac33a
Showing
4 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include <stdio.h> | ||
#include <seccomp.h> | ||
#include <sys/types.h> | ||
#include <sys/stat.h> | ||
#include <fcntl.h> | ||
#include <errno.h> | ||
|
||
#include "../runner.h" | ||
|
||
|
||
int golang_seccomp_rules(struct config *_config) { | ||
int syscalls_blacklist[] = {SCMP_SYS(socket), | ||
SCMP_SYS(fork), SCMP_SYS(vfork), | ||
SCMP_SYS(kill), | ||
#ifdef __NR_execveat | ||
SCMP_SYS(execveat) | ||
#endif | ||
}; | ||
int syscalls_blacklist_length = sizeof(syscalls_blacklist) / sizeof(int); | ||
scmp_filter_ctx ctx = NULL; | ||
// load seccomp rules | ||
ctx = seccomp_init(SCMP_ACT_ALLOW); | ||
if (!ctx) { | ||
return LOAD_SECCOMP_FAILED; | ||
} | ||
for (int i = 0; i < syscalls_blacklist_length; i++) { | ||
if (seccomp_rule_add(ctx, SCMP_ACT_KILL, syscalls_blacklist[i], 0) != 0) { | ||
return LOAD_SECCOMP_FAILED; | ||
} | ||
} | ||
// do not allow "w" and "rw" using open | ||
if (seccomp_rule_add(ctx, SCMP_ACT_KILL, SCMP_SYS(open), 1, SCMP_CMP(1, SCMP_CMP_MASKED_EQ, O_WRONLY, O_WRONLY)) != 0) { | ||
return LOAD_SECCOMP_FAILED; | ||
} | ||
if (seccomp_rule_add(ctx, SCMP_ACT_KILL, SCMP_SYS(open), 1, SCMP_CMP(1, SCMP_CMP_MASKED_EQ, O_RDWR, O_RDWR)) != 0) { | ||
return LOAD_SECCOMP_FAILED; | ||
} | ||
// do not allow "w" and "rw" using openat | ||
if (seccomp_rule_add(ctx, SCMP_ACT_KILL, SCMP_SYS(openat), 1, SCMP_CMP(2, SCMP_CMP_MASKED_EQ, O_WRONLY, O_WRONLY)) != 0) { | ||
return LOAD_SECCOMP_FAILED; | ||
} | ||
if (seccomp_rule_add(ctx, SCMP_ACT_KILL, SCMP_SYS(openat), 1, SCMP_CMP(2, SCMP_CMP_MASKED_EQ, O_RDWR, O_RDWR)) != 0) { | ||
return LOAD_SECCOMP_FAILED; | ||
} | ||
|
||
if (seccomp_load(ctx) != 0) { | ||
return LOAD_SECCOMP_FAILED; | ||
} | ||
seccomp_release(ctx); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include <stdio.h> | ||
#include <seccomp.h> | ||
#include <sys/types.h> | ||
#include <sys/stat.h> | ||
#include <fcntl.h> | ||
#include <errno.h> | ||
|
||
#include "../runner.h" | ||
|
||
|
||
int node_seccomp_rules(struct config *_config) { | ||
int syscalls_blacklist[] = {SCMP_SYS(socket), | ||
SCMP_SYS(fork), SCMP_SYS(vfork), | ||
SCMP_SYS(kill), | ||
#ifdef __NR_execveat | ||
SCMP_SYS(execveat) | ||
#endif | ||
}; | ||
int syscalls_blacklist_length = sizeof(syscalls_blacklist) / sizeof(int); | ||
scmp_filter_ctx ctx = NULL; | ||
// load seccomp rules | ||
ctx = seccomp_init(SCMP_ACT_ALLOW); | ||
if (!ctx) { | ||
return LOAD_SECCOMP_FAILED; | ||
} | ||
for (int i = 0; i < syscalls_blacklist_length; i++) { | ||
if (seccomp_rule_add(ctx, SCMP_ACT_KILL, syscalls_blacklist[i], 0) != 0) { | ||
return LOAD_SECCOMP_FAILED; | ||
} | ||
} | ||
if (seccomp_load(ctx) != 0) { | ||
return LOAD_SECCOMP_FAILED; | ||
} | ||
seccomp_release(ctx); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters