Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2898130ybl; Sun, 2 Feb 2020 09:17:20 -0800 (PST) X-Google-Smtp-Source: APXvYqxcsEuOPHvKbrP1ibY7stuNY35mW7i6yTcDfUCwvVHdfP5+lUKXZpNio2O/tFNopHfo1LtW X-Received: by 2002:a9d:7c9a:: with SMTP id q26mr15614758otn.206.1580663840558; Sun, 02 Feb 2020 09:17:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580663840; cv=none; d=google.com; s=arc-20160816; b=vYZ6GRjAWqHGOZ6C2EoWxI26j2/9rdW/i+Qce2HsIpKEKwWWIHSNxiB1qA8+LrF5t6 1VEFtGvSSFfjOpojtmrAmI6aqpySzDWZtGgBx9vNHmxsOvpKqU4xDY3fcgIX0F9yGJu1 4Epd6YeL2wm0Ko+38UDTAKo0kNgR09+D536gzpRA1He9vFrDhKF1P2RqgTlzgHEUt9rO B4QzsYMEGJM/NRzRDhuBnm/SF3DE2qvjOaEd1tiPJo+Cf0Etbd+BG5wwcSev0p58PBJF ylL4Cyh95BTa0ehpfeMGnfn1VRdJuO6XXsQJ5njg7crH4XzhkRN2mv+da34H//lcOvW9 x1rQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=fNIctzUQqpzBYKShq+agBaG6jK3vI6wtoz79iRuDrBw=; b=Wiv8wVypigXz/FodUSVtwRpCsL/AdL/7qpjkpNupoX/9kK8d3fVg54xZNgv1LrBMfY Tbu80iFyHOSwElGT06H4VpjpqxUtKcKmI3BXleg9EpURSKEeiFXSmeUZGpMPLMvd6vjs y0vc7rrRFmDYZ+wIT06Z6YOf2nWK32Vygut8DKmZ/SgJJC32UpXGPb1YxBxiqDVXFQ7k 728Nce4NdapAXsHNkPuoIABu8TDIeXsYTZmA5GAP5JSYnmwzz/Oi7/iwiwViEn02B7jI YWsoR0NOIQbQswmfiPoMEj45n6fj2fKG1/NIuBjcBDds2H0ZkK+4/JhMteTCsh7rvwyK V+Zg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t3si4274641otp.230.2020.02.02.09.16.39; Sun, 02 Feb 2020 09:17:20 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727027AbgBBRN7 (ORCPT + 99 others); Sun, 2 Feb 2020 12:13:59 -0500 Received: from mail-qt1-f196.google.com ([209.85.160.196]:36061 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726905AbgBBRN6 (ORCPT ); Sun, 2 Feb 2020 12:13:58 -0500 Received: by mail-qt1-f196.google.com with SMTP id t13so9630421qto.3; Sun, 02 Feb 2020 09:13:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fNIctzUQqpzBYKShq+agBaG6jK3vI6wtoz79iRuDrBw=; b=sWkCGbdMQWvcwW4ZHprK51piBkeEU7tV8JfOcgdx8Bt5urzx+A56RoD4TFU3buuuM+ 6+3MuC5BTUgurRTh/MZ5YnuKisJEFFWVt9FUQ5IPXVI1m/QyFY+4rjCJHQvP5Uj535XQ NFLijm93UgzkXOtl/HIEGrOFSfy4id0ft5MFu3++hrivKTl7SCNUcemMJPhO2+X9x0Oi Edpab/AL3K+6EUjpYH0t0Wu2PlV1EkwST5wkZpyi7skfGilEv5PXAAJhGzj5VCxj67te iMQWnCSz9G8ls8NJTy74JwVIA8L2G5OOynIpCmzAi9AAKhqCTNbq9cngodyizQn96O0v niVw== X-Gm-Message-State: APjAAAWAOoIO3xJTV39+3AJi9v+uqOK7c3eS/ih2U6jg2CwPE+Uu7T37 yEBTu+pDtKbo9CESAKu01Jo= X-Received: by 2002:aed:2321:: with SMTP id h30mr20706652qtc.355.1580663637426; Sun, 02 Feb 2020 09:13:57 -0800 (PST) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id 3sm8150081qte.59.2020.02.02.09.13.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Feb 2020 09:13:57 -0800 (PST) From: Arvind Sankar To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Ard Biesheuvel Cc: linux-efi@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/7] x86/boot: Reload GDTR after copying to the end of the buffer Date: Sun, 2 Feb 2020 12:13:49 -0500 Message-Id: <20200202171353.3736319-4-nivedita@alum.mit.edu> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200202171353.3736319-1-nivedita@alum.mit.edu> References: <20200130200440.1796058-1-nivedita@alum.mit.edu> <20200202171353.3736319-1-nivedita@alum.mit.edu> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The GDT may get overwritten during the copy or during extract_kernel, which will cause problems if any segment register is touched before the GDTR is reloaded by the decompressed kernel. For safety update the GDTR to point to the GDT within the copied kernel. Signed-off-by: Arvind Sankar --- arch/x86/boot/compressed/head_64.S | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index c56b30bd9c7b..27eb2a6786db 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -439,6 +439,16 @@ trampoline_return: cld popq %rsi + /* + * The GDT may get overwritten either during the copy we just did or + * during extract_kernel below. To avoid any issues, repoint the GDTR + * to the new copy of the GDT. + */ + leaq gdt64(%rbx), %rax + subq %rbp, 2(%rax) + addq %rbx, 2(%rax) + lgdt (%rax) + /* * Jump to the relocated address. */ -- 2.24.1