Commit 10ab825b authored by Oleg Nesterov's avatar Oleg Nesterov Committed by Linus Torvalds
Browse files

change kernel threads to ignore signals instead of blocking them

Currently kernel threads use sigprocmask(SIG_BLOCK) to protect against
signals.  This doesn't prevent the signal delivery, this only blocks
signal_wake_up().  Every "killall -33 kthreadd" means a "struct siginfo"

Change kthreadd_setup() to set all handlers to SIG_IGN instead of blocking
them (make a new helper ignore_signals() for that).  If the kernel thread
needs some signal, it should use allow_signal() anyway, and in that case it
should not use CLONE_SIGHAND.

Note that we can't change daemonize() (should die!) in the same way,
because it can be used along with CLONE_SIGHAND.  This means that
allow_signal() still should unblock the signal to work correctly with
daemonize()ed threads.

However, disallow_signal() doesn't block the signal any longer but ignores

NOTE: with or without this patch the kernel threads are not protected from
handle_stop_signal(), this seems harmless, but not good.
Signed-off-by: default avatarOleg Nesterov <>
Acked-by: default avatar"Eric W. Biederman" <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent 5de18d16
......@@ -1317,6 +1317,7 @@ extern int in_egroup_p(gid_t);
extern void proc_caches_init(void);
extern void flush_signals(struct task_struct *);
extern void ignore_signals(struct task_struct *);
extern void flush_signal_handlers(struct task_struct *, int force_default);
extern int dequeue_signal(struct task_struct *tsk, sigset_t *mask, siginfo_t *info);
......@@ -347,7 +347,7 @@ int disallow_signal(int sig)
return -EINVAL;
sigaddset(&current->blocked, sig);
current->sighand->action[(sig)-1].sa.sa_handler = SIG_IGN;
return 0;
......@@ -215,24 +215,13 @@ EXPORT_SYMBOL(kthread_stop);
static __init void kthreadd_setup(void)
struct task_struct *tsk = current;
struct k_sigaction sa;
sigset_t blocked;
set_task_comm(tsk, "kthreadd");
/* Block and flush all signals */
sigprocmask(SIG_BLOCK, &blocked, NULL);
/* SIG_IGN makes children autoreap: see do_notify_parent(). */ = SIG_IGN; = 0;
siginitset(&, sigmask(SIGCHLD));
do_sigaction(SIGCHLD, &sa, (struct k_sigaction *)0);
set_user_nice(current, -5);
set_cpus_allowed(current, CPU_MASK_ALL);
set_user_nice(tsk, -5);
set_cpus_allowed(tsk, CPU_MASK_ALL);
int kthreadd(void *unused)
......@@ -209,6 +209,16 @@ void flush_signals(struct task_struct *t)
spin_unlock_irqrestore(&t->sighand->siglock, flags);
void ignore_signals(struct task_struct *t)
int i;
for (i = 0; i < _NSIG; ++i)
t->sighand->action[i].sa.sa_handler = SIG_IGN;
* Flush all handlers for a task.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment