]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
ksplice: Clear garbage data on the kernel stack when handling signals.
authorNelson Elhage <nelson.elhage@oracle.com>
Tue, 20 Sep 2011 20:40:00 +0000 (16:40 -0400)
committerGuru Anbalagane <guru.anbalagane@oracle.com>
Thu, 22 Sep 2011 05:38:42 +0000 (22:38 -0700)
arch/x86/kernel/entry_32.S
arch/x86/kernel/entry_64.S

index 5c1a91974918d1b6104c9068ed4eef41ff6e30ab..35c8120b25ecb2785e8931b8a1acfd081956eb90 100644 (file)
@@ -625,7 +625,7 @@ work_notifysig:                             # deal with pending signals and
        jne work_notifysig_v86          # returning to kernel-space or
                                        # vm86-space
        xorl %edx, %edx
-       call do_notify_resume
+       call clear_stack_do_notify_resume
        jmp resume_userspace_sig
 
        ALIGN
@@ -638,10 +638,37 @@ work_notifysig_v86:
        movl %esp, %eax
 #endif
        xorl %edx, %edx
-       call do_notify_resume
+       call clear_stack_do_notify_resume
        jmp resume_userspace_sig
 END(work_pending)
 
+       # Clear the stack before handling signals
+       ALIGN
+#define STACK_CLEAR_WORDS      0x80
+ENTRY(clear_stack_do_notify_resume)
+       testl $_TIF_SIGPENDING, %ecx
+       jnz do_notify_resume
+
+       push %eax
+       push %ecx
+       push %edi
+
+       movl %esp, %edi
+       subl $4, %edi
+       movl $STACK_CLEAR_WORDS, %ecx
+       xorl %eax, %eax
+
+       std
+       rep stosl
+       cld
+
+       pop %edi
+       pop %ecx
+       pop %eax
+
+       jmp do_notify_resume
+END(clear_stack_do_notify_resume)
+
        # perform syscall exit tracing
        ALIGN
 syscall_trace_entry:
index 8a445a0c989e095bc84557861d4a4e73e09e3e90..e1b62393ec434e1bef629c6d53ce585df37f4759 100644 (file)
@@ -660,7 +660,7 @@ int_signal:
        jz 1f
        movq %rsp,%rdi          # &ptregs -> arg1
        xorl %esi,%esi          # oldset -> arg2
-       call do_notify_resume
+       call clear_stack_do_notify_resume
 1:     movl $_TIF_WORK_MASK,%edi
 int_restore_rest:
        RESTORE_REST
@@ -919,7 +919,7 @@ retint_signal:
        movq $-1,ORIG_RAX(%rsp)
        xorl %esi,%esi          # oldset
        movq %rsp,%rdi          # &pt_regs
-       call do_notify_resume
+       call clear_stack_do_notify_resume
        RESTORE_REST
        DISABLE_INTERRUPTS(CLBR_NONE)
        TRACE_IRQS_OFF
@@ -1387,7 +1387,7 @@ paranoid_userspace:
        ENABLE_INTERRUPTS(CLBR_NONE)
        xorl %esi,%esi                  /* arg2: oldset */
        movq %rsp,%rdi                  /* arg1: &pt_regs */
-       call do_notify_resume
+       call clear_stack_do_notify_resume
        DISABLE_INTERRUPTS(CLBR_NONE)
        TRACE_IRQS_OFF
        jmp paranoid_userspace
@@ -1521,7 +1521,7 @@ nmi_userspace:
        ENABLE_INTERRUPTS(CLBR_NONE)
        xorl %esi,%esi                  /* arg2: oldset */
        movq %rsp,%rdi                  /* arg1: &pt_regs */
-       call do_notify_resume
+       call clear_stack_do_notify_resume
        DISABLE_INTERRUPTS(CLBR_NONE)
        jmp nmi_userspace
 nmi_schedule:
@@ -1543,6 +1543,28 @@ ENTRY(ignore_sysret)
        CFI_ENDPROC
 END(ignore_sysret)
 
+       # Clear the stack before handling signals
+#define STACK_CLEAR_WORDS      0x80
+ENTRY(clear_stack_do_notify_resume)
+       testl $_TIF_SIGPENDING, %edx
+       jnz do_notify_resume
+
+       pushq %rdi
+
+       movq %rsp, %rdi
+       subq $8, %rdi
+       movl $STACK_CLEAR_WORDS, %ecx
+       xorq %rax, %rax
+
+       std
+       rep stosq
+       cld
+
+       popq %rdi
+
+       jmp do_notify_resume
+END(clear_stack_do_notify_resume)
+
 /*
  * End of kprobes section
  */