x86/mm: Fix SME encryption stack ptr handling

sme_encrypt_execute() stashes the stack pointer on entry into %rbp
because it allocates a one-page stack in the non-encrypted area for the
encryption routine to use. When the latter is done, it restores it from
%rbp again, before returning.

However, it uses the FRAME_* macros partially but restores %rsp from
%rbp explicitly with a MOV. And this is fine as long as the macros
*actually* do something.

Unless, you do a !CONFIG_FRAME_POINTER build where those macros
are empty. Then, we still restore %rsp from %rbp but %rbp contains
*something* and this leads to a stack corruption. The manifestation
being a triple-fault during early boot when testing SME. Good luck to me
debugging this with the clumsy endless-loop-in-asm method and narrowing
it down gradually. :-(

So, long story short, open-code the frame macros so that there's no
monkey business and we avoid subtly breaking SME depending on the
.config.

Fixes: 6ebcb060713f ("x86/mm: Add support to encrypt the kernel in-place")
Signed-off-by: Borislav Petkov <bp@suse.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Tom Lendacky <thomas.lendacky@amd.com>
Cc: Brijesh Singh <brijesh.singh@amd.com>
Link: http://lkml.kernel.org/r/20170827163924.25552-1-bp@alien8.de

authored by

Borislav Petkov and committed by
Thomas Gleixner
6e0b52d4 ea2800dd

+3 -3
+3 -3
arch/x86/mm/mem_encrypt_boot.S
··· 15 15 #include <asm/page.h> 16 16 #include <asm/processor-flags.h> 17 17 #include <asm/msr-index.h> 18 - #include <asm/frame.h> 19 18 20 19 .text 21 20 .code64 ··· 32 33 * R8 - physcial address of the pagetables to use for encryption 33 34 */ 34 35 35 - FRAME_BEGIN /* RBP now has original stack pointer */ 36 + push %rbp 37 + movq %rsp, %rbp /* RBP now has original stack pointer */ 36 38 37 39 /* Set up a one page stack in the non-encrypted memory area */ 38 40 movq %rcx, %rax /* Workarea stack page */ ··· 64 64 pop %r12 65 65 66 66 movq %rbp, %rsp /* Restore original stack pointer */ 67 - FRAME_END 67 + pop %rbp 68 68 69 69 ret 70 70 ENDPROC(sme_encrypt_execute)