Skip to contentSkip to conversation

x86: suppress stack overrun message for init_task

PATCH In review Jan Beulich 2 participants 5 messages Nov 20, 2009 – Nov 23, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: suppress stack overrun message for init_task

init_task doesn't get its stack end location set to STACK_END_MAGIC, and hence the message is confusing rather than helpful in this case.

---
 arch/x86/mm/fault.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/mm/fault.c +1 -1
@@ -658,7 +658,7 @@ no_context(struct pt_regs *regs, unsigne
 	show_fault_oops(regs, error_code, address);
 
 	stackend = end_of_stack(tsk);
-	if (*stackend != STACK_END_MAGIC)
+	if (tsk != &init_task && *stackend != STACK_END_MAGIC)
 		printk(KERN_ALERT "Thread overran stack, or stack corrupted\n");
 
 	tsk->thread.cr2		= address;
#1 lore raw
Quoted 5 lines · Jan Beulich

init_task doesn't get its stack end location set to STACK_END_MAGIC, and hence the message is confusing rather than helpful in this case.

Yeah, this is a good catch. STACK_END_MAGIC is written in fork(), init is not forked.

However, isn't it better if we can do the same detection for init too?

Quoted 23 lines

---
arch/x86/mm/fault.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/mm/fault.c +1 -2
@@ -658,7 +658,7 @@ no_context(struct pt_regs *regs, unsigne
 	show_fault_oops(regs, error_code, address);
 
 	stackend = end_of_stack(tsk);
-	if (*stackend != STACK_END_MAGIC)
+	if (tsk != &init_task && *stackend != STACK_END_MAGIC)
 		printk(KERN_ALERT "Thread overran stack, or stack corrupted\n");
 
 	tsk->thread.cr2		= address;
 
 
 
--

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Signature · 1 line
Live like a child, think like the god.
#2 lore raw
In reply to Jan Beulich
Quoted 5 lines · Jan Beulich

init_task doesn't get its stack end location set to STACK_END_MAGIC, and hence the message is confusing rather than helpful in this case.

How about the patch below? It is totally untested. ;)

-------------->

init process should also write STACK_END_MAGIC to the end of its stack.

----

init/main.c +3 -0
index 5988deb..5a8f1b9 100644
@@ -69,6 +69,7 @@
 #include <linux/kmemtrace.h>
 #include <linux/sfi.h>
 #include <linux/shmem_fs.h>
+#include <linux/magic.h>
 #include <trace/boot.h>
 
 #include <asm/io.h>
@@ -798,7 +799,9 @@ static void __init do_pre_smp_initcalls(void)
 
 static void run_init_process(char *init_filename)
 {
+	unsigned long *stack_end = end_of_stack(&init_task);
 	argv_init[0] = init_filename;
+	*stack_end = STACK_END_MAGIC;
 	kernel_execve(init_filename, argv_init, envp_init);
 }
 
#3 lore raw
Quoted 8 lines
Quoted 1 line
Quoted 1 line

AméricoWang <[email protected]> 21.11.09 11:31 >>>

Quoted 5 lines · Jan Beulich

init_task doesn't get its stack end location set to STACK_END_MAGIC, and hence the message is confusing rather than helpful in this case.

Quoted 6 lines

How about the patch below? It is totally untested. ;)

-------------->

init process should also write STACK_END_MAGIC to the end of its stack.

This seems way too late to me - in order to avoid any false reports, it would really need to be part of INIT_TASK() I believe, but I didn't find a way to make it so.

Jan

Quoted 24 lines

----

init/main.c +3 -0
index 5988deb..5a8f1b9 100644
@@ -69,6 +69,7 @@
 #include <linux/kmemtrace.h>
 #include <linux/sfi.h>
 #include <linux/shmem_fs.h>
+#include <linux/magic.h>
 #include <trace/boot.h>
 
 #include <asm/io.h>
@@ -798,7 +799,9 @@ static void __init do_pre_smp_initcalls(void)
 
 static void run_init_process(char *init_filename)
 {
+	unsigned long *stack_end = end_of_stack(&init_task);
 	argv_init[0] = init_filename;
+	*stack_end = STACK_END_MAGIC;
 	kernel_execve(init_filename, argv_init, envp_init);
 }
#4 lore raw

[tip:x86/debug] x86: Suppress stack overrun message for init_task

In reply to Jan Beulich
Commit-ID:  0e7810be30f66e9f430c4ce2cd3b14634211690f
Gitweb:     http://git.kernel.org/tip/0e7810be30f66e9f430c4ce2cd3b14634211690f
Author:     Jan Beulich <[email protected]>
AuthorDate: Fri, 20 Nov 2009 14:00:14 +0000
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 23 Nov 2009 11:45:34 +0100

x86: Suppress stack overrun message for init_task

init_task doesn't get its stack end location set to STACK_END_MAGIC, and hence the message is confusing rather than helpful in this case.

LKML-Reference: <[email protected]>

---
 arch/x86/mm/fault.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/mm/fault.c +1 -1
index f4cee90..071eee6 100644
@@ -658,7 +658,7 @@ no_context(struct pt_regs *regs, unsigned long error_code,
 	show_fault_oops(regs, error_code, address);
 
 	stackend = end_of_stack(tsk);
-	if (*stackend != STACK_END_MAGIC)
+	if (tsk != &init_task && *stackend != STACK_END_MAGIC)
 		printk(KERN_ALERT "Thread overran stack, or stack corrupted\n");
 
 	tsk->thread.cr2		= address;