mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-05 08:43:55 -06:00
seccomp: add elevateprivileges argument to command line
This patch introduces the new argument [,elevateprivileges=allow|deny|children] to the `-sandbox on'. It allows or denies Qemu process to elevate its privileges by blacklisting all set*uid|gid system calls. The 'children' option will let forks and execves run unprivileged. Signed-off-by: Eduardo Otubo <otubo@redhat.com>
This commit is contained in:
parent
2b716fa6d6
commit
73a1e64725
4 changed files with 48 additions and 3 deletions
27
vl.c
27
vl.c
|
@ -29,6 +29,7 @@
|
|||
|
||||
#ifdef CONFIG_SECCOMP
|
||||
#include "sysemu/seccomp.h"
|
||||
#include "sys/prctl.h"
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_VDE)
|
||||
|
@ -275,6 +276,10 @@ static QemuOptsList qemu_sandbox_opts = {
|
|||
.name = "obsolete",
|
||||
.type = QEMU_OPT_STRING,
|
||||
},
|
||||
{
|
||||
.name = "elevateprivileges",
|
||||
.type = QEMU_OPT_STRING,
|
||||
},
|
||||
{ /* end of list */ }
|
||||
},
|
||||
};
|
||||
|
@ -1056,6 +1061,28 @@ static int parse_sandbox(void *opaque, QemuOpts *opts, Error **errp)
|
|||
}
|
||||
}
|
||||
|
||||
value = qemu_opt_get(opts, "elevateprivileges");
|
||||
if (value) {
|
||||
if (g_str_equal(value, "deny")) {
|
||||
seccomp_opts |= QEMU_SECCOMP_SET_PRIVILEGED;
|
||||
} else if (g_str_equal(value, "children")) {
|
||||
seccomp_opts |= QEMU_SECCOMP_SET_PRIVILEGED;
|
||||
|
||||
/* calling prctl directly because we're
|
||||
* not sure if host has CAP_SYS_ADMIN set*/
|
||||
if (prctl(PR_SET_NO_NEW_PRIVS, 1)) {
|
||||
error_report("failed to set no_new_privs "
|
||||
"aborting");
|
||||
return -1;
|
||||
}
|
||||
} else if (g_str_equal(value, "allow")) {
|
||||
/* default value */
|
||||
} else {
|
||||
error_report("invalid argument for elevateprivileges");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (seccomp_start(seccomp_opts) < 0) {
|
||||
error_report("failed to install seccomp syscall filter "
|
||||
"in the kernel");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue