Skip to content

Commit

Permalink
seccomp: add obsolete option
Browse files Browse the repository at this point in the history
This patch introduces the argument [,obsolete=allow] to the -sandbox
option. It allows Qemu to run safely on old system that still relies on
old system calls.

Signed-off-by: Eduardo Otubo <eduardo.otubo@profitbricks.com>
  • Loading branch information
Eduardo Otubo committed Mar 1, 2017
1 parent 31e6031 commit 54a57eb
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
2 changes: 1 addition & 1 deletion include/sysemu/seccomp.h
Expand Up @@ -17,5 +17,5 @@

#include <seccomp.h>

int seccomp_start(void);
int seccomp_start(unsigned int obsolete);
#endif
9 changes: 7 additions & 2 deletions qemu-options.hx
Expand Up @@ -3702,13 +3702,18 @@ Old param mode (ARM only).
ETEXI

DEF("sandbox", HAS_ARG, QEMU_OPTION_sandbox, \
"-sandbox <arg> Enable seccomp mode 2 system call filter (default 'off').\n",
"-sandbox on[,obsolete=allow] Enable seccomp mode 2 system call filter (default 'off').\n" \
" obsolete: Allow obsolete system calls",
QEMU_ARCH_ALL)
STEXI
@item -sandbox @var{arg}
@item -sandbox @var{arg}[,obsolete=@var{string}]
@findex -sandbox
Enable Seccomp mode 2 system call filter. 'on' will enable syscall filtering and 'off' will
disable it. The default is 'off'.
@table @option
@item obsolete=@var{string}
Enable Obsolete system calls
@end table
ETEXI

DEF("readconfig", HAS_ARG, QEMU_OPTION_readconfig,
Expand Down
25 changes: 24 additions & 1 deletion qemu-seccomp.c
Expand Up @@ -31,7 +31,12 @@ struct QemuSeccompSyscall {
uint8_t priority;
};

static const struct QemuSeccompSyscall obsolete[] = {
{ SCMP_SYS(readdir), 255 },
};

static const struct QemuSeccompSyscall blacklist[] = {
{ SCMP_SYS(readdir), 255 },
{ SCMP_SYS(reboot), 255 },
{ SCMP_SYS(swapon), 255 },
{ SCMP_SYS(swapoff), 255 },
Expand All @@ -56,7 +61,20 @@ static const struct QemuSeccompSyscall blacklist[] = {
{ SCMP_SYS(vserver), 255 },
};

int seccomp_start(void)
static int is_obsolete(int syscall)
{
unsigned int i = 0;

for (i = 0; i < ARRAY_SIZE(obsolete); i++) {
if (syscall == obsolete[i].num) {
return 1;
}
}

return 0;
}

int seccomp_start(unsigned int obsolete)
{
int rc = 0;
unsigned int i = 0;
Expand All @@ -69,6 +87,11 @@ int seccomp_start(void)
}

for (i = 0; i < ARRAY_SIZE(blacklist); i++) {
if (obsolete) {
if(is_obsolete(blacklist[i].num)) {
continue;
}
}
rc = seccomp_rule_add(ctx, SCMP_ACT_KILL, blacklist[i].num, 0);
if (rc < 0) {
goto seccomp_return;
Expand Down
10 changes: 9 additions & 1 deletion vl.c
Expand Up @@ -265,6 +265,10 @@ static QemuOptsList qemu_sandbox_opts = {
.name = "enable",
.type = QEMU_OPT_BOOL,
},
{
.name = "obsolete",
.type = QEMU_OPT_STRING,
},
{ /* end of list */ }
},
};
Expand Down Expand Up @@ -1027,7 +1031,11 @@ static int parse_sandbox(void *opaque, QemuOpts *opts, Error **errp)
/* FIXME: change this to true for 1.3 */
if (qemu_opt_get_bool(opts, "enable", false)) {
#ifdef CONFIG_SECCOMP
if (seccomp_start() < 0) {
unsigned int obsolete = 0;

if (strcmp(qemu_opt_get(opts,"obsolete"), "allow") == 0) obsolete = 1;

if (seccomp_start(obsolete) < 0) {
error_report("failed to install seccomp syscall filter "
"in the kernel");
return -1;
Expand Down

0 comments on commit 54a57eb

Please sign in to comment.