};
static int
-sb_rt_sigaction(scmp_filter_ctx ctx)
+sb_rt_sigaction(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
{
int i, rc;
int param[] = { SIGINT, SIGTERM, SIGPIPE, SIGUSR1, SIGUSR2, SIGHUP, SIGCHLD,
}
static int
-sb_execve(scmp_filter_ctx ctx)
+sb_execve(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
{
int rc;
- sandbox_cfg_t *elem;
+ sandbox_cfg_t *elem = NULL;
// for each dynamic parameter filters
- elem = filter_dynamic;
- for (; elem != NULL; elem = elem->next) {
+ for (elem = filter; elem != NULL; elem = elem->next) {
if (elem->prot == 1 && elem->syscall == SCMP_SYS(execve)) {
rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(execve), 1,
SCMP_CMP(0, SCMP_CMP_EQ, elem->param));
if (rc != 0) {
- log_err(LD_BUG,"(Sandbox) failed to add syscall, received libseccomp "
+ log_err(LD_BUG,"(Sandbox) failed to add execve syscall, received libseccomp "
"error %d", rc);
return rc;
}
}
static int
-sb_time(scmp_filter_ctx ctx)
+sb_time(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
{
return seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(time), 1,
SCMP_CMP(0, SCMP_CMP_EQ, 0));
}
static int
-sb_accept4(scmp_filter_ctx ctx)
+sb_accept4(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
{
return seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(socketcall), 1,
SCMP_CMP(0, SCMP_CMP_EQ, 18));
#ifdef __NR_mmap2
static int
-sb_mmap2(scmp_filter_ctx ctx)
+sb_mmap2(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
{
int rc = 0;
// TODO parameters
static int
-sb_open(scmp_filter_ctx ctx)
+sb_open(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
{
int rc;
- sandbox_cfg_t *elem;
+ sandbox_cfg_t *elem = NULL;
// for each dynamic parameter filters
- elem = filter_dynamic;
- for (; elem != NULL; elem = elem->next) {
+ for (elem = filter; elem != NULL; elem = elem->next) {
if (elem->prot == 1 && elem->syscall == SCMP_SYS(open)) {
rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(open), 1,
SCMP_CMP(0, SCMP_CMP_EQ, elem->param));
if (rc != 0) {
- log_err(LD_BUG,"(Sandbox) failed to add syscall, received libseccomp "
+ log_err(LD_BUG,"(Sandbox) failed to add open syscall, received libseccomp "
"error %d", rc);
return rc;
}
// TODO parameters
static int
-sb_openat(scmp_filter_ctx ctx)
+sb_openat(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
{
int rc;
- sandbox_cfg_t *elem;
+ sandbox_cfg_t *elem = NULL;
// for each dynamic parameter filters
- elem = filter_dynamic;
- for (; elem != NULL; elem = elem->next) {
+ for (elem = filter; elem != NULL; elem = elem->next) {
if (elem->prot == 1 && elem->syscall == SCMP_SYS(openat)) {
rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(openat), 1,
SCMP_CMP(1, SCMP_CMP_EQ, elem->param));
if (rc != 0) {
- log_err(LD_BUG,"(Sandbox) failed to add syscall, received libseccomp "
+ log_err(LD_BUG,"(Sandbox) failed to add openat syscall, received libseccomp "
"error %d", rc);
return rc;
}
}
static int
-sb_clock_gettime(scmp_filter_ctx ctx)
+sb_clock_gettime(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
{
return seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(clock_gettime), 1,
SCMP_CMP(0, SCMP_CMP_EQ, CLOCK_MONOTONIC));
// TODO: param not working
static int
-sb_socket(scmp_filter_ctx ctx)
+sb_socket(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
{
int rc = 0;
// TODO: param not working
static int
-sb_setsockopt(scmp_filter_ctx ctx)
+sb_setsockopt(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
{
int rc = 0;
#ifdef __NR_fcntl64
static int
-sb_fcntl64(scmp_filter_ctx ctx)
+sb_fcntl64(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
{
int rc = 0;
// allows everything but will keep for now..
static int
-sb_epoll_ctl(scmp_filter_ctx ctx)
+sb_epoll_ctl(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
{
int rc = 0;
* this list.
*/
static int
-sb_prctl(scmp_filter_ctx ctx)
+sb_prctl(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
{
int rc = 0;
* does not NEED tobe here.. only occurs before filter
*/
static int
-sb_mprotect(scmp_filter_ctx ctx)
+sb_mprotect(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
{
int rc = 0;
* does not NEED tobe here.. only occurs before filter
*/
static int
-sb_rt_sigprocmask(scmp_filter_ctx ctx)
+sb_rt_sigprocmask(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
{
int rc = 0;
* does not NEED tobe here.. only occurs before filter
*/
static int
-sb_flock(scmp_filter_ctx ctx)
+sb_flock(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
{
int rc = 0;
* does not NEED tobe here.. only occurs before filter
*/
static int
-sb_futex(scmp_filter_ctx ctx)
+sb_futex(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
{
int rc = 0;
* does not NEED tobe here.. only occurs before filter
*/
static int
-sb_mremap(scmp_filter_ctx ctx)
+sb_mremap(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
{
int rc = 0;
rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(mremap), 1,
- SCMP_CMP(1, SCMP_CMP_EQ, MREMAP_MAYMOVE));
+ SCMP_CMP(3, SCMP_CMP_EQ, MREMAP_MAYMOVE));
if (rc)
return rc;
}
static int
-sb_poll(scmp_filter_ctx ctx)
+sb_poll(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
{
int rc = 0;
elem->ptype = PARAM_PTR;
elem->param = (intptr_t) prot_strdup((char*) file);
elem->prot = 1;
- elem->next = filter_dynamic;
- filter_dynamic = elem;
+
+ elem->next = *cfg;
+ *cfg = elem;
return 0;
}
elem->ptype = PARAM_PTR;
elem->param = (intptr_t) prot_strdup((char*) file);;
elem->prot = 1;
- elem->next = filter_dynamic;
- filter_dynamic = elem;
+
+ elem->next = *cfg;
+ *cfg = elem;
return 0;
}
elem->ptype = PARAM_PTR;
elem->param = (intptr_t) prot_strdup((char*) com);;
elem->prot = 1;
- elem->next = filter_dynamic;
- filter_dynamic = elem;
+
+ elem->next = *cfg;
+ *cfg = elem;
return 0;
}
// function pointer
for (i = 0; i < ARRAY_LENGTH(filter_func); i++) {
- if ((filter_func[i])(ctx)) {
- log_err(LD_BUG,"(Sandbox) failed to add syscall, received libseccomp "
- "error %d", rc);
+ if ((filter_func[i])(ctx, cfg)) {
+ log_err(LD_BUG,"(Sandbox) failed to add syscall %d, received libseccomp "
+ "error %d", i, rc);
return rc;
}
}
return 0;
}
+
+static int register_cfg(sandbox_cfg_t* cfg) {
+ sandbox_cfg_t *elem = NULL;
+
+ if (filter_dynamic == NULL) {
+ filter_dynamic = cfg;
+ return 0;
+ }
+
+ for (elem = filter_dynamic; elem->next != NULL; elem = elem->next);
+
+ elem->next = cfg;
+
+ return 0;
+}
+
#endif // USE_LIBSECCOMP
#ifdef USE_LIBSECCOMP
if (install_syscall_filter(cfg))
return -2;
+ if (register_cfg(cfg))
+ return -3;
+
return 0;
}