From: Arnd Bergmann <arnd@arndb.de>

Christian Borntr�ger noticed that the kernel can crash after <SysRq>-T.  It
appears that the show_task function gets called for all tasks, which does
not work if one of the tasks is running in a system call on another CPU. 
In that case the result of thread_saved_pc and show_stack is undefined and
likely to cause a crash.

For tasks running in user space on other CPUs, show_task() is probably
harmless, but I'm not sure if that's true on all architectures.

The patch below is still racy for tasks that are about to sleep, but it
demonstrates the problem.



---

 25-akpm/kernel/sched.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)

diff -puN kernel/sched.c~show_task-fix kernel/sched.c
--- 25/kernel/sched.c~show_task-fix	Wed Feb 11 18:37:12 2004
+++ 25-akpm/kernel/sched.c	Wed Feb 11 18:37:12 2004
@@ -2917,13 +2917,13 @@ static void show_task(task_t * p)
 	else
 		printk("?");
 #if (BITS_PER_LONG == 32)
-	if (p == current)
-		printk(" current  ");
+	if (state == TASK_RUNNING)
+		printk(" running ");
 	else
 		printk(" %08lX ", thread_saved_pc(p));
 #else
-	if (p == current)
-		printk("   current task   ");
+	if (state == TASK_RUNNING)
+		printk("  running task   ");
 	else
 		printk(" %016lx ", thread_saved_pc(p));
 #endif
@@ -2945,7 +2945,8 @@ static void show_task(task_t * p)
 	else
 		printk(" (NOTLB)\n");
 
-	show_stack(p, NULL);
+	if (state != TASK_RUNNING)
+		show_stack(p, NULL);
 }
 
 void show_state(void)

_