Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30071C6FD1F for ; Tue, 14 Mar 2023 20:34:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229692AbjCNUeG (ORCPT ); Tue, 14 Mar 2023 16:34:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229765AbjCNUeD (ORCPT ); Tue, 14 Mar 2023 16:34:03 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1392D3B210; Tue, 14 Mar 2023 13:33:46 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 64D6B61994; Tue, 14 Mar 2023 20:33:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 593FDC4339B; Tue, 14 Mar 2023 20:33:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678826025; bh=iN04j8aiExsMR4SAjvFhCPSopIclwuHB2+vsqetGB2o=; h=In-Reply-To:References:Date:From:To:Cc:Subject:From; b=EqkjMMufTXpVwvKOtms63LFXnEXRSuVovPNXl9WsIfWdp1iS4w9LrKotvYvQH0eRo Bcxiu1jOqjqzk8OOiy2hZIHy4cMu8OJURLa6jcM8fUMG+V2kCLDEcDM5SYmsVWzRGr /fB4ZEUDTWhVeZjkYj9w7ZmnsFHLj8RerHum/1Ee3GimVfxfTqOJnkiuxY0nLBcijr jYXIYjerGE2QsiwbAC/mh6Xvr6Qqs/MkRh2Kmv1fOYM1ayPhMau+i2u3t1fJ0TCUBU rHT0AaVLNVtqRDZxt/Vz00JhhfE6lIOi1r/AL695KyiqoCUaHRdL6h19a7nK4WOi3T M2R8aiDPd/r6A== Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailauth.nyi.internal (Postfix) with ESMTP id 31C8927C005B; Tue, 14 Mar 2023 16:33:44 -0400 (EDT) Received: from imap48 ([10.202.2.98]) by compute3.internal (MEProxy); Tue, 14 Mar 2023 16:33:44 -0400 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvddviedgudegvdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvvefutgesthdtredtreertdenucfhrhhomhepfdet nhguhicunfhuthhomhhirhhskhhifdcuoehluhhtoheskhgvrhhnvghlrdhorhhgqeenuc ggtffrrghtthgvrhhnpedvhfeuvddthfdufffhkeekffetgffhledtleegffetheeugeej ffduhefgteeihfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfh hrohhmpegrnhguhidomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqudduiedu keehieefvddqvdeifeduieeitdekqdhluhhtoheppehkvghrnhgvlhdrohhrgheslhhinh hugidrlhhuthhordhush X-ME-Proxy: Feedback-ID: ieff94742:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 7CCAA31A0063; Tue, 14 Mar 2023 16:33:42 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-221-gec32977366-fm-20230306.001-gec329773 Mime-Version: 1.0 Message-Id: <259a1148-faf0-4765-b777-6f36459c9307@app.fastmail.com> In-Reply-To: References: Date: Tue, 14 Mar 2023 13:33:21 -0700 From: "Andy Lutomirski" To: "Evgeniy Baskov" , "Ard Biesheuvel" Cc: "Borislav Petkov" , "Dave Hansen" , "Ingo Molnar" , "Peter Zijlstra (Intel)" , "Thomas Gleixner" , "Alexey Khoroshilov" , "Peter Jones" , "Gerd Hoffmann" , "Limonciello, Mario" , joeyli , lvc-project@linuxtesting.org, "the arch/x86 maintainers" , linux-efi@vger.kernel.org, "Linux Kernel Mailing List" , linux-hardening@vger.kernel.org Subject: Re: [PATCH v5 09/27] x86/boot: Remove mapping from page fault handler Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 14, 2023, at 3:13 AM, Evgeniy Baskov wrote: > After every implicit mapping is removed, this code is no longer needed. > > Remove memory mapping from page fault handler to ensure that there are > no hidden invalid memory accesses. This patch is *by far* the scariest of the bunch in my boot. And it violates a basic principle of kernel development: it's better to run in degraded mode than to fail outright unless running in degraded mode is dangerous for some reason. And this boot code is not actually meaningfully exposed to attack. Anyone who can get the boot code to consume garbage likely *already* controls the system, including anything that we might write to TPM or any other verification mechanism. So I think this should log an error, set a flag to make sure we print an even louder error after full boot, but still add the mapping and keep trying. --Andy > > Tested-by: Mario Limonciello > Signed-off-by: Evgeniy Baskov > --- > arch/x86/boot/compressed/ident_map_64.c | 26 ++++++++++--------------- > 1 file changed, 10 insertions(+), 16 deletions(-) > > diff --git a/arch/x86/boot/compressed/ident_map_64.c > b/arch/x86/boot/compressed/ident_map_64.c > index eb28ce9812c5..378f99b1d7e8 100644 > --- a/arch/x86/boot/compressed/ident_map_64.c > +++ b/arch/x86/boot/compressed/ident_map_64.c > @@ -393,27 +393,21 @@ void do_boot_page_fault(struct pt_regs *regs, > unsigned long error_code) > { > unsigned long address = native_read_cr2(); > unsigned long end; > - bool ghcb_fault; > + char *msg; > > - ghcb_fault = sev_es_check_ghcb_fault(address); > + if (sev_es_check_ghcb_fault(address)) > + msg = "Page-fault on GHCB page:"; > + else > + msg = "Unexpected page-fault:"; > > address &= PMD_MASK; > end = address + PMD_SIZE; > > /* > - * Check for unexpected error codes. Unexpected are: > - * - Faults on present pages > - * - User faults > - * - Reserved bits set > - */ > - if (error_code & (X86_PF_PROT | X86_PF_USER | X86_PF_RSVD)) > - do_pf_error("Unexpected page-fault:", error_code, address, regs->ip); > - else if (ghcb_fault) > - do_pf_error("Page-fault on GHCB page:", error_code, address, regs->ip); > - > - /* > - * Error code is sane - now identity map the 2M region around > - * the faulting address. > + * Since all memory allocations are made explicit > + * now, every page fault at this stage is an > + * error and the error handler is there only > + * for debug purposes. > */ > - kernel_add_identity_map(address, end, MAP_WRITE); > + do_pf_error(msg, error_code, address, regs->ip); > } > -- > 2.39.2