Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3478292ybz; Mon, 4 May 2020 03:54:11 -0700 (PDT) X-Google-Smtp-Source: APiQypJum3lAd6ih27L3IZzl0nZTAIHkG/sUNjZRrVDz3n2+ghk3Q/T+ImqIuNZe4IauOm1pR6xR X-Received: by 2002:a17:906:90c1:: with SMTP id v1mr13340164ejw.322.1588589651321; Mon, 04 May 2020 03:54:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588589651; cv=none; d=google.com; s=arc-20160816; b=XLlms6S9fCwiFU3GZfjxxZ2aIN55cWW3iyVjmsQflGyqIb6fS3X2oeI0HnJo+XHSSt m/263pS/873vr9ftaxpVU7usG5JEiPAfDbuqDIk4bAfEu+7ct/S7y4F8DX0iz8x8lu55 2SST66PtPtYKA9x4CwLeC5ca0iLt5ev7eA+vczxBd1hYEW0U0Y+sYF8OuEzde7SPmlFg qyPRXz8GW+6JQ11aCsJ6vKi8hWXJPv/EMhJltJ6dzIjQ+/YQ5no2gO1ZUJA4tXXdAUl7 PgmB8X+rNEXovdke5zCN1lHy7aFClp4MFfeoWd2HqwXTNdfpo8KQPf9VqTy2MvMb56Ns eMLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=iRUNm3gcqi81lpr43dwmxdWf16YWxyP1UxTVlnpFzUU=; b=CfihIJ6cuRQrX71BUC6FDHzij9S5CI5XWwjNlR1d6BWyIHwqB7jObSWP2XuuFgOUwG /Tc+8FcktRs+1N5Z58Frbz7dXAtghumzxO3c9qrtDvH+lMUDVzUrx+R6ZoA8DobYlS1k OJ7q2FlrkqS2VJ1R9NwqxveGZDV3+sujcb+8cMNSxP+4jlDCVaHdsksrgwoMpZa5YavK O9+aLFmZ8UX4gsd2WFnzWIUhiZ8s2Us9M4H95H4HaWrWzK4LHTsN24Wqv8wWJKciYmId 7r2DFdtPTz8dEdAKELd0+jXW9JRFKFV4/i6wfSVZy8NnhQXxehtyHwpDFWNKFxfJCbn0 vTKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=kuIp+12Q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p8si6986664ejz.441.2020.05.04.03.53.40; Mon, 04 May 2020 03:54:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=kuIp+12Q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728108AbgEDKlf (ORCPT + 99 others); Mon, 4 May 2020 06:41:35 -0400 Received: from mail.skyhub.de ([5.9.137.197]:55946 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726445AbgEDKlf (ORCPT ); Mon, 4 May 2020 06:41:35 -0400 Received: from zn.tnic (p200300EC2F08AF00A9258889345EFBFA.dip0.t-ipconnect.de [IPv6:2003:ec:2f08:af00:a925:8889:345e:fbfa]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id DC0E51EC011B; Mon, 4 May 2020 12:41:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1588588894; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=iRUNm3gcqi81lpr43dwmxdWf16YWxyP1UxTVlnpFzUU=; b=kuIp+12Q+Ly/02XXR6hpYKN7OouGtkNo7biM9HOEmVEhTzPn6oWp7JLSYxLEcLL7THnsuI uOJ/KMNOHqrpBJLxGMZrz6Dnr3mvcCxOKjbb+pFhKh3I/1xOg9r8213Q4Y8B7Cn3h6pD+d lUiNekNhlKGzhQzLbDWp8+pUbFsCGjw= Date: Mon, 4 May 2020 12:41:29 +0200 From: Borislav Petkov To: Joerg Roedel Cc: x86@kernel.org, hpa@zytor.com, Andy Lutomirski , Dave Hansen , Peter Zijlstra , Thomas Hellstrom , Jiri Slaby , Dan Williams , Tom Lendacky , Juergen Gross , Kees Cook , David Rientjes , Cfir Cohen , Erdem Aktas , Masami Hiramatsu , Mike Stunes , Joerg Roedel , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: Re: [PATCH v3 12/75] x86/boot/compressed/64: Switch to __KERNEL_CS after GDT is loaded Message-ID: <20200504104129.GD15046@zn.tnic> References: <20200428151725.31091-1-joro@8bytes.org> <20200428151725.31091-13-joro@8bytes.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200428151725.31091-13-joro@8bytes.org> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 28, 2020 at 05:16:22PM +0200, Joerg Roedel wrote: > From: Joerg Roedel > > When the pre-decompression code loads its first GDT in startup_64, it is > still running on the CS value of the previous GDT. In the case of SEV-ES > this is the EFI GDT. > > To make exception handling work (especially IRET) the CPU needs to > switch to a CS value in the current GDT, so jump to __KERNEL_CS after > the first GDT is loaded. > > Signed-off-by: Joerg Roedel > --- > arch/x86/boot/compressed/head_64.S | 8 ++++++++ > 1 file changed, 8 insertions(+) > > diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S > index 4f7e6b84be07..6b11060c3a0f 100644 > --- a/arch/x86/boot/compressed/head_64.S > +++ b/arch/x86/boot/compressed/head_64.S > @@ -393,6 +393,14 @@ SYM_CODE_START(startup_64) > addq %rax, 2(%rax) > lgdt (%rax) > > + /* Reload CS so IRET returns to a CS actually in the GDT */ > + pushq $__KERNEL_CS > + leaq .Lon_kernel_cs(%rip), %rax > + pushq %rax > + lretq > + > +.Lon_kernel_cs: > + > /* > * paging_prepare() sets up the trampoline and checks if we need to > * enable 5-level paging. > -- So I'm thinking I should take this one even now on the grounds that it sanitizes CS to something known-good than what was there before and who knows what set it and loaded the kernel...? And that is a good thing in itself. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette