diff options
author | Oleg Nesterov <oleg@tv-sign.ru> | 2008-04-30 03:53:03 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-04-30 11:29:37 -0400 |
commit | fae5fa44f1fd079ffbed8e0add929dd7bbd1347f (patch) | |
tree | 8990ac958d29733cb61733ae69265472f5e1d13c | |
parent | 193191035ad6268db9f561e81e3474b8be89a5ba (diff) |
signals: fix /sbin/init protection from unwanted signals
The global init has a lot of long standing problems with the unhandled fatal
signals.
- The "is_global_init(current)" check in get_signal_to_deliver()
protects only the main thread. Sub-thread can dequee the fatal
signal and shutdown the whole thread group except the main thread.
If it dequeues SIGSTOP /sbin/init will be stopped, this is not
right too. Note that we can't use is_global_init(->group_leader),
this breaks exec and this can't solve other problems we have.
- Even if afterwards ignored, the fatal signals sets SIGNAL_GROUP_EXIT
on delivery. This breaks exec, has other bad implications, and this
is just wrong.
Introduce the new SIGNAL_UNKILLABLE flag to fix these problems. It also helps
to solve some other problems addressed by the subsequent patches.
Currently we use this flag for the global init only, but it could also be used
by kthreads and (perhaps) by the sub-namespace inits.
Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
Acked-by: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Roland McGrath <roland@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | include/linux/sched.h | 2 | ||||
-rw-r--r-- | init/main.c | 2 | ||||
-rw-r--r-- | kernel/signal.c | 9 |
3 files changed, 10 insertions, 3 deletions
diff --git a/include/linux/sched.h b/include/linux/sched.h index 0917b3df12d5..fe970cdca83c 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h | |||
@@ -561,6 +561,8 @@ struct signal_struct { | |||
561 | #define SIGNAL_CLD_CONTINUED 0x00000020 | 561 | #define SIGNAL_CLD_CONTINUED 0x00000020 |
562 | #define SIGNAL_CLD_MASK (SIGNAL_CLD_STOPPED|SIGNAL_CLD_CONTINUED) | 562 | #define SIGNAL_CLD_MASK (SIGNAL_CLD_STOPPED|SIGNAL_CLD_CONTINUED) |
563 | 563 | ||
564 | #define SIGNAL_UNKILLABLE 0x00000040 /* for init: ignore fatal signals */ | ||
565 | |||
564 | /* If true, all threads except ->group_exit_task have pending SIGKILL */ | 566 | /* If true, all threads except ->group_exit_task have pending SIGKILL */ |
565 | static inline int signal_group_exit(const struct signal_struct *sig) | 567 | static inline int signal_group_exit(const struct signal_struct *sig) |
566 | { | 568 | { |
diff --git a/init/main.c b/init/main.c index 624266b524d4..1f4406477f83 100644 --- a/init/main.c +++ b/init/main.c | |||
@@ -802,6 +802,8 @@ static int noinline init_post(void) | |||
802 | (void) sys_dup(0); | 802 | (void) sys_dup(0); |
803 | (void) sys_dup(0); | 803 | (void) sys_dup(0); |
804 | 804 | ||
805 | current->signal->flags |= SIGNAL_UNKILLABLE; | ||
806 | |||
805 | if (ramdisk_execute_command) { | 807 | if (ramdisk_execute_command) { |
806 | run_init_process(ramdisk_execute_command); | 808 | run_init_process(ramdisk_execute_command); |
807 | printk(KERN_WARNING "Failed to execute %s\n", | 809 | printk(KERN_WARNING "Failed to execute %s\n", |
diff --git a/kernel/signal.c b/kernel/signal.c index 02ef3548aeb0..646a8765696a 100644 --- a/kernel/signal.c +++ b/kernel/signal.c | |||
@@ -728,7 +728,8 @@ static void complete_signal(int sig, struct task_struct *p, int group) | |||
728 | * Found a killable thread. If the signal will be fatal, | 728 | * Found a killable thread. If the signal will be fatal, |
729 | * then start taking the whole group down immediately. | 729 | * then start taking the whole group down immediately. |
730 | */ | 730 | */ |
731 | if (sig_fatal(p, sig) && !(signal->flags & SIGNAL_GROUP_EXIT) && | 731 | if (sig_fatal(p, sig) && |
732 | !(signal->flags & (SIGNAL_UNKILLABLE | SIGNAL_GROUP_EXIT)) && | ||
732 | !sigismember(&t->real_blocked, sig) && | 733 | !sigismember(&t->real_blocked, sig) && |
733 | (sig == SIGKILL || !(t->ptrace & PT_PTRACED))) { | 734 | (sig == SIGKILL || !(t->ptrace & PT_PTRACED))) { |
734 | /* | 735 | /* |
@@ -1615,7 +1616,8 @@ static int do_signal_stop(int signr) | |||
1615 | } else { | 1616 | } else { |
1616 | struct task_struct *t; | 1617 | struct task_struct *t; |
1617 | 1618 | ||
1618 | if (!likely(sig->flags & SIGNAL_STOP_DEQUEUED) || | 1619 | if (unlikely((sig->flags & (SIGNAL_STOP_DEQUEUED | SIGNAL_UNKILLABLE)) |
1620 | != SIGNAL_STOP_DEQUEUED) || | ||
1619 | unlikely(signal_group_exit(sig))) | 1621 | unlikely(signal_group_exit(sig))) |
1620 | return 0; | 1622 | return 0; |
1621 | /* | 1623 | /* |
@@ -1761,7 +1763,8 @@ relock: | |||
1761 | /* | 1763 | /* |
1762 | * Global init gets no signals it doesn't want. | 1764 | * Global init gets no signals it doesn't want. |
1763 | */ | 1765 | */ |
1764 | if (is_global_init(current)) | 1766 | if (unlikely(signal->flags & SIGNAL_UNKILLABLE) && |
1767 | !signal_group_exit(signal)) | ||
1765 | continue; | 1768 | continue; |
1766 | 1769 | ||
1767 | if (sig_kernel_stop(signr)) { | 1770 | if (sig_kernel_stop(signr)) { |