From b0363ac87062e42849d0ec3d9966495694aa6120 Mon Sep 17 00:00:00 2001 From: Sasha Levin Date: Wed, 14 Jan 2015 20:41:18 -0500 Subject: [PATCH] ksplice: Clear garbage data on the kernel stack when handling signals The garbage data can give false-positives for the Ksplice safety checks making it difficult (or sometimes impossible) to apply the rebootless updates. Clear the garbage with 0-words to avoid this. Signed-off-by: Sasha Levin Signed-off-by: Santosh Shilimkar --- arch/x86/kernel/entry_32.S | 29 ++++++++++++++++++++++++++++- arch/x86/kernel/entry_64.S | 25 +++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S index 1c309763e321..9b0d1bd1d15a 100644 --- a/arch/x86/kernel/entry_32.S +++ b/arch/x86/kernel/entry_32.S @@ -628,7 +628,7 @@ work_notifysig: # deal with pending signals and cmpb $USER_RPL, %bl jb resume_kernel xorl %edx, %edx - call do_notify_resume + call clear_stack_do_notify_resume jmp resume_userspace #ifdef CONFIG_VM86 @@ -642,6 +642,33 @@ work_notifysig_v86: #endif 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 02c2eff7478d..f9ba92ca936a 100644 --- a/arch/x86/kernel/entry_64.S +++ b/arch/x86/kernel/entry_64.S @@ -401,7 +401,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_EXTRA_REGS @@ -867,7 +867,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_EXTRA_REGS DISABLE_INTERRUPTS(CLBR_NONE) TRACE_IRQS_OFF @@ -1651,3 +1651,24 @@ 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) -- 2.50.1