From patchwork Tue Nov 22 11:12:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Evgeniy Baskov X-Patchwork-Id: 24282 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2138927wrr; Tue, 22 Nov 2022 03:18:20 -0800 (PST) X-Google-Smtp-Source: AA0mqf7Hv1NuYC8UCbMFZ6fCLMzFYH0B60+qp/q7UVVXTbVIz9QogdsWQ0YWJnZtKZz80YHPiJeZ X-Received: by 2002:a05:6402:24a0:b0:458:ad54:20d5 with SMTP id q32-20020a05640224a000b00458ad5420d5mr20317230eda.86.1669115900446; Tue, 22 Nov 2022 03:18:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669115900; cv=none; d=google.com; s=arc-20160816; b=o7W0LeYaFlJuSDoqMzH18hDxAnUoOpty4RX2WY9VtaBrejEh+W+qjBGgu69okMNXhI WrylU7eXybAcFpvEA0obvIAnNuwMjvA8DmJ5wPcUCz2Qs5/HkvDTyfBN0tFqGcMzS2GR p8QxXhpvEbn08cp5yitILK2uu2uk7nTMb+ZxUNGQkSZz6LJ8ss1ivqD5OALFxS42PuDt bHmRYZvj+YAk/j7QMw6R/qy4LJTBSAv6elF+atvHAz3uZMp4FfBCSywovoWb3s6yoEz/ EHhFPnwYTfPt3MFRuh5MVXsu4graarjcprwDsKiUd+FUSUj4h/IcOTWBx9BbtbXL0rxK Puuw== 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=6oUI8mIWLd1Fo2Wh2YHphseFjFuqPo1vi/6/ODurdpA=; b=wKEYwb76nJskKLkPg4chw7QFNnMR/C8A5X1LpmbDAXJwtT2yaB+5nXazlBdv5QoaIn YZwtv5PJ7rqBKGiVvNKk12AKHhVIO4H1kCGm6p+lPVck+66G4LWpvOrJLkgtvMy9lMvU r6b6208+dTKlZWXhz1wTUGCLV/AoSJKmrBHyeZXAP/RjxVV+xl6htNPZValHBBwthTpD DJ/ykGUuXYX41WfuNLZEHxB1aOwnO5DpcW9gWTsSEQZkeyy6kUhUUfhwYhDOoRFDrvg2 Hc2SgzEZURd9O/N+jdhqQIRCxi7B+BmSw6disspw6p6sW8kWf257kXWW1snoGRkeua2E JJig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=Qlx40wQ5; 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 hw20-20020a170907a0d400b0077b6ecac099si1780437ejc.287.2022.11.22.03.17.53; Tue, 22 Nov 2022 03:18:20 -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=Qlx40wQ5; 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 S232667AbiKVLON (ORCPT + 99 others); Tue, 22 Nov 2022 06:14:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232730AbiKVLMu (ORCPT ); Tue, 22 Nov 2022 06:12:50 -0500 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B62862AC7; Tue, 22 Nov 2022 03:12:48 -0800 (PST) Received: from localhost.localdomain (unknown [83.149.199.65]) by mail.ispras.ru (Postfix) with ESMTPSA id 8D6E840737CB; Tue, 22 Nov 2022 11:12:42 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 8D6E840737CB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1669115562; bh=6oUI8mIWLd1Fo2Wh2YHphseFjFuqPo1vi/6/ODurdpA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qlx40wQ5kSLXszjhsQVxrO7xRhMyp9Oeuf12SIidIpokRDaEqNZ0ZRiVGEDVJVEVw Xo1PjqI0fJjpP8NhqxzQ+0D/QKO4G4UgcycPQVTvRJjf/mZXYg3Dhf50S0Z2+PWHK0 RWWb5DFfcPIQe+twwUa/qAqFFUbJtoOnF8anC/3Y= 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 09/24] x86/boot: Remove mapping from page fault handler Date: Tue, 22 Nov 2022 14:12:18 +0300 Message-Id: <7438db5fded11a28310267a7b51b483a5f61d0d4.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?1750194874459667208?= X-GMAIL-MSGID: =?utf-8?q?1750194874459667208?= 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. 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 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); }