From 54a57eb150ca3e5b67e9a81394c6cfa4ac82a6ff Mon Sep 17 00:00:00 2001 From: Eduardo Otubo Date: Wed, 1 Mar 2017 23:17:29 +0100 Subject: [PATCH] seccomp: add obsolete option 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 --- include/sysemu/seccomp.h | 2 +- qemu-options.hx | 9 +++++++-- qemu-seccomp.c | 25 ++++++++++++++++++++++++- vl.c | 10 +++++++++- 4 files changed, 41 insertions(+), 5 deletions(-) diff --git a/include/sysemu/seccomp.h b/include/sysemu/seccomp.h index cfc06008cb..9ff12f4b14 100644 --- a/include/sysemu/seccomp.h +++ b/include/sysemu/seccomp.h @@ -17,5 +17,5 @@ #include -int seccomp_start(void); +int seccomp_start(unsigned int obsolete); #endif diff --git a/qemu-options.hx b/qemu-options.hx index faf5cf8d45..21572bd487 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -3702,13 +3702,18 @@ Old param mode (ARM only). ETEXI DEF("sandbox", HAS_ARG, QEMU_OPTION_sandbox, \ - "-sandbox 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, diff --git a/qemu-seccomp.c b/qemu-seccomp.c index f8877b07b5..a8f9ada966 100644 --- a/qemu-seccomp.c +++ b/qemu-seccomp.c @@ -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 }, @@ -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; @@ -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; diff --git a/vl.c b/vl.c index e10a27bdd6..9823af94bc 100644 --- a/vl.c +++ b/vl.c @@ -265,6 +265,10 @@ static QemuOptsList qemu_sandbox_opts = { .name = "enable", .type = QEMU_OPT_BOOL, }, + { + .name = "obsolete", + .type = QEMU_OPT_STRING, + }, { /* end of list */ } }, }; @@ -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;