* [PATCH 0/3] fix SIGNAL_UNKILLABLE && SIGKILL interaction
[not found] ` <20171102160705.GA11973@redhat.com>
@ 2017-11-03 18:41 ` Oleg Nesterov
2017-11-03 18:42 ` [PATCH 1/3] protect the traced SIGNAL_UNKILLABLE tasks from SIGKILL Oleg Nesterov
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Oleg Nesterov @ 2017-11-03 18:41 UTC (permalink / raw)
To: Andrew Morton, Eric W. Biederman
Cc: security, Robert O'Callahan, Kees Cook, Andy Lutomirski,
Dmitry Vyukov, Kyle Huey, linux-kernel
On 11/02, Oleg Nesterov wrote:
>
> I need to write the changelog, and perhaps even split this small patch for
> better documentation.
OK, it is not clear if I answered Eric's concerns or not, let me send the
patches for review anyway. I tried to document every change in signal.c.
Oleg.
kernel/signal.c | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/3] protect the traced SIGNAL_UNKILLABLE tasks from SIGKILL
2017-11-03 18:41 ` [PATCH 0/3] fix SIGNAL_UNKILLABLE && SIGKILL interaction Oleg Nesterov
@ 2017-11-03 18:42 ` Oleg Nesterov
2017-11-03 18:42 ` [PATCH 2/3] protect the SIGNAL_UNKILLABLE tasks from !sig_kernel_only() signals Oleg Nesterov
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Oleg Nesterov @ 2017-11-03 18:42 UTC (permalink / raw)
To: Andrew Morton, Eric W. Biederman
Cc: security, Robert O'Callahan, Kees Cook, Andy Lutomirski,
Dmitry Vyukov, Kyle Huey, linux-kernel
The comment in sig_ignored() says "Tracers may want to know about
even ignored signals" but SIGKILL can not be reported to debugger
and it is just wrong to return 0 in this case: SIGKILL should only
kill the SIGNAL_UNKILLABLE task if it comes from the parent ns.
Change sig_ignored() to ignore ->ptrace if sig == SIGKILL and rely
on sig_task_ignored().
SISGTOP coming from within the namespace is not really right too
but at least debugger can intercept it, and we can't drop it here
because this will break "gdb -p 1": ptrace_attach() won't work.
Perhaps we will add another ->ptrace check later, we will see.
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
kernel/signal.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/kernel/signal.c b/kernel/signal.c
index 800a18f..b9aebe1 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -94,13 +94,15 @@ static int sig_ignored(struct task_struct *t, int sig, bool force)
if (sigismember(&t->blocked, sig) || sigismember(&t->real_blocked, sig))
return 0;
- if (!sig_task_ignored(t, sig, force))
- return 0;
-
/*
- * Tracers may want to know about even ignored signals.
+ * Tracers may want to know about even ignored signal unless it
+ * is SIGKILL which can't be reported anyway but can be ignored
+ * by SIGNAL_UNKILLABLE task.
*/
- return !t->ptrace;
+ if (t->ptrace && sig != SIGKILL)
+ return 0;
+
+ return sig_task_ignored(t, sig, force);
}
/*
--
2.5.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/3] protect the SIGNAL_UNKILLABLE tasks from !sig_kernel_only() signals
2017-11-03 18:41 ` [PATCH 0/3] fix SIGNAL_UNKILLABLE && SIGKILL interaction Oleg Nesterov
2017-11-03 18:42 ` [PATCH 1/3] protect the traced SIGNAL_UNKILLABLE tasks from SIGKILL Oleg Nesterov
@ 2017-11-03 18:42 ` Oleg Nesterov
2017-11-03 18:42 ` [PATCH 3/3] remove the no longer needed SIGNAL_UNKILLABLE check in complete_signal() Oleg Nesterov
2017-11-13 14:53 ` [PATCH 0/3] fix SIGNAL_UNKILLABLE && SIGKILL interaction Oleg Nesterov
3 siblings, 0 replies; 7+ messages in thread
From: Oleg Nesterov @ 2017-11-03 18:42 UTC (permalink / raw)
To: Andrew Morton, Eric W. Biederman
Cc: security, Robert O'Callahan, Kees Cook, Andy Lutomirski,
Dmitry Vyukov, Kyle Huey, linux-kernel
Change sig_task_ignored() to drop the SIG_DFL && !sig_kernel_only()
signals even if force == T. This simplifies the next change and this
matches the same check in get_signal() which will drop these signals
anyway.
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
kernel/signal.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/signal.c b/kernel/signal.c
index b9aebe1..8fc0182 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -78,7 +78,7 @@ static int sig_task_ignored(struct task_struct *t, int sig, bool force)
handler = sig_handler(t, sig);
if (unlikely(t->signal->flags & SIGNAL_UNKILLABLE) &&
- handler == SIG_DFL && !force)
+ handler == SIG_DFL && !(force && sig_kernel_only(sig)))
return 1;
return sig_handler_ignored(handler, sig);
--
2.5.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/3] remove the no longer needed SIGNAL_UNKILLABLE check in complete_signal()
2017-11-03 18:41 ` [PATCH 0/3] fix SIGNAL_UNKILLABLE && SIGKILL interaction Oleg Nesterov
2017-11-03 18:42 ` [PATCH 1/3] protect the traced SIGNAL_UNKILLABLE tasks from SIGKILL Oleg Nesterov
2017-11-03 18:42 ` [PATCH 2/3] protect the SIGNAL_UNKILLABLE tasks from !sig_kernel_only() signals Oleg Nesterov
@ 2017-11-03 18:42 ` Oleg Nesterov
2017-11-03 19:14 ` Kees Cook
2017-11-13 14:53 ` [PATCH 0/3] fix SIGNAL_UNKILLABLE && SIGKILL interaction Oleg Nesterov
3 siblings, 1 reply; 7+ messages in thread
From: Oleg Nesterov @ 2017-11-03 18:42 UTC (permalink / raw)
To: Andrew Morton, Eric W. Biederman
Cc: security, Robert O'Callahan, Kees Cook, Andy Lutomirski,
Dmitry Vyukov, Kyle Huey, linux-kernel
complete_signal() checks SIGNAL_UNKILLABLE before it starts to destroy the
thread group, today this is wrong in many ways.
If nothing else, fatal_signal_pending() should always imply that the whole
thread group (except ->group_exit_task if it is not NULL) is killed, this
check breaks the rule.
After the previous changes we can rely on sig_task_ignored(); sig_fatal(sig)
&& SIGNAL_UNKILLABLE can only be true if we actually want to kill this task
and sig == SIGKILL OR it is traced and debugger can intercept the signal.
This should hopefully fix the problem reported by Dmitry. This test-case
static int init(void *arg)
{
for (;;)
pause();
}
int main(void)
{
char stack[16 * 1024];
for (;;) {
int pid = clone(init, stack + sizeof(stack)/2,
CLONE_NEWPID | SIGCHLD, NULL);
assert(pid > 0);
assert(ptrace(PTRACE_ATTACH, pid, 0, 0) == 0);
assert(waitpid(-1, NULL, WSTOPPED) == pid);
assert(ptrace(PTRACE_DETACH, pid, 0, SIGSTOP) == 0);
assert(syscall(__NR_tkill, pid, SIGKILL) == 0);
assert(pid == wait(NULL));
}
}
triggers the WARN_ON_ONCE(!(task->jobctl & JOBCTL_STOP_PENDING)) in
task_participate_group_stop(). do_signal_stop()->signal_group_exit()
checks SIGNAL_GROUP_EXIT and return false, but task_set_jobctl_pending()
checks fatal_signal_pending() and does not set JOBCTL_STOP_PENDING.
And his should fix the minor security problem reported by Kyle,
SECCOMP_RET_TRACE can miss fatal_signal_pending() the same way if
the task is the root of a pid namespace.
Reported-by: Dmitry Vyukov <dvyukov@google.com>
Reported-by: Kyle Huey <me@kylehuey.com>
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
kernel/signal.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/kernel/signal.c b/kernel/signal.c
index 8fc0182..7e15b56 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -931,9 +931,9 @@ static void complete_signal(int sig, struct task_struct *p, int group)
* then start taking the whole group down immediately.
*/
if (sig_fatal(p, sig) &&
- !(signal->flags & (SIGNAL_UNKILLABLE | SIGNAL_GROUP_EXIT)) &&
+ !(signal->flags & SIGNAL_GROUP_EXIT) &&
!sigismember(&t->real_blocked, sig) &&
- (sig == SIGKILL || !t->ptrace)) {
+ (sig == SIGKILL || !p->ptrace)) {
/*
* This signal will be fatal to the whole group.
*/
--
2.5.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 3/3] remove the no longer needed SIGNAL_UNKILLABLE check in complete_signal()
2017-11-03 18:42 ` [PATCH 3/3] remove the no longer needed SIGNAL_UNKILLABLE check in complete_signal() Oleg Nesterov
@ 2017-11-03 19:14 ` Kees Cook
0 siblings, 0 replies; 7+ messages in thread
From: Kees Cook @ 2017-11-03 19:14 UTC (permalink / raw)
To: Oleg Nesterov
Cc: Andrew Morton, Eric W. Biederman, security,
Robert O'Callahan, Andy Lutomirski, Dmitry Vyukov, Kyle Huey,
LKML
On Fri, Nov 3, 2017 at 11:42 AM, Oleg Nesterov <oleg@redhat.com> wrote:
> complete_signal() checks SIGNAL_UNKILLABLE before it starts to destroy the
> thread group, today this is wrong in many ways.
>
> If nothing else, fatal_signal_pending() should always imply that the whole
> thread group (except ->group_exit_task if it is not NULL) is killed, this
> check breaks the rule.
>
> After the previous changes we can rely on sig_task_ignored(); sig_fatal(sig)
> && SIGNAL_UNKILLABLE can only be true if we actually want to kill this task
> and sig == SIGKILL OR it is traced and debugger can intercept the signal.
>
> This should hopefully fix the problem reported by Dmitry. This test-case
>
> static int init(void *arg)
> {
> for (;;)
> pause();
> }
>
> int main(void)
> {
> char stack[16 * 1024];
>
> for (;;) {
> int pid = clone(init, stack + sizeof(stack)/2,
> CLONE_NEWPID | SIGCHLD, NULL);
> assert(pid > 0);
>
> assert(ptrace(PTRACE_ATTACH, pid, 0, 0) == 0);
> assert(waitpid(-1, NULL, WSTOPPED) == pid);
>
> assert(ptrace(PTRACE_DETACH, pid, 0, SIGSTOP) == 0);
> assert(syscall(__NR_tkill, pid, SIGKILL) == 0);
> assert(pid == wait(NULL));
> }
> }
>
> triggers the WARN_ON_ONCE(!(task->jobctl & JOBCTL_STOP_PENDING)) in
> task_participate_group_stop(). do_signal_stop()->signal_group_exit()
> checks SIGNAL_GROUP_EXIT and return false, but task_set_jobctl_pending()
> checks fatal_signal_pending() and does not set JOBCTL_STOP_PENDING.
>
> And his should fix the minor security problem reported by Kyle,
> SECCOMP_RET_TRACE can miss fatal_signal_pending() the same way if
> the task is the root of a pid namespace.
>
> Reported-by: Dmitry Vyukov <dvyukov@google.com>
> Reported-by: Kyle Huey <me@kylehuey.com>
> Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Thanks for digging through this! Two birds, one stone, etc. :)
-Kees
> ---
> kernel/signal.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/signal.c b/kernel/signal.c
> index 8fc0182..7e15b56 100644
> --- a/kernel/signal.c
> +++ b/kernel/signal.c
> @@ -931,9 +931,9 @@ static void complete_signal(int sig, struct task_struct *p, int group)
> * then start taking the whole group down immediately.
> */
> if (sig_fatal(p, sig) &&
> - !(signal->flags & (SIGNAL_UNKILLABLE | SIGNAL_GROUP_EXIT)) &&
> + !(signal->flags & SIGNAL_GROUP_EXIT) &&
> !sigismember(&t->real_blocked, sig) &&
> - (sig == SIGKILL || !t->ptrace)) {
> + (sig == SIGKILL || !p->ptrace)) {
> /*
> * This signal will be fatal to the whole group.
> */
> --
> 2.5.0
>
>
--
Kees Cook
Pixel Security
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 0/3] fix SIGNAL_UNKILLABLE && SIGKILL interaction
2017-11-03 18:41 ` [PATCH 0/3] fix SIGNAL_UNKILLABLE && SIGKILL interaction Oleg Nesterov
` (2 preceding siblings ...)
2017-11-03 18:42 ` [PATCH 3/3] remove the no longer needed SIGNAL_UNKILLABLE check in complete_signal() Oleg Nesterov
@ 2017-11-13 14:53 ` Oleg Nesterov
2017-11-13 20:00 ` Kyle Huey
3 siblings, 1 reply; 7+ messages in thread
From: Oleg Nesterov @ 2017-11-13 14:53 UTC (permalink / raw)
To: Andrew Morton, Eric W. Biederman
Cc: security, Robert O'Callahan, Kees Cook, Andy Lutomirski,
Dmitry Vyukov, Kyle Huey, linux-kernel
ping...
Dmitry confirms this actually fixes the problem reported by syzkaller
we discussed in another thread.
On 11/03, Oleg Nesterov wrote:
>
> On 11/02, Oleg Nesterov wrote:
> >
> > I need to write the changelog, and perhaps even split this small patch for
> > better documentation.
>
> OK, it is not clear if I answered Eric's concerns or not, let me send the
> patches for review anyway. I tried to document every change in signal.c.
>
> Oleg.
>
> kernel/signal.c | 18 ++++++++++--------
> 1 file changed, 10 insertions(+), 8 deletions(-)
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 0/3] fix SIGNAL_UNKILLABLE && SIGKILL interaction
2017-11-13 14:53 ` [PATCH 0/3] fix SIGNAL_UNKILLABLE && SIGKILL interaction Oleg Nesterov
@ 2017-11-13 20:00 ` Kyle Huey
0 siblings, 0 replies; 7+ messages in thread
From: Kyle Huey @ 2017-11-13 20:00 UTC (permalink / raw)
To: Oleg Nesterov
Cc: Andrew Morton, Eric W. Biederman, security,
Robert O'Callahan, Kees Cook, Andy Lutomirski, Dmitry Vyukov,
open list
On Mon, Nov 13, 2017 at 6:53 AM, Oleg Nesterov <oleg@redhat.com> wrote:
> ping...
>
> Dmitry confirms this actually fixes the problem reported by syzkaller
> we discussed in another thread.
>
>
> On 11/03, Oleg Nesterov wrote:
>>
>> On 11/02, Oleg Nesterov wrote:
>> >
>> > I need to write the changelog, and perhaps even split this small patch for
>> > better documentation.
>>
>> OK, it is not clear if I answered Eric's concerns or not, let me send the
>> patches for review anyway. I tried to document every change in signal.c.
>>
>> Oleg.
>>
>> kernel/signal.c | 18 ++++++++++--------
>> 1 file changed, 10 insertions(+), 8 deletions(-)
>
I can confirm that your patches fix the issue I reported as well.
- Kyle
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2017-11-13 20:00 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <CAP045Ap9Xv67GaeskDt_gAajp1Cni_S0Z0u_vsuw_ptRUuJD6Q@mail.gmail.com>
[not found] ` <20171102160705.GA11973@redhat.com>
2017-11-03 18:41 ` [PATCH 0/3] fix SIGNAL_UNKILLABLE && SIGKILL interaction Oleg Nesterov
2017-11-03 18:42 ` [PATCH 1/3] protect the traced SIGNAL_UNKILLABLE tasks from SIGKILL Oleg Nesterov
2017-11-03 18:42 ` [PATCH 2/3] protect the SIGNAL_UNKILLABLE tasks from !sig_kernel_only() signals Oleg Nesterov
2017-11-03 18:42 ` [PATCH 3/3] remove the no longer needed SIGNAL_UNKILLABLE check in complete_signal() Oleg Nesterov
2017-11-03 19:14 ` Kees Cook
2017-11-13 14:53 ` [PATCH 0/3] fix SIGNAL_UNKILLABLE && SIGKILL interaction Oleg Nesterov
2017-11-13 20:00 ` Kyle Huey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).