From patchwork Tue Oct 25 14:12:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Evgeniy Baskov X-Patchwork-Id: 10827 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1033361wru; Tue, 25 Oct 2022 07:15:54 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6M1c7EaKUL+Ze9qvMZNFLzUzNVqptI2CLAfgxSycZ1bAQCMzfpkei8tcoEH6XWDl2oXxex X-Received: by 2002:a65:6cc4:0:b0:412:35fa:5bce with SMTP id g4-20020a656cc4000000b0041235fa5bcemr32208716pgw.466.1666707354345; Tue, 25 Oct 2022 07:15:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666707354; cv=none; d=google.com; s=arc-20160816; b=VVKb/tYvlWGABUd83ewfs8TMY4G42W1ixFH9zAs1qCmPOy2hCexLWMCiBLeGK/5VsF kCnDD3yOvGqP6OxSHa4I7kIkq948Z+iK3yggL56kogiZywK4TQ9vy738VHNDdvF26rJ8 trUHhOKbLgzRy4NhUl45BPxiqp1m/baiDHCJeiHu0QuPiVhO3Yhlwo2fIyKmlZ4rxO4V FWtpiBTAnqatNPRuQo54WPSmcRmbNiHw8F+cm6z693JkovAF+WHKL1gm1NY15FtxFip+ CQZIQxqouwsLL/s67sjkDdmzuqQCAVrcCbgWiiY98yATeeb1Wy7EfVbY6Dvfmva4A1mZ 0ISA== 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=bLo8SKzI6m8S91IVaglgF8mOxCQMqZtqBjyc3705zno=; b=c/6au5crObpidh1emrPCwzyGwgm9KwxBwG1wr2JTQwdCgfwdFJPDD8pXD8VML3OPO5 J3KvsQ4KDTST4p4hbEHkxxN2pGyuaLMJwVf4ONeLapT+R7dnUPMCv68a63K+qnFSh3Rt 2LP5/QcNMwkHbwShnLKON3paw5Qqu6VYPCWb/V6gWfYRF1B1R62hBrCZdx1Xz1Xpp3KM BMnSf+6O6j2n7OYWF/JlzoD9MQDhOoVWjisNWRSKuVnzuujuitaI6ZGaNLB4dCKgcQUX w9LU2Ofvtqey692C+cj7y8NUwWfbC+xoNEgEjD7QbeP6gRTrePXw3wuyCyXtAKrFJD4W +kbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=hnuPICTq; 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 c18-20020a170903235200b0016f1781307csi3346543plh.303.2022.10.25.07.15.40; Tue, 25 Oct 2022 07:15:54 -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=hnuPICTq; 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 S233092AbiJYONw (ORCPT + 99 others); Tue, 25 Oct 2022 10:13:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233035AbiJYONp (ORCPT ); Tue, 25 Oct 2022 10:13:45 -0400 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 232B1ABF20; Tue, 25 Oct 2022 07:13:34 -0700 (PDT) Received: from localhost.localdomain (unknown [83.149.199.65]) by mail.ispras.ru (Postfix) with ESMTPSA id 940B7419E9FC; Tue, 25 Oct 2022 14:13:32 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 940B7419E9FC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1666707212; bh=bLo8SKzI6m8S91IVaglgF8mOxCQMqZtqBjyc3705zno=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hnuPICTqGcCHyv5JohVZn/Iy9SZjGNEZ4lT4u5gTHIXacVP46flHXSp/TI/APoCPh QVNNlkItKMde/F2KIUv617thzrs3mC8aBhh6/PJkKhfuRudq/Lyt9x9f9pqQNQxig0 8wuv2LrjxyIW63fwqPnglCC96nvvlLw25CLJ3wCc= 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 , lvc-project@linuxtesting.org, x86@kernel.org, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH v2 09/23] x86/boot: Remove mapping from page fault handler Date: Tue, 25 Oct 2022 17:12:47 +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, 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747669330631834782?= X-GMAIL-MSGID: =?utf-8?q?1747669330631834782?= 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. 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 fec795a4ce23..ba5108c58a4e 100644 --- a/arch/x86/boot/compressed/ident_map_64.c +++ b/arch/x86/boot/compressed/ident_map_64.c @@ -386,27 +386,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); }