Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp928977lqt; Fri, 7 Jun 2024 03:03:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWwhWv2VTmNAMR4KcLTiHZfhnWY/8450DdXKKBOn4a1qqZGs3/cGxo93LfC3NM/FQqH0jOcS/h0sraX7JQgn7YQcb10W1HmxnQQQXgXnQ== X-Google-Smtp-Source: AGHT+IHb2J0VEAFteKp/XYNB/b90mO166sQlKjAX03Vr4uagHpESK7/Wh5rXjYacpjoepNZ20fx8 X-Received: by 2002:a17:906:7749:b0:a61:7f85:e31c with SMTP id a640c23a62f3a-a6cba5962damr166163866b.12.1717754586148; Fri, 07 Jun 2024 03:03:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717754586; cv=pass; d=google.com; s=arc-20160816; b=idYfJNabQB1s+cp2nBjcbZXRtPjq9MSYfKecY2BgaW2Mx8vxcx+5OkM1crshhbQa8a jLI2BZ+KpDFu7AEb29JkQc9ELXjIfNoNZv4AUsQ6QLIo40PKPxo48FUSrE2YAMM72mIa IE0qYID5yigOvZoxtUsVx/Rc4Acv6Lq8hea7Dc41Jow5ecJO6wPTQIB30s/L/Pt+tU/T 4cgYWsJyk084LVVE6+Vr3ow3T8J8fg2AHChWJyrlWS/DUaG7EXvJRPji3ngCuzvI2S8D 1hjVuAJwF2ubqcEVIK/7ObQXWHHqGC9FjDyzIC7jaRNZ0E6jvS5wOJJ5HVArQs4k0u9g 6+nQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=NH3oO20QFn673bgiV5dG3f+GU8g8vUS9TOFN0xj1Yvs=; fh=JWKTcHPX39ZSy+xSWQ17mloJs2b022GMkxLy8/dz1LQ=; b=LSN9eU7LHXquU1zThojbqEHAsrpub1LQbi5rsZVjqIh0nLhqIaxjYmwbVJ3XbLox09 mr18w+pR/T6DX7Ic/8GQeLxypdhHiaRrPVWH5a1CF5LezMk8/RrhPv6mObWW07ACIjZi FzVoQzxW0SG10vMe9WNAzkAuIeS/oqboXG8pWlCw4F9FB7YVa+fCE9ob7STVhtghakKB ytY00sQJWzAoPEqyck8dLPzLFLB3rMQyIHgsaANCnyw7dB9N0B/lDJSbAiNLQas5pDfY nDczkg5Bjy6r2+tBCS0YJ6IdI3QSSS8C6wbfVcmZ43z+2xyvfjDeeJMrvaYaXwoFY9rH aiOw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QR4j25i4; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-205775-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205775-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. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a6c8074baa2si164784466b.1053.2024.06.07.03.03.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 03:03:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-205775-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QR4j25i4; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-205775-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205775-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 831A31F24A33 for ; Fri, 7 Jun 2024 10:02:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B501415F30E; Fri, 7 Jun 2024 10:01:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="QR4j25i4" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 4F77415D5AD for ; Fri, 7 Jun 2024 10:00:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717754460; cv=none; b=BjmVwfXI1lFwcYu0lO3ogiPgJG4Tty8M4i4m50dX61DfxZuT9DT627yIbD+1mSIi1itAq5XE2fYqLYvhsnHBYD84sGdYpeCmA4cbaO337hLlYcmAIUfoMyKgQUsBk4Ly4wtTm4vsCOVcOMSuaosj9mSYziMiTumutPZUdrkk/I4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717754460; c=relaxed/simple; bh=FmBJwoatTD3ubavkLq7yAGUCYfFAazwL4EVqq/cDjuQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fvNpm5SunWWovVxp9BVD6kpLb6ZUh0hqMIYyWirDRHEYqgc6kXPU1cw5ccio7DapoIbaMnzBWGwm6EdS7sXDK+H2VDi6+a3dUsK6Q0JU+M2Bue7pnfOemy8es0zmPUhghKzgEg14vBcaEUssss5thbFOrYxAFuEhHvQesbWiFUk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=QR4j25i4; arc=none smtp.client-ip=170.10.129.124 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=1717754458; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=NH3oO20QFn673bgiV5dG3f+GU8g8vUS9TOFN0xj1Yvs=; b=QR4j25i4CcYC8ij7Mi5+p5iJZIxBfUlE1hsJaOM/o3uOhlfYbxgUtyl8J0e8E9cvOAoi8g WM71pNtnyzg8j5kfsh21KoxbHPePnuzdZ0ZYMSY+3fuP8qnxDtKcP2bWfpF0jVj1GARaLu lrqCfcQ79zRtYSvn/fNrkATocftH3o0= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-247-xgL2DSfJMR-vi7a64Cs1NA-1; Fri, 07 Jun 2024 06:00:54 -0400 X-MC-Unique: xgL2DSfJMR-vi7a64Cs1NA-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C312F1955F34; Fri, 7 Jun 2024 10:00:51 +0000 (UTC) Received: from localhost (unknown [10.72.113.124]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B87A41956089; Fri, 7 Jun 2024 10:00:49 +0000 (UTC) Date: Fri, 7 Jun 2024 18:00:44 +0800 From: Baoquan He To: Coiby Xu Cc: kexec@lists.infradead.org, Ondrej Kozina , Milan Broz , Thomas Staudt , Daniel P =?iso-8859-1?Q?=2E_Berrang=E9?= , Kairui Song , Jan Pazdziora , Pingfan Liu , 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: Re: [PATCH v4 7/7] x86/crash: make the page that stores the dm crypt keys inaccessible Message-ID: References: <20240523050451.788754-1-coxu@redhat.com> <20240523050451.788754-8-coxu@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240523050451.788754-8-coxu@redhat.com> X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 On 05/23/24 at 01:04pm, Coiby Xu wrote: > 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 | 21 +++++++++++++++++++++ > 1 file changed, 21 insertions(+) > > diff --git a/arch/x86/kernel/machine_kexec_64.c b/arch/x86/kernel/machine_kexec_64.c > index b180d8e497c3..fc0a80f4254e 100644 > --- a/arch/x86/kernel/machine_kexec_64.c > +++ b/arch/x86/kernel/machine_kexec_64.c > @@ -545,13 +545,34 @@ static void kexec_mark_crashkres(bool protect) > kexec_mark_range(control, crashk_res.end, protect); > } > > +static void kexec_mark_dm_crypt_keys(bool protect) > +{ > + unsigned long start_paddr, end_paddr; > + unsigned int nr_pages; > + > + if (kexec_crash_image->dm_crypt_keys_addr) { > + start_paddr = kexec_crash_image->dm_crypt_keys_addr; > + end_paddr = start_paddr + kexec_crash_image->dm_crypt_keys_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_prot( > + (unsigned long)phys_to_virt(start_paddr), > + nr_pages, > + __pgprot(_PAGE_PRESENT | _PAGE_NX | _PAGE_RW)); > + } > +} > + > void arch_kexec_protect_crashkres(void) > { > kexec_mark_crashkres(true); > + kexec_mark_dm_crypt_keys(true); Isn't crashkernel region covering crypt keys' storing region? Do we need mark it again specifically? Not sure if I miss anything. > } > > void arch_kexec_unprotect_crashkres(void) > { > + kexec_mark_dm_crypt_keys(false); > kexec_mark_crashkres(false); > } > #endif > -- > 2.45.0 >