seccomp: Invalidate seccomp mode to catch death failures
[ Upstream commit 495ac3069a6235bfdf516812a2a9b256671bbdf9 ] If seccomp tries to kill a process, it should never see that process again. To enforce this proactively, switch the mode to something impossible. If encountered: WARN, reject all syscalls, and attempt to kill the process again even harder. Cc: Andy Lutomirski <luto@amacapital.net> Cc: Will Drewry <wad@chromium.org> Fixes: 8112c4f140fa ("seccomp: remove 2-phase API") Cc: stable@vger.kernel.org Signed-off-by: Kees Cook <keescook@chromium.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
ed63e785cc
commit
829da7db63
1 changed files with 10 additions and 0 deletions
|
@ -29,6 +29,9 @@
|
||||||
#include <linux/syscalls.h>
|
#include <linux/syscalls.h>
|
||||||
#include <linux/sysctl.h>
|
#include <linux/sysctl.h>
|
||||||
|
|
||||||
|
/* Not exposed in headers: strictly internal use only. */
|
||||||
|
#define SECCOMP_MODE_DEAD (SECCOMP_MODE_FILTER + 1)
|
||||||
|
|
||||||
#ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER
|
#ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER
|
||||||
#include <asm/syscall.h>
|
#include <asm/syscall.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -1026,6 +1029,7 @@ static void __secure_computing_strict(int this_syscall)
|
||||||
#ifdef SECCOMP_DEBUG
|
#ifdef SECCOMP_DEBUG
|
||||||
dump_stack();
|
dump_stack();
|
||||||
#endif
|
#endif
|
||||||
|
current->seccomp.mode = SECCOMP_MODE_DEAD;
|
||||||
seccomp_log(this_syscall, SIGKILL, SECCOMP_RET_KILL_THREAD, true);
|
seccomp_log(this_syscall, SIGKILL, SECCOMP_RET_KILL_THREAD, true);
|
||||||
do_exit(SIGKILL);
|
do_exit(SIGKILL);
|
||||||
}
|
}
|
||||||
|
@ -1254,6 +1258,7 @@ static int __seccomp_filter(int this_syscall, const struct seccomp_data *sd,
|
||||||
case SECCOMP_RET_KILL_THREAD:
|
case SECCOMP_RET_KILL_THREAD:
|
||||||
case SECCOMP_RET_KILL_PROCESS:
|
case SECCOMP_RET_KILL_PROCESS:
|
||||||
default:
|
default:
|
||||||
|
current->seccomp.mode = SECCOMP_MODE_DEAD;
|
||||||
seccomp_log(this_syscall, SIGSYS, action, true);
|
seccomp_log(this_syscall, SIGSYS, action, true);
|
||||||
/* Dump core only if this is the last remaining thread. */
|
/* Dump core only if this is the last remaining thread. */
|
||||||
if (action != SECCOMP_RET_KILL_THREAD ||
|
if (action != SECCOMP_RET_KILL_THREAD ||
|
||||||
|
@ -1306,6 +1311,11 @@ int __secure_computing(const struct seccomp_data *sd)
|
||||||
return 0;
|
return 0;
|
||||||
case SECCOMP_MODE_FILTER:
|
case SECCOMP_MODE_FILTER:
|
||||||
return __seccomp_filter(this_syscall, sd, false);
|
return __seccomp_filter(this_syscall, sd, false);
|
||||||
|
/* Surviving SECCOMP_RET_KILL_* must be proactively impossible. */
|
||||||
|
case SECCOMP_MODE_DEAD:
|
||||||
|
WARN_ON_ONCE(1);
|
||||||
|
do_exit(SIGKILL);
|
||||||
|
return -1;
|
||||||
default:
|
default:
|
||||||
BUG();
|
BUG();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue