* [PATCHv2] signal: protect SIGNAL_UNKILLABLE from unintentional clearing.
@ 2017-01-04 12:20 Jamie Iles
2017-01-05 18:18 ` Oleg Nesterov
0 siblings, 1 reply; 2+ messages in thread
From: Jamie Iles @ 2017-01-04 12:20 UTC (permalink / raw)
To: linux-kernel, oleg
Cc: Jamie Iles, Alexander Viro, Ingo Molnar, Peter Zijlstra,
Andrew Morton
Since 00cd5c37af (ptrace: permit ptracing of /sbin/init) we can now
trace init processes. init is initially protected with
SIGNAL_UNKILLABLE which will prevent fatal signals such as SIGSTOP, but
there are a number of paths during tracing where SIGNAL_UNKILLABLE can
be implicitly cleared.
This can result in init becoming stoppable/killable after tracing. For
example, running:
while true; do kill -STOP 1; done &
strace -p 1
and then stopping strace and the kill loop will result in init being
left in state TASK_STOPPED. Sending SIGCONT to init will resume it, but
init will now respond to future SIGSTOP signals rather than ignoring
them.
Make sure that when setting SIGNAL_STOP_CONTINUED/SIGNAL_STOP_STOPPED
that we don't clear SIGNAL_UNKILLABLE.
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Jamie Iles <jamie.iles@oracle.com>
---
v1->v2:
- dropped set/clear helpers
- added signal_set_stop_flags
include/linux/sched.h | 10 ++++++++++
kernel/signal.c | 4 ++--
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/include/linux/sched.h b/include/linux/sched.h
index e9c009dc3a4a..4d7761f15f5b 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -830,6 +830,16 @@ struct signal_struct {
#define SIGNAL_UNKILLABLE 0x00000040 /* for init: ignore fatal signals */
+#define SIGNAL_STOP_MASK (SIGNAL_CLD_MASK | SIGNAL_STOP_STOPPED | \
+ SIGNAL_STOP_CONTINUED)
+
+static inline void signal_set_stop_flags(struct signal_struct *sig,
+ unsigned int flags)
+{
+ WARN_ON(sig->flags & (SIGNAL_GROUP_EXIT|SIGNAL_GROUP_COREDUMP));
+ sig->flags = (sig->flags & ~SIGNAL_STOP_MASK) | flags;
+}
+
/* If true, all threads except ->group_exit_task have pending SIGKILL */
static inline int signal_group_exit(const struct signal_struct *sig)
{
diff --git a/kernel/signal.c b/kernel/signal.c
index 75761acc77cf..33d443d5d89b 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -346,7 +346,7 @@ static bool task_participate_group_stop(struct task_struct *task)
* fresh group stop. Read comment in do_signal_stop() for details.
*/
if (!sig->group_stop_count && !(sig->flags & SIGNAL_STOP_STOPPED)) {
- sig->flags = SIGNAL_STOP_STOPPED;
+ signal_set_stop_flags(sig, SIGNAL_STOP_STOPPED);
return true;
}
return false;
@@ -837,7 +837,7 @@ static bool prepare_signal(int sig, struct task_struct *p, bool force)
* will take ->siglock, notice SIGNAL_CLD_MASK, and
* notify its parent. See get_signal_to_deliver().
*/
- signal->flags = why | SIGNAL_STOP_CONTINUED;
+ signal_set_stop_flags(signal, why | SIGNAL_STOP_CONTINUED);
signal->group_stop_count = 0;
signal->group_exit_code = 0;
}
--
2.11.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCHv2] signal: protect SIGNAL_UNKILLABLE from unintentional clearing.
2017-01-04 12:20 [PATCHv2] signal: protect SIGNAL_UNKILLABLE from unintentional clearing Jamie Iles
@ 2017-01-05 18:18 ` Oleg Nesterov
0 siblings, 0 replies; 2+ messages in thread
From: Oleg Nesterov @ 2017-01-05 18:18 UTC (permalink / raw)
To: Jamie Iles
Cc: linux-kernel, Alexander Viro, Ingo Molnar, Peter Zijlstra,
Andrew Morton
On 01/04, Jamie Iles wrote:
>
> This can result in init becoming stoppable/killable after tracing. For
> example, running:
>
> while true; do kill -STOP 1; done &
> strace -p 1
>
> and then stopping strace and the kill loop will result in init being
> left in state TASK_STOPPED. Sending SIGCONT to init will resume it, but
> init will now respond to future SIGSTOP signals rather than ignoring
> them.
and to SIGKILL.
Another problem is that /sbin/init should ignore SIGKILL even when ptraced,
but this needs another patch, will try to do tomorrow. And yet another problem
with force_sig(), it should probably take ptrace and/or SIGTRAP into account.
Thanks Jamie,
Acked-by: Oleg Nesterov <oleg@redhat.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-01-05 18:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-04 12:20 [PATCHv2] signal: protect SIGNAL_UNKILLABLE from unintentional clearing Jamie Iles
2017-01-05 18:18 ` Oleg Nesterov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox