Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp808107rdd; Tue, 9 Jan 2024 23:16:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IFpHBAlgD9O6KYQ/lIQBLrXwGghOjAwx/01ZaRd8pCiMJOvFZ6SQO/KsiGGx3DtkRn37DfX X-Received: by 2002:a17:906:7d07:b0:a2a:72f1:bc7a with SMTP id u7-20020a1709067d0700b00a2a72f1bc7amr330142ejo.87.1704871009576; Tue, 09 Jan 2024 23:16:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704871009; cv=none; d=google.com; s=arc-20160816; b=iuyThq4Ikuza1lS1/qhJ6f3VGmLFNMBE1EhbNNRu2yHgfzeycZeuKWaV8NJCPkIQ0A nxBWxjdzwPfsanJjCQKwHRWp7rDWVKq+p5uolwLGSwZPMf2emdI1V+kz96L/SBjXFwKm Jb5wRiDQEWQsEDJrTk/HwxDI4+JGt1AOItdoKz8VrSNkG+XTRhK9ZDIswrYvHvpmT+0q dIHhaAgZEuR/PVgbC9niWHZnzSPu0ZiaoOX4tGyAGYa3UZfj9bfK8obW8dqA8DA0lRZ/ qPipZdTVWawQJkt1OY5eE4oplLUKgKRiI5Mnw9Rq0cumVAfSi8Ma4uO5ZtOPN+oc3ob3 xUNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=PudTy4UMKikLIiXUIiw3l2EC2dKIPcn2JPVx++F8WCw=; fh=0CnQcBBpPPCzbO2LVNr7a4xtuL8tReXWok6+u5weL08=; b=0H1+lzTn+CEy/OhOaDR4pYJpwJW6U0mWP53HyYNsr/QXsZ/Y49jtumhZS0ns9disMw VIJ7uVKb+LjfGX8FOq1aVI7UG7O1sMB13jOJ/N6D38EduRD3IFrPmZkPPakzdAn+CLpg eoo3GEV4pcD54tQPUnPJADXM6pEq1hI6EpBiWA3MCou6ckt132hAx7T0/bcMTnfhv4nH Wyi5JwKmXNnOCtFUa9e7oS5tHqnRGXw44PMWD5gAn3wssWVbVReO2sptQLymUX2X+MMm Ty7VYMq8gPvfEtSjBQ/fphLnhr4IfCSq8+qx+JZDrXSpG1M/EG5xDxWMNDZ8nbyX2yQp hR2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="GbY/pXwc"; spf=pass (google.com: domain of linux-kernel+bounces-21778-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21778-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id lg18-20020a170906f89200b00a27acfd50d1si1489592ejb.951.2024.01.09.23.16.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 23:16:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-21778-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="GbY/pXwc"; spf=pass (google.com: domain of linux-kernel+bounces-21778-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21778-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 42F381F25B09 for ; Wed, 10 Jan 2024 07:16:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 10B7A3F8C2; Wed, 10 Jan 2024 07:15:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="GbY/pXwc" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D36863EA96 for ; Wed, 10 Jan 2024 07:15:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704870950; 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=PudTy4UMKikLIiXUIiw3l2EC2dKIPcn2JPVx++F8WCw=; b=GbY/pXwcySk3cdIJCpO4ZMEOMvkwxxVZxGE99/GcZPAwf1AqtdVdsaeG50cAIoGwqNbjwU ElmLqqlOzjTr6YhR5TcxbzIDtmR2+v1tBvx1RmBSqguvBc5wIVWzB6Qxji641cgZUR9I5B SxtFiGfj/YoEaFmEu0K7IWxwcmYHkzo= Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-662-ATLLaRc3P7qOyehsFcR_8g-1; Wed, 10 Jan 2024 02:15:46 -0500 X-MC-Unique: ATLLaRc3P7qOyehsFcR_8g-1 Received: by mail-pg1-f197.google.com with SMTP id 41be03b00d2f7-5ca5b61c841so1126754a12.3 for ; Tue, 09 Jan 2024 23:15:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704870946; x=1705475746; 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=PudTy4UMKikLIiXUIiw3l2EC2dKIPcn2JPVx++F8WCw=; b=fFWntteoTKWpyahbciKJDAXIRjeDyXY7o/sXJPH2R6bA58E2mv4jvmn59/mSvBAxVC BCtznCXUV8dU77WWn2yQMep3o3taQqWodXdDiJWJeo4y4m92BDJ0NLFHPRiYXbNkfImj UV5UJgHPuOvSArm3STKRV9b2PwGPmXz+4lZ0Ash8M6ZuQpdFgct7w3uLiJdmTNWmsBZ0 ayx+CtxATw3k16M69w/63z1m/9JDe9Bx/lMWpIMMnsfKeZv2tBUpZei/fDWKe1V7DxlJ ghlSCUzGl1iuiVFm1YNJRkV515dFTfkcx/pZG16wOskJBQ0EQcJle9iPSpwWpv91Pc1Y YlNg== X-Gm-Message-State: AOJu0YwLOE62tFl6Zy3LZZ+ZwwMwVwfaUc//UbcezttzcCFGO+nj7bIg mgnY9iuhtMwVWz0Vd+eezfC0nUqUjXEzb+5xGqKkb1oSPMyeoGSUjhnwFPpytNJDWCMD40P0D7G C0HHIZOdbo3uXKNKFHB5+mv4x8ExhQ5lX X-Received: by 2002:a17:903:230a:b0:1d5:6b59:bc9e with SMTP id d10-20020a170903230a00b001d56b59bc9emr548214plh.113.1704870945695; Tue, 09 Jan 2024 23:15:45 -0800 (PST) X-Received: by 2002:a17:903:230a:b0:1d5:6b59:bc9e with SMTP id d10-20020a170903230a00b001d56b59bc9emr548193plh.113.1704870945323; Tue, 09 Jan 2024 23:15:45 -0800 (PST) Received: from localhost ([43.228.180.230]) by smtp.gmail.com with ESMTPSA id m5-20020a170902db8500b001d4c955cc00sm2906719pld.271.2024.01.09.23.15.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 23:15:45 -0800 (PST) From: Coiby Xu To: kexec@lists.infradead.org Cc: Ondrej Kozina , Milan Broz , Thomas Staudt , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , 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 v2 5/5] x86/crash: make the page that stores the dm crypt key inaccessible Date: Wed, 10 Jan 2024 15:15:20 +0800 Message-ID: <20240110071522.1308935-6-coxu@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240110071522.1308935-1-coxu@redhat.com> References: <20240110071522.1308935-1-coxu@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This adds an addition layer of protection for the saved copy of dm crypt 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 | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/arch/x86/kernel/machine_kexec_64.c b/arch/x86/kernel/machine_kexec_64.c index 1a3e2c05a8a5..c9c814b934b8 100644 --- a/arch/x86/kernel/machine_kexec_64.c +++ b/arch/x86/kernel/machine_kexec_64.c @@ -546,14 +546,32 @@ static void kexec_mark_crashkres(bool protect) kexec_mark_range(control, crashk_res.end, protect); } +static void kexec_mark_dm_crypt_key(bool protect) +{ + unsigned long start_paddr, end_paddr; + unsigned int nr_pages; + + if (kexec_crash_image->dm_crypt_key_addr) { + start_paddr = kexec_crash_image->dm_crypt_key_addr; + end_paddr = start_paddr + kexec_crash_image->dm_crypt_key_sz - 1; + nr_pages = (PAGE_ALIGN(end_paddr) - PAGE_ALIGN_DOWN(start_paddr))/PAGE_SIZE; + if (protect) + set_memory_np((unsigned long)phys_to_virt(start_paddr), nr_pages); + else + set_memory_rw((unsigned long)phys_to_virt(start_paddr), nr_pages); + } +} + void arch_kexec_protect_crashkres(void) { kexec_mark_crashkres(true); + kexec_mark_dm_crypt_key(true); } void arch_kexec_unprotect_crashkres(void) { kexec_mark_crashkres(false); + kexec_mark_dm_crypt_key(false); } /* -- 2.43.0