From patchwork Tue Nov 22 11:12:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Evgeniy Baskov X-Patchwork-Id: 24271 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2137928wrr; Tue, 22 Nov 2022 03:15:50 -0800 (PST) X-Google-Smtp-Source: AA0mqf73SPUEPohrzwmrj964Mzy2nIrrM5Uu2uvPWPMn9dF1dEpSQvQmhGk7sOS/BHsuFI1s08/s X-Received: by 2002:a17:907:1750:b0:7ad:8608:a0a1 with SMTP id lf16-20020a170907175000b007ad8608a0a1mr19345187ejc.110.1669115749951; Tue, 22 Nov 2022 03:15:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669115749; cv=none; d=google.com; s=arc-20160816; b=xsdlneVoXNWEJj98Og9onsjAn9a08IWiyIDdypJqAHn7bhbxoGjfh7SS689CBPaq2A B2CeDqZFirCEfYTvbbg8ycu9UoqLUEkppEP9Uu8L0uS4LmqU46IsxWppLQtDO4fwkitG Da/72BfosOlvqa4o1Gy0pAbZv2iNBTtz3798zb7FmHd9BRx6lrDCyKc5k8p72E45XYvo uqytvQeYqXgnj9FYKzsppv7KoiZhfwJfO+IQ/h59iSKP5jAd/daeVOS2Z20TPIINmk+c cVqNB5rnwSfOgYAUMk7X/G0eZCA70fzdR7yn5nmGoSs8FtyFL5gKQ2MbkXgxPWSuDSsI ebGg== 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=BpKkE08pGa4/tENRHiY7qw/EE8nLB3cro9XVgZTsBAw=; b=ga4RKnWZmfwcZbn7Uh54HPH3JvwHMfmQRVXdE0sCqHXO45MjuIcr+FTVcFDqmOwc2b gy6+zQsufFqtCsFb0xIhZfwUmCtOAtTBdv++PG/UjQ+92Ti91U4sMiVzqECxQTWfXquF erTyI9yPYltyFDQN9J6cmMNmDblmdVC/tBh5Nu9dy3qmuobq8bPHwNXuAOjJW+sszoSW Bc0qNRDfcSB+rmwr627otow7irtJhj4tzkxkEsKH9TdqIoWh4Cz2HifDprG9OZqsQ8hZ 6RatPM6z0mm2b9NrAg7s/qEKGYeBE5pMipl/aEs1p+0dNP6sJPQUvwV1NyGVonWLxqZ1 v8oQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=PQb0M3Nm; 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 hr19-20020a1709073f9300b00781c9c3b6f5si1477955ejc.474.2022.11.22.03.15.23; Tue, 22 Nov 2022 03:15:49 -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=PQb0M3Nm; 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 S233081AbiKVLMz (ORCPT + 99 others); Tue, 22 Nov 2022 06:12:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231318AbiKVLMq (ORCPT ); Tue, 22 Nov 2022 06:12:46 -0500 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 827E4C63; Tue, 22 Nov 2022 03:12:44 -0800 (PST) Received: from localhost.localdomain (unknown [83.149.199.65]) by mail.ispras.ru (Postfix) with ESMTPSA id CAD0E419E9FE; Tue, 22 Nov 2022 11:12:40 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru CAD0E419E9FE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1669115561; bh=BpKkE08pGa4/tENRHiY7qw/EE8nLB3cro9XVgZTsBAw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PQb0M3NmHKE4mjvR8FkYprV6wfylG4Wny30D4B9GDmIqFp6ZA6qnrzIK1uzUhZM3i iB8AaltGRhVuzZNx9Pm0z/irK7KPNwEow466DP1NIyLgt6J/+xpRCRxm7SDoVlAS0e 6tq/1ibw4A0V0voThBa3dmkSfwnjid9568J5B9Gk= 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 v3 03/24] x86/boot: Set cr0 to known state in trampoline Date: Tue, 22 Nov 2022 14:12:12 +0300 Message-Id: <6aada664ff70ec913faae672bb3c16db14b36049.1668958803.git.baskov@ispras.ru> 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?1750194716575042601?= X-GMAIL-MSGID: =?utf-8?q?1750194716575042601?= Ensure WP bit to be set to prevent boot code from writing to non-writable memory pages. Tested-by: Mario Limonciello 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..2a4372b84fc8 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -684,9 +684,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