seccomp: kill process instead of thread for unknown actions
PATCH 1/1 seccomp: kill process instead of thread for unknown actions
Asynchronous termination of a thread outside of the userspace thread library's knowledge is an unsafe operation that leaves the process in an inconsistent, corrupt, and possibly unrecoverable state. In order to make new actions that may be added in the future safe on kernels not aware of them, change the default action from SECCOMP_RET_KILL_THREAD to SECCOMP_RET_KILL_PROCESS.
---
This fundamental problem with SECCOMP_RET_KILL_THREAD, and that it should be considered unsafe and deprecated, was recently noted/fixed seccomp in the man page and its example. Here I've only changed the default action for new/unknown action codes. Ideally the behavior for strict seccomp mode would be changed too but I think that breaks stability policy; in any case it's less likely to be an issue since strict mode is hard or impossible to use reasonably in a multithreaded process.
Unfortunately changing this now won't help older kernels where unknown new actions would still be handled unsafely, but at least it makes it so the problem will fade away over time.
kernel/seccomp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/seccomp.c +3 -3
@@ -910,10 +910,10 @@ static int __seccomp_filter(int this_syscall, const struct seccomp_data *sd,seccomp_init_siginfo (&info, this_syscall, data);do_coredump (&info); } -if (action ==SECCOMP_RET_KILL_PROCESS ) -do_group_exit (SIGSYS ); -else +if (action ==SECCOMP_RET_KILL_THREAD )do_exit (SIGSYS ); +else +do_group_exit (SIGSYS ); }unreachable ();
Signature · 1 line
2.21.0
Quoted 19 lines · Rich Felker
Asynchronous termination of a thread outside of the userspace thread library's knowledge is an unsafe operation that leaves the process in an inconsistent, corrupt, and possibly unrecoverable state. In order to make new actions that may be added in the future safe on kernels not aware of them, change the default action from
SECCOMP_RET_KILL_THREADtoSECCOMP_RET_KILL_PROCESS.Signed-off-by Rich Felker <[email protected]>---
This fundamental problem with
SECCOMP_RET_KILL_THREAD, and that it should be considered unsafe and deprecated, was recently noted/fixed seccomp in the man page and its example. Here I've only changed the default action for new/unknown action codes. Ideally the behavior for strict seccomp mode would be changed too but I think that breaks stability policy; in any case it's less likely to be an issue since strict mode is hard or impossible to use reasonably in a multithreaded process.
Quoted 3 lines
Unfortunately changing this now won't help older kernels where unknown new actions would still be handled unsafely, but at least it makes it so the problem will fade away over time.
I think this is probably fine to change now. I'd always wanted to "upgrade" the default to KILL_PROCESS, but wanted to wait for KILL_PROCESS to exist at all for a while first. :)
I'm not aware of any filter generators (e.g. libseccomp, Chrome) that depend on unknown filter return values to cause a KILL_THREAD, and everything I've seen indicates that they aren't _accidentally_ depending on it either (i.e. they both produce "valid" filters). It's possible that something out there doesn't, and in that case, we likely need to make a special case for whatever bad filter value it chose, but we can cross that bridge when we come to it.
I've added Kyle and Robert to CC as well, as they have noticed subtle changes to seccomp behavior in the past. I *think* this change should be fine, but perhaps they will see something I don't. :)
Quoted 9 lines
kernel/seccomp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)kernel/seccomp.c +0
-0
kernel/seccomp.c static int __seccomp_filter(int this_syscall, const struct seccomp_data *sd, · line 916
Quoted 10 lines
kernel/seccomp.c +3
-3@@ -910,10 +910,10 @@ static int __seccomp_filter(int this_syscall, const struct seccomp_data *sd,seccomp_init_siginfo (&info, this_syscall, data);do_coredump (&info); } -if (action ==SECCOMP_RET_KILL_PROCESS ) -do_group_exit (SIGSYS ); -else +if (action ==SECCOMP_RET_KILL_THREAD )do_exit (SIGSYS ); +else +do_group_exit (SIGSYS );
I need to think a little more, but I suspect we should change the coredump logic (above the quoted code) too... (i.e. "action == SECCOMP_RET_KILL_PROCESS" -> "action != SECCOMP_RET_KILL_THREAD")
Quoted 6 lines
kernel/seccomp.c +0
-0}unreachable ();Signature · 1 line
2.21.0
Thanks!
-Kees
Signature · 1 line
Kees Cook
Quoted 37 lines · Kees Cook
Quoted 19 lines · Rich Felker
Asynchronous termination of a thread outside of the userspace thread library's knowledge is an unsafe operation that leaves the process in an inconsistent, corrupt, and possibly unrecoverable state. In order to make new actions that may be added in the future safe on kernels not aware of them, change the default action from
SECCOMP_RET_KILL_THREADtoSECCOMP_RET_KILL_PROCESS.Signed-off-by Rich Felker <[email protected]>---
This fundamental problem with
SECCOMP_RET_KILL_THREAD, and that it should be considered unsafe and deprecated, was recently noted/fixed seccomp in the man page and its example. Here I've only changed the default action for new/unknown action codes. Ideally the behavior for strict seccomp mode would be changed too but I think that breaks stability policy; in any case it's less likely to be an issue since strict mode is hard or impossible to use reasonably in a multithreaded process.Quoted 3 lines
Unfortunately changing this now won't help older kernels where unknown new actions would still be handled unsafely, but at least it makes it so the problem will fade away over time.
I think this is probably fine to change now. I'd always wanted to "upgrade" the default to
KILL_PROCESS, but wanted to wait forKILL_PROCESSto exist at all for a while first. :)I'm not aware of any filter generators (e.g. libseccomp, Chrome) that depend on unknown filter return values to cause a
KILL_THREAD, and everything I've seen indicates that they aren't _accidentally_ depending on it either (i.e. they both produce "valid" filters). It's possible that something out there doesn't, and in that case, we likely need to make a special case for whatever bad filter value it chose, but we can cross that bridge when we come to it.
Quoted 3 lines
I've added Kyle and Robert to CC as well, as they have noticed subtle changes to seccomp behavior in the past. I *think* this change should be fine, but perhaps they will see something I don't. :)
I can't think of anything here that would break stuff, though I do believe rr needs some changes to how it handles this (I don't think our current behavior is an accurate emulation of the kernel).
- Kyle
Quoted 37 lines
Quoted 9 lines
kernel/seccomp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)kernel/seccomp.c +0
-0kernel/seccomp.c static int __seccomp_filter(int this_syscall, const struct seccomp_data *sd, · line 916
Quoted 10 lines
kernel/seccomp.c +3
-3@@ -910,10 +910,10 @@ static int __seccomp_filter(int this_syscall, const struct seccomp_data *sd,seccomp_init_siginfo (&info, this_syscall, data);do_coredump (&info); } -if (action ==SECCOMP_RET_KILL_PROCESS ) -do_group_exit (SIGSYS ); -else +if (action ==SECCOMP_RET_KILL_THREAD )do_exit (SIGSYS ); +else +do_group_exit (SIGSYS );I need to think a little more, but I suspect we should change the coredump logic (above the quoted code) too... (i.e. "action ==
SECCOMP_RET_KILL_PROCESS" -> "action !=SECCOMP_RET_KILL_THREAD")Quoted 6 lines
kernel/seccomp.c +0
-1}unreachable (); --2.21.0
Thanks!
-Kees
--
Kees Cook
Kees Cook
AppliedQuoted 6 lines · Rich Felker
Asynchronous termination of a thread outside of the userspace thread library's knowledge is an unsafe operation that leaves the process in an inconsistent, corrupt, and possibly unrecoverable state. In order to make new actions that may be added in the future safe on kernels not aware of them, change the default action from
SECCOMP_RET_KILL_THREADtoSECCOMP_RET_KILL_PROCESS.
Applied, thanks!
[1/1] seccomp: kill process instead of thread for unknown actions
https://git.kernel.org/kees/c/4d671d922d51
I tweaked the coredump logic and added a selftest (and CCed you) for the behavior (since it wasn't included in the existing tests).
Signature · 1 line
Kees Cook