From nobody Sun Dec 14 21:32:49 2025 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 3A8C324A7E8 for ; Thu, 16 Jan 2025 07:31:38 +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=1737012700; cv=none; b=iqpqcl8C5zufFX6nfo8e10N7eEn61rLSE6qvLQcTBEDUygONNE4zq8Ft0micDjxxTLdojJDe1HnMcnUNXvqFFCCoU2mb4J++MZOdGVnutTyjJQY2h3s5naKt5UujwFhN+H3/z7NrkUtHMjgJLaUSsxUyAlu9bVpuOkgj/wd6Jq4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737012700; c=relaxed/simple; bh=EThvmEzVlpHYF9dCWrf7epLqiSWrsbtL4xk2fKAeHP4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hMTUFD2tHQ2mkBCbWHZS1qxaR6OOyTWxzIA+94a+ylkTtS38mrwihBO2zAL+HhpuV6Xr5sSuA3FkLQX78BG9YcxGpS5mfRzG8V0zgEhh/0WFnIPts3Hdbk2GxROenevNuLAZby+bHvedOhyJ0N+DS+pM9dorzqGZ8p4+LfI+BFc= 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=DXsCyRxi; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="DXsCyRxi" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737012698; 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=4HyMInoAYn9hX25Xcky+1R5gRqRXU1eKRQBtwuBzyQo=; b=DXsCyRxiJG8FQLDeo+pUFFMrYhJmXV2YYWpb7UVWNXW8kwXbiPWqDZRm2B9foZc6I902Vs Oi4A0Zvzx29K+uWQDeK7GFdBXmIUkOjunP15C5bTFl7eETq+r0GKdXuKGZHW9z7gWFtgwJ ZDLz1Sgnn1d6J0K42em7/GxCa3+ZA9k= Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-583-victoL4wMDGq2LUFazHzzg-1; Thu, 16 Jan 2025 02:31:36 -0500 X-MC-Unique: victoL4wMDGq2LUFazHzzg-1 X-Mimecast-MFC-AGG-ID: victoL4wMDGq2LUFazHzzg Received: by mail-pl1-f198.google.com with SMTP id d9443c01a7336-2165433e229so14166145ad.1 for ; Wed, 15 Jan 2025 23:31:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737012695; x=1737617495; 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=4HyMInoAYn9hX25Xcky+1R5gRqRXU1eKRQBtwuBzyQo=; b=No8Whr0JMufmD2Evd1l1aTD82LcqML9viM46QYivFctfY1S+GAf6Hs5ZJH3mYaf86w z/9nbCGgkZu8FYkDnGagH416tx3RKzv71sIzk0DQGaw5hLQLMj+ipswPv8mX3O8BrrKj 1ewxIqXTGus4A3xEzjUmOm2HQdYbQfdeWaolmi30DG44ZnmH9f/HVX9LPAbAE9NPbFmd XNqcpDezUpi+b3tYF4rJ3DFS90us4roGZVb1e4uhKyufox5yxF4L9osiQA7CEqGw8XrG 6Lbjpuc/ngTjnf7sKJ1ESvmzxac+Om1dfGTPmFYx7DNRNgSjbUlSoHLCoabHBi1pcgWh /gXA== X-Forwarded-Encrypted: i=1; AJvYcCVJxCUnQjuch71r/3kS46xaVcR1DprrBDzXPXwAcHcK+pAqAzjBM/oorjMH9n68oK6eOIPUbAlz65nL5OI=@vger.kernel.org X-Gm-Message-State: AOJu0Yy6xIOwFFfRU+lwl6n1KfUkR7h9sxJ6uzHowKclVrMzkwpBVKQK eaXP0avFtVRC14fH73GzBXTkG5MNgzJiWMxZKMagZh+LuJg2s/e8gPZS2XEu2a6c6Z67V4ujA1R t/AZzafD+JVeh+Mpfu5fjvpZhEZsPBTXsENS9Pyvl8tGjStThuXuuVt2pz6AQPA== X-Gm-Gg: ASbGncvXY9X5mN91V6jJHcM55AoOMRYT1M78EBDtwOYRJaCwgpZbDqtUlMTxDlmePLE tOGC5bsUCnw8Zphx91obcSqpZRkxs0LNGqgl0urdeEx4pX8CKRzzvbVSWErQAxsqRvV4bg7ncE5 kN4mGyW556d4oSwfhIU8TFmSd4gFaOesz2LYsi1VvjrzCwkqSB7PxALczzeH7l8KPlik0vNd7UX RX9bSUi87JEid50tRQ7wVsw9ys8ByDr0ibmSInpnZA5c3Ku X-Received: by 2002:a17:902:cec3:b0:216:7ee9:220b with SMTP id d9443c01a7336-21a83f4f43amr572986885ad.22.1737012694940; Wed, 15 Jan 2025 23:31:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IGnDcvWN0Dcty6Dcu7TZDQFkD2YMlJT6ykiEDCc5NZUb+o/QPLJQrH8BeqNF7oR5PEH5HIFtA== X-Received: by 2002:a17:902:cec3:b0:216:7ee9:220b with SMTP id d9443c01a7336-21a83f4f43amr572986675ad.22.1737012694645; Wed, 15 Jan 2025 23:31:34 -0800 (PST) Received: from localhost ([43.228.180.230]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9f256fe3sm93416395ad.243.2025.01.15.23.31.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jan 2025 23:31:34 -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 , 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 v7 7/7] x86/crash: make the page that stores the dm crypt keys inaccessible Date: Thu, 16 Jan 2025 15:31:31 +0800 Message-ID: <20250116073131.1044000-1-coxu@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250116065825.1041558-1-coxu@redhat.com> References: <20250116065825.1041558-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: quoted-printable Content-Type: text/plain; charset="utf-8" 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 | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/arch/x86/kernel/machine_kexec_64.c b/arch/x86/kernel/machine_k= exec_64.c index 9c9ac606893e..7389b912ba43 100644 --- a/arch/x86/kernel/machine_kexec_64.c +++ b/arch/x86/kernel/machine_kexec_64.c @@ -579,13 +579,35 @@ static void kexec_mark_crashkres(bool protect) kexec_mark_range(control, crashk_res.end, protect); } =20 +/* make the memory storing dm crypt keys in/accessible */ +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 =3D kexec_crash_image->dm_crypt_keys_addr; + end_paddr =3D start_paddr + kexec_crash_image->dm_crypt_keys_sz - 1; + nr_pages =3D (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); } =20 void arch_kexec_unprotect_crashkres(void) { + kexec_mark_dm_crypt_keys(false); kexec_mark_crashkres(false); } #endif --=20 2.47.1