Skip to content

Commit 2d39b3c

Browse files
jamieilestorvalds
authored andcommitted
signal: protect SIGNAL_UNKILLABLE from unintentional clearing.
Since commit 00cd5c3 ("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. Link: http://lkml.kernel.org/r/20170104122017.25047-1-jamie.iles@oracle.com Signed-off-by: Jamie Iles <jamie.iles@oracle.com> Acked-by: Oleg Nesterov <oleg@redhat.com> Cc: Alexander Viro <viro@zeniv.linux.org.uk> Cc: Ingo Molnar <mingo@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 20f664a commit 2d39b3c

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

‎include/linux/sched.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,16 @@ struct signal_struct {
854854

855855
#define SIGNAL_UNKILLABLE 0x00000040 /* for init: ignore fatal signals */
856856

857+
#define SIGNAL_STOP_MASK (SIGNAL_CLD_MASK | SIGNAL_STOP_STOPPED | \
858+
SIGNAL_STOP_CONTINUED)
859+
860+
static inline void signal_set_stop_flags(struct signal_struct *sig,
861+
unsigned int flags)
862+
{
863+
WARN_ON(sig->flags & (SIGNAL_GROUP_EXIT|SIGNAL_GROUP_COREDUMP));
864+
sig->flags = (sig->flags & ~SIGNAL_STOP_MASK) | flags;
865+
}
866+
857867
/* If true, all threads except ->group_exit_task have pending SIGKILL */
858868
static inline int signal_group_exit(const struct signal_struct *sig)
859869
{

‎kernel/signal.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ static bool task_participate_group_stop(struct task_struct *task)
346346
* fresh group stop. Read comment in do_signal_stop() for details.
347347
*/
348348
if (!sig->group_stop_count && !(sig->flags & SIGNAL_STOP_STOPPED)) {
349-
sig->flags = SIGNAL_STOP_STOPPED;
349+
signal_set_stop_flags(sig, SIGNAL_STOP_STOPPED);
350350
return true;
351351
}
352352
return false;
@@ -843,7 +843,7 @@ static bool prepare_signal(int sig, struct task_struct *p, bool force)
843843
* will take ->siglock, notice SIGNAL_CLD_MASK, and
844844
* notify its parent. See get_signal_to_deliver().
845845
*/
846-
signal->flags = why | SIGNAL_STOP_CONTINUED;
846+
signal_set_stop_flags(signal, why | SIGNAL_STOP_CONTINUED);
847847
signal->group_stop_count = 0;
848848
signal->group_exit_code = 0;
849849
}

0 commit comments

Comments
 (0)