From patchwork Wed Jan 10 07:15:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Coiby Xu X-Patchwork-Id: 186700 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp627521dyi; Tue, 9 Jan 2024 23:16:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IE0pfmpQ+o/qMDsAhUOcPBnDF2kw42zT/wy8IWXFLMuZTB0jECEAPdRY/2m7sEPgYA3ie9Z X-Received: by 2002:a05:6870:b14c:b0:205:dd93:45a5 with SMTP id a12-20020a056870b14c00b00205dd9345a5mr310951oal.70.1704871016271; Tue, 09 Jan 2024 23:16:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704871016; cv=none; d=google.com; s=arc-20160816; b=xjstZguHWm9l1xRDUnNbJ196WBPSqH9rvKjY1WEcx6JoukjSOI1Abm8W9+JB3h60Z2 i+G6/AqyT1ZDkwk3a9GdH57FzzqM5P4BpS3WzbDqC2z0Yc3LOL47oTExbRhF6Ae2AXjq OJoZbY7m3GyMZaua18Mu+WMBcgbqaUjGwAR3DRW2y/OvIfdPrGkxgvpdLIcgF+8V1ngD tXBx9TjIhzfICQkKpTJihOWpxvOviXi/2Qm9/xXkrKe2XVexG4Flu2fTjp3QcLMZISB8 l+g8OAwJnKPCIQjM1IUKOtrIFgEf7Tu4dC2kqak/iiO89WSHDDAIt2RRONrJ62mhVbLV 6QjQ== 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21778-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id bs186-20020a6328c3000000b005cdc2cc9a16si2820835pgb.804.2024.01.09.23.16.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 23:16:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-21778-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21778-ouuuleilei=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 0BA35288A52 for ; Wed, 10 Jan 2024 07:16:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DBDF43F8E1; Wed, 10 Jan 2024 07:15:54 +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_P_=2E_Berrang=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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787686830707478763 X-GMAIL-MSGID: 1787686830707478763 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); } /*