From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751250AbdH0Qjd (ORCPT ); Sun, 27 Aug 2017 12:39:33 -0400 Received: from mail.skyhub.de ([5.9.137.197]:36836 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751182AbdH0Qjc (ORCPT ); Sun, 27 Aug 2017 12:39:32 -0400 From: Borislav Petkov To: X86 ML Cc: Tom Lendacky , LKML , Brijesh Singh Subject: [PATCH] x86/mm: Fix SME encryption stack ptr handling Date: Sun, 27 Aug 2017 18:39:24 +0200 Message-Id: <20170827163924.25552-1-bp@alien8.de> X-Mailer: git-send-email 2.13.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Borislav Petkov 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. Signed-off-by: Borislav Petkov Acked-by: Tom Lendacky Cc: Brijesh Singh --- arch/x86/mm/mem_encrypt_boot.S | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/x86/mm/mem_encrypt_boot.S b/arch/x86/mm/mem_encrypt_boot.S index b327e0472448..730e6d541df1 100644 --- a/arch/x86/mm/mem_encrypt_boot.S +++ b/arch/x86/mm/mem_encrypt_boot.S @@ -15,7 +15,6 @@ #include #include #include -#include .text .code64 @@ -33,7 +32,8 @@ ENTRY(sme_encrypt_execute) * R8 - physcial address of the pagetables to use for encryption */ - FRAME_BEGIN /* RBP now has original stack pointer */ + push %rbp + movq %rsp, %rbp /* RBP now has original stack pointer */ /* Set up a one page stack in the non-encrypted memory area */ movq %rcx, %rax /* Workarea stack page */ @@ -64,7 +64,7 @@ ENTRY(sme_encrypt_execute) pop %r12 movq %rbp, %rsp /* Restore original stack pointer */ - FRAME_END + pop %rbp ret ENDPROC(sme_encrypt_execute) -- 2.13.0