x86: simplify stackprotector self-check
authorArjan van de Ven <arjan@linux.intel.com>
Sat, 12 Jul 2008 16:36:38 +0000 (09:36 -0700)
committerIngo Molnar <mingo@elte.hu>
Sun, 13 Jul 2008 19:08:38 +0000 (21:08 +0200)
Clean up the code by removing no longer needed code;
make sure the pda is updated and kept in sync

Signed-off-by: Arjan van de Ven <arjan@linux.intel.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
include/asm-x86/pda.h
kernel/panic.c

index 62b7349..a5ff5bb 100644 (file)
@@ -131,4 +131,5 @@ do {                                                                        \
 
 #define PDA_STACKOFFSET (5*8)
 
+#define refresh_stack_canary() write_pda(stack_canary, current->stack_canary)
 #endif
index 28153ae..87445a8 100644 (file)
@@ -328,37 +328,21 @@ EXPORT_SYMBOL(warn_on_slowpath);
 #ifndef GCC_HAS_SP
 #warning You have selected the CONFIG_CC_STACKPROTECTOR option, but the gcc used does not support this.
 #endif
+
 static unsigned long __stack_check_testing;
+
 /*
  * Self test function for the stack-protector feature.
  * This test requires that the local variable absolutely has
- * a stack slot, hence the barrier()s.
+ * a stack slot.
  */
 static noinline void __stack_chk_test_func(void)
 {
-       unsigned long foo;
-       barrier();
-       /*
-        * we need to make sure we're not about to clobber the return address,
-        * while real exploits do this, it's unhealthy on a running system.
-        * Besides, if we would, the test is already failed anyway so
-        * time to pull the emergency brake on it.
-        */
-       if ((unsigned long)__builtin_return_address(0) ==
-                                       *(((unsigned long *)&foo)+1)) {
-               printk(KERN_ERR "No -fstack-protector-stack-frame!\n");
-       }
-#ifdef CONFIG_FRAME_POINTER
-       /* We also don't want to clobber the frame pointer */
-       if ((unsigned long)__builtin_return_address(0) ==
-                                       *(((unsigned long *)&foo)+2)) {
-               printk(KERN_ERR "No -fstack-protector-stack-frame!\n");
-       }
-#endif
-       if (current->stack_canary != *(((unsigned long *)&foo)+1))
-               printk(KERN_ERR "No -fstack-protector canary found\n");
+       unsigned long dummy_buffer[64]; /* force gcc to use the canary */
 
        current->stack_canary = ~current->stack_canary;
+       refresh_stack_canary();
+       dummy_buffer[3] = 1; /* fool gcc into keeping the variable */
 }
 
 static int __stack_chk_test(void)
@@ -371,6 +355,7 @@ static int __stack_chk_test(void)
                WARN_ON(1);
        };
        current->stack_canary = ~current->stack_canary;
+       refresh_stack_canary();
        return 0;
 }
 /*