From patchwork Thu Dec 15 12:37:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Evgeniy Baskov X-Patchwork-Id: 33617 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp325909wrn; Thu, 15 Dec 2022 04:39:27 -0800 (PST) X-Google-Smtp-Source: AA0mqf7eZtDi4jlNG/q73fPHe8LffPAGXoSIaVRTVsgfldVx8HWRr/jKwCMXoT8ZHrDCJzJaJnjz X-Received: by 2002:a05:6a20:7f9b:b0:aa:23cb:a1a6 with SMTP id d27-20020a056a207f9b00b000aa23cba1a6mr47628929pzj.0.1671107967654; Thu, 15 Dec 2022 04:39:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671107967; cv=none; d=google.com; s=arc-20160816; b=AOGiUJLFG4xUtmpL8mKCR+KVTCS2y7O41upTcKN+0INOQoF6VhJAzIqzLRyAmFFkEx 3/mhKFEsJZvfs6YzSGUn9osn3at8lLfDBw4HrOmkeqODoCN7ZDATHbYyQW9PCD5vXNzj OUkTMaK4HwinkI6hEialQuM92qvUsqqICRGO7gdKIIl3hEA2PTIfowjyrzoPery2SCOg puoYBlgNk7tFoHzg0lz49p3YBwrEmDpkbC07amhrkIg7PXhBLhLAmNBD2QM31fPy2ZwE Opi2/pgOZH5rUJHO/1759xlRxwFOqejLGfZTlnWjB7KHLOQPzfC/pSYDgbbWzWzipYtR 7jQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=SwDfOB+ZJqWv7uKClTclDaOfdPpVCbhrtUZIQmw7gCY=; b=V6hhpMzKLuDnGK2LLM0b9MN3pQK3oD7xi2gXnKxJ+zJ6KFAnvH5FsyeWGyjhRLwe2a RAxN8VADKh7GQqQr8Gp12iC3jsIzMkSFVG0wyvAGRruycBvPo5kSHZjBSYAZnta1clQk 4d1VtXGa1l5egT8PXp+eu64xulLed7Zyb2Nkd+lT4uTVpdyRZlOM2Stb/tT/bct/Kx2E 2bp7V80rrOY8Ez29iniWzaXLxlrOxAdg5mOgV5hqcZgMrQc706U4204W0W5Se4jJhNp5 MmbSK9S84wf0I3PjC/iOrY25nkUS8mZFaw8enOISO4eDD244IfvHWM6cm2qy+TmF60eY P+/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=kAwf1a2q; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b23-20020a656697000000b004827ef5f0bbsi1641735pgw.373.2022.12.15.04.39.14; Thu, 15 Dec 2022 04:39:27 -0800 (PST) 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=kAwf1a2q; 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 S229795AbiLOMi6 (ORCPT + 99 others); Thu, 15 Dec 2022 07:38:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229784AbiLOMii (ORCPT ); Thu, 15 Dec 2022 07:38:38 -0500 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85D752EF60; Thu, 15 Dec 2022 04:38:25 -0800 (PST) Received: from localhost.localdomain (unknown [83.149.199.65]) by mail.ispras.ru (Postfix) with ESMTPSA id DD69240737A3; Thu, 15 Dec 2022 12:38:21 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru DD69240737A3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1671107902; bh=SwDfOB+ZJqWv7uKClTclDaOfdPpVCbhrtUZIQmw7gCY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kAwf1a2qQRf9lp+O9D9yQUGIduGuX8cXxqrGHshJkLhrbTfq1ASqktpkIG7BH7Qob hum7FI1oWVWoOQXA0voiwp7xtezG3gSJj2av52VDkVak+EZN1n3Jcn/zZaUAA1VFO7 efxCBUsd9HDzgkf/ofCGl7ugw3KV2ZrnauSRIrXo= From: Evgeniy Baskov To: Ard Biesheuvel Cc: Evgeniy Baskov , Borislav Petkov , Andy Lutomirski , Dave Hansen , Ingo Molnar , Peter Zijlstra , Thomas Gleixner , Alexey Khoroshilov , Peter Jones , "Limonciello, Mario" , joeyli , lvc-project@linuxtesting.org, x86@kernel.org, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH v4 03/26] x86/boot: Set cr0 to known state in trampoline Date: Thu, 15 Dec 2022 15:37:54 +0300 Message-Id: X-Mailer: git-send-email 2.37.4 In-Reply-To: References: MIME-Version: 1.0 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752283708488352207?= X-GMAIL-MSGID: =?utf-8?q?1752283708488352207?= Ensure WP bit to be set to prevent boot code from writing to non-writable memory pages. Tested-by: Mario Limonciello Tested-by: Peter Jones Signed-off-by: Evgeniy Baskov Acked-by: Ard Biesheuvel --- 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 a75712991df3..9f2e8f50fc71 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -660,9 +660,8 @@ SYM_CODE_START(trampoline_32bit_src) pushl $__KERNEL_CS pushl %eax - /* Enable paging again. */ - movl %cr0, %eax - btsl $X86_CR0_PG_BIT, %eax + /* Enable paging and set CR0 to known state (this also sets WP flag) */ + movl $CR0_STATE, %eax movl %eax, %cr0 lret