From patchwork Thu Jun 1 07:24:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Coiby Xu X-Patchwork-Id: 101795 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp118414vqr; Thu, 1 Jun 2023 00:45:47 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7+VIp/7Mf5Rd6dMkHDQKfMuSjsfOIZVgGiEioayO96a1LfiKC7WAlIs8KKX5LvSJJh+1cp X-Received: by 2002:a05:6a00:18a1:b0:648:1311:fbc4 with SMTP id x33-20020a056a0018a100b006481311fbc4mr11039543pfh.33.1685605547074; Thu, 01 Jun 2023 00:45:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685605547; cv=none; d=google.com; s=arc-20160816; b=kN9UvnaPaHErvxEZIHsrOw79TGJ9+lklKjxuRartEThUQZhxgqwyYUZjjYCquxXO1w q7P9PJOi2n3ipMWDpxudo0O/P2bDeITGM3jtGG/QaaWPXcrccT9f96AFXgY7HmE9Gjg8 K52RJE7nDR6u8PtdndKQ7MIbVglUVGfGabUOw6GZpcBIzgw5OeR8yrGtur6Eoo7rgXNi +M/X2RG8LGYBWRJ7T+xr6FKZS9uAmJNe9tAepxEwpPct4KRcSlcRFqgRPoaj7PiokWPU WOSHMbfwKuU1Rwxb1z6njKoV8vD4pAK77R7B3LScRVjC38nppWBsYORySKx9xwj2A/dh Mp7g== 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; bh=aefU4VwU8oFOQYKmAqFmOKJxhlCYs6WtVK98Xo9Ylw8=; b=ArXSJM9a7AS3sbM5xoEtAMql3VzdZBX/HEZVWN4euzTUDhP/tfwCUrLMxF72SL0G8d Xl/4HX/tO0A+IdRF5biUmCOGIZEE6AuzF68vZ5gNkmSqY+an6CeaTZ8U0S0GkLGAGVBU UgeTCoSUNckVneSMI7B3nk279KiTqWq85s3C7KMeKoog1YTF6Oy4XVpy09yFuq/nL0Xw QP+WxFrfWoFQOcxDRDNZtdPGeH9xTd5KmBQ6O8JFWOecbHqnDkyrqUpmJg7B/XxocQgg 5JPtqtrfirnznkv+vzHh7HaWiAQ6S1/tBFU1VwKuFzsgA00Nh5gKzEC6fm06MDX5jLyw MmCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WETCygIf; 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=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 125-20020a620683000000b0064d5e926241si2154928pfg.149.2023.06.01.00.45.32; Thu, 01 Jun 2023 00:45:47 -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=@redhat.com header.s=mimecast20190719 header.b=WETCygIf; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231965AbjFAH0L (ORCPT + 99 others); Thu, 1 Jun 2023 03:26:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231895AbjFAHZ5 (ORCPT ); Thu, 1 Jun 2023 03:25:57 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C58E180 for ; Thu, 1 Jun 2023 00:25:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685604309; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aefU4VwU8oFOQYKmAqFmOKJxhlCYs6WtVK98Xo9Ylw8=; b=WETCygIfvoUR4I/DFrO0Vu0WkJ/DyQ+6nprEwNcFQcTNr4cqMn7qoM4qlWhev97ZLRCc/8 SboM+RmR1oFlStBSlFS3jlU1DdEm/9UhS6Qtx1bEi/xwrNRc1DFxtHudmodzACopnj7vRy kbWjh8FFJMa5rew0SV22jWLX2isBTmM= Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-433-oUVdstSjMGWKwHLJB7JtBw-1; Thu, 01 Jun 2023 03:25:08 -0400 X-MC-Unique: oUVdstSjMGWKwHLJB7JtBw-1 Received: by mail-pg1-f199.google.com with SMTP id 41be03b00d2f7-528ab7097afso566462a12.1 for ; Thu, 01 Jun 2023 00:25:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685604307; x=1688196307; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aefU4VwU8oFOQYKmAqFmOKJxhlCYs6WtVK98Xo9Ylw8=; b=PQjxXAEYSS7baW7CSbcDyJph30QjAAVj3P+JmVJIomsHogVO77gj1yo3bLmNnsB7T/ WAjEq4rP20nrvZJy4tmV4Wls2Coi9nAFwNq53Yz+JD40eFjWbqVDOTLYNBrbK1kDoAYt jjkbid2G8OECKrrVfkgXGQ76LY3Q7Gg3HnZJCMHn1RXU6XgFMoTnJ9FiyAcciGCnhO/6 KgjOL3wb9xokW66rHBwa/el/YOqOGayJsY/J6f0ByD+shIxDvHhq78bYkInwDgEaVfzH HznseSFTGq6rEpBexBdxZBjrORIF4Hi2qabJ4zXAH4t6Dd8Js+Nagr2mhx9lD9URtoFe MVSQ== X-Gm-Message-State: AC+VfDz511Gpo29Mywaym1fLFiI2kP94cQ6RxGCGtMatZ5TS2QiojKy9 BKHF7HT+berYiL9aOfGTTmWw2p7jRlNMB1qnMyBJCr8hmEXNAQkBGQdSQxFIV6JMyeYp24s7aN9 luOtlVTyTbz4qQiMkQE5huVpz X-Received: by 2002:a05:6a21:998c:b0:10c:37ed:3e88 with SMTP id ve12-20020a056a21998c00b0010c37ed3e88mr8900710pzb.23.1685604307395; Thu, 01 Jun 2023 00:25:07 -0700 (PDT) X-Received: by 2002:a05:6a21:998c:b0:10c:37ed:3e88 with SMTP id ve12-20020a056a21998c00b0010c37ed3e88mr8900696pzb.23.1685604307121; Thu, 01 Jun 2023 00:25:07 -0700 (PDT) Received: from localhost ([43.228.180.230]) by smtp.gmail.com with ESMTPSA id y15-20020a17090322cf00b001ac5896e96esm2644901plg.207.2023.06.01.00.25.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jun 2023 00:25:06 -0700 (PDT) From: Coiby Xu To: kexec@lists.infradead.org Cc: Milan Broz , Thomas Staudt , Kairui Song , dm-devel@redhat.com, Jan Pazdziora , Pingfan Liu , Baoquan He , Dave Young , linux-kernel@vger.kernel.org, x86@kernel.org, Dave Hansen , Vitaly Kuznetsov , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" Subject: [PATCH 5/5] x86/crash: make the page that stores the LUKS volume key inaccessible Date: Thu, 1 Jun 2023 15:24:44 +0800 Message-Id: <20230601072444.2033855-6-coxu@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230601072444.2033855-1-coxu@redhat.com> References: <20230601072444.2033855-1-coxu@redhat.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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?1767485522082247443?= X-GMAIL-MSGID: =?utf-8?q?1767485522082247443?= This adds an addition layer of protection for the saved copy of LUKS volume key. Trying to access the saved copy will cause page fault. Suggested-by: Pingfan Liu Signed-off-by: Coiby Xu --- arch/x86/kernel/machine_kexec_64.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/arch/x86/kernel/machine_kexec_64.c b/arch/x86/kernel/machine_kexec_64.c index 1a3e2c05a8a5..82d1ecb35827 100644 --- a/arch/x86/kernel/machine_kexec_64.c +++ b/arch/x86/kernel/machine_kexec_64.c @@ -546,9 +546,23 @@ static void kexec_mark_crashkres(bool protect) kexec_mark_range(control, crashk_res.end, protect); } +static void kexec_mark_luks_volume_key_inaccessible(void) +{ + unsigned long start_paddr, end_paddr; + unsigned int nr_pages; + + if (kexec_crash_image->luks_volume_key_addr) { + start_paddr = kexec_crash_image->luks_volume_key_addr; + end_paddr = start_paddr + kexec_crash_image->luks_volume_key_sz - 1; + nr_pages = (PAGE_ALIGN(end_paddr) - PAGE_ALIGN_DOWN(start_paddr))/PAGE_SIZE; + set_memory_np((unsigned long)phys_to_virt(start_paddr), nr_pages); + } +} + void arch_kexec_protect_crashkres(void) { kexec_mark_crashkres(true); + kexec_mark_luks_volume_key_inaccessible(); } void arch_kexec_unprotect_crashkres(void)