Skip to content

Commit

Permalink
seccomp: prefer SCMP_ACT_KILL_PROCESS if available
Browse files Browse the repository at this point in the history
The upcoming libseccomp release should have SCMP_ACT_KILL_PROCESS
action (seccomp/libseccomp#96).

SCMP_ACT_KILL_PROCESS is preferable to immediately terminate the
offending process, rather than having the SIGSYS handler running.

Use SECCOMP_GET_ACTION_AVAIL to check availability of kernel support,
as libseccomp will fallback on SCMP_ACT_KILL otherwise, and we still
prefer SCMP_ACT_TRAP.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Acked-by: Eduardo Otubo <otubo@redhat.com>
  • Loading branch information
elmarco authored and otubo committed Aug 23, 2018
1 parent 6f2231e commit bda08a5
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion qemu-seccomp.c
Expand Up @@ -20,6 +20,7 @@
#include <sys/prctl.h>
#include <seccomp.h>
#include "sysemu/seccomp.h"
#include <linux/seccomp.h>

/* For some architectures (notably ARM) cacheflush is not supported until
* libseccomp 2.2.3, but configure enforces that we are using a more recent
Expand Down Expand Up @@ -107,12 +108,40 @@ static const struct QemuSeccompSyscall blacklist[] = {
{ SCMP_SYS(sched_get_priority_min), QEMU_SECCOMP_SET_RESOURCECTL },
};

static inline __attribute__((unused)) int
qemu_seccomp(unsigned int operation, unsigned int flags, void *args)
{
#ifdef __NR_seccomp
return syscall(__NR_seccomp, operation, flags, args);
#else
errno = ENOSYS;
return -1;
#endif
}

static uint32_t qemu_seccomp_get_kill_action(void)
{
#if defined(SECCOMP_GET_ACTION_AVAIL) && defined(SCMP_ACT_KILL_PROCESS) && \
defined(SECCOMP_RET_KILL_PROCESS)
{
uint32_t action = SECCOMP_RET_KILL_PROCESS;

if (qemu_seccomp(SECCOMP_GET_ACTION_AVAIL, 0, &action) == 0) {
return SCMP_ACT_KILL_PROCESS;
}
}
#endif

return SCMP_ACT_TRAP;
}


static int seccomp_start(uint32_t seccomp_opts)
{
int rc = 0;
unsigned int i = 0;
scmp_filter_ctx ctx;
uint32_t action = qemu_seccomp_get_kill_action();

ctx = seccomp_init(SCMP_ACT_ALLOW);
if (ctx == NULL) {
Expand All @@ -125,7 +154,7 @@ static int seccomp_start(uint32_t seccomp_opts)
continue;
}

rc = seccomp_rule_add_array(ctx, SCMP_ACT_TRAP, blacklist[i].num,
rc = seccomp_rule_add_array(ctx, action, blacklist[i].num,
blacklist[i].narg, blacklist[i].arg_cmp);
if (rc < 0) {
goto seccomp_return;
Expand Down

0 comments on commit bda08a5

Please sign in to comment.