From acad7bf64ac7be7ed3f83437efeac0f92d681e01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Dziepak?= Date: Sun, 14 Sep 2014 19:07:40 +0200 Subject: [PATCH] kernel/x86_64: make sure stack is properly aligned in syscalls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Just following the path of least resistance and adding andq $~15, %rsp where appropriate. That should also make things harder to break when changing the amount of stuff placed on stack before calling the actual syscall routine. Signed-off-by: Paweł Dziepak --- src/system/kernel/arch/x86/64/interrupts.S | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/system/kernel/arch/x86/64/interrupts.S b/src/system/kernel/arch/x86/64/interrupts.S index db73a4fba4..a63cd009b8 100644 --- a/src/system/kernel/arch/x86/64/interrupts.S +++ b/src/system/kernel/arch/x86/64/interrupts.S @@ -315,6 +315,7 @@ FUNCTION(x86_64_syscall_entry): // Frame pointer is the iframe. movq %rsp, %rbp + andq $~15, %rsp // Preserve call number (R14 is callee-save), get thread pointer. movq %rax, %r14 @@ -367,10 +368,10 @@ FUNCTION(x86_64_syscall_entry): // TODO: post-syscall tracing +.Lsyscall_return: // Restore the original stack pointer and return. movq %rbp, %rsp -.Lsyscall_return: // Clear the restarted flag. testl $THREAD_FLAGS_SYSCALL_RESTARTED, THREAD_flags(%r12) jz 2f @@ -493,6 +494,7 @@ FUNCTION(x86_64_syscall_entry): // Make space on the stack. subq %rcx, %rsp + andq $~15, %rsp movq %rsp, %rdi // Set a fault handler.