Commit b25e6716 authored by Mike Frysinger's avatar Mike Frysinger Committed by James Morris

seccomp: dump core when using SECCOMP_RET_KILL

The SECCOMP_RET_KILL mode is documented as immediately killing the
process as if a SIGSYS had been sent and not caught (similar to a
SIGKILL).  However, a SIGSYS is documented as triggering a coredump
which does not happen today.

This has the advantage of being able to more easily debug a process
that fails a seccomp filter.  Today, most apps need to recompile and
change their filter in order to get detailed info out, or manually run
things through strace, or enable detailed kernel auditing.  Now we get
coredumps that fit into existing system-wide crash reporting setups.

From a security pov, this shouldn't be a problem.  Unhandled signals
can already be sent externally which trigger a coredump independent of
the status of the seccomp filter.  The act of dumping core itself does
not cause change in execution of the program.

URL: https://crbug.com/676357Signed-off-by: default avatarMike Frysinger <vapier@chromium.org>
Acked-by: default avatarJorge Lucangeli Obes <jorgelo@chromium.org>
Acked-by: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatarJames Morris <james.l.morris@oracle.com>
parent d69dece5
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include <linux/atomic.h> #include <linux/atomic.h>
#include <linux/audit.h> #include <linux/audit.h>
#include <linux/compat.h> #include <linux/compat.h>
#include <linux/coredump.h>
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/seccomp.h> #include <linux/seccomp.h>
#include <linux/slab.h> #include <linux/slab.h>
...@@ -486,6 +487,17 @@ void put_seccomp_filter(struct task_struct *tsk) ...@@ -486,6 +487,17 @@ void put_seccomp_filter(struct task_struct *tsk)
} }
} }
static void seccomp_init_siginfo(siginfo_t *info, int syscall, int reason)
{
memset(info, 0, sizeof(*info));
info->si_signo = SIGSYS;
info->si_code = SYS_SECCOMP;
info->si_call_addr = (void __user *)KSTK_EIP(current);
info->si_errno = reason;
info->si_arch = syscall_get_arch();
info->si_syscall = syscall;
}
/** /**
* seccomp_send_sigsys - signals the task to allow in-process syscall emulation * seccomp_send_sigsys - signals the task to allow in-process syscall emulation
* @syscall: syscall number to send to userland * @syscall: syscall number to send to userland
...@@ -496,13 +508,7 @@ void put_seccomp_filter(struct task_struct *tsk) ...@@ -496,13 +508,7 @@ void put_seccomp_filter(struct task_struct *tsk)
static void seccomp_send_sigsys(int syscall, int reason) static void seccomp_send_sigsys(int syscall, int reason)
{ {
struct siginfo info; struct siginfo info;
memset(&info, 0, sizeof(info)); seccomp_init_siginfo(&info, syscall, reason);
info.si_signo = SIGSYS;
info.si_code = SYS_SECCOMP;
info.si_call_addr = (void __user *)KSTK_EIP(current);
info.si_errno = reason;
info.si_arch = syscall_get_arch();
info.si_syscall = syscall;
force_sig_info(SIGSYS, &info, current); force_sig_info(SIGSYS, &info, current);
} }
#endif /* CONFIG_SECCOMP_FILTER */ #endif /* CONFIG_SECCOMP_FILTER */
...@@ -634,10 +640,17 @@ static int __seccomp_filter(int this_syscall, const struct seccomp_data *sd, ...@@ -634,10 +640,17 @@ static int __seccomp_filter(int this_syscall, const struct seccomp_data *sd,
return 0; return 0;
case SECCOMP_RET_KILL: case SECCOMP_RET_KILL:
default: default: {
siginfo_t info;
audit_seccomp(this_syscall, SIGSYS, action); audit_seccomp(this_syscall, SIGSYS, action);
/* Show the original registers in the dump. */
syscall_rollback(current, task_pt_regs(current));
/* Trigger a manual coredump since do_exit skips it. */
seccomp_init_siginfo(&info, this_syscall, data);
do_coredump(&info);
do_exit(SIGSYS); do_exit(SIGSYS);
} }
}
unreachable(); unreachable();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment