sysrq: Fix possible race with exiting task
Anton Vorontsov [Tue, 7 Feb 2012 06:49:39 +0000 (10:49 +0400)]
sysrq should grab the tasklist lock, otherwise calling force_sig() is
not safe, as it might race with exiting task, which ->sighand might be
set to NULL already.

Signed-off-by: Anton Vorontsov <anton.vorontsov@linaro.org>
Acked-by: David Rientjes <rientjes@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

drivers/tty/sysrq.c

index 7867b7c..a1bcad7 100644 (file)
@@ -322,11 +322,13 @@ static void send_sig_all(int sig)
 {
        struct task_struct *p;
 
+       read_lock(&tasklist_lock);
        for_each_process(p) {
                if (p->mm && !is_global_init(p))
                        /* Not swapper, init nor kernel thread */
                        force_sig(sig, p);
        }
+       read_unlock(&tasklist_lock);
 }
 
 static void sysrq_handle_term(int key)