Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp751464rwi; Thu, 20 Oct 2022 04:59:52 -0700 (PDT) X-Google-Smtp-Source: AMsMyM59J22/5kUggWDAlQmpT5PapPmk1/iUCySLVA0p0xtgaMImBY4qV/o1GNZeFto1GjE9++x3 X-Received: by 2002:a17:906:5a4b:b0:78d:4e5a:d101 with SMTP id my11-20020a1709065a4b00b0078d4e5ad101mr10308737ejc.196.1666267192478; Thu, 20 Oct 2022 04:59:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666267192; cv=none; d=google.com; s=arc-20160816; b=vAAEudixHLFVgDMtH77wjEogIx5HBqFBBqhJgP7HM0Twp6C9QFnHCvlRLsfPF7IzUl CLMCEftJKxLrZvKbh/RRyLwreVFJR/vHUyRsJqSk8KiP2LHQWpGhizHy0BBK41Jd1HWr ftigrEJ8fsBedUQX6ilB97cVU3QyUtfEeB23m/jrEmEQEHnZJ5seVfSIt5mJKi7rOEvO Fm07P3m1CQrXDMIHeF/qmqX+lsLJ8EgO8g8t0HczkCbm88xWdMcvRv6ViroicOVD6Igo Mehfzrfslku3MXFOoNs3TPCyGaSwu400snmlwXu6EZChO1PefYW1/rPANuJZoVDHL1nA fhwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:message-id:user-agent :references:in-reply-to:subject:cc:to:from:date:mime-version :dkim-signature:dkim-filter; bh=JSJsZe6/71Z81WHPKaHYPDomkrzHejx2StTWNfL7FaA=; b=kzMW4ugKnMj51MVbdRAXCXfcffor6ANFiBIu8KOwmbrzCINCd/IcECpfder6YjRcW5 E+MbJMJY4xUsv9pJa0WyFl9n0h9WU0CFKbLQ6dV8ZkfMP/P92SwsEAv6tUfTyLlZ5n55 vOQISBGPbFFKBMW8R+7rGFx07Q5JHNno/Jh4c4YykKcelgxHAkIltFhNbB3SWNA+aKgA X3+DOpnQysATZQJ/f2PiQgNcoo5/aH8gstp27DQ4goLwh2In+EuaU6qGj52Z56Tx9Ybm Ci5dwdulvjN9Q+qaOeIyTFN+ZkznUq/xRKdqXsRYS+Qwcfe3qMpvKxUyvLSTaZeHk69Y brgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=CO7qefBX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n25-20020a170906379900b00782b2a97825si14084640ejc.337.2022.10.20.04.59.23; Thu, 20 Oct 2022 04:59:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=CO7qefBX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231330AbiJTLX0 (ORCPT + 99 others); Thu, 20 Oct 2022 07:23:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231318AbiJTLXT (ORCPT ); Thu, 20 Oct 2022 07:23:19 -0400 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1647C5096; Thu, 20 Oct 2022 04:23:18 -0700 (PDT) Received: from mail.ispras.ru (unknown [83.149.199.84]) by mail.ispras.ru (Postfix) with ESMTPSA id CD5F2419E9C7; Thu, 20 Oct 2022 11:23:16 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru CD5F2419E9C7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1666264996; bh=JSJsZe6/71Z81WHPKaHYPDomkrzHejx2StTWNfL7FaA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=CO7qefBXOON0y0sUSW5zZ/L19hjPwUJewa5YGxft6oZGUHTBHrykxzgid6P6A1/0s NtgOqwGtrOZIzjPxvyBW5HpfwL7R6yblFNAVkDbSBTiNOBOmggH+5fu7zE3l4CTCVJ nZJI0mtNwSAX2tR/gMcpurkz/az+2WHZI9DazG2w= MIME-Version: 1.0 Date: Thu, 20 Oct 2022 14:23:16 +0300 From: Evgeniy Baskov To: Ard Biesheuvel Cc: Borislav Petkov , Andy Lutomirski , Dave Hansen , Ingo Molnar , Peter Zijlstra , Thomas Gleixner , Alexey Khoroshilov , lvc-project@linuxtesting.org, x86@kernel.org, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH 03/16] x86/boot: Set cr0 to known state in trampoline In-Reply-To: References: User-Agent: Roundcube Webmail/1.4.4 Message-ID: <3591ec1f2195095effd08e11fe45986b@ispras.ru> X-Sender: baskov@ispras.ru Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2022-10-19 10:06, Ard Biesheuvel wrote: > On Tue, 6 Sept 2022 at 12:41, Evgeniy Baskov wrote: >> >> Ensure WP bit to be set to prevent boot code from writing to >> non-writable memory pages. >> >> Signed-off-by: Evgeniy Baskov >> --- >> arch/x86/boot/compressed/head_64.S | 5 ++--- >> 1 file changed, 2 insertions(+), 3 deletions(-) >> >> diff --git a/arch/x86/boot/compressed/head_64.S >> b/arch/x86/boot/compressed/head_64.S >> index d33f060900d2..5273367283b7 100644 >> --- a/arch/x86/boot/compressed/head_64.S >> +++ b/arch/x86/boot/compressed/head_64.S >> @@ -619,9 +619,8 @@ SYM_CODE_START(trampoline_32bit_src) >> /* Set up new stack */ >> leal TRAMPOLINE_32BIT_STACK_END(%ecx), %esp >> >> - /* Disable paging */ >> - movl %cr0, %eax >> - btrl $X86_CR0_PG_BIT, %eax > > Why do we no longer care about CR0's prior value? I think we don't need to preserve any of those flags (we nether use floating point instructions nor call EFI functions with this cr0 value) and it's better to set cr0 to the well-known state. CR0 is also being set to the constant value while switching from protected to long mode, so it is already done in one of the code paths. If I am missing something, let me know, I will change it to only set WP and clear PG. > >> + /* Disable paging and setup CR0 */ >> + movl $(CR0_STATE & ~X86_CR0_PG), %eax >> movl %eax, %cr0 >> >> /* Check what paging mode we want to be in after the >> trampoline */ >> -- >> 2.35.1 >>