From: Nelson Elhage Date: Tue, 20 Sep 2011 20:40:00 +0000 (-0400) Subject: ksplice: Clear garbage data on the kernel stack when handling signals. X-Git-Tag: v2.6.39-400.9.0~892 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=3b4659b5d14ca729408d68ac0bddf0f69cbfc92d;p=users%2Fjedix%2Flinux-maple.git ksplice: Clear garbage data on the kernel stack when handling signals. --- diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S index 5c1a91974918d..35c8120b25ecb 100644 --- a/arch/x86/kernel/entry_32.S +++ b/arch/x86/kernel/entry_32.S @@ -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: diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S index 8a445a0c989e0..e1b62393ec434 100644 --- a/arch/x86/kernel/entry_64.S +++ b/arch/x86/kernel/entry_64.S @@ -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 */