Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3717946imm; Mon, 8 Oct 2018 08:26:55 -0700 (PDT) X-Google-Smtp-Source: ACcGV62ibWdBVw6/5sbXuHzii8hTDgpyR8h708MkDn5XwyiB3Pt4lUyH7CDa9AsnZl/xY93DwDWi X-Received: by 2002:a62:215b:: with SMTP id h88-v6mr25418144pfh.233.1539012415832; Mon, 08 Oct 2018 08:26:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539012415; cv=none; d=google.com; s=arc-20160816; b=SjNhKcPBwDGW56QUM3ho+64fYjWMY8ZndrHjUtRO/ARbfs96Zxaq04hClMQ9yQOqOX BtI5dCP9tonZ/MJ91/PyKqx/K7m5nGPhvGgX2XlNtqKwVpdUNh08Av+FFR3OnaOVxE6E LwbLpjcGlkJoza9M4nVLl6ruqTgIaUE3FeopAm575VV7kukj6Oy3pKi4Kz03CWvuLs6x 2VOoP0QwZ27pRexDMR+5wMOAnG3vM1ITMIk2Hm/CfYXVGZ4ryS980ar9TqzXPs7ZcSBw K3iCx86x/XyiOoiqVfrKdciQ/O9xF3/M3xYaAWVsBn7ffJk9ebO/wVdTKMqnyX2ys/Za 8cmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=evpIaiArQYuuMmYhqwATXOVVD1guyPMrg1vdX+3YBXk=; b=N/jOTM1Qj6YAt5iP7eLAMibUh9IPn8mumEytxRpM8cRXfg3gxQTdp5bzVxKwEJEdQH KAIb3nrHNqL2LBleN9Xvh+DNB8K1syexJ1HjlP6GKIxd/bCxxVkz8xAxqfHhJ5FLKrhC L/LllXDUvUbWPu7Gl/4NoGMKB4ojpLTGr18vbuyLKdyo0DO8y+K2yUl2Dl+Yyz/Vo7oP 057uKdSmoLGXM0oDMslzLlUpW2GQSA/RDUjvwIP4u+XRd5eewKqqHJvGrhxYAEgCtV8b 7FU1+nn2NYYhPLeCHH2QCsSigd/OmLscdPwmWHL3zRtmSdB5H7820J19tumplh8UieIH iTUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="KTV/ND/A"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 16-v6si23337934pfc.21.2018.10.08.08.26.40; Mon, 08 Oct 2018 08:26:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="KTV/ND/A"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728210AbeJHWih (ORCPT + 99 others); Mon, 8 Oct 2018 18:38:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:57320 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728197AbeJHWig (ORCPT ); Mon, 8 Oct 2018 18:38:36 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 43A682089D; Mon, 8 Oct 2018 15:26:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539012381; bh=4oFR1r4Rg19huhhjFCNss0diV4LwGgMfLyqId/iWh+g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KTV/ND/AtWjqNq0p9xABZ3Ffxt5t1le2FiaCQE+GkoP6PAvrMySnIgECCVQ6SoZgK PeDVISz+VSLHvY2IxrkEVUjL64py2VaUzRyb9jHKjEVMnefmSc0n1+FZsVlqJrAodI AUuvRB+vJ/qUbyjDT8332IDOG2F+CN5VqSSj8HDg= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Kairui Song , Borislav Petkov , tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, brijesh.singh@amd.com, kexec@lists.infradead.org, dyoung@redhat.com, bhe@redhat.com, ghook@redhat.com, Sasha Levin Subject: [PATCH AUTOSEL 4.18 58/58] x86/boot: Fix kexec booting failure in the SEV bit detection code Date: Mon, 8 Oct 2018 11:25:23 -0400 Message-Id: <20181008152523.70705-58-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181008152523.70705-1-sashal@kernel.org> References: <20181008152523.70705-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kairui Song [ Upstream commit bdec8d7fa55e6f5314ed72e5a0b435d90ff90548 ] Commit 1958b5fc4010 ("x86/boot: Add early boot support when running with SEV active") can occasionally cause system resets when kexec-ing a second kernel even if SEV is not active. That's because get_sev_encryption_bit() uses 32-bit rIP-relative addressing to read the value of enc_bit - a variable which caches a previously detected encryption bit position - but kexec may allocate the early boot code to a higher location, beyond the 32-bit addressing limit. In this case, garbage will be read and get_sev_encryption_bit() will return the wrong value, leading to accessing memory with the wrong encryption setting. Therefore, remove enc_bit, and thus get rid of the need to do 32-bit rIP-relative addressing in the first place. [ bp: massage commit message heavily. ] Fixes: 1958b5fc4010 ("x86/boot: Add early boot support when running with SEV active") Suggested-by: Borislav Petkov Signed-off-by: Kairui Song Signed-off-by: Borislav Petkov Reviewed-by: Tom Lendacky Cc: linux-kernel@vger.kernel.org Cc: tglx@linutronix.de Cc: mingo@redhat.com Cc: hpa@zytor.com Cc: brijesh.singh@amd.com Cc: kexec@lists.infradead.org Cc: dyoung@redhat.com Cc: bhe@redhat.com Cc: ghook@redhat.com Link: https://lkml.kernel.org/r/20180927123845.32052-1-kasong@redhat.com Signed-off-by: Sasha Levin --- arch/x86/boot/compressed/mem_encrypt.S | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/arch/x86/boot/compressed/mem_encrypt.S b/arch/x86/boot/compressed/mem_encrypt.S index eaa843a52907..a480356e0ed8 100644 --- a/arch/x86/boot/compressed/mem_encrypt.S +++ b/arch/x86/boot/compressed/mem_encrypt.S @@ -25,20 +25,6 @@ ENTRY(get_sev_encryption_bit) push %ebx push %ecx push %edx - push %edi - - /* - * RIP-relative addressing is needed to access the encryption bit - * variable. Since we are running in 32-bit mode we need this call/pop - * sequence to get the proper relative addressing. - */ - call 1f -1: popl %edi - subl $1b, %edi - - movl enc_bit(%edi), %eax - cmpl $0, %eax - jge .Lsev_exit /* Check if running under a hypervisor */ movl $1, %eax @@ -69,15 +55,12 @@ ENTRY(get_sev_encryption_bit) movl %ebx, %eax andl $0x3f, %eax /* Return the encryption bit location */ - movl %eax, enc_bit(%edi) jmp .Lsev_exit .Lno_sev: xor %eax, %eax - movl %eax, enc_bit(%edi) .Lsev_exit: - pop %edi pop %edx pop %ecx pop %ebx @@ -113,8 +96,6 @@ ENTRY(set_sev_encryption_mask) ENDPROC(set_sev_encryption_mask) .data -enc_bit: - .int 0xffffffff #ifdef CONFIG_AMD_MEM_ENCRYPT .balign 8 -- 2.17.1