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 73720C61DA4 for ; Wed, 15 Mar 2023 13:25:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231708AbjCONZz (ORCPT ); Wed, 15 Mar 2023 09:25:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231194AbjCONZu (ORCPT ); Wed, 15 Mar 2023 09:25:50 -0400 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 652D7273B; Wed, 15 Mar 2023 06:25:47 -0700 (PDT) Received: from mail.ispras.ru (unknown [83.149.199.84]) by mail.ispras.ru (Postfix) with ESMTPSA id 935B640737A0; Wed, 15 Mar 2023 13:25:45 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 935B640737A0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1678886745; bh=5igAFA4dKdE8mXj3pZN7Akkxtzzw4a9m5+AgebeEnvQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=IRt/7dZjLZW6Y7nbnNLrY8RSlpplYbxUbGbrNTRr0yTvQMzmCoNwn22mnt1fBI2si lyA+XjYveVqzvpRjgQLDYhqAl7hl5t6YQZ1xnE/4lAzIHImnf7FqL5BELrvUGofWgb sTA1htYkCubTQqqOX+fpGadWSMT6Egmg9yQw73Sg= MIME-Version: 1.0 Date: Wed, 15 Mar 2023 16:25:45 +0300 From: Evgeniy Baskov To: Andy Lutomirski Cc: Ard Biesheuvel , 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 In-Reply-To: <259a1148-faf0-4765-b777-6f36459c9307@app.fastmail.com> References: <259a1148-faf0-4765-b777-6f36459c9307@app.fastmail.com> User-Agent: Roundcube Webmail/1.4.4 Message-ID: <909bd8fed79cfc295a269539e7c77a98@ispras.ru> X-Sender: baskov@ispras.ru Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2023-03-14 23:33, Andy Lutomirski wrote: > 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. Good point. This patch can be dropped and replaced by the loud warning, since it is not required for the functioning of the rest of the series it is here mainly to indicate bugs in the kernel rather than for the increased protection. But I would not expect anything in the working systems, I made my best to map all the things explicitly. And since no code but the extraction code is supposed to be run (interrupts are disabled and we are not using any UEFI services there), this should be practically save to remove the implicit mapping. And at least this allowed me to find out about the insufficient size of the boot page tables which did not account for the ACPI and UEFI mappings. (patch 4 "x86/boot: Increase boot page table size") If this patch is dropped now, I can send the follow up patch later adding the warning. Thanks, Evgeniy Baskov > > --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(-) >> ...