From nobody Tue Sep 29 06:11:02 2026 Received: from flow-b7-smtp.messagingengine.com (flow-b7-smtp.messagingengine.com [202.12.124.142]) (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 88A41352010; Tue, 11 Aug 2026 17:53:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.142 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786470797; cv=none; b=e6EFzYIPTGAYjf/g6JoSUCgJXDRKkF+RQTOgbZbR6Xu92gh10zaFnv3yqHUgxLZFAWsXRD9m+DgyfGHNwAF9gdsFlWtxJOSpzb3lOt0N8490NGJDJ1L37AQT35lFEUmoeV7UsxJbZetXHa5Dpd0wZGLK45jw9TnFCN73YJNXWVs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786470797; c=relaxed/simple; bh=ANx9MWoq3jtJg3hwYWWlAs9ePKOKT7sdhCnzQy4xxjo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mlnLeHs0yqvKURNaWPs9vSHRXaguSvrpH47X14b2NWWD0LLGoioZCQ097qwtiF65wmjy+OuBHLxJ2AiFSylrBv5V66cOxZHWaAQ95wqjzKNXlPow8MCAWPLQqZsR4No4KpNMyA1AcqYuVS3N+Z4UpcowPSuIOyB45GmOC4nV78s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=jaseg.de; spf=pass smtp.mailfrom=jaseg.de; dkim=pass (2048-bit key) header.d=jaseg.de header.i=@jaseg.de header.b=bcI27Xge; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=PdCNW6xp; arc=none smtp.client-ip=202.12.124.142 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=jaseg.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=jaseg.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=jaseg.de header.i=@jaseg.de header.b="bcI27Xge"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="PdCNW6xp" Received: from phl-compute-08.internal (phl-compute-08.internal [10.202.2.48]) by mailflow.stl.internal (Postfix) with ESMTP id 20E4A130010C; Tue, 11 Aug 2026 13:53:13 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Tue, 11 Aug 2026 13:53:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jaseg.de; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1786470792; x=1786477992; bh=6bzYVrzwmgCxs1BAVE3pg33ZbHvutLaxuLFDziO3j5s=; b= bcI27Xgefx7p/5EIJQwftgbpvO5xbhyQvUijxfe5lVDAqyY+fYJfIhKaWs1SId5h iCajUTbExspHQ0NmFeIilMuSmDj1HGY8R3StcexlvninnGRbjaIzKRPvh1pfWj0Y 4N+v43B8Hpn+L7vL2mKr5VKeTR41GSmIMtmxCq6WwGMr5xLi7Kyu2heugjXYdzML Moi1BXAQnsWQ7nzy3kEEL+w/qgUSiBueMIBgolB5oKcjc+wZM+NsJdam3isuz/Fz LREjp4/GOAq0fFGYJI9yJQkU07vKIGOhe7p+vKrmrn+UgxdGRXPYiDjb5sGDQ6SU b8xitavmMV6Bgt7U36KW/A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1786470792; x= 1786477992; bh=6bzYVrzwmgCxs1BAVE3pg33ZbHvutLaxuLFDziO3j5s=; b=P dCNW6xpi1mN3p3koEB0o3OQTpob2y8vaqd5Jw7xtCovcdCiiFZwJTw5E3zAAk8Pk t1gmBkV2YjUGRq5wy2UHjKxdGK9npQ3h5CkvPKLKkdOzhJgIVTdvW4cCoOb72P/Y StGUUPUW3gY2jl7tciu9f9af0n7PQhyVkzXTBx7FkZ5RnO9EBZUdtJC2kQY8qtsY fgmRH4ZE9CjDdXZ5jer4QGRzQuYNDLt5VVYEhK8jBr3zMJOPhQzX2mDyC8IFYeiB Wqgl3IsX/eyJofhyg2xCw5hl7Qz0fQWLhqaxOQLc/rBPCzyeuGLvEJkCiuuhJ8PR kMNy/jou2hvlE4s71xOKQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTEwrH8wfhgctv1ErvL0nhEWRZaXCL40jelDGtxObnm8dQ+WB7ldi7zgGP18fqrN+C 7xne4qHVB4V9kXTny9F3UzpVvRvOC+vTRbUvHE754Z1otc2eFdFHJmjh2luxatp0pqWwYy sRKrXvmGl66/LIjfpMZjwK9kOj46ks+olR0W88tI3sOrJxqKyJcEI0DOFTt1YNjUFLRRyj iHYKN+FQnILJq0PWlXi8sHSJU6WpS6NMySRow97FBBcIDr2FI/M1huQ7BdiSPQY9tzBu/P Ctv1qfsiGpDZ4DjvEs5TfiMr3xHnr/zYsFyi6aFPQHrx/6AOsIqWNugJkcAhGMC9jATngj PsYwLs2afmtUbJFrF9pVWN/ueehFiV4iqe1vK7Uil7dEB1ZoerwVUPSf+EH5Er+YoOKMn/ bl8akgMI1uL3WWLdOzwKvEEJwRmYYKXvrBGkbESTPvfFFYUjNLj4SGDvyCd1kqNFX3kqtz HlR88uWTDziuwE0rFpj3kW5HwsI0yC8CSB84yGGiXKoT+iw1+vCALkSh0ieOMAiE1KMSkA C5ZeiquXLwsgm9nTcBQDN+WxS55rWEeuX5UMsECC2BtGAzDPKGiqOR+SeFj/vPoUr01tpr TJycXnYh9lfAnJVuJ9hsWPPtO+MKT2bSAZijEeNf6g1jd2G/hPpvETrWGo2w X-ME-Proxy: Feedback-ID: i60a14417:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 11 Aug 2026 13:53:06 -0400 (EDT) From: =?utf-8?q?Jan_Sebastian_G=C3=B6tte?= Date: Tue, 11 Aug 2026 19:52:50 +0200 Subject: [PATCH v2 01/13] kexec: add CRASH_WIPE_SECRETS to wipe secrets before kdump 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260811-crash-zeroize-rework-v2-1-9561d13c2340@jaseg.de> References: <20260811-crash-zeroize-rework-v2-0-9561d13c2340@jaseg.de> In-Reply-To: <20260811-crash-zeroize-rework-v2-0-9561d13c2340@jaseg.de> To: Andrew Morton , Baoquan He , Mike Rapoport , Pasha Tatashin , Pratyush Yadav , Dave Young , Catalin Marinas , Will Deacon , David Howells , Jarkko Sakkinen , Jonathan Corbet , Shuah Khan , Paul Moore , James Morris , "Serge E. Hallyn" , Lukas Wunner , Ignat Korchagin , Herbert Xu , "David S. Miller" , Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , Trond Myklebust , Anna Schumaker , Mimi Zohar , James Bottomley , Marc Dionne , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Eric Biggers , "Theodore Y. Ts'o" , Jaegeuk Kim , Alexander Viro , Christian Brauner , Jan Kara , Alasdair Kergon , Mike Snitzer , Mikulas Patocka , Benjamin Marzinski Cc: kexec@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, keyrings@vger.kernel.org, linux-doc@vger.kernel.org, linux-security-module@vger.kernel.org, linux-crypto@vger.kernel.org, linux-nvme@lists.infradead.org, linux-nfs@vger.kernel.org, linux-integrity@vger.kernel.org, linux-afs@lists.infradead.org, netdev@vger.kernel.org, linux-fscrypt@vger.kernel.org, linux-fsdevel@vger.kernel.org, dm-devel@lists.linux.dev, =?utf-8?q?Jan_Sebastian_G=C3=B6tte?= X-Mailer: b4 0.15.2 When kdump is used to capture system memory after a panic(), any secret keys currently in RAM end up in the dump. Add an opt-in atomic notifier chain, crash_wipe_secrets_notifier_list, invoked late into __crash_kexec(). Subsystems holding secrets can register a callback to wipe them. Callbacks are run after machine_crash_shutdown() has already stopped the other CPUs and disabled preemption. Callbacks must not wait on locks, which will never be released. This is a best-effort, defence-in-depth measure, not a guarantee. Secrets in flight on the stack, in registers, in DMA buffers, or in other places in memory are out of scope. Signed-off-by: Jan Sebastian G=C3=B6tte --- include/linux/crash_core.h | 16 ++++++++++++++++ kernel/Kconfig.kexec | 16 ++++++++++++++++ kernel/crash_core.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) diff --git a/include/linux/crash_core.h b/include/linux/crash_core.h index bc087124cd78..4230463f3faa 100644 --- a/include/linux/crash_core.h +++ b/include/linux/crash_core.h @@ -5,6 +5,7 @@ #include #include #include +#include =20 struct kimage; =20 @@ -34,6 +35,21 @@ static inline void arch_kexec_protect_crashkres(void) { } static inline void arch_kexec_unprotect_crashkres(void) { } #endif =20 +#ifdef CONFIG_CRASH_WIPE_SECRETS +int crash_wipe_secrets_register(struct notifier_block *nb); +int crash_wipe_secrets_unregister(struct notifier_block *nb); +#else +static inline int crash_wipe_secrets_register(struct notifier_block *nb) +{ + return 0; +} + +static inline int crash_wipe_secrets_unregister(struct notifier_block *nb) +{ + return 0; +} +#endif + #ifndef arch_crash_handle_hotplug_event static inline void arch_crash_handle_hotplug_event(struct kimage *image, v= oid *arg) { } #endif diff --git a/kernel/Kconfig.kexec b/kernel/Kconfig.kexec index 15632358bcf7..1d2d273145df 100644 --- a/kernel/Kconfig.kexec +++ b/kernel/Kconfig.kexec @@ -179,4 +179,20 @@ config CRASH_MAX_MEMORY_RANGES the computation behind the value provided through the /sys/kernel/crash_elfcorehdr_size attribute. =20 +config CRASH_WIPE_SECRETS + bool "Wipe secrets before kdump" + depends on CRASH_DUMP + help + Wipe secrets (e.g. kernel keyring and memfd_secret pages) on crash or + panic. This is a best effort, defense-in-depth feature: If the panic + happens at a really bad time, or if copies of the secrets are present + in places like on the stack, in I/O buffers, or in userspace memory + not allocated through memfd_secret, they may still be leaked. + + Note that enabling this feature carries some risk of crashing the + system during the wipe process if the kernel was already unstable + when the panic happened. + + If unsure, say N. + endmenu diff --git a/kernel/crash_core.c b/kernel/crash_core.c index 2b36aa9fade0..95f5c0415e60 100644 --- a/kernel/crash_core.c +++ b/kernel/crash_core.c @@ -23,6 +23,7 @@ #include #include #include +#include =20 #include #include @@ -33,6 +34,33 @@ /* Per cpu memory for storing cpu states in case of system crash. */ note_buf_t __percpu *crash_notes; =20 +#ifdef CONFIG_CRASH_WIPE_SECRETS +ATOMIC_NOTIFIER_HEAD(crash_wipe_secrets_notifier_list); + +int crash_wipe_secrets_register(struct notifier_block *nb) +{ + return atomic_notifier_chain_register( + &crash_wipe_secrets_notifier_list, nb); +} +EXPORT_SYMBOL_GPL(crash_wipe_secrets_register); + +int crash_wipe_secrets_unregister(struct notifier_block *nb) +{ + return atomic_notifier_chain_unregister( + &crash_wipe_secrets_notifier_list, nb); +} +EXPORT_SYMBOL_GPL(crash_wipe_secrets_unregister); + +static void crash_wipe_secrets(void) +{ + pr_info("Wiping sensitive secrets...\n"); + atomic_notifier_call_chain(&crash_wipe_secrets_notifier_list, 0, NULL); + pr_info("Done wiping secrets.\n"); +} +#else +static inline void crash_wipe_secrets(void) { } +#endif /* CONFIG_CRASH_WIPE_SECRETS */ + /* time to wait for possible DMA to finish before starting the kdump kernel * when a CMA reservation is used */ @@ -142,6 +170,7 @@ void __noclone __crash_kexec(struct pt_regs *regs) crash_save_vmcoreinfo(); machine_crash_shutdown(&fixed_regs); crash_cma_clear_pending_dma(); + crash_wipe_secrets(); machine_kexec(kexec_crash_image); } kexec_unlock(); --=20 2.53.0 From nobody Tue Sep 29 06:11:02 2026 Received: from flow-b7-smtp.messagingengine.com (flow-b7-smtp.messagingengine.com [202.12.124.142]) (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 6E2C6353A94; Tue, 11 Aug 2026 17:53:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.142 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786470804; cv=none; b=mPJSlEcksMFXpOK6vhlonZgH5H0e5ZHE0mJZJi604OWBAhXkO7TWrhBVLTC/SAkRIiDMADIe7CTW/mCl5jRgZR4o+01bY6cfR4lYtUK/6hN4dvm6cmDRhyTWS71zwr+A0MV6eL52zScZxMa5T+ce7hX5jX/+Fwln5XWdaacWQPI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786470804; c=relaxed/simple; bh=LTAReVc9x33R8uYRFqmmctmj7lFmtsfAK2qsskKYG6k=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FQAkYCwep3DxVnfOjcyiFkhtYgQelHXpfyHcVBTTKJIdGNZeHl1cGg2FbLrAsdTrd5iyb4sIIsLYUUem/MpAqd9ixz7l9s5DCMtwaGCmzmLse1KzN7lDzmWjUPb5YGfk5xK3TG66s1Zc3qpQMeR+vHvko9B5NKCHjuifyUObc2Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=jaseg.de; spf=pass smtp.mailfrom=jaseg.de; dkim=pass (2048-bit key) header.d=jaseg.de header.i=@jaseg.de header.b=QkWk+O+I; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=JDK0hyLP; arc=none smtp.client-ip=202.12.124.142 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=jaseg.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=jaseg.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=jaseg.de header.i=@jaseg.de header.b="QkWk+O+I"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="JDK0hyLP" Received: from phl-compute-08.internal (phl-compute-08.internal [10.202.2.48]) by mailflow.stl.internal (Postfix) with ESMTP id 6B744130016C; Tue, 11 Aug 2026 13:53:21 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Tue, 11 Aug 2026 13:53:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jaseg.de; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1786470801; x=1786478001; bh=drS8nyfS/5n/9X4otzCRfuA2cT+uvRCf3SjirFiIRoo=; b= QkWk+O+IqbOXXrBukMGBQdbUdPA1KgNBvThM4OEZTKN8XpOagHUofAFG1d1GR0ao /lYX1uSnQOpRvbvBo8VQVpXEd+yKNzZBvE641sl2Ttw5KCW90N1yb9Xc9aWTvJ+4 xvr5xnDrHDEAkJAPTfIN+w27hRJFgxz3k/73vpih+tg+BRUVzXl3xyjuCF9AKkX4 ui+Mo0rDMoxmZpHVqNTF0DmWMAdRdfhWu7pk5oTYovuv09/KgDB+MZdvbDavQSH7 rx6blAFkBeLVeUMUFKx5/AfC7mkG2ceQc6gSeO3jDjRn0c9F7A50k4X7JfQdp36W DYaXkdMfmfOE5iyBgwWj7A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1786470801; x= 1786478001; bh=drS8nyfS/5n/9X4otzCRfuA2cT+uvRCf3SjirFiIRoo=; b=J DK0hyLPHLvx4qRVfCyhcGaY3Y1afb/Vr6BSxZ+SPEkbntfgaOn3F/kaQ55e/DxpY MF4ppmUTtSC+i3NwhKwiUU8tVt5edI7hjrpkhlgm8jHHb/vnsiqQlbQmwKe2gElS Yxt8h5eVOzzYCSAw9E8TNszM0vfl9lRNNiykjDUWSsSaaRdIdHpBElBkLvT+wo7h LF/926SMCsrhNUHaIx06eCNigbGYwQwANiIXGVuTJEP2ET+U0v8jnyrTC/LaUMFm 3U6E0p1RUXgaQrWhipCy3DiU6Ztdr94fYDc7ollSUWH7sZHSzTojL3uivjRFAHCg cTMFmqJEuklLuwg+uoKqw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTEJEGuCgn7zSteBDxNtSJjV76+V4CnevXg+/HpV8pBcUcuiCNODIEIDrvYJtfUig4 YbV/QY7F/5FmNh0pRZPVmKSRgYy7+KF1hyAgmaSBfjrBu1Tf17UBdgE0OKLaTkwTcf35M8 A3BG9gU1kUODTHqS0pdsippevO97iASgI9eCstdiieZcmNJMxjp+Dk/kb2yyT19QSKiq2/ PYmZLQclF7ZDW1mh1YN6ilSkOCjygxJsr5eR/wz7HE2fkmdnLW9InISWV9kR+irzxvtO9I pnBZF98lSAmI852yZY0IsRjcC4lEqWDe/NVDMPZFCYAeAfD86idfVCQ6A0RRy8MpCwFrGi JaamIhViNAMRkMCXjV9YL6sd6IHyq/tf2HlfDMjgIP2APCVaZFFwrE7zrV7ovbBban3Iu7 W/Uh5FMdKsGj5pZx7P6MCTneY76byI6K9C/6cbEqr5VdWRn4duFZrtBn2D1tYrI8NiPdWc ppdDBXno6JjG1NA7VgMw1eNcNKfSPsYaWA1j2XBlxJK1+DKisAb9rbUMzR+NeEbFpeQxKg w7AZvvx58bqYqiXZjVrLVsnJ4IKjr0WeLWQcsrUy/zeFdUPOGwdqK34r2DtI5AwmetFmPP 0W7aqfZ35Td15bHqKqCcppuR1Zm69cCvNfIMnYwrbZbhpOtGuGMgQK9/Qtsg X-ME-Proxy: Feedback-ID: i60a14417:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 11 Aug 2026 13:53:14 -0400 (EDT) From: =?utf-8?q?Jan_Sebastian_G=C3=B6tte?= Date: Tue, 11 Aug 2026 19:52:51 +0200 Subject: [PATCH v2 02/13] crash-core: Flush caches on CRASH_WIPE_SECRETS 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260811-crash-zeroize-rework-v2-2-9561d13c2340@jaseg.de> References: <20260811-crash-zeroize-rework-v2-0-9561d13c2340@jaseg.de> In-Reply-To: <20260811-crash-zeroize-rework-v2-0-9561d13c2340@jaseg.de> To: Andrew Morton , Baoquan He , Mike Rapoport , Pasha Tatashin , Pratyush Yadav , Dave Young , Catalin Marinas , Will Deacon , David Howells , Jarkko Sakkinen , Jonathan Corbet , Shuah Khan , Paul Moore , James Morris , "Serge E. Hallyn" , Lukas Wunner , Ignat Korchagin , Herbert Xu , "David S. Miller" , Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , Trond Myklebust , Anna Schumaker , Mimi Zohar , James Bottomley , Marc Dionne , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Eric Biggers , "Theodore Y. Ts'o" , Jaegeuk Kim , Alexander Viro , Christian Brauner , Jan Kara , Alasdair Kergon , Mike Snitzer , Mikulas Patocka , Benjamin Marzinski Cc: kexec@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, keyrings@vger.kernel.org, linux-doc@vger.kernel.org, linux-security-module@vger.kernel.org, linux-crypto@vger.kernel.org, linux-nvme@lists.infradead.org, linux-nfs@vger.kernel.org, linux-integrity@vger.kernel.org, linux-afs@lists.infradead.org, netdev@vger.kernel.org, linux-fscrypt@vger.kernel.org, linux-fsdevel@vger.kernel.org, dm-devel@lists.linux.dev, =?utf-8?q?Jan_Sebastian_G=C3=B6tte?= X-Mailer: b4 0.15.2 Replace memzero_expclit with our custom wrapper that additionally flushes the target address ranges from CPU caches. On ARM64, while memzero_explicit is already reasonably reliable for wiping secrets from memory during kdump, it can theoretically leave residue in DRAM when the last memzero_explicit writes are still in flight in caches when shutting down the caches in machine_kexec. We need to swap every memzero_explicit call because ARM64 do not have a wholesale "flush all caches" primitive and only support flushes targeted to a particular address range. Architectures other than ARM64, notably x86-64, are not affected by this cache flush issue. Signed-off-by: Jan Sebastian G=C3=B6tte --- arch/arm64/kernel/machine_kexec.c | 20 ++++++++++++++++++++ include/linux/crash_core.h | 21 +++++++++++++++++++++ kernel/crash_core.c | 23 +++++++++++++++++++++++ 3 files changed, 64 insertions(+) diff --git a/arch/arm64/kernel/machine_kexec.c b/arch/arm64/kernel/machine_= kexec.c index c5693a32e49b..12bf3c90f519 100644 --- a/arch/arm64/kernel/machine_kexec.c +++ b/arch/arm64/kernel/machine_kexec.c @@ -6,6 +6,7 @@ * Copyright (C) Huawei Futurewei Technologies. */ =20 +#include #include #include #include @@ -15,6 +16,7 @@ #include #include =20 +#include #include #include #include @@ -221,6 +223,24 @@ void machine_crash_shutdown(struct pt_regs *regs) pr_info("Starting crashdump kernel...\n"); } =20 +#ifdef CONFIG_CRASH_WIPE_SECRETS +/* + * Queue each wiped range for cleaning to the point of coherency. Deferri= ng + * the barrier until the notifier chain is complete avoids one DSB per ran= ge. + */ +void arch_crash_wipe_range(void *addr, size_t size) +{ + unsigned long start =3D (unsigned long)addr; + + dcache_clean_poc_nosync(start, start + size); +} + +void arch_crash_wipe_flush(void) +{ + dsb(sy); +} +#endif + #if defined(CONFIG_CRASH_DUMP) && defined(CONFIG_HIBERNATION) /* * To preserve the crash dump kernel image, the relevant memory segments diff --git a/include/linux/crash_core.h b/include/linux/crash_core.h index 4230463f3faa..d3e4192b7e6d 100644 --- a/include/linux/crash_core.h +++ b/include/linux/crash_core.h @@ -6,6 +6,7 @@ #include #include #include +#include =20 struct kimage; =20 @@ -15,6 +16,26 @@ struct crash_mem { struct range ranges[] __counted_by(max_nr_ranges); }; =20 +#ifdef CONFIG_CRASH_WIPE_SECRETS +/* + * Record a range that has already been wiped, or wipe and record it in one + * operation. Architectures may use the ranges to push the wipes out to + * memory before kexec disables the caches. + */ +void crash_wipe_cache_range(void *addr, size_t size); +void crash_wipe_memzero(void *addr, size_t size); + +void arch_crash_wipe_range(void *addr, size_t size); +void arch_crash_wipe_flush(void); +#else +static inline void crash_wipe_cache_range(void *addr, size_t size) { } + +static inline void crash_wipe_memzero(void *addr, size_t size) +{ + memzero_explicit(addr, size); +} +#endif + #ifdef CONFIG_CRASH_DUMP =20 int crash_shrink_memory(unsigned long new_size); diff --git a/kernel/crash_core.c b/kernel/crash_core.c index 95f5c0415e60..42faf8d0a4c4 100644 --- a/kernel/crash_core.c +++ b/kernel/crash_core.c @@ -51,10 +51,33 @@ int crash_wipe_secrets_unregister(struct notifier_block= *nb) } EXPORT_SYMBOL_GPL(crash_wipe_secrets_unregister); =20 +/* + * Some kexec paths disable the data cache without first cleaning it. Give + * architectures valid virtual ranges for the wiped data, then let them de= fer + * any completion barrier until all crash-wipe callbacks have run. + */ +void __weak arch_crash_wipe_range(void *addr, size_t size) { } +void __weak arch_crash_wipe_flush(void) { } + +void crash_wipe_cache_range(void *addr, size_t size) +{ + if (size) + arch_crash_wipe_range(addr, size); +} +EXPORT_SYMBOL_GPL(crash_wipe_cache_range); + +void crash_wipe_memzero(void *addr, size_t size) +{ + memzero_explicit(addr, size); + crash_wipe_cache_range(addr, size); +} +EXPORT_SYMBOL_GPL(crash_wipe_memzero); + static void crash_wipe_secrets(void) { pr_info("Wiping sensitive secrets...\n"); atomic_notifier_call_chain(&crash_wipe_secrets_notifier_list, 0, NULL); + arch_crash_wipe_flush(); pr_info("Done wiping secrets.\n"); } #else --=20 2.53.0 From nobody Tue Sep 29 06:11:02 2026 Received: from flow-b7-smtp.messagingengine.com (flow-b7-smtp.messagingengine.com [202.12.124.142]) (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 38272352019; Tue, 11 Aug 2026 17:53:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.142 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786470813; cv=none; b=LHxtkRaEOUSNA9+gNj76J8bKwn2vibtbMxfBWOfCBD9CxB6bikoyglu7csZT3NbolBYr18AFuvgVXntZLymr4iLBI9wjat9247KqvYcRNGFGAPcr1e37lV5K2+XT9R/5ajPZXoUK4vq6r9k2QEQF7tbynmbHhGayHsVOq9iH8UM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786470813; c=relaxed/simple; bh=xh+jSFpG7PebS1CtYDfykFESIRGN1em8j+sgogKLx2U=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gXgo6uOjIV/9sGDclTlDpE3T45E5pQw+etQtmGEGBbFr/7C4UCZQFReTOpBMsy0m57U1OgTwHKC6mEdyKu1Pbv7N1bMRAWHqgrouxJIqAVohvkLWA8TXJmaX43J34q+f79O3cP/UtPP292zyi20YCBk+hBZjnP++7GZpq9MbykM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=jaseg.de; spf=pass smtp.mailfrom=jaseg.de; dkim=pass (2048-bit key) header.d=jaseg.de header.i=@jaseg.de header.b=ijtaT8kD; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=F7n+tHYS; arc=none smtp.client-ip=202.12.124.142 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=jaseg.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=jaseg.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=jaseg.de header.i=@jaseg.de header.b="ijtaT8kD"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="F7n+tHYS" Received: from phl-compute-05.internal (phl-compute-05.internal [10.202.2.45]) by mailflow.stl.internal (Postfix) with ESMTP id 2036D1300386; Tue, 11 Aug 2026 13:53:30 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-05.internal (MEProxy); Tue, 11 Aug 2026 13:53:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jaseg.de; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1786470809; x=1786478009; bh=b3ArJhoaqsFvEuZHlfyWAtV6SGaCuVy7Av0qaKtOt1k=; b= ijtaT8kDvWYfd3yO7OtyiAlRE0ZIplb3TPK1W2M6BA10SuK0UgAtjcGX0oE3nhdJ PiZWC22o8wcjvWRNS/zjkaIimr0n9LVRM0tvbIy4UML1hZWjtYDZl+CiJ/g69qP2 ha+ZWvdrDWeVRbtW49NmTxjxwlmhD+g2G718CyihW1245v+yYuBiLqm81Xi8pn+i lDW/+3bli1cJsp4GgqYBlW2dnGvdRyH5uazX0dA0QPmBy4llq+Ru3JmXd4W3Bfs1 ON6eS3YwR6pclmES5s264NOV2erZgIAUuR+AxbOS0JUZEPv1qD5oKKpQj6wQnekz zP7bJ3Ky1wfC9BUlGo7URw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1786470809; x= 1786478009; bh=b3ArJhoaqsFvEuZHlfyWAtV6SGaCuVy7Av0qaKtOt1k=; b=F 7n+tHYSFuWlN4o4SYZgF6PerK9cXZHzNOIbAIrxvG/Jw3R42BCKEUWgzv74DtCyw rUcgXzQbXuFLrIutTWJ1kejWT9+CRwoJUT9aiVCyOBR/uPiZRKpdwLiSB7PM5+/H BfnYe93/namBn1D+o63fBYUwZC/UaAvT2VSMRQLwopNnnawgjZ0iSlRNOa8tZqwO RR2uHPELbcTiJi77bnhtXa5CfyUJ8inB8K20y/BcPQe9YbbLeDiFu9vS1GRwTVts krh7NortTp/iCcQXgux/TCCZV620afOa+8s30z4mKCT0g8nwlQGQln4AY19Q6hjs GQdHtxAcicxAkr+1jlmwQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTFP5tmiXRyqpvhao8uWnDWsuVG58E3QcpY8nNF+TN3d4+2z3XaWQJ1+2uEKcUq9Jg +xH/KDfBOi31TfxVE5vy2aZ5W5Eono+bvv7mBiiNvVW/C9tjIvrxCLzv7Tz6GJOSvAG1cd t11+FzpQNbill+yp1ZC7JKPVzEaxQ4CH2HewKTU1gYEn0mNFldMXWgoBvZ/c5OhwLZogLW sZeOMCUfQY9vOvCjGHA0ivpYn+5HBy3sK6RswFREIaUm9jlhbU7pV5ZXGDLpJAMlUAJ/Lo y1vjaaTNNEiBF07QqH8YbZg0fsVTsE2lSAku2XiqZRlB3GAWdGnDFC/NxQNHJZjZwh0bAL NFU+sk1NjKbEiriHkWskXNqpRyiqngUiDobuBKM0QHx4IectPTiNVC0LAnkIil116cieth zlAJFqSExn0DMecmyqjTsWkD2ngU3mch+rJhp5ghpPvHYcUsU6CHEmiNL5gcm7pKojpoO8 fUnDVi8q2D+tB3RNg8+bAG4knndc4v8UKvQON5b1dgXr5OKaBku6F7yXG1GPPJwkfrL7jQ EGcTagLVCnPlAjtfXZXy0P8J7sS0XyACESJHYYDdJ2OUni4Z+skjWf20Xpwr+zWL1ubmDC Ll6gwazrEjfo6CiwO2x+aWpiJNWOBFsNaCTo8jTyf1t3R3yZMgHWANJia/Qw X-ME-Proxy: Feedback-ID: i60a14417:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 11 Aug 2026 13:53:23 -0400 (EDT) From: =?utf-8?q?Jan_Sebastian_G=C3=B6tte?= Date: Tue, 11 Aug 2026 19:52:52 +0200 Subject: [PATCH v2 03/13] arm64/mm: add set_direct_map_default_nosplit() 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260811-crash-zeroize-rework-v2-3-9561d13c2340@jaseg.de> References: <20260811-crash-zeroize-rework-v2-0-9561d13c2340@jaseg.de> In-Reply-To: <20260811-crash-zeroize-rework-v2-0-9561d13c2340@jaseg.de> To: Andrew Morton , Baoquan He , Mike Rapoport , Pasha Tatashin , Pratyush Yadav , Dave Young , Catalin Marinas , Will Deacon , David Howells , Jarkko Sakkinen , Jonathan Corbet , Shuah Khan , Paul Moore , James Morris , "Serge E. Hallyn" , Lukas Wunner , Ignat Korchagin , Herbert Xu , "David S. Miller" , Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , Trond Myklebust , Anna Schumaker , Mimi Zohar , James Bottomley , Marc Dionne , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Eric Biggers , "Theodore Y. Ts'o" , Jaegeuk Kim , Alexander Viro , Christian Brauner , Jan Kara , Alasdair Kergon , Mike Snitzer , Mikulas Patocka , Benjamin Marzinski Cc: kexec@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, keyrings@vger.kernel.org, linux-doc@vger.kernel.org, linux-security-module@vger.kernel.org, linux-crypto@vger.kernel.org, linux-nvme@lists.infradead.org, linux-nfs@vger.kernel.org, linux-integrity@vger.kernel.org, linux-afs@lists.infradead.org, netdev@vger.kernel.org, linux-fscrypt@vger.kernel.org, linux-fsdevel@vger.kernel.org, dm-devel@lists.linux.dev, =?utf-8?q?Jan_Sebastian_G=C3=B6tte?= X-Mailer: b4 0.15.2 set_direct_map_default_noflush() goes through split_kernel_leaf_mapping(), which takes pgtable_split_lock and may sleep. That makes it unusable from atomic contexts such as the panic path. Add set_direct_map_default_nosplit(), which skips the split and only walks the page tables to apply the permission change. Callers must guarantee the page is already mapped at page granularity. This holds for any page that had set_direct_map_invalid_noflush() applied to it, as that call performed the split. Architectures that do not need to split the linear map get a generic fallback to set_direct_map_default_noflush(). Signed-off-by: Jan Sebastian G=C3=B6tte --- arch/arm64/include/asm/set_memory.h | 2 ++ arch/arm64/mm/pageattr.c | 21 +++++++++++++++++++++ include/linux/set_memory.h | 17 ++++++++++++++++- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/set_memory.h b/arch/arm64/include/asm/s= et_memory.h index 90f61b17275e..cb5f44bb5a94 100644 --- a/arch/arm64/include/asm/set_memory.h +++ b/arch/arm64/include/asm/set_memory.h @@ -13,6 +13,8 @@ int set_memory_valid(unsigned long addr, int numpages, in= t enable); =20 int set_direct_map_invalid_noflush(struct page *page); int set_direct_map_default_noflush(struct page *page); +int set_direct_map_default_nosplit(struct page *page); +#define set_direct_map_default_nosplit set_direct_map_default_nosplit int set_direct_map_valid_noflush(struct page *page, unsigned nr, bool vali= d); bool kernel_page_present(struct page *page); =20 diff --git a/arch/arm64/mm/pageattr.c b/arch/arm64/mm/pageattr.c index bbe98ac9ad8c..a7bb6bfa12ed 100644 --- a/arch/arm64/mm/pageattr.c +++ b/arch/arm64/mm/pageattr.c @@ -275,6 +275,27 @@ int set_direct_map_default_noflush(struct page *page) PAGE_SIZE, set_mask, clear_mask); } =20 +/* Caller must guarantee @page is already mapped at page granularity. */ +int set_direct_map_default_nosplit(struct page *page) +{ + struct page_change_data data =3D { + .set_mask =3D __pgprot(PTE_PRESENT_VALID_KERNEL | PTE_WRITE), + .clear_mask =3D __pgprot(PTE_PRESENT_INVALID | PTE_RDONLY), + }; + unsigned long addr =3D (unsigned long)page_address(page); + int ret; + + if (!can_set_direct_map()) + return 0; + + lazy_mmu_mode_enable(); + ret =3D walk_kernel_page_table_range_lockless(addr, addr + PAGE_SIZE, + &pageattr_ops, NULL, &data); + lazy_mmu_mode_disable(); + + return ret; +} + static int __set_memory_enc_dec(unsigned long addr, int numpages, bool encrypt) diff --git a/include/linux/set_memory.h b/include/linux/set_memory.h index 3030d9245f5a..65d0fa010368 100644 --- a/include/linux/set_memory.h +++ b/include/linux/set_memory.h @@ -44,7 +44,22 @@ static inline bool kernel_page_present(struct page *page) { return true; } -#else /* CONFIG_ARCH_HAS_SET_DIRECT_MAP */ +#endif /* !CONFIG_ARCH_HAS_SET_DIRECT_MAP */ + +/* + * Variant of set_direct_map_default_noflush() that is safe to call from a= tomic + * context, for pages the caller knows are already mapped at page granular= ity. + * Architectures that need to split the linear map, and can therefore slee= p, + * override this. + */ +#ifndef set_direct_map_default_nosplit +static inline int set_direct_map_default_nosplit(struct page *page) +{ + return set_direct_map_default_noflush(page); +} +#endif + +#ifdef CONFIG_ARCH_HAS_SET_DIRECT_MAP /* * Some architectures, e.g. ARM64 can disable direct map modifications at * boot time. Let them overrive this query. --=20 2.53.0 From nobody Tue Sep 29 06:11:02 2026 Received: from flow-b7-smtp.messagingengine.com (flow-b7-smtp.messagingengine.com [202.12.124.142]) (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 D9E26345EBF; Tue, 11 Aug 2026 17:53:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.142 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786470823; cv=none; b=XIhKwerlsDNqY+TyX8+EKp5sK0FkJzFT3TsutEFAbplvoaqbG5tBJVCPFVo8jr2zkz3KWas6mmJba1Z2Xv7bKyFC3hPdE+adNCZY84pFddPtBVx8EKzcl2T51ocsqxat9LG7BYNRnTn38CW+Jrf3qfpkH94m2ih7glIj6t9mzbI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786470823; c=relaxed/simple; bh=M3mVjTHbvX0WOxUousoB5IWnn494279HaO9ZiP+A8u8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=F3/Y/tWIZBbP9za/4QdjIxRb1NNOYokxX4D8nwjex18qvmmwnEquUGqkWnCYpnZ3MZ3lmIc3vGiF200KOHH7cY2kpg8dhrLaqtMJyPeXV04Z8UtfKPI9bZJktsTjDJR5eKQaJEcErvBK/nnSl2+sFQ+bAOF0No+D+XB0wGrkWXM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=jaseg.de; spf=pass smtp.mailfrom=jaseg.de; dkim=pass (2048-bit key) header.d=jaseg.de header.i=@jaseg.de header.b=BOkDF4Rz; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=N4iS5iTG; arc=none smtp.client-ip=202.12.124.142 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=jaseg.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=jaseg.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=jaseg.de header.i=@jaseg.de header.b="BOkDF4Rz"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="N4iS5iTG" Received: from phl-compute-06.internal (phl-compute-06.internal [10.202.2.46]) by mailflow.stl.internal (Postfix) with ESMTP id A52E71300394; Tue, 11 Aug 2026 13:53:39 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-06.internal (MEProxy); Tue, 11 Aug 2026 13:53:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jaseg.de; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1786470819; x=1786478019; bh=J+WO8Wd8uVuaOAqPz02lOuhC1hujQODpzz8Mj2pgUKU=; b= BOkDF4Rz9/gooVjq3RpQHo3JgqyWe2UvkdyKkquJvQvwFmzg6JKoOyLQdtfEo9os mQPrjjoZ8lPFt6CGUqgCaJL+KYD79POq7sSJkXuoAF2eXi1fvAA85T4Ytwt5ur/Q nx+jUlDfH4eyDYxijQfeU7PLX023FwP9I1sIH97UyPDrGaSgF4aquxz32lGhkUgt VPPGFo6LQAwm4b5XHSLQz91GJaXZDpSzOuxSp+H+TfvoKfrvN4LXASTCzHd6zyeS EnDHlJha5SzE+CxhuQmFzFgWrs6c+eUJ8hr/mOBW15qfn+mIXzBlbV0RD4Rgtgzg 1zeoXrPUD16fpAI8XoHcOw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1786470819; x= 1786478019; bh=J+WO8Wd8uVuaOAqPz02lOuhC1hujQODpzz8Mj2pgUKU=; b=N 4iS5iTGKooqdrvcsJTYS61BR/GSIT45Oo6QqU8ZU7sU0mXhtwYj7MB3Jt/Dx0ROe WWCQLGzlOjc/ospWcxf6DRzXygSS7RJUve2IQJZUBh795lT0a4nr7wM+C75qpRZY pAnHy1c3fGCJV8cdgknI5GL/qnynMG3dZKY3ktFPOILbcp96/cEcLmK1HqjrMdtZ bVd1bKcDGJtqBekmzpDH8Kt/eUgT9wx7T1mZRCUw7rWoiHNEWiJRkv45NdCb7Ivo 8FBBpiS2U0nx5YufR55NmpXxHPL9ZGwYjt8vxD9aiX5ieIIFJl3fZp4EQaqD0WLU zCDK0gxpQBPdBrFDcum2g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTFP5tmiXRyqpvhao8uWnDWsuVG58E3QcpY8nNF+TN3d4+2z3XaWQJ1+2uEKcUq9Jg +xH/KDfBOi31TfxVE5vy2aZ5W5Eono+bvv7mBiiNvVW/C9tjIvrxCLzv7Tz6GJOSvAG1cd t11+FzpQNbill+yp1ZC7JKPVzEaxQ4CH2HewKTU1gYEn0mNFldMXWgoBvZ/c5OhwLZogLW sZeOMCUfQY9vOvCjGHA0ivpYn+5HBy3sK6RswFREIaUm9jlhbU7pV5ZXGDLpJAMlUAJ/Lo y1vjaaTNNEiBF07QqH8YbZg0fsVTsE2lSAku2XiqZRlB3GAWdGnDFC/NxQNHJZjZwh0bYp 2D+LN2F74Yl3YoQ3TYGxnERSWoIxBO0+Rj9TdO4erTRPzAa6AXV7HsZRupEU6wVR1PLnZ/ qD+OrnCT6HXewM+ux4wHGxmKexKv0hHPnfmxW9hJCXJtO2BNPDGZ1Lle6+NhqPYEPMPKNb X8R7eH/IiY0blGg6UPTOthFqGg5f8FXU1DJLEWoGZiH7qMjHDYZC3g35sbvFkqkMCq4alf ePCRDURBuId8UuInZQ/cP018GY4SJfHKmWBqr+4fdNBUm01zIs5NrvTiIC/1gDOpHLjt7/ vRSUj7PMIURe49UfkaLBCD/7OYrpKZ/VT/L3AAfTp/3bPR88OP01AB0LJ4dA X-ME-Proxy: Feedback-ID: i60a14417:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 11 Aug 2026 13:53:31 -0400 (EDT) From: =?utf-8?q?Jan_Sebastian_G=C3=B6tte?= Date: Tue, 11 Aug 2026 19:52:53 +0200 Subject: [PATCH v2 04/13] mm/secretmem: wipe secret pages before kdump 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260811-crash-zeroize-rework-v2-4-9561d13c2340@jaseg.de> References: <20260811-crash-zeroize-rework-v2-0-9561d13c2340@jaseg.de> In-Reply-To: <20260811-crash-zeroize-rework-v2-0-9561d13c2340@jaseg.de> To: Andrew Morton , Baoquan He , Mike Rapoport , Pasha Tatashin , Pratyush Yadav , Dave Young , Catalin Marinas , Will Deacon , David Howells , Jarkko Sakkinen , Jonathan Corbet , Shuah Khan , Paul Moore , James Morris , "Serge E. Hallyn" , Lukas Wunner , Ignat Korchagin , Herbert Xu , "David S. Miller" , Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , Trond Myklebust , Anna Schumaker , Mimi Zohar , James Bottomley , Marc Dionne , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Eric Biggers , "Theodore Y. Ts'o" , Jaegeuk Kim , Alexander Viro , Christian Brauner , Jan Kara , Alasdair Kergon , Mike Snitzer , Mikulas Patocka , Benjamin Marzinski Cc: kexec@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, keyrings@vger.kernel.org, linux-doc@vger.kernel.org, linux-security-module@vger.kernel.org, linux-crypto@vger.kernel.org, linux-nvme@lists.infradead.org, linux-nfs@vger.kernel.org, linux-integrity@vger.kernel.org, linux-afs@lists.infradead.org, netdev@vger.kernel.org, linux-fscrypt@vger.kernel.org, linux-fsdevel@vger.kernel.org, dm-devel@lists.linux.dev, =?utf-8?q?Jan_Sebastian_G=C3=B6tte?= X-Mailer: b4 0.15.2 Register a CRASH_WIPE_SECRETS notifier that wipes secretmem folios. As a result, when CONFIG_CRASH_WIPE_SECRETS is set, secretmem areas will be cleared before the kdump kernel is kexec'ed. The notifier runs after the other CPUs have been stopped, so the page cache cannot be mutated concurrently and the xarray may be walked without taking the i_pages lock. This is a best effort, defense in depth measure. s_inode_list_lock is taken with trylock only. If a CPU was stopped mid-modification the list may be inconsistent, and this late into the panic path, there's nothing we can do about it. Signed-off-by: Jan Sebastian G=C3=B6tte --- mm/secretmem.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/mm/secretmem.c b/mm/secretmem.c index d29865075b6e..db00b7d06080 100644 --- a/mm/secretmem.c +++ b/mm/secretmem.c @@ -13,9 +13,11 @@ #include #include #include +#include #include #include #include +#include #include #include =20 @@ -187,6 +189,54 @@ static const struct inode_operations secretmem_iops = =3D { =20 static struct vfsmount *secretmem_mnt; =20 +/* Called far into vpanic from crash_core.c with other CPUs stopped and + * preemption disabled + */ +static int secretmem_crash_wipe(struct notifier_block *nb, unsigned long a= ction, + void *data) +{ + struct super_block *sb; + struct inode *inode; + + if (!secretmem_mnt) + return NOTIFY_DONE; + sb =3D secretmem_mnt->mnt_sb; + + /* If the list was modified in the exact moment we panic'ed, it might be + * in an inconsistent state that would be unsafe to iterate. If we can't + * get the lock, too bad, that's all we can do here. + */ + if (!spin_trylock(&sb->s_inode_list_lock)) { + pr_crit("crash_wipe_secrets: can't acquire secretmem superblock lock.\n" + "crash_wipe_secrets: skipping zeroizing secretmem.\n"); + return NOTIFY_DONE; + } + + list_for_each_entry(inode, &sb->s_inodes, i_sb_list) { + XA_STATE(xas, &inode->i_mapping->i_pages, 0); + struct folio *folio; + + /* no need for locks if we're burning down the house :) */ + xas_for_each(&xas, folio, ULONG_MAX) { + if (xas_retry(&xas, folio) || xa_is_value(folio)) + continue; + + /* secretmem_fault() already split the linear map */ + set_direct_map_default_nosplit(folio_page(folio, 0)); + folio_zero_segment(folio, 0, folio_size(folio)); + crash_wipe_cache_range(folio_address(folio), + folio_size(folio)); + } + } + spin_unlock(&sb->s_inode_list_lock); + /* off to kexec()! */ + return NOTIFY_DONE; +} + +static struct notifier_block secretmem_wipe_nb =3D { + .notifier_call =3D secretmem_crash_wipe +}; + static struct file *secretmem_file_create(unsigned long flags) { struct file *file; @@ -212,6 +262,8 @@ static struct file *secretmem_file_create(unsigned long= flags) inode->i_mode |=3D S_IFREG; inode->i_size =3D 0; =20 + inode_sb_list_add(inode); + atomic_inc(&secretmem_users); =20 return file; @@ -263,6 +315,7 @@ static int __init secretmem_init(void) if (IS_ERR(secretmem_mnt)) return PTR_ERR(secretmem_mnt); =20 + crash_wipe_secrets_register(&secretmem_wipe_nb); return 0; } fs_initcall(secretmem_init); --=20 2.53.0 From nobody Tue Sep 29 06:11:02 2026 Received: from flow-b7-smtp.messagingengine.com (flow-b7-smtp.messagingengine.com [202.12.124.142]) (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 D9CFA3546D9; Tue, 11 Aug 2026 17:53:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.142 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786470833; cv=none; b=OE/HUw+46wb9PQU9GcJLOj9aULgw+iJCXFgVSQiMLoLY3kG6vyIUhcCLyl4eqLc6mYB1n4ka85KpbNjNDXAlnB7kIL7ccTMCY1J9PPA+nyMbCmBUIf+cGQliPMoWW4VY38FgEEEbN9nKKQbwN3F6xwnz1EDxGbzNoslE0ptZSs8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786470833; c=relaxed/simple; bh=D1EEPfJupuPDhVOtTAnEwmkcoO9CoDfH0bLS6OMgw4w=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=B03El6ZzcBUYCs+nyrNc4KHPwg8RfIz5HhBsqvv4ASPY9/tSG014U9aF2gJJDs7xmjOwOjLt+D7NoYtjxm8VwrnfTInRkk38AEOXffmNirR893CE/FR33ve2tcpEcfJIYOi/89p8K9N3wbnFN/46Xm2AP939Dvb956wEk1oDNGQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=jaseg.de; spf=pass smtp.mailfrom=jaseg.de; dkim=pass (2048-bit key) header.d=jaseg.de header.i=@jaseg.de header.b=Z8bwl0Xj; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=aYONY/pb; arc=none smtp.client-ip=202.12.124.142 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=jaseg.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=jaseg.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=jaseg.de header.i=@jaseg.de header.b="Z8bwl0Xj"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="aYONY/pb" Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41]) by mailflow.stl.internal (Postfix) with ESMTP id BF9781300395; Tue, 11 Aug 2026 13:53:48 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-01.internal (MEProxy); Tue, 11 Aug 2026 13:53:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jaseg.de; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1786470828; x=1786478028; bh=qSx5jstEMxGImoS/91W19MHOeSaIonN8JmHYqcRdoo0=; b= Z8bwl0XjcJPZQLjW9pXCAUF5EWldkGiE9BEEdn2IuAMsXkmfOq3/dvpxmwnP2ZlY 8URUSWG/4y0tCxepJplqISoEiYwfVYK/s8vhmV3uUUrGk7zFTdPqMNIWZs+LJLOA DyCqajFHL7DmdzdzkamxO9z9Wob/c73E7WLPk597ZlIvHS6jmRJcdG7aHu8F2dTW imnXcLgJEGG44MAZQwOinFHlEgCrj6F0218t2fYyyxdt+sm7vHVsMLaS2sM+KzUd IucUdBz7PmGhmm4mCSpIW5y7I3249h8Bo0TbSyj3VAlroAAslctclu3lTZEFlZsZ 2cMCxiZZ3x+umDldQ8whqg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1786470828; x= 1786478028; bh=qSx5jstEMxGImoS/91W19MHOeSaIonN8JmHYqcRdoo0=; b=a YONY/pbby/jHIFWGCQYz+RGUa9FvXes2QTVlDwZtO0+s6y3GL7Z5zvn5OrsxGQO2 2CjUf18XoqUu7baCU6uNkr1s/KP55lhhgN6I1S5KKzcgSKi4I4ccbwwOkbop0hph KrXZtXVQHK9BAjpJipdmlDKNbWmElQYO0/vPrhkYdaQ8FlfJg+CjWrk3WneBjwRg pc+DdLurAGOzcoGOyySJWcadJMh5G3tKOlt3JRBZP/Nm7V58QJLsdxkMviUfgKSz faob06Ye2Y6SZRYVO2pKJpjllwmXmNruMWGdOQU6jJuwND0RWOAx2Wp0dtqCg2ma mGm/TdYa22Upi948CkHlA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTFP5tmiXRyqpvhao8uWnDWsuVG58E3QcpY8nNF+TN3d4+2z3XaWQJ1+2uEKcUq9Jg +xH/KDfBOi31TfxVE5vy2aZ5W5Eono+bvv7mBiiNvVW/C9tjIvrxCLzv7Tz6GJOSvAG1cd t11+FzpQNbill+yp1ZC7JKPVzEaxQ4CH2HewKTU1gYEn0mNFldMXWgoBvZ/c5OhwLZogLW sZeOMCUfQY9vOvCjGHA0ivpYn+5HBy3sK6RswFREIaUm9jlhbU7pV5ZXGDLpJAMlUAJ/Lo y1vjaaTNNEiBF07QqH8YbZg0fsVTsE2lSAku2XiqZRlB3GAWdGnDFC/NxQNHJZjZwh0bh8 kqbkKWELcjtAChbH2Wzn4QOL41OlbQEqlswqKr3P1+VpFR+XsiNX3rUaf5vdKXSnolPw5Q /Ll/uLB1cldMhqyZbAiZQTCYwXiJkO7FdRZ/9Gqe2gvfTrCfAfdNHgTLVZMsAD+fn76T3x gFGfQHvbVS8RM9muaXsf/hhgBhDP9KsibwWWSg2C80hHXEUnxirzCVePR8OTs9vajPnbRl X6LpwU+UjkzYg6auPW6XF1a5W10elYx6W0MaLbP3aPYktTrXr0mX/LqhjI0xOv8F8rUXJl m+CCx3AZq3TzeBvltaEQBfoUWTY6LYm9OAxOqDrHYgNL3v9VOvbb9AA+vdHQ X-ME-Proxy: Feedback-ID: i60a14417:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 11 Aug 2026 13:53:41 -0400 (EDT) From: =?utf-8?q?Jan_Sebastian_G=C3=B6tte?= Date: Tue, 11 Aug 2026 19:52:54 +0200 Subject: [PATCH v2 05/13] security/keys: wipe key payloads before kdump 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260811-crash-zeroize-rework-v2-5-9561d13c2340@jaseg.de> References: <20260811-crash-zeroize-rework-v2-0-9561d13c2340@jaseg.de> In-Reply-To: <20260811-crash-zeroize-rework-v2-0-9561d13c2340@jaseg.de> To: Andrew Morton , Baoquan He , Mike Rapoport , Pasha Tatashin , Pratyush Yadav , Dave Young , Catalin Marinas , Will Deacon , David Howells , Jarkko Sakkinen , Jonathan Corbet , Shuah Khan , Paul Moore , James Morris , "Serge E. Hallyn" , Lukas Wunner , Ignat Korchagin , Herbert Xu , "David S. Miller" , Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , Trond Myklebust , Anna Schumaker , Mimi Zohar , James Bottomley , Marc Dionne , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Eric Biggers , "Theodore Y. Ts'o" , Jaegeuk Kim , Alexander Viro , Christian Brauner , Jan Kara , Alasdair Kergon , Mike Snitzer , Mikulas Patocka , Benjamin Marzinski Cc: kexec@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, keyrings@vger.kernel.org, linux-doc@vger.kernel.org, linux-security-module@vger.kernel.org, linux-crypto@vger.kernel.org, linux-nvme@lists.infradead.org, linux-nfs@vger.kernel.org, linux-integrity@vger.kernel.org, linux-afs@lists.infradead.org, netdev@vger.kernel.org, linux-fscrypt@vger.kernel.org, linux-fsdevel@vger.kernel.org, dm-devel@lists.linux.dev, =?utf-8?q?Jan_Sebastian_G=C3=B6tte?= X-Mailer: b4 0.15.2 When CONFIG_CRASH_WIPE_SECRETS is set, try to erase key payloads on panic before jumping to the kdump kernel. CRASH_WIPE_SECRETS notifiers run during panic() with other CPUs stopped and preemption disabled. In this state, we can't rely on free()'ing being safe, so we define a new `wipe` key op. Signed-off-by: Jan Sebastian G=C3=B6tte --- Documentation/security/keys/core.rst | 13 +++++++++++ include/linux/key-type.h | 9 ++++++++ security/keys/key.c | 43 ++++++++++++++++++++++++++++++++= ++++ 3 files changed, 65 insertions(+) diff --git a/Documentation/security/keys/core.rst b/Documentation/security/= keys/core.rst index 326b8a973828..35cb00a87c46 100644 --- a/Documentation/security/keys/core.rst +++ b/Documentation/security/keys/core.rst @@ -1596,6 +1596,19 @@ The structure has a number of fields, some of which = are mandatory: It is not safe to sleep in this method; the caller may hold spinlocks. =20 =20 + * ``void (*wipe)(struct key *key);`` + + This method is optional. It is called from the panic path when + CONFIG_CRASH_WIPE_SECRETS is enabled, to erase the key material from + memory before the kdump kernel is started, so that it does not end up= in + the crash dump. Unlike destroy(), it must only clear the payload, not + free it. + + This method is called with all other CPUs stopped and preemption + disabled, and only for positively instantiated keys. It must not slee= p, + allocate, free or take locks, as they will never be released. + + * ``void (*describe)(const struct key *key, struct seq_file *p);`` =20 This method is optional. It is called during /proc/keys reading to diff --git a/include/linux/key-type.h b/include/linux/key-type.h index bb97bd3e5af4..21e07db0c5f2 100644 --- a/include/linux/key-type.h +++ b/include/linux/key-type.h @@ -122,6 +122,15 @@ struct key_type { /* clear the data from a key (optional) */ void (*destroy)(struct key *key); =20 + /* wipe the key material without free'ing (optional) + * - used from CONFIG_CRASH_WIPE_SECRETS during panic to keep keys out + * of crash dumps + * - called from the panic path with other CPUs stopped and preemption + * disabled + * - must not sleep, allocate, free or take locks + */ + void (*wipe)(struct key *key); + /* describe a key */ void (*describe)(const struct key *key, struct seq_file *p); =20 diff --git a/security/keys/key.c b/security/keys/key.c index b34a64d81d47..213e6f1d5d83 100644 --- a/security/keys/key.c +++ b/security/keys/key.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include "internal.h" @@ -1268,6 +1269,47 @@ void unregister_key_type(struct key_type *ktype) } EXPORT_SYMBOL(unregister_key_type); =20 +/* Called far into vpanic from crash_core.c with other CPUs stopped and + * preemption disabled + */ +static int key_crash_wipe(struct notifier_block *nb, unsigned long action, + void *data) +{ + struct rb_node *node; + + /* If we can't acquire the lock, the rbtree might be in an inconsistent + * state. That's all we can do then, as there's no point to waiting + * at this stage. + */ + if (!spin_trylock(&key_serial_lock)) { + pr_crit("crash_wipe_secrets: can't acquire key_serial_lock. skipping key= rings.\n"); + return NOTIFY_DONE; + } + + for (node =3D rb_first(&key_serial_tree); node; node =3D rb_next(node)) { + struct key *key =3D rb_entry(node, struct key, serial_node); + + /* Negatively instantiated keys have key->state < 0 and never + * had a payload attached, so only wipe positive ones. + */ + if (key->type =3D=3D &key_type_keyring || !key_is_positive(key)) + continue; + + /* We have a dedicated wipe callback for this since free'ing + * isn't safe at this point + */ + if (key->type->wipe) + key->type->wipe(key); + } + spin_unlock(&key_serial_lock); + /* off to kexec()! */ + return NOTIFY_DONE; +} + +static struct notifier_block key_crash_wipe_nb =3D { + .notifier_call =3D key_crash_wipe +}; + /* * Initialise the key management state. */ @@ -1290,4 +1332,5 @@ void __init key_init(void) =20 rb_insert_color(&root_key_user.node, &key_user_tree); + crash_wipe_secrets_register(&key_crash_wipe_nb); } --=20 2.53.0 From nobody Tue Sep 29 06:11:02 2026 Received: from flow-b7-smtp.messagingengine.com (flow-b7-smtp.messagingengine.com [202.12.124.142]) (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 21C883546DC; Tue, 11 Aug 2026 17:53:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.142 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786470840; cv=none; b=Q4bnIjFPJKNeR7LTLKiix/JbUacKoDFPlbPV5zSjxL0h0JABtU4VPo5XcuUiXhgrDaiGPexlX+os6eDOQWd50vYvp6DgZJQY2FYFSAAu2TcdaR0evtcHo2Di04veCnK1DPcz+71ocnFe/WAL7xd4v+M2jx60bZMuodsir5p4DLo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786470840; c=relaxed/simple; bh=+WO5tcXU5gpFFK/RhD6QSfAv9Wy2LNZra39n6oSqBJE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Cq6WuRUEvBhGsiQB/m+dk31RspyJm8Z++hJeB4LVvL8F7Z1s9bagikXqUGcadaKM+W25cj68VrOU2d/LBK3hgwwvES306oI4hH+sMY1hAxZ6Pk1JCPvl2OeeZkMUUAneUXqfNepFN/6CEmtFPXu2b+m49X/nM+tjELOnPbojn3M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=jaseg.de; spf=pass smtp.mailfrom=jaseg.de; dkim=pass (2048-bit key) header.d=jaseg.de header.i=@jaseg.de header.b=CZJ+DP1c; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Yto8vG2b; arc=none smtp.client-ip=202.12.124.142 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=jaseg.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=jaseg.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=jaseg.de header.i=@jaseg.de header.b="CZJ+DP1c"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Yto8vG2b" Received: from phl-compute-04.internal (phl-compute-04.internal [10.202.2.44]) by mailflow.stl.internal (Postfix) with ESMTP id 0645A1300397; Tue, 11 Aug 2026 13:53:57 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Tue, 11 Aug 2026 13:53:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jaseg.de; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1786470836; x=1786478036; bh=3JSH/iI45wy3MD9zA4sQib4hD7ZbkdXLzpNiNtsaJcE=; b= CZJ+DP1ctATAeRR/KJYvTUIM3t8q9GDjhKCZJvatoQooWR6rVWNSly772PQ/TfUy ENUwOmU25bKc8x8iO+5/ZiNSoxDpy65ZsBKcuwerOM0xJtAMRQlKbIA2r4+K7cpo 4bjjS9E5oRvoOp38MPHnL+07j7CKJyZfjvfarLFn9unjoYWs69bl7jCUKKr8Ndsa JTNOUd8st5x+6dnD+tzTK+EJVuqdzDYdM5RKFtGLtt2fo6MdxoDxsQEmWWm+1h5h 9r0ieubu+uMTq53Onf1eIiRRGrIEDqzqRf1iGgAN3ZRTwO/3zZolwRXxQuwQVsSO JLp/WAXW/e6HViLutxDuDA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1786470836; x= 1786478036; bh=3JSH/iI45wy3MD9zA4sQib4hD7ZbkdXLzpNiNtsaJcE=; b=Y to8vG2bwv0UUn+XNWPlW4HltiAZMSeXAls7xJHf405to9maLImvQ9bJiV7xuBJPt xUIZWEgivpvjAZ/1QdoIo+b9/FKpN+LOU/6eXGlSokf48mJSnxOdoAhuJl9haavG p1QQ0O5H31ulz2f1KK09UhIo4WQbcFU/ccZ7Ax2MFwad5tcauqP8cfc3flFLwxGe Y75oecP+XNv5iwLqvldxhGrdvSZiAdo1RNEgog64rZDGoXYdeDr3/Tn4wnsVZDlr v5P57anNA1u+0/KQAx/G2WWflCk6nIRdXxiG9tYHoiaBV0XQv8Cuv39dxLYqb4Hf eNT7F4OO6XotcScVosu+Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTFP5tmiXRyqpvhao8uWnDWsuVG58E3QcpY8nNF+TN3d4+2z3XaWQJ1+2uEKcUq9Jg +xH/KDfBOi31TfxVE5vy2aZ5W5Eono+bvv7mBiiNvVW/C9tjIvrxCLzv7Tz6GJOSvAG1cd t11+FzpQNbill+yp1ZC7JKPVzEaxQ4CH2HewKTU1gYEn0mNFldMXWgoBvZ/c5OhwLZogLW sZeOMCUfQY9vOvCjGHA0ivpYn+5HBy3sK6RswFREIaUm9jlhbU7pV5ZXGDLpJAMlUAJ/Lo y1vjaaTNNEiBF07QqH8YbZg0fsVTsE2lSAku2XiqZRlB3GAWdGnDFC/NxQNHJZjZwh0bM3 cLQaepUv4mccOXTYHSJClVmCRVjSn+gHGZSrZSr9AIOtFX696ePpwSJ3GivOeqzsZkLmTk yyYQq6X2LYjRyPVZRsKI2XFbuaBY59zZqLm0Ubjaf2Up6v/CUhpiejbTg9OndalmiNo1NB TgyZExpcvXKCRncIx0T/h5V17Yq+BBkt1Lp9C6cm0M6/7WFjIX6uj79fa7WzCqocBHAItx lYJGO4yn0BYCEOUjuH4msbchVi4ZaVb/zXzuqFPnUz6EFLEG1rjqsToNrsNvdQ0zdS7Ksc iAXcKrD3AR2kiGeCuPM2c70LXnp+ct6Uu0ATWnPyvkCwQAMtKo2ec5wQGj0w X-ME-Proxy: Feedback-ID: i60a14417:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 11 Aug 2026 13:53:50 -0400 (EDT) From: =?utf-8?q?Jan_Sebastian_G=C3=B6tte?= Date: Tue, 11 Aug 2026 19:52:55 +0200 Subject: [PATCH v2 06/13] security/keys: implement wipe op for user-type keys 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260811-crash-zeroize-rework-v2-6-9561d13c2340@jaseg.de> References: <20260811-crash-zeroize-rework-v2-0-9561d13c2340@jaseg.de> In-Reply-To: <20260811-crash-zeroize-rework-v2-0-9561d13c2340@jaseg.de> To: Andrew Morton , Baoquan He , Mike Rapoport , Pasha Tatashin , Pratyush Yadav , Dave Young , Catalin Marinas , Will Deacon , David Howells , Jarkko Sakkinen , Jonathan Corbet , Shuah Khan , Paul Moore , James Morris , "Serge E. Hallyn" , Lukas Wunner , Ignat Korchagin , Herbert Xu , "David S. Miller" , Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , Trond Myklebust , Anna Schumaker , Mimi Zohar , James Bottomley , Marc Dionne , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Eric Biggers , "Theodore Y. Ts'o" , Jaegeuk Kim , Alexander Viro , Christian Brauner , Jan Kara , Alasdair Kergon , Mike Snitzer , Mikulas Patocka , Benjamin Marzinski Cc: kexec@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, keyrings@vger.kernel.org, linux-doc@vger.kernel.org, linux-security-module@vger.kernel.org, linux-crypto@vger.kernel.org, linux-nvme@lists.infradead.org, linux-nfs@vger.kernel.org, linux-integrity@vger.kernel.org, linux-afs@lists.infradead.org, netdev@vger.kernel.org, linux-fscrypt@vger.kernel.org, linux-fsdevel@vger.kernel.org, dm-devel@lists.linux.dev, =?utf-8?q?Jan_Sebastian_G=C3=B6tte?= X-Mailer: b4 0.15.2 Wipe the payload of "user" and "logon" keys, and of the key types reusing the user-type ops: s390 cert_store, NVMe TLS PSK, NFS idmap and PKCS#7. Used by CONFIG_CRASH_WIPE_SECRETS. Signed-off-by: Jan Sebastian G=C3=B6tte --- crypto/asymmetric_keys/pkcs7_key_type.c | 1 + drivers/nvme/common/keyring.c | 1 + fs/nfs/nfs4idmap.c | 2 ++ include/keys/user-type.h | 1 + security/keys/user_defined.c | 15 +++++++++++++++ 5 files changed, 20 insertions(+) diff --git a/crypto/asymmetric_keys/pkcs7_key_type.c b/crypto/asymmetric_ke= ys/pkcs7_key_type.c index b930d3bbf1af..663a246742f7 100644 --- a/crypto/asymmetric_keys/pkcs7_key_type.c +++ b/crypto/asymmetric_keys/pkcs7_key_type.c @@ -74,6 +74,7 @@ static struct key_type key_type_pkcs7 =3D { .instantiate =3D generic_key_instantiate, .revoke =3D user_revoke, .destroy =3D user_destroy, + .wipe =3D user_wipe, .describe =3D user_describe, .read =3D user_read, }; diff --git a/drivers/nvme/common/keyring.c b/drivers/nvme/common/keyring.c index 32d16c53133b..33303f035fb1 100644 --- a/drivers/nvme/common/keyring.c +++ b/drivers/nvme/common/keyring.c @@ -84,6 +84,7 @@ static struct key_type nvme_tls_psk_key_type =3D { .instantiate =3D generic_key_instantiate, .revoke =3D user_revoke, .destroy =3D user_destroy, + .wipe =3D user_wipe, .describe =3D nvme_tls_psk_describe, .read =3D user_read, }; diff --git a/fs/nfs/nfs4idmap.c b/fs/nfs/nfs4idmap.c index bc397110d977..26f579ae2c73 100644 --- a/fs/nfs/nfs4idmap.c +++ b/fs/nfs/nfs4idmap.c @@ -190,6 +190,7 @@ static struct key_type key_type_id_resolver =3D { .instantiate =3D generic_key_instantiate, .revoke =3D user_revoke, .destroy =3D user_destroy, + .wipe =3D user_wipe, .describe =3D user_describe, .read =3D user_read, }; @@ -412,6 +413,7 @@ static struct key_type key_type_id_resolver_legacy =3D { .instantiate =3D generic_key_instantiate, .revoke =3D user_revoke, .destroy =3D user_destroy, + .wipe =3D user_wipe, .describe =3D user_describe, .read =3D user_read, .request_key =3D nfs_idmap_legacy_upcall, diff --git a/include/keys/user-type.h b/include/keys/user-type.h index 386c31432789..685fa054b0ac 100644 --- a/include/keys/user-type.h +++ b/include/keys/user-type.h @@ -40,6 +40,7 @@ extern void user_free_preparse(struct key_preparsed_paylo= ad *prep); extern int user_update(struct key *key, struct key_preparsed_payload *prep= ); extern void user_revoke(struct key *key); extern void user_destroy(struct key *key); +extern void user_wipe(struct key *key); extern void user_describe(const struct key *user, struct seq_file *m); extern long user_read(const struct key *key, char *buffer, size_t buflen); =20 diff --git a/security/keys/user_defined.c b/security/keys/user_defined.c index 6f88b507f927..f4897c19c2dd 100644 --- a/security/keys/user_defined.c +++ b/security/keys/user_defined.c @@ -6,6 +6,7 @@ */ =20 #include +#include #include #include #include @@ -28,6 +29,7 @@ struct key_type key_type_user =3D { .update =3D user_update, .revoke =3D user_revoke, .destroy =3D user_destroy, + .wipe =3D user_wipe, .describe =3D user_describe, .read =3D user_read, }; @@ -48,6 +50,7 @@ struct key_type key_type_logon =3D { .update =3D user_update, .revoke =3D user_revoke, .destroy =3D user_destroy, + .wipe =3D user_wipe, .describe =3D user_describe, .vet_description =3D logon_vet_description, }; @@ -152,6 +155,18 @@ void user_destroy(struct key *key) =20 EXPORT_SYMBOL_GPL(user_destroy); =20 +void user_wipe(struct key *key) +{ + struct user_key_payload *upayload =3D key->payload.data[0]; + + if (upayload) + crash_wipe_memzero(upayload->data, upayload->datalen); + key->payload.data[1] =3D NULL; + key->payload.data[2] =3D NULL; + key->payload.data[3] =3D NULL; +} +EXPORT_SYMBOL_GPL(user_wipe); + /* * describe the user key */ --=20 2.53.0 From nobody Tue Sep 29 06:11:02 2026 Received: from flow-b7-smtp.messagingengine.com (flow-b7-smtp.messagingengine.com [202.12.124.142]) (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 933723546D7; Tue, 11 Aug 2026 17:54:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.142 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786470848; cv=none; b=IiLtm3pEP59DzgGc7JaQAukR2k7LWyjYgycoa3XyPOkXTCAGbd1X3074AN6haePsxxkDeHq4JCM+3KFcvZrXTHjeh/mVSlLIL4YZrM+UoRHTf7w2kCPQf1uyqXbl8G6bXjjPIWkALnq2cMFgE/w1//BbvqvvQQ6BHEAMMcJwWug= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786470848; c=relaxed/simple; bh=dLmnCMrwGiZmuxsn1+1ltOBeSqEbD7lNdGjE68Bw/IA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fRBI9tFhcHYrC0zz6uYlzrRc7NdgPwy5we8UxYQXhGRSSx4vbidBxr5WJ8mIMES4RAoJiWycrk7natDYN5v9sCtGHF2DtR1tJAna8TyO1Fl212CJmI+FWJYhs8AiUjqkDNuGO9kVp+iHyRo5699nsN4k3yM+nTSIhDfKUtt/tCY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=jaseg.de; spf=pass smtp.mailfrom=jaseg.de; dkim=pass (2048-bit key) header.d=jaseg.de header.i=@jaseg.de header.b=CO0Kje71; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=koLw6IQ5; arc=none smtp.client-ip=202.12.124.142 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=jaseg.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=jaseg.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=jaseg.de header.i=@jaseg.de header.b="CO0Kje71"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="koLw6IQ5" Received: from phl-compute-06.internal (phl-compute-06.internal [10.202.2.46]) by mailflow.stl.internal (Postfix) with ESMTP id 768401300399; Tue, 11 Aug 2026 13:54:05 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-06.internal (MEProxy); Tue, 11 Aug 2026 13:54:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jaseg.de; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1786470845; x=1786478045; bh=ZpsnlNCccEzAx1VvGs1BtMr3ZszQOnPZ7Dvx24ZVOoQ=; b= CO0Kje71ADHAkCmXbnQAZokL+eSWvgwPZWPHmSNOEOVHrTnQpYRqXb1hqK2Uh/r/ Yd3x7VDfQYmeW35C1EDJN1ovLe9G9sdhLEjE0SMuPLGt7/sOh1Wd8prN4/uu6Lqm qha8bFKTOzaB8Xl1n8NkI2GfBXs1RX2UJHbEueS78UVr7xN+39obSLaQs6q0l5Dq EANeKWNx1Q4PWyA8udr9f3AfbbuhlciRtcPB1Z8t3mMBdrnykbUwsqViH6leJRVs PF3UGXQF48IPvFdkDna56xKJyD6BHZwD6coo+eOmMthRuKaA7WeKH/2uHqZpzrYY 6UMvpA7pj39GegQSfpmpMQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1786470845; x= 1786478045; bh=ZpsnlNCccEzAx1VvGs1BtMr3ZszQOnPZ7Dvx24ZVOoQ=; b=k oLw6IQ54IYbzIorzGo/Fm0B2EF48jdeMVhpkER6hAlAzec9z9ubOQ6rRjdPVTFcc MubOaAcsdMKqhJkjfR/utkUOiNg+8gEExZHQMDjQa59TqonNX06lcrgg8XkjpTb4 pnacKb6GoWq2VHJU70pbHR2oEK19mZk2PvSoj5X8jk4vD10oej5X/bb6bWaz3eU3 YYzcZU9/r753lY6x867A1rWK4WybMP5WuuH9Zoi+DwdxDogx1dBFXyxxTT1hy8/t 1ZAeV9pkJoYJ/b5bVN0hfT4BQqAFEklAkju521/YsTD7qA1u50yFPH++xKyGKKCp PH4kIQZwcW7p8gtl1lzEg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTFz4vgNe8oY8QyUL0mlPqEECv57Qi7HCBIaM0H0fEpf1xbY2+8hZG6UpCbiC57xgk VavagF0YgIkokz9w1ZYP1FsIKkSgwmPUkWwZZopzEj1hsTumYxogfZ8LsE2lIsmrvQrzxe DNsAmjkffjDdnK7Hikwb1PBijPzdc+/pLDsJWa/G9io4Zr2WihJBScLGTtc/AAEph99TK7 KMYjrfPBzTMOGahPoGoXnc0LQ7Z6pMXIRNlA+PEZw+HSeBor1z9UME1MTUTi3zab2cdg5l S2ygLFXboS6erW/oqrZ0wC4vZEyPuJEZAHdMIjRfMGBWirnE5Gt0LHQJATpVfpt20aHeVC WVD3qwZKQUbal0U+m98B4JhWUSNaJDclWMKiggs1inMalAO0xRnRH3Oouto/luMbNsCB2k eSSMm2vjcQBKUvPCfA9hEqFDdbvDb3quCu37KQrVNZypjOu6fL7cprPZRqICDDKVtkztFU yrFIasOIyWnuenf8eW7I1Zps/ju1bW9xOHNoW4ln3/bmbFFIXA1cNSJEjke0FYBk7fwY26 UXB3NzWKPPR2sQ+sCGiPGl0CFHNyi7yjk0GLrJPi2Yr6boERxx1j+qh0F9fuatJNPph+i3 qUZDH/7D50/AxoO6XxEpOgSyBH2Tr99IP5LbQWtXdp+AhwI4U5A+5y275YDg X-ME-Proxy: Feedback-ID: i60a14417:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 11 Aug 2026 13:53:58 -0400 (EDT) From: =?utf-8?q?Jan_Sebastian_G=C3=B6tte?= Date: Tue, 11 Aug 2026 19:52:56 +0200 Subject: [PATCH v2 07/13] security/keys: implement wipe op for big_key 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260811-crash-zeroize-rework-v2-7-9561d13c2340@jaseg.de> References: <20260811-crash-zeroize-rework-v2-0-9561d13c2340@jaseg.de> In-Reply-To: <20260811-crash-zeroize-rework-v2-0-9561d13c2340@jaseg.de> To: Andrew Morton , Baoquan He , Mike Rapoport , Pasha Tatashin , Pratyush Yadav , Dave Young , Catalin Marinas , Will Deacon , David Howells , Jarkko Sakkinen , Jonathan Corbet , Shuah Khan , Paul Moore , James Morris , "Serge E. Hallyn" , Lukas Wunner , Ignat Korchagin , Herbert Xu , "David S. Miller" , Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , Trond Myklebust , Anna Schumaker , Mimi Zohar , James Bottomley , Marc Dionne , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Eric Biggers , "Theodore Y. Ts'o" , Jaegeuk Kim , Alexander Viro , Christian Brauner , Jan Kara , Alasdair Kergon , Mike Snitzer , Mikulas Patocka , Benjamin Marzinski Cc: kexec@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, keyrings@vger.kernel.org, linux-doc@vger.kernel.org, linux-security-module@vger.kernel.org, linux-crypto@vger.kernel.org, linux-nvme@lists.infradead.org, linux-nfs@vger.kernel.org, linux-integrity@vger.kernel.org, linux-afs@lists.infradead.org, netdev@vger.kernel.org, linux-fscrypt@vger.kernel.org, linux-fsdevel@vger.kernel.org, dm-devel@lists.linux.dev, =?utf-8?q?Jan_Sebastian_G=C3=B6tte?= X-Mailer: b4 0.15.2 For keys stored in shmem only the ChaCha20-Poly1305 key is reachable here, so wiping it is enough to render the payload unreadable. Used by CONFIG_CRASH_WIPE_SECRETS. Signed-off-by: Jan Sebastian G=C3=B6tte --- security/keys/big_key.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/security/keys/big_key.c b/security/keys/big_key.c index 268f702df380..c01a212bec90 100644 --- a/security/keys/big_key.c +++ b/security/keys/big_key.c @@ -8,6 +8,7 @@ =20 #define pr_fmt(fmt) "big_key: "fmt #include +#include #include #include #include @@ -35,6 +36,8 @@ struct big_key_payload { */ #define BIG_KEY_FILE_THRESHOLD (sizeof(struct inode) + sizeof(struct dentr= y)) =20 +static void big_key_wipe(struct key *key); + /* * big_key defined keys take an arbitrary string as the description and an * arbitrary blob of data as the payload @@ -46,6 +49,7 @@ struct key_type key_type_big_key =3D { .instantiate =3D generic_key_instantiate, .revoke =3D big_key_revoke, .destroy =3D big_key_destroy, + .wipe =3D big_key_wipe, .describe =3D big_key_describe, .read =3D big_key_read, .update =3D big_key_update, @@ -279,6 +283,19 @@ long big_key_read(const struct key *key, char *buffer,= size_t buflen) return ret; } =20 +static void big_key_wipe(struct key *key) +{ + struct big_key_payload *payload =3D to_big_key_payload(key->payload); + + if (payload->data) { + if (payload->length > BIG_KEY_FILE_THRESHOLD) + crash_wipe_memzero(payload->data, + CHACHA20POLY1305_KEY_SIZE); + else + crash_wipe_memzero(payload->data, payload->length); + } +} + /* * Register key type */ --=20 2.53.0 From nobody Tue Sep 29 06:11:02 2026 Received: from flow-b7-smtp.messagingengine.com (flow-b7-smtp.messagingengine.com [202.12.124.142]) (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 1ED1A360EE4; Tue, 11 Aug 2026 17:54:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.142 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786470857; cv=none; b=SIGW5SW7BhiG5cCFkKzyB00dRQPN+wqh62NdN0ugdcNRhZmUY711hdcbjv8thAVgNfGmTYuoDIz05rn65ZLZ7W3dQTrDr+kzwiD5xe2It4o4zLoAKTBzM1ZgppaItCUxON0jvsmtj0WXlyoY7F3MGFckxinsqT/qx6WFJ3PzrKM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786470857; c=relaxed/simple; bh=647dHowxYyRQyO+sUKOtz6G8zNBCMu1y2kwFN1XIyZw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=V6LYn4UyXMO87FUadYtZYgktX+D0a60dxg/ts8x1pdVjOBukdj/gIvln50RvzfkVd4yMm0YuXMSWf3XkEqrZUeiEV6zv7aktujUqJHbsOhHpjpTr8bHajeG/5G4uQqyiC9nToQ2TkQIdGEFDmPDeSciMc0YueBABoMPUkMfwDqY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=jaseg.de; spf=pass smtp.mailfrom=jaseg.de; dkim=pass (2048-bit key) header.d=jaseg.de header.i=@jaseg.de header.b=U3I428v4; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=NFVSFrFr; arc=none smtp.client-ip=202.12.124.142 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=jaseg.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=jaseg.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=jaseg.de header.i=@jaseg.de header.b="U3I428v4"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="NFVSFrFr" Received: from phl-compute-08.internal (phl-compute-08.internal [10.202.2.48]) by mailflow.stl.internal (Postfix) with ESMTP id E7CC4130039C; Tue, 11 Aug 2026 13:54:13 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Tue, 11 Aug 2026 13:54:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jaseg.de; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1786470853; x=1786478053; bh=FZBYWhL5n7JQ+WX8bMFfUS0qJovxuh7QkbRbWkvh2HQ=; b= U3I428v4Xek0tSEHP9VEkmh84J7xFx2TdU9S8LG8Hnyrt9FFLS3afQgWc4pLxMUh oDOB6G5O6t7bhE7LBdDe7Xd9k/LUDmytiRYGMYxaetH4N17pKTtDPgG3q1z6H0a3 n4bfRz3VifmOrPkTBoHURT9d88Xjb8ZNs4IcVbOStH++mstZ1HzzikSXnbDdM5AR cmqQjmAR7Ht+lxSsR9pE6KZ0pEOwmVYwt5c9IWgrVHohtRzyTh+Q9pgb+T6Y8ggs vZ56sq37RhJOa3ubp9HuVWHnMzWAeOzxc4Y5zb5Je1U7IWLAxVfnOXNOfayNvO5/ gbYudKk97aPgWYyIByBOOQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1786470853; x= 1786478053; bh=FZBYWhL5n7JQ+WX8bMFfUS0qJovxuh7QkbRbWkvh2HQ=; b=N FVSFrFrsdHDuwX5bmwEFi+vfM4jbvPi1714oBu1Pe04LTQ4ur68y0wRIxq8PvQ/d CK5ZGpzx+b0HGehJPn6zOIyrzHk/fGVB5FsDztbzGbCNFUuW3H0GhsS6WsR3vv6Z BcB+8GzdZv2ZYrvwtzxpKcc6jVQrIpKkmaNznEjvmBPKa6D2QAMF1RqYLeKx/JPO 6FXrwSg7EIiA7UuparnXo61bTYDNTFy4zcXHHvvcPINcmkoilfMZj4hVTChqLkl7 mtUmU/6kAdq5UxKLWXnh2n2Q/VTAv/mlYQ4g00356aF5Px9u2TMDaBPeEvhaI8Pf /0Wg9vZV7YHTADO1cCo0A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTFqRXkqeRY8YxPaiPG6bKtumQZ44ueOyE0ycsRtkYHYtMPeLw9KqkFTfoymoPXANQ f8xIE59to9muOon1MQaYxt7DdSPzezKDm/5lwbw25fHysrcDraGpHHDQDBxbs7DNakPMfM e6H9gUHyYw6Jnjx4Hrnr8P0aqcdlkP/OQCvkpK5i8nwVpDOUjiFIrGc2aHzhOHJwaTCmvE SohzxPZY/BMExH4tATsvbW62+v/yi0C/jL+BZWLe9AwElVYGEpH8rm9jM3a5qxQfAZo+/L Re7VHgx53z5HSeOGiZCoxmlFJwvoInomet06PrQYp2gmHd77fq1CpUHnH937B47mzUIvku yUh4mUkbwyIu2ja7cJVK9b5XTWYB3dNvbtYJydefJ79hiiQApVeOYD7m1nli1tUKbs9WrY rf6TqxumbHWQJhS9dRF7SycnMHQ6BSeUFwSC0Jc9Hnz+CpcUylmf2b4TB1iS15234kpK4m awbwTHUT4h4bvy2Idl4MLcnpcyjQdT8Ab8gCmErQCN0e7s7wL39Q0j7anatprW32BrU2u5 COL6aNgtIPHavUk6F00gHusdEiFqlhHp0D1PYqraDFPTljJ+i0kxTOlnCQbqK1AkW0Osfk J/vfxzuBWvaQmujMPvnwYblwydfhIlNC7DKYrx/NLuL6fNaINYhWN84Nk/Lg X-ME-Proxy: Feedback-ID: i60a14417:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 11 Aug 2026 13:54:07 -0400 (EDT) From: =?utf-8?q?Jan_Sebastian_G=C3=B6tte?= Date: Tue, 11 Aug 2026 19:52:57 +0200 Subject: [PATCH v2 08/13] security/keys: implement wipe op for trusted and encrypted keys 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260811-crash-zeroize-rework-v2-8-9561d13c2340@jaseg.de> References: <20260811-crash-zeroize-rework-v2-0-9561d13c2340@jaseg.de> In-Reply-To: <20260811-crash-zeroize-rework-v2-0-9561d13c2340@jaseg.de> To: Andrew Morton , Baoquan He , Mike Rapoport , Pasha Tatashin , Pratyush Yadav , Dave Young , Catalin Marinas , Will Deacon , David Howells , Jarkko Sakkinen , Jonathan Corbet , Shuah Khan , Paul Moore , James Morris , "Serge E. Hallyn" , Lukas Wunner , Ignat Korchagin , Herbert Xu , "David S. Miller" , Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , Trond Myklebust , Anna Schumaker , Mimi Zohar , James Bottomley , Marc Dionne , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Eric Biggers , "Theodore Y. Ts'o" , Jaegeuk Kim , Alexander Viro , Christian Brauner , Jan Kara , Alasdair Kergon , Mike Snitzer , Mikulas Patocka , Benjamin Marzinski Cc: kexec@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, keyrings@vger.kernel.org, linux-doc@vger.kernel.org, linux-security-module@vger.kernel.org, linux-crypto@vger.kernel.org, linux-nvme@lists.infradead.org, linux-nfs@vger.kernel.org, linux-integrity@vger.kernel.org, linux-afs@lists.infradead.org, netdev@vger.kernel.org, linux-fscrypt@vger.kernel.org, linux-fsdevel@vger.kernel.org, dm-devel@lists.linux.dev, =?utf-8?q?Jan_Sebastian_G=C3=B6tte?= X-Mailer: b4 0.15.2 Wipe the decrypted key material and the sealed blob held in the payload. Used by CONFIG_CRASH_WIPE_SECRETS. Signed-off-by: Jan Sebastian G=C3=B6tte --- security/keys/encrypted-keys/encrypted.c | 13 +++++++++++++ security/keys/trusted-keys/trusted_core.c | 15 +++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/security/keys/encrypted-keys/encrypted.c b/security/keys/encry= pted-keys/encrypted.c index 59cb77b237b3..9d6fe08ecb7a 100644 --- a/security/keys/encrypted-keys/encrypted.c +++ b/security/keys/encrypted-keys/encrypted.c @@ -12,6 +12,7 @@ */ =20 #include +#include #include #include #include @@ -970,11 +971,23 @@ static void encrypted_destroy(struct key *key) kfree_sensitive(key->payload.data[0]); } =20 +static void encrypted_wipe(struct key *key) +{ + struct encrypted_key_payload *epayload =3D key->payload.data[0]; + + if (!epayload) + return; + + crash_wipe_memzero(epayload->payload_data, + epayload->payload_datalen + epayload->datablob_len); +} + struct key_type key_type_encrypted =3D { .name =3D "encrypted", .instantiate =3D encrypted_instantiate, .update =3D encrypted_update, .destroy =3D encrypted_destroy, + .wipe =3D encrypted_wipe, .describe =3D user_describe, .read =3D encrypted_read, }; diff --git a/security/keys/trusted-keys/trusted_core.c b/security/keys/trus= ted-keys/trusted_core.c index 0509d9955f2a..7b220c6381b5 100644 --- a/security/keys/trusted-keys/trusted_core.c +++ b/security/keys/trusted-keys/trusted_core.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -325,11 +326,25 @@ static void trusted_destroy(struct key *key) kfree_sensitive(key->payload.data[0]); } =20 +static void trusted_wipe(struct key *key) +{ + struct trusted_key_payload *p =3D key->payload.data[0]; + + if (!p) + return; + + crash_wipe_memzero(p->key, sizeof(p->key)); + crash_wipe_memzero(p->blob, sizeof(p->blob)); + p->key_len =3D 0; + p->blob_len =3D 0; +} + struct key_type key_type_trusted =3D { .name =3D "trusted", .instantiate =3D trusted_instantiate, .update =3D trusted_update, .destroy =3D trusted_destroy, + .wipe =3D trusted_wipe, .describe =3D user_describe, .read =3D trusted_read, }; --=20 2.53.0 From nobody Tue Sep 29 06:11:02 2026 Received: from flow-b7-smtp.messagingengine.com (flow-b7-smtp.messagingengine.com [202.12.124.142]) (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 E059835B65D; Tue, 11 Aug 2026 17:54:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.142 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786470866; cv=none; b=mMrbum3KONV23epK3IjyO/l8bFKMFDjFpOJbrqJ0/i20lJ5mFlgc6794VzW48TM80yMXP/jnjFaysr3VpOYSpcf8VEuSByr6O4eaSTnAPzn+Fk25KxbtI3D9R+tnW2zu1s4AfGTFtvNVU7aDpsYL8u5Ce6HYBc62SsptyCsG79g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786470866; c=relaxed/simple; bh=pFhp6xnik0wvtR0KY8MWR4dOyalbUlDaPKD/cfIHUmA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=W6u41UyEdDqPxvG7+HzQU8M7IE5oXKWkg87EzNWaX2W6chbZkGr4DOQ9PbAfxtpD1Sd9WthL5X20x7BsPfxDQtVrel0EznAmIqaG2PxSPQZAx4wcLAIYi4+bqae8V4NXhMsXctZyCU5XclObQvomo/5VTDnCbzmIUbBeJjUD1DQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=jaseg.de; spf=pass smtp.mailfrom=jaseg.de; dkim=pass (2048-bit key) header.d=jaseg.de header.i=@jaseg.de header.b=qB2Jy7vX; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=TRxBuSxw; arc=none smtp.client-ip=202.12.124.142 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=jaseg.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=jaseg.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=jaseg.de header.i=@jaseg.de header.b="qB2Jy7vX"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="TRxBuSxw" Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41]) by mailflow.stl.internal (Postfix) with ESMTP id C358513003A6; Tue, 11 Aug 2026 13:54:22 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-01.internal (MEProxy); Tue, 11 Aug 2026 13:54:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jaseg.de; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1786470862; x=1786478062; bh=6GTy/7ZYnhxwkN3CoOvmK6vIIxg2qB1mjCGqyHajM1A=; b= qB2Jy7vX5C5g7HFTE11w3KW7iFGS08Hi2Z6fdKdbd+NH+vR4665E+YY32z+VrqHW e8VqhnOhmjyMa+NhOcxYaLSFJm4O2aPGvq4PP0flRu/uCP3GXTHNw4uZQN9Jdn5m iDDZ/byDI9F+wTQibuac57c6zH2r3wPapyRCaq71th2vwXrzwW1kJwv4/K+v10Xc S/HsLRiVsm96zzjZc3hnudlFMXt4fH2Ygh4Y6AoAzx9jJsK9iJAN2YUhK9QqJCvd mQzgHE16IfdSAAeBDmYhEdflm5INZlpdetbk6F4+XseJ8OSLrgHIidqZ7Tvl6149 gZM82j6UrZMR4gFcY37t3g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1786470862; x= 1786478062; bh=6GTy/7ZYnhxwkN3CoOvmK6vIIxg2qB1mjCGqyHajM1A=; b=T RxBuSxw+xYevsT25Hc1JPuxXZqY/uEsl8wSxfZhf/AnKlFUhLhxDA6OAGexc/MPq yo4PqNgNydIVClSZ3ANQkB+z3UkR32qE7fBDOKJlV2ywY71eXlLfNkDQmBS75Caw Gb5aPaFEYzA/RZqFwZZ7kP8Mj31loYQbhJfKe9D7873Xr2U0jy0m6K9ka6JILxIb npR/zyq+eq6XNbfqaIWlAGkJucqyPYs4Y1Uw/X4bU1kkyrXwCZ0N8BcWdYyVXSI1 1/D5iiCrk0Ijt8TBdbCTi30INqZ8bShadFPJ4WPiTgAbfc52SukdVu0W4GMsCW+L n5fdbrFiJ8s2Rm29o5wZw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTFz4vgNe8oY8QyUL0mlPqEECv57Qi7HCBIaM0H0fEpf1xbY2+8hZG6UpCbiC57xgk VavagF0YgIkokz9w1ZYP1FsIKkSgwmPUkWwZZopzEj1hsTumYxogfZ8LsE2lIsmrvQrzxe DNsAmjkffjDdnK7Hikwb1PBijPzdc+/pLDsJWa/G9io4Zr2WihJBScLGTtc/AAEph99TK7 KMYjrfPBzTMOGahPoGoXnc0LQ7Z6pMXIRNlA+PEZw+HSeBor1z9UME1MTUTi3zab2cdg5l S2ygLFXboS6erW/oqrZ0wC4vZEyPuJEZAHdMIjRfMGBWirnE5Gt0LHQJATpVfpt20aHeDl XyB37WkgHmCL0bqV/gwYjrSWwACRVv3L2mFYMT6Mo8TeRqIhBfn+EZ+AprPeNbPdQGricJ fO7wnskH9wB1YuqUpy/Yx4yIVrnrUMhSspS5ClTRyNPxGziAfpZ/o6pFI/pcdBeJrhWtVd c/IPXtIPiAGqw8VslzaK5j2qHpjEI9MJdVRoNbyWuxPSNIqfN/6kAbwCFumcLChonGTjyx H616czHqhxUWbir/Tq/u5KYre5BpB9QBmnbWNbZpMwYCQH7GlGObbgqRwGUDDtBN3ktFC5 fRYyjzm6ZZWpXmztHWaeJ2+3hyK7XjHM2TIVurBh/oB9ziDN7H8PBTB/+KCw X-ME-Proxy: Feedback-ID: i60a14417:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 11 Aug 2026 13:54:15 -0400 (EDT) From: =?utf-8?q?Jan_Sebastian_G=C3=B6tte?= Date: Tue, 11 Aug 2026 19:52:58 +0200 Subject: [PATCH v2 09/13] security/keys: implement wipe op for asymmetric keys 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260811-crash-zeroize-rework-v2-9-9561d13c2340@jaseg.de> References: <20260811-crash-zeroize-rework-v2-0-9561d13c2340@jaseg.de> In-Reply-To: <20260811-crash-zeroize-rework-v2-0-9561d13c2340@jaseg.de> To: Andrew Morton , Baoquan He , Mike Rapoport , Pasha Tatashin , Pratyush Yadav , Dave Young , Catalin Marinas , Will Deacon , David Howells , Jarkko Sakkinen , Jonathan Corbet , Shuah Khan , Paul Moore , James Morris , "Serge E. Hallyn" , Lukas Wunner , Ignat Korchagin , Herbert Xu , "David S. Miller" , Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , Trond Myklebust , Anna Schumaker , Mimi Zohar , James Bottomley , Marc Dionne , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Eric Biggers , "Theodore Y. Ts'o" , Jaegeuk Kim , Alexander Viro , Christian Brauner , Jan Kara , Alasdair Kergon , Mike Snitzer , Mikulas Patocka , Benjamin Marzinski Cc: kexec@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, keyrings@vger.kernel.org, linux-doc@vger.kernel.org, linux-security-module@vger.kernel.org, linux-crypto@vger.kernel.org, linux-nvme@lists.infradead.org, linux-nfs@vger.kernel.org, linux-integrity@vger.kernel.org, linux-afs@lists.infradead.org, netdev@vger.kernel.org, linux-fscrypt@vger.kernel.org, linux-fsdevel@vger.kernel.org, dm-devel@lists.linux.dev, =?utf-8?q?Jan_Sebastian_G=C3=B6tte?= X-Mailer: b4 0.15.2 Add wipe op to the subtype and implement it for public_key. Used by CONFIG_CRASH_WIPE_SECRETS. Signed-off-by: Jan Sebastian G=C3=B6tte --- crypto/asymmetric_keys/asymmetric_type.c | 11 +++++++++++ crypto/asymmetric_keys/public_key.c | 15 +++++++++++++++ include/keys/asymmetric-subtype.h | 5 +++++ 3 files changed, 31 insertions(+) diff --git a/crypto/asymmetric_keys/asymmetric_type.c b/crypto/asymmetric_k= eys/asymmetric_type.c index 16a7ae16593c..a0a68ebd0746 100644 --- a/crypto/asymmetric_keys/asymmetric_type.c +++ b/crypto/asymmetric_keys/asymmetric_type.c @@ -481,6 +481,16 @@ static void asymmetric_key_destroy(struct key *key) asymmetric_key_free_kids(kids); } =20 +/* wipe the key without freeing. used by CONFIG_CRASH_WIPE_SECRETS. */ +static void asymmetric_key_wipe(struct key *key) +{ + struct asymmetric_key_subtype *subtype =3D asymmetric_key_subtype(key); + + if (subtype && subtype->wipe) + subtype->wipe(key->payload.data[asym_crypto], + key->payload.data[asym_auth]); +} + static struct key_restriction *asymmetric_restriction_alloc( key_restrict_link_func_t check, struct key *key) @@ -612,6 +622,7 @@ struct key_type key_type_asymmetric =3D { .match_preparse =3D asymmetric_key_match_preparse, .match_free =3D asymmetric_key_match_free, .destroy =3D asymmetric_key_destroy, + .wipe =3D asymmetric_key_wipe, .describe =3D asymmetric_key_describe, .lookup_restriction =3D asymmetric_lookup_restriction, .asym_query =3D query_asymmetric_key, diff --git a/crypto/asymmetric_keys/public_key.c b/crypto/asymmetric_keys/p= ublic_key.c index 09a0b83d5d77..9931d56337e5 100644 --- a/crypto/asymmetric_keys/public_key.c +++ b/crypto/asymmetric_keys/public_key.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -58,6 +59,19 @@ static void public_key_destroy(void *payload0, void *pay= load3) public_key_signature_free(payload3); } =20 +/* wipe the key without freeing. used by CONFIG_CRASH_WIPE_SECRETS. */ +static void public_key_wipe(void *payload0, void *payload3) +{ + struct public_key *key =3D payload0; + + if (key) { + if (key->key) + crash_wipe_memzero(key->key, key->keylen); + if (key->params) + crash_wipe_memzero(key->params, key->paramlen); + } +} + /* * Given a public_key, and an encoding and hash_algo to be used for signing * and/or verification with that key, determine the name of the correspond= ing @@ -464,6 +478,7 @@ struct asymmetric_key_subtype public_key_subtype =3D { .name_len =3D sizeof("public_key") - 1, .describe =3D public_key_describe, .destroy =3D public_key_destroy, + .wipe =3D public_key_wipe, .query =3D software_key_query, .eds_op =3D software_key_eds_op, .verify_signature =3D public_key_verify_signature_2, diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-su= btype.h index d55171f640a0..17c74070c101 100644 --- a/include/keys/asymmetric-subtype.h +++ b/include/keys/asymmetric-subtype.h @@ -32,6 +32,11 @@ struct asymmetric_key_subtype { /* Destroy a key of this subtype */ void (*destroy)(void *payload_crypto, void *payload_auth); =20 + /* Wipe a key of this subtype without freeing it (optional). Used by + * CONFIG_CRASH_WIPE_SECRETS from the panic path. + */ + void (*wipe)(void *payload_crypto, void *payload_auth); + int (*query)(const struct kernel_pkey_params *params, struct kernel_pkey_query *info); =20 --=20 2.53.0 From nobody Tue Sep 29 06:11:02 2026 Received: from flow-b7-smtp.messagingengine.com (flow-b7-smtp.messagingengine.com [202.12.124.142]) (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 E5248363C46; Tue, 11 Aug 2026 17:54:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.142 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786470875; cv=none; b=hLXn2OqajOaPKsrktYKs6M8/gnaqgksaNABUj7JWPM8zJKLAZNhvNgOOD4NTpIsBwli0u2dJext8omeBbcr5iaelM1ryQ18Tqc3Lp52A+AKvDTfm5EglbsePAzXW3yssq9EXLP0PBDTQrtl3At6M+IgmmK+GJmKmPIoK+0PpYjg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786470875; c=relaxed/simple; bh=jsjzOPXRhYaJq2rSEgIsrW20GZctQWh42g/kY4t0bCk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PuAPVZhTGgLkI3stTkJqfOOknMdx+tNtyJqIonUUExiVDRMRjuEcze0A2PQ6c6WO6IuMzQJirKbA9mQNDDzMMC/bql2eToXSJFfYyq7i6UqpL5QYCDW/vfMa4SnhtAQhYJd+u+vTocqtBJqg00MfLzym6HcgCK0GuqW5fFtXT7k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=jaseg.de; spf=pass smtp.mailfrom=jaseg.de; dkim=pass (2048-bit key) header.d=jaseg.de header.i=@jaseg.de header.b=hU63RqXY; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=SPD0YyzA; arc=none smtp.client-ip=202.12.124.142 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=jaseg.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=jaseg.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=jaseg.de header.i=@jaseg.de header.b="hU63RqXY"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="SPD0YyzA" Received: from phl-compute-06.internal (phl-compute-06.internal [10.202.2.46]) by mailflow.stl.internal (Postfix) with ESMTP id D650813003AD; Tue, 11 Aug 2026 13:54:31 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-06.internal (MEProxy); Tue, 11 Aug 2026 13:54:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jaseg.de; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1786470871; x=1786478071; bh=xAM3Q/HBwmz4JVRL14+ds0PYCfNcU1k9FDcBLO4TEyw=; b= hU63RqXYUX7dR3ti5JXHaOPEYLzV7fuN96eKtn8RUYFDvNMfAYH+xRYP8mUkO4Vr bJAoEHBb4WkzdXQvxKfgNUa5V+iOXoY/WDKSx8UvHrDz8Nvv9CpbktshEpZwp9RC TZ6Okhcxu45Mnblk92hN99ie9UvB6eAUgbIx8f71QKwTCsMRHIjgcAa53XGzZ3OE z9D56yxEAng2g2B1NWyGEONfMAkTrinvBSTCVnlO0LER9KqdHu/GXWSRhGrxtRaW dUU1BpVP67ufQHSXd4Wfwi8Mk2FtbOwNW1uVZmZR1PfwEHthRYgnK7oZLMBWdXXa kQ+X/QJXfM/soI1Ayn6E4A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1786470871; x= 1786478071; bh=xAM3Q/HBwmz4JVRL14+ds0PYCfNcU1k9FDcBLO4TEyw=; b=S PD0YyzAO3i0iPOSceA/VwD8y9HsrVhqBs81kDs44awp1UE25tBjzrQIjJ2X3hLIp UqqsAD4FTBx4AaFBTdOq8UEOPJK2yCc8SKAHcfgUaHW7mjP5lRNMPN24kgBxQ3tD pPlnFEKMSiWn1BanUYpHRtsoRaCaGU9eEc3H8tqDCtIPzeCzRk0qdxln/phxzvYH 1o0rhSNQPxowCccqdfuoj00u3AmmTD9WCN1qNEhSNY3SZl4u8IAUgJd/cDOuVH0g 1Wryg4mVjyqjY1NgzXhFwnbdF+O6PvwO6EPpKgayWnnl9hrWSUMXBA7wCjoExGY3 szwyCbvR2yQaY36T81Leg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTFGa2nY7jnTk2Iw9v4bB0J0yF1ICaJd32/qXm98Bvn0uDADx+C3Kw/Flk6iixyPGu 72/phBwy47Kg8FJyFrGdC++k215U13L/0xFYZCpTa0z/w1NtK5dvlR08GndYlyZFvTP5gF Dlk263KcILQ417hZPN5ksrl0Nvpbmk/SlilTO3h+HTntssEQr1ld/ICv8lLA9/v6l7Z51B Ox2NlVVO9b906SW9ppu7yHcQtehxM0oDmo9WAr6dDp967nPaXzwEavIcDXzrIMh6NogcTT QJsGa7BorA3mOK9lmdQq3QUA5wm6ullbc5aPHMSxvblIqqAHtDNqCX4Ur6Kq6Hz6embcdc vYdRVb13nBNQZMEFR3UDwQKUUNDw/OfDBUUzUeypFz90S2GfV8DZBApkiCuQjPmksk3nWc wCsKwOoVmEb4wZSE3HdwY+yNaBF/rm6bOSeuJtLdyT3FY6SAATvIkCdjNh2rdNEkIi+AwH s1tX9R58abOkm3pxLdRrMBhxKEKfqdzDrrDOcup8QPmcON/iMcAk8BZWNh9KftZnP6dqXp AX30EG1VB3mNP30/5c6IurQTvxF/NyGreDSbmjc+cGCYdq2ypAFzLTKOGh2gE9QHdT/XOF 4Qyzi+DQRPh2c/zeEebScgmFshMBa9nAjTvnIyZqJn5W80oSWHo8Yc23MYpw X-ME-Proxy: Feedback-ID: i60a14417:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 11 Aug 2026 13:54:24 -0400 (EDT) From: =?utf-8?q?Jan_Sebastian_G=C3=B6tte?= Date: Tue, 11 Aug 2026 19:52:59 +0200 Subject: [PATCH v2 10/13] rxrpc: implement wipe op for rxrpc keys 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260811-crash-zeroize-rework-v2-10-9561d13c2340@jaseg.de> References: <20260811-crash-zeroize-rework-v2-0-9561d13c2340@jaseg.de> In-Reply-To: <20260811-crash-zeroize-rework-v2-0-9561d13c2340@jaseg.de> To: Andrew Morton , Baoquan He , Mike Rapoport , Pasha Tatashin , Pratyush Yadav , Dave Young , Catalin Marinas , Will Deacon , David Howells , Jarkko Sakkinen , Jonathan Corbet , Shuah Khan , Paul Moore , James Morris , "Serge E. Hallyn" , Lukas Wunner , Ignat Korchagin , Herbert Xu , "David S. Miller" , Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , Trond Myklebust , Anna Schumaker , Mimi Zohar , James Bottomley , Marc Dionne , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Eric Biggers , "Theodore Y. Ts'o" , Jaegeuk Kim , Alexander Viro , Christian Brauner , Jan Kara , Alasdair Kergon , Mike Snitzer , Mikulas Patocka , Benjamin Marzinski Cc: kexec@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, keyrings@vger.kernel.org, linux-doc@vger.kernel.org, linux-security-module@vger.kernel.org, linux-crypto@vger.kernel.org, linux-nvme@lists.infradead.org, linux-nfs@vger.kernel.org, linux-integrity@vger.kernel.org, linux-afs@lists.infradead.org, netdev@vger.kernel.org, linux-fscrypt@vger.kernel.org, linux-fsdevel@vger.kernel.org, dm-devel@lists.linux.dev, =?utf-8?q?Jan_Sebastian_G=C3=B6tte?= X-Mailer: b4 0.15.2 Wipe session keys and tickets of client key tokens, and add a server key wipe op implemented by rxkad and rxgk. Used by CONFIG_CRASH_WIPE_SECRETS. Signed-off-by: Jan Sebastian G=C3=B6tte --- net/rxrpc/ar-internal.h | 5 +++++ net/rxrpc/key.c | 34 ++++++++++++++++++++++++++++++++++ net/rxrpc/rxgk.c | 11 +++++++++++ net/rxrpc/rxkad.c | 14 ++++++++++++++ net/rxrpc/server_key.c | 11 +++++++++++ 5 files changed, 75 insertions(+) diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h index 865f05fe37ab..6466eb5a9929 100644 --- a/net/rxrpc/ar-internal.h +++ b/net/rxrpc/ar-internal.h @@ -282,6 +282,11 @@ struct rxrpc_security { /* Destroy the payload of a server key */ void (*destroy_server_key)(struct key *); =20 + /* Wipe the payload of a server key without freeing it. Used by + * CONFIG_CRASH_WIPE_SECRETS from the panic path. + */ + void (*wipe_server_key)(struct key *); + /* Describe a server key */ void (*describe_server_key)(const struct key *, struct seq_file *); =20 diff --git a/net/rxrpc/key.c b/net/rxrpc/key.c index a0aa78d89289..e612b7a8df13 100644 --- a/net/rxrpc/key.c +++ b/net/rxrpc/key.c @@ -11,6 +11,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt =20 #include +#include #include #include #include @@ -26,6 +27,7 @@ static int rxrpc_preparse(struct key_preparsed_payload *); static void rxrpc_free_preparse(struct key_preparsed_payload *); static void rxrpc_destroy(struct key *); +static void rxrpc_wipe(struct key *); static void rxrpc_describe(const struct key *, struct seq_file *); static long rxrpc_read(const struct key *, char *, size_t); =20 @@ -40,6 +42,7 @@ struct key_type key_type_rxrpc =3D { .free_preparse =3D rxrpc_free_preparse, .instantiate =3D generic_key_instantiate, .destroy =3D rxrpc_destroy, + .wipe =3D rxrpc_wipe, .describe =3D rxrpc_describe, .read =3D rxrpc_read, }; @@ -570,6 +573,31 @@ static void rxrpc_free_token_list(struct rxrpc_key_tok= en *token) } } =20 +static void rxrpc_wipe_token_list(struct rxrpc_key_token *token) +{ + struct rxrpc_key_token *next; + + for (; token; token =3D next) { + next =3D token->next; + switch (token->security_index) { + case RXRPC_SECURITY_RXKAD: + crash_wipe_memzero(token->kad->session_key, + sizeof(token->kad->session_key)); + crash_wipe_memzero(token->kad->ticket, + token->kad->ticket_len); + break; + case RXRPC_SECURITY_YFS_RXGK: + crash_wipe_memzero(token->rxgk->key.data, + token->rxgk->key.len); + crash_wipe_memzero(token->rxgk->ticket.data, + token->rxgk->ticket.len); + break; + default: + break; + } + } +} + /* * Clean up preparse data. */ @@ -586,6 +614,12 @@ static void rxrpc_destroy(struct key *key) rxrpc_free_token_list(key->payload.data[0]); } =20 +/* wipe the key without freeing. used by CONFIG_CRASH_WIPE_SECRETS. */ +static void rxrpc_wipe(struct key *key) +{ + rxrpc_wipe_token_list(key->payload.data[0]); +} + /* * describe the rxrpc key */ diff --git a/net/rxrpc/rxgk.c b/net/rxrpc/rxgk.c index 77a67ace1d24..51c428fb3a60 100644 --- a/net/rxrpc/rxgk.c +++ b/net/rxrpc/rxgk.c @@ -8,6 +8,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt =20 #include +#include #include #include #include @@ -68,6 +69,15 @@ static void rxgk_destroy_server_key(struct key *key) rxgk_free_server_key(&key->payload); } =20 +/* wipe the key without freeing. used by CONFIG_CRASH_WIPE_SECRETS. */ +static void rxgk_wipe_server_key(struct key *key) +{ + struct krb5_buffer *server_key =3D (void *)&key->payload.data[2]; + + if (server_key->data) + crash_wipe_memzero(server_key->data, server_key->len); +} + static void rxgk_describe_server_key(const struct key *key, struct seq_fil= e *m) { const struct krb5_enctype *krb5 =3D key->payload.data[0]; @@ -1338,6 +1348,7 @@ const struct rxrpc_security rxgk_yfs =3D { .preparse_server_key =3D rxgk_preparse_server_key, .free_preparse_server_key =3D rxgk_free_preparse_server_key, .destroy_server_key =3D rxgk_destroy_server_key, + .wipe_server_key =3D rxgk_wipe_server_key, .describe_server_key =3D rxgk_describe_server_key, .init_connection_security =3D rxgk_init_connection_security, .alloc_txbuf =3D rxgk_alloc_txbuf, diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c index ca9f0e82cb9a..054ab67aca32 100644 --- a/net/rxrpc/rxkad.c +++ b/net/rxrpc/rxkad.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -91,6 +92,18 @@ static void rxkad_destroy_server_key(struct key *key) key->payload.data[0] =3D NULL; } =20 +/* wipe the key without freeing. used by CONFIG_CRASH_WIPE_SECRETS. */ +static void rxkad_wipe_server_key(struct key *key) +{ + struct des_ctx *des_key =3D key->payload.data[0]; + + if (des_key) + crash_wipe_memzero(des_key, sizeof(*des_key)); + + /* the raw 8-byte key is kept inline in the payload union */ + crash_wipe_memzero(&key->payload.data[2], 8); +} + /* * initialise connection security */ @@ -1127,6 +1140,7 @@ const struct rxrpc_security rxkad =3D { .preparse_server_key =3D rxkad_preparse_server_key, .free_preparse_server_key =3D rxkad_free_preparse_server_key, .destroy_server_key =3D rxkad_destroy_server_key, + .wipe_server_key =3D rxkad_wipe_server_key, .init_connection_security =3D rxkad_init_connection_security, .alloc_txbuf =3D rxkad_alloc_txbuf, .secure_packet =3D rxkad_secure_packet, diff --git a/net/rxrpc/server_key.c b/net/rxrpc/server_key.c index 3efe104b1930..a8e736d58793 100644 --- a/net/rxrpc/server_key.c +++ b/net/rxrpc/server_key.c @@ -26,6 +26,7 @@ static int rxrpc_vet_description_s(const char *); static int rxrpc_preparse_s(struct key_preparsed_payload *); static void rxrpc_free_preparse_s(struct key_preparsed_payload *); static void rxrpc_destroy_s(struct key *); +static void rxrpc_wipe_s(struct key *); static void rxrpc_describe_s(const struct key *, struct seq_file *); =20 /* @@ -40,6 +41,7 @@ struct key_type key_type_rxrpc_s =3D { .free_preparse =3D rxrpc_free_preparse_s, .instantiate =3D generic_key_instantiate, .destroy =3D rxrpc_destroy_s, + .wipe =3D rxrpc_wipe_s, .describe =3D rxrpc_describe_s, }; =20 @@ -105,6 +107,15 @@ static void rxrpc_destroy_s(struct key *key) sec->destroy_server_key(key); } =20 +/* wipe the key without freeing. used by CONFIG_CRASH_WIPE_SECRETS. */ +static void rxrpc_wipe_s(struct key *key) +{ + const struct rxrpc_security *sec =3D key->payload.data[1]; + + if (sec && sec->wipe_server_key) + sec->wipe_server_key(key); +} + static void rxrpc_describe_s(const struct key *key, struct seq_file *m) { const struct rxrpc_security *sec =3D key->payload.data[1]; --=20 2.53.0 From nobody Tue Sep 29 06:11:02 2026 Received: from flow-b7-smtp.messagingengine.com (flow-b7-smtp.messagingengine.com [202.12.124.142]) (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 583C035C6B5; Tue, 11 Aug 2026 17:54:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.142 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786470883; cv=none; b=AQ+0JbmwtpEbGOj2OWTlKjHwk3ELz/OPZBDWyQB/3Q3J7klbWNN6jeYgiQPBf4NscH1MIvBh98vqjSNHcLVQw3h9oF4shUKAxL5VtNLx8O755RBB0B5ZT6xDQGOTOWRzdsfbpZxBkgZFnQzVF44U4DghOFJ5RHhFV8AGLCFyb/s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786470883; c=relaxed/simple; bh=C8uzopovspx+jzCgMd++lGEt0kWPN90/8kmHq0MlVWw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gq4UuupX7OnQ6nFYgZGSosWBdoE4myC6cODVEaI229f6uuq4UO32zhCDJ0R7oild6ekixZUdZDMRZcjyIAYXeHU7kZ0WOkfID3HStHFItzjQX5hpBIv8YdV0DjyT2nbkfjseYPhZVf6fDsPlFg3jJYBt2ppJKRBsiq2OLtk5HMg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=jaseg.de; spf=pass smtp.mailfrom=jaseg.de; dkim=pass (2048-bit key) header.d=jaseg.de header.i=@jaseg.de header.b=JwupcXb6; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=X1drl2a8; arc=none smtp.client-ip=202.12.124.142 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=jaseg.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=jaseg.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=jaseg.de header.i=@jaseg.de header.b="JwupcXb6"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="X1drl2a8" Received: from phl-compute-06.internal (phl-compute-06.internal [10.202.2.46]) by mailflow.stl.internal (Postfix) with ESMTP id 27DAA13003B1; Tue, 11 Aug 2026 13:54:40 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-06.internal (MEProxy); Tue, 11 Aug 2026 13:54:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jaseg.de; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1786470880; x=1786478080; bh=qRdj1vbz8p2iExAmHiccg0/3QeT/qpwETqEzoy9C6Gk=; b= JwupcXb6vzWjnE7B6o+zL2gfG8BHxyuMrxqZ62dPDH1rPf9NqIyWAOdDMXPMJ7qc /RpVi/cf9Tx8gTrJ+7e59DMK1p9rrWA47VdDD0S5wkuEvM4Yh9sl12Pqoi5lY27+ vR//UyiTXobTrATjv1eJUKqK8rv5CmyWHMOTcNY5Kx9AvFxvjFWM1stEsB/jA73N 05DfmzbDI70gFHOCvdJZD72aAXGj/cMwYLSuqMq+je5ynyLzdtc4Q5UZlzwkkQUm z7iqkMQsLvWGq4KBFOHDTr8IIZIpWEHgX6l8Ngk7dJnFXIT16yx3h3Dun3DHNXoO Z7PZXrEr+y8/ZAr1tZynsA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1786470880; x= 1786478080; bh=qRdj1vbz8p2iExAmHiccg0/3QeT/qpwETqEzoy9C6Gk=; b=X 1drl2a8xrd4tktJc08EFNz+Yca5f7KtFC6GwPc2bc+Lv5Wzmg38PqCBQl84MnNuo yvA+LGUypfTn8JR8yEFt7GGriz0XrlSCMpRn5jblIi42eemOQ2oR6GvcOtE/B7dt Qwn1vALD2p6dLbAwcuF3eqoqwP/U8l+lYJlYmjp9UG4K12TiptH0WkfTRlJgHqiU KSed7ev1ENdboNP3czU79Db0QE+aPI9QsohNfATxcdRrzJ+ct3MGgGV80WFKyoUK it2GgGSa32FYm+gd86u2RNNxKbo/n48hyUPTVqPOKe6kjBQE25Wp3AigNeeRlSJB mkqSOR9aKdZhqEFlwXLxg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTFCz0Ji0ZFixqgSD/OqUUF4WVuqQyEz0ee6kaomlH2rCyU90DaPXp9i3px2Lq+46e zZlpuku5qPti3Gv38qfq9xHPmHStFaNGWUmW+rS5ek9JmDGNNRsgxagXJtF9Le+4XfImj6 mvMRPguD+8olj0InbNxmoLdJWN0NXIY/BV8bJGOsCN5DcFzTXrQNXDLJ5EPLOl/eJIbITE fuecBbgsXxiwgqmdOe8RK2G3tEPcBtYf6l6zHVsw1qVGswhc+c+1u5vXrkKBY9NmW4VKq8 bvVbENKoHBjwphNqlCAPHx41cLq72VIcTLcaeIhNcr+RTNY3yub1H3GKyFpQQN9DEaiInz G8kwhPzX4fKDKFMJHiDdv476bp0EU4pCQHsrnAjj4PK9JHfApNpmBNBOd9/d2BE2ctMGwe QfR6GBtnKVoAg6eRj7FywHBVVRfXjhUSDkbMlT+8u84dCMPccPUkd9ZEmGHvVX/v1wZ9Zh RipOHWMdXpVMKkC1X+4O/fxjbhxCIsI+e6+caIbc7yG1lgcjZOCA6bDY975/SJMasWJr/B h5v0sK4TQfJ/XV25PeuAXylmTVnWaZxZhJ6BKDSTc2DV7dRtbFyS38lagxkb6hL1jbQvcJ EO2BPT+v/huL8aZtyS8/X9QTZRBrSife8dNDrDCwQaamKL1jBZqLUpKNHn9Q X-ME-Proxy: Feedback-ID: i60a14417:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 11 Aug 2026 13:54:33 -0400 (EDT) From: =?utf-8?q?Jan_Sebastian_G=C3=B6tte?= Date: Tue, 11 Aug 2026 19:53:00 +0200 Subject: [PATCH v2 11/13] fscrypt: wipe master keys before kdump 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260811-crash-zeroize-rework-v2-11-9561d13c2340@jaseg.de> References: <20260811-crash-zeroize-rework-v2-0-9561d13c2340@jaseg.de> In-Reply-To: <20260811-crash-zeroize-rework-v2-0-9561d13c2340@jaseg.de> To: Andrew Morton , Baoquan He , Mike Rapoport , Pasha Tatashin , Pratyush Yadav , Dave Young , Catalin Marinas , Will Deacon , David Howells , Jarkko Sakkinen , Jonathan Corbet , Shuah Khan , Paul Moore , James Morris , "Serge E. Hallyn" , Lukas Wunner , Ignat Korchagin , Herbert Xu , "David S. Miller" , Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , Trond Myklebust , Anna Schumaker , Mimi Zohar , James Bottomley , Marc Dionne , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Eric Biggers , "Theodore Y. Ts'o" , Jaegeuk Kim , Alexander Viro , Christian Brauner , Jan Kara , Alasdair Kergon , Mike Snitzer , Mikulas Patocka , Benjamin Marzinski Cc: kexec@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, keyrings@vger.kernel.org, linux-doc@vger.kernel.org, linux-security-module@vger.kernel.org, linux-crypto@vger.kernel.org, linux-nvme@lists.infradead.org, linux-nfs@vger.kernel.org, linux-integrity@vger.kernel.org, linux-afs@lists.infradead.org, netdev@vger.kernel.org, linux-fscrypt@vger.kernel.org, linux-fsdevel@vger.kernel.org, dm-devel@lists.linux.dev, =?utf-8?q?Jan_Sebastian_G=C3=B6tte?= X-Mailer: b4 0.15.2 fscrypt master keys hang off the superblock rather than a keyring of their own key type, so register a separate notifier that walks the live superblocks via the new super_blocks_crash_wipe() helper. Signed-off-by: Jan Sebastian G=C3=B6tte --- fs/crypto/block.c | 10 +++++++ fs/crypto/fscrypt_private.h | 15 ++++++++++ fs/crypto/keyring.c | 68 +++++++++++++++++++++++++++++++++++++++++= +++- fs/crypto/keysetup_v1.c | 15 ++++++++++ fs/super.c | 29 +++++++++++++++++++ include/linux/fs.h | 4 +++ 6 files changed, 140 insertions(+), 1 deletion(-) diff --git a/fs/crypto/block.c b/fs/crypto/block.c index 5193f8ba3ee0..a2fa1469b3c4 100644 --- a/fs/crypto/block.c +++ b/fs/crypto/block.c @@ -15,6 +15,7 @@ =20 #include #include +#include #include #include #include @@ -144,6 +145,15 @@ int fscrypt_prepare_inline_crypt_key(struct fscrypt_pr= epared_key *prep_key, return err; } =20 +#ifdef CONFIG_CRASH_WIPE_SECRETS +void fscrypt_crash_wipe_inline_crypt_key(struct fscrypt_prepared_key *prep= _key) +{ + if (prep_key->blk_key) + crash_wipe_memzero(prep_key->blk_key->bytes, + sizeof(prep_key->blk_key->bytes)); +} +#endif /* CONFIG_CRASH_WIPE_SECRETS */ + void fscrypt_destroy_inline_crypt_key(struct super_block *sb, struct fscrypt_prepared_key *prep_key) { diff --git a/fs/crypto/fscrypt_private.h b/fs/crypto/fscrypt_private.h index 74329e0953d1..95cb50e5cbcd 100644 --- a/fs/crypto/fscrypt_private.h +++ b/fs/crypto/fscrypt_private.h @@ -413,6 +413,10 @@ int fscrypt_prepare_inline_crypt_key(struct fscrypt_pr= epared_key *prep_key, void fscrypt_destroy_inline_crypt_key(struct super_block *sb, struct fscrypt_prepared_key *prep_key); =20 +#ifdef CONFIG_CRASH_WIPE_SECRETS /* && CONFIG_FS_ENCRYPTION_INLINE_CRYPT */ +void fscrypt_crash_wipe_inline_crypt_key(struct fscrypt_prepared_key *prep= _key); +#endif + int fscrypt_derive_sw_secret(struct super_block *sb, const u8 *wrapped_key, size_t wrapped_key_size, u8 sw_secret[BLK_CRYPTO_SW_SECRET_SIZE]); @@ -454,6 +458,13 @@ fscrypt_destroy_inline_crypt_key(struct super_block *s= b, { } =20 +#ifdef CONFIG_CRASH_WIPE_SECRETS /* && !CONFIG_FS_ENCRYPTION_INLINE_CRYPT = */ +static inline void +fscrypt_crash_wipe_inline_crypt_key(struct fscrypt_prepared_key *prep_key) +{ +} +#endif + static inline int fscrypt_derive_sw_secret(struct super_block *sb, const u8 *wrapped_key, size_t wrapped_key_size, @@ -760,6 +771,10 @@ static inline int fscrypt_require_key(struct inode *in= ode) =20 void fscrypt_put_direct_key(struct fscrypt_direct_key *dk); =20 +#ifdef CONFIG_CRASH_WIPE_SECRETS +void fscrypt_crash_wipe_direct_keys(void); +#endif + int fscrypt_setup_v1_file_key(struct fscrypt_inode_info *ci, const u8 *raw_master_key); =20 diff --git a/fs/crypto/keyring.c b/fs/crypto/keyring.c index 76e28d1e0064..5ac302146eb2 100644 --- a/fs/crypto/keyring.c +++ b/fs/crypto/keyring.c @@ -19,6 +19,7 @@ */ =20 #include +#include #include #include #include @@ -239,8 +240,9 @@ void fscrypt_destroy_keyring(struct super_block *sb) fscrypt_initiate_key_removal(sb, mk); } } + /* Stop panic-time walkers from finding @keyring before it is freed. */ + smp_store_release(&sb->s_master_keys, NULL); kfree_sensitive(keyring); - sb->s_master_keys =3D NULL; } =20 static struct hlist_head * @@ -640,6 +642,13 @@ static void fscrypt_provisioning_key_destroy(struct ke= y *key) kfree_sensitive(key->payload.data[0]); } =20 +/* wipe the key without freeing. used by CONFIG_CRASH_WIPE_SECRETS. */ +static void fscrypt_provisioning_key_wipe(struct key *key) +{ + if (key->payload.data[0]) + crash_wipe_memzero(key->payload.data[0], key->datalen); +} + static struct key_type key_type_fscrypt_provisioning =3D { .name =3D "fscrypt-provisioning", .preparse =3D fscrypt_provisioning_key_preparse, @@ -647,6 +656,7 @@ static struct key_type key_type_fscrypt_provisioning = =3D { .instantiate =3D generic_key_instantiate, .describe =3D fscrypt_provisioning_key_describe, .destroy =3D fscrypt_provisioning_key_destroy, + .wipe =3D fscrypt_provisioning_key_wipe, }; =20 /* @@ -1220,6 +1230,58 @@ int fscrypt_ioctl_get_key_status(struct file *filp, = void __user *uarg) } EXPORT_SYMBOL_GPL(fscrypt_ioctl_get_key_status); =20 +#ifdef CONFIG_CRASH_WIPE_SECRETS +/* + * Wipe the master keys of one superblock. The master keys don't live on a + * keyring of their own key_type, so the keyrings core can't reach them. + */ +static void fscrypt_crash_wipe_sb(struct super_block *sb) +{ + struct fscrypt_keyring *keyring =3D sb->s_master_keys; + size_t i; + + if (!keyring) + return; + + for (i =3D 0; i < ARRAY_SIZE(keyring->key_hashtable); i++) { + struct fscrypt_master_key *mk; + + hlist_for_each_entry(mk, &keyring->key_hashtable[i], mk_node) { + struct fscrypt_inode_info *ci; + struct fscrypt_mode_key *node; + + crash_wipe_memzero(&mk->mk_secret, + sizeof(mk->mk_secret)); + + list_for_each_entry(node, &mk->mk_mode_keys, link) + fscrypt_crash_wipe_inline_crypt_key(&node->key); + + list_for_each_entry(ci, &mk->mk_decrypted_inodes, + ci_master_key_link) + fscrypt_crash_wipe_inline_crypt_key(&ci->ci_enc_key); + } + } +} + +/* Called far into vpanic from crash_core.c with other CPUs stopped and + * preemption disabled + */ +static int fscrypt_crash_wipe(struct notifier_block *nb, unsigned long act= ion, + void *data) +{ + if (!super_blocks_crash_wipe(fscrypt_crash_wipe_sb)) + pr_crit("crash_wipe_secrets: can't acquire sb_lock. skipping fscrypt key= s.\n"); + + fscrypt_crash_wipe_direct_keys(); + + return NOTIFY_DONE; +} + +static struct notifier_block fscrypt_crash_wipe_nb =3D { + .notifier_call =3D fscrypt_crash_wipe +}; +#endif /* CONFIG_CRASH_WIPE_SECRETS */ + void __init fscrypt_init_keyring(void) { int err; @@ -1235,4 +1297,8 @@ void __init fscrypt_init_keyring(void) if (err) panic("failed to register fscrypt-provisioning key type (%d)", err); + +#ifdef CONFIG_CRASH_WIPE_SECRETS + crash_wipe_secrets_register(&fscrypt_crash_wipe_nb); +#endif } diff --git a/fs/crypto/keysetup_v1.c b/fs/crypto/keysetup_v1.c index 87fe13ccb253..08dd0a682a8f 100644 --- a/fs/crypto/keysetup_v1.c +++ b/fs/crypto/keysetup_v1.c @@ -23,6 +23,7 @@ #include #include #include +#include #include =20 #include "fscrypt_private.h" @@ -118,6 +119,20 @@ void fscrypt_put_direct_key(struct fscrypt_direct_key = *dk) free_direct_key(dk); } =20 +#ifdef CONFIG_CRASH_WIPE_SECRETS +void fscrypt_crash_wipe_direct_keys(void) +{ + struct fscrypt_direct_key *dk; + unsigned int i; + + /* No locking: all other CPUs are stopped, so nothing can race with us. */ + hash_for_each(fscrypt_direct_keys, i, dk, dk_node) { + crash_wipe_memzero(dk->dk_raw, sizeof(dk->dk_raw)); + fscrypt_crash_wipe_inline_crypt_key(&dk->dk_key); + } +} +#endif /* CONFIG_CRASH_WIPE_SECRETS */ + /* * Find/insert the given key into the fscrypt_direct_keys table. If found= , it * is returned with elevated refcount, and 'to_insert' is freed if non-NUL= L. If diff --git a/fs/super.c b/fs/super.c index 5feecf5d9038..cd51e9cfe93b 100644 --- a/fs/super.c +++ b/fs/super.c @@ -2463,3 +2463,32 @@ int sb_init_dio_done_wq(struct super_block *sb) return 0; } EXPORT_SYMBOL_GPL(sb_init_dio_done_wq); + +#ifdef CONFIG_CRASH_WIPE_SECRETS +/** + * super_blocks_crash_wipe - run @wipe against every live superblock + * @wipe: callback to invoke for each superblock + * + * Called from the panic path with other CPUs stopped and preemption disab= led. + * The callback must not sleep, allocate, free or take locks. + * + * Returns false without doing anything if @sb_lock could not be acquired,= in + * which case the list may be inconsistent and walking it is unsafe. + */ +bool super_blocks_crash_wipe(void (*wipe)(struct super_block *sb)) +{ + struct super_block *sb; + + /* There is no point in waiting for a lock that will never be released + * at this stage. + */ + if (!spin_trylock(&sb_lock)) + return false; + + list_for_each_entry(sb, &super_blocks, s_list) + wipe(sb); + + spin_unlock(&sb_lock); + return true; +} +#endif diff --git a/include/linux/fs.h b/include/linux/fs.h index 072d8cd09a0b..7832a77908d2 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2378,6 +2378,10 @@ extern __printf(2, 3) int super_setup_bdi_name(struct super_block *sb, char *fmt, ...); extern int super_setup_bdi(struct super_block *sb); =20 +#ifdef CONFIG_CRASH_WIPE_SECRETS +bool super_blocks_crash_wipe(void (*wipe)(struct super_block *sb)); +#endif + static inline void super_set_uuid(struct super_block *sb, const u8 *uuid, = unsigned len) { if (WARN_ON(len > sizeof(sb->s_uuid))) --=20 2.53.0 From nobody Tue Sep 29 06:11:02 2026 Received: from flow-b7-smtp.messagingengine.com (flow-b7-smtp.messagingengine.com [202.12.124.142]) (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 AC9603793CE; Tue, 11 Aug 2026 17:54:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.142 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786470892; cv=none; b=N8mV0uEDc7NWJBZaD71n8hWohzri201q/G/MlDXlOJSP5HbUiuE2Nd240b1plJqMzr6dpGdvlO3AhsUu7kN5siU+tCZ8VAJTd0jlTFIinS1UdIutcBs8whbBvwtjnDeUEi+5X/+/tPcB3qcD7Q/kjDLcJXrbC0oKiHOtCJXWtNk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786470892; c=relaxed/simple; bh=TIZ+okVHrCyUtsr8WbeYKknQaRJKbYF43YJPJkdZtTM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hMrevhqdAYlzhGr857bJDmY0E2zf3+1vT6vMrP/BigEyPVBLCyTP7QtC5Fgkrg8o+PfLZmvWSyroXc1ROrsWkcr4GxQVVRG7eMweL8A66euqS0FMsA1fKDG0qs19/kPHAg4JgYQiMiGdqT2/7Hj4uga0dIoaWj3sFmDHFGPRuXg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=jaseg.de; spf=pass smtp.mailfrom=jaseg.de; dkim=pass (2048-bit key) header.d=jaseg.de header.i=@jaseg.de header.b=bYeDYVhg; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=GI03wCRG; arc=none smtp.client-ip=202.12.124.142 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=jaseg.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=jaseg.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=jaseg.de header.i=@jaseg.de header.b="bYeDYVhg"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="GI03wCRG" Received: from phl-compute-12.internal (phl-compute-12.internal [10.202.2.52]) by mailflow.stl.internal (Postfix) with ESMTP id A131F130038D; Tue, 11 Aug 2026 13:54:48 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-12.internal (MEProxy); Tue, 11 Aug 2026 13:54:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jaseg.de; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1786470888; x=1786478088; bh=jFYKhNM35RpDRZh/43hulCmfEJyGilMf3A0rl4qWOVM=; b= bYeDYVhgtPE017gK8myw81IgEJUTe3W99CDML8CpqHp7fU6iAnzN86+mOx7pU8Z/ Xz25faE9dCrff2JgEY85A8il0GldVKWSWgOy4hiTb9CwSrAu1UA8ybprakhSKiLG oIITSW+Nrjy2Sq/XXAbDUY1ZyI6YiBMXr9Yk2a9seCS5IMaaJ7N61dHXvoUtlz8j 3p4rf5eJtJC2ubYbpyEbWFEarW2qhkEHelWMe2AjTl6Xz3oyvWcBgxSp9m5mz04M PiZPAArXKeBHB+U1EAtjh1PXTUxgcDuNYNeEWLP/jcovinleNGmuNB3spTKuDtdC x6aphUNJ+Y8113Z0XSyupg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1786470888; x= 1786478088; bh=jFYKhNM35RpDRZh/43hulCmfEJyGilMf3A0rl4qWOVM=; b=G I03wCRG7sUINfnlJx1HoFrWP/Blr/bsvRmMMtdVhY+z8ikl856vyYKiKSfxJk7TJ +Du+2B8fdmMwoashdCtrBOjKrt7zkIVhzPJwU97BFtkm9yeBnyEW9wLTOSe9RXan IF1LrphRdo4Uk3avywoso/2ZA+IcNlIwlF46V0biEWeEsORBdaR7O6+Kzp+FqjId by1N2tuNRk4YQ/cm2z2zowmmSbKc+xqSKdOTtViGytJI12Acn61UHhiLYE0YFZ+l o+fCUXptxoEXuPVdfPm34ZKvgqE/lbkjRsqBea+Ym0d7dKpsuXfQrUtlDEY+S3wi JfrtqmZ9utgGiPwezfe5A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTFP5tmiXRyqpvhao8uWnDWsuVG58E3QcpY8nNF+TN3d4+2z3XaWQJ1+2uEKcUq9Jg +xH/KDfBOi31TfxVE5vy2aZ5W5Eono+bvv7mBiiNvVW/C9tjIvrxCLzv7Tz6GJOSvAG1cd t11+FzpQNbill+yp1ZC7JKPVzEaxQ4CH2HewKTU1gYEn0mNFldMXWgoBvZ/c5OhwLZogLW sZeOMCUfQY9vOvCjGHA0ivpYn+5HBy3sK6RswFREIaUm9jlhbU7pV5ZXGDLpJAMlUAJ/Lo y1vjaaTNNEiBF07QqH8YbZg0fsVTsE2lSAku2XiqZRlB3GAWdGnDFC/NxQNHJZjZwh0bMi 3ropPtGEXwJYJAu285XzhREMMjarFs0U0qMD7zjrDHqt6fJ8xSO2sk61ZxfqGLG5LEahc7 vwAk5zUO0ZCCm9fM+L422IUoCWwqFOjz+0aNT0kFyZ0Q1Ln5ckpifI68KSJbkT7he4JGsz gnYBtMLYaheT0cogeUK3622EJ3Z+e4Ukbofzl4+gPfWHBkTRbmKjtE6P4Ot7qNxDbkBV9f 6r8fT1r6KlUCPnqErm914p+GFvLXJ9n92U6RxanpRYnFHvVP6n6k2ggCnlgrXR6Uub55UK uDCtbwOviWOwgtdaHKlTAzhxVcXj+aqh2aNk2mWVG/8eK7aDZGpVw69gy5wQ X-ME-Proxy: Feedback-ID: i60a14417:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 11 Aug 2026 13:54:41 -0400 (EDT) From: =?utf-8?q?Jan_Sebastian_G=C3=B6tte?= Date: Tue, 11 Aug 2026 19:53:01 +0200 Subject: [PATCH v2 12/13] crypto: api - wipe tfm contexts before kdump 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260811-crash-zeroize-rework-v2-12-9561d13c2340@jaseg.de> References: <20260811-crash-zeroize-rework-v2-0-9561d13c2340@jaseg.de> In-Reply-To: <20260811-crash-zeroize-rework-v2-0-9561d13c2340@jaseg.de> To: Andrew Morton , Baoquan He , Mike Rapoport , Pasha Tatashin , Pratyush Yadav , Dave Young , Catalin Marinas , Will Deacon , David Howells , Jarkko Sakkinen , Jonathan Corbet , Shuah Khan , Paul Moore , James Morris , "Serge E. Hallyn" , Lukas Wunner , Ignat Korchagin , Herbert Xu , "David S. Miller" , Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , Trond Myklebust , Anna Schumaker , Mimi Zohar , James Bottomley , Marc Dionne , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Eric Biggers , "Theodore Y. Ts'o" , Jaegeuk Kim , Alexander Viro , Christian Brauner , Jan Kara , Alasdair Kergon , Mike Snitzer , Mikulas Patocka , Benjamin Marzinski Cc: kexec@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, keyrings@vger.kernel.org, linux-doc@vger.kernel.org, linux-security-module@vger.kernel.org, linux-crypto@vger.kernel.org, linux-nvme@lists.infradead.org, linux-nfs@vger.kernel.org, linux-integrity@vger.kernel.org, linux-afs@lists.infradead.org, netdev@vger.kernel.org, linux-fscrypt@vger.kernel.org, linux-fsdevel@vger.kernel.org, dm-devel@lists.linux.dev, =?utf-8?q?Jan_Sebastian_G=C3=B6tte?= X-Mailer: b4 0.15.2 tfm structs contain key material like expanded key schedules. Under CONFIG_CRASH_WIPE_SECRETS, wipe all tfms before kdump to prevent leakage. Copies outside the tfm context, e.g. on the stack or in hardware key registers, are not covered. Also change two kfree() calls to kfree_sensitive() for good measure. Signed-off-by: Jan Sebastian G=C3=B6tte --- crypto/api.c | 78 ++++++++++++++++++++++++++++++++++++++++++++--= ---- include/linux/crypto.h | 11 +++++++ 2 files changed, 81 insertions(+), 8 deletions(-) diff --git a/crypto/api.c b/crypto/api.c index 24227582cfcf..f919f52e8b5f 100644 --- a/crypto/api.c +++ b/crypto/api.c @@ -10,13 +10,16 @@ * and Nettle, by Niels M=C3=B6ller. */ =20 +#include #include #include #include #include #include #include +#include #include +#include #include #include #include @@ -397,6 +400,60 @@ static unsigned int crypto_ctxsize(struct crypto_alg *= alg, u32 type, u32 mask) return len; } =20 +#ifdef CONFIG_CRASH_WIPE_SECRETS +/* + * tfm allocations are tracked on crypto_tfm_list so that they can be wiped + * before kdump. + */ +static HLIST_HEAD(crypto_tfm_list); +static DEFINE_SPINLOCK(crypto_tfm_list_lock); + +static int crypto_crash_wipe(struct notifier_block *nb, unsigned long acti= on, + void *data) +{ + struct crypto_tfm *tfm; + + rcu_read_lock(); + hlist_for_each_entry_rcu(tfm, &crypto_tfm_list, wipe_list) + crash_wipe_memzero(tfm->__crt_ctx, tfm->wipe_size); + rcu_read_unlock(); + + /* off to kexec()! */ + return NOTIFY_DONE; +} + +static struct notifier_block crypto_wipe_nb =3D { + .notifier_call =3D crypto_crash_wipe +}; + +static int __init crypto_tfm_track_init(void) +{ + crash_wipe_secrets_register(&crypto_wipe_nb); + return 0; +} +core_initcall(crypto_tfm_track_init); + +/* @size is the size of __crt_ctx */ +static void crypto_track_tfm(struct crypto_tfm *tfm, size_t size) +{ + tfm->wipe_size =3D size; + + spin_lock(&crypto_tfm_list_lock); + hlist_add_head_rcu(&tfm->wipe_list, &crypto_tfm_list); + spin_unlock(&crypto_tfm_list_lock); +} + +static void crypto_untrack_tfm(struct crypto_tfm *tfm) +{ + spin_lock(&crypto_tfm_list_lock); + hlist_del_rcu(&tfm->wipe_list); + spin_unlock(&crypto_tfm_list_lock); +} +#else +static void crypto_track_tfm(struct crypto_tfm *tfm, size_t size) { } +static void crypto_untrack_tfm(struct crypto_tfm *tfm) { } +#endif /* CONFIG_CRASH_WIPE_SECRETS */ + void crypto_shoot_alg(struct crypto_alg *alg) { down_write(&crypto_alg_sem); @@ -409,15 +466,16 @@ struct crypto_tfm *__crypto_alloc_tfm(struct crypto_a= lg *alg, u32 type, u32 mask) { struct crypto_tfm *tfm; - unsigned int tfm_size; + unsigned int ctx_size; int err =3D -ENOMEM; =20 - tfm_size =3D sizeof(*tfm) + crypto_ctxsize(alg, type, mask); - tfm =3D kzalloc(tfm_size, GFP_KERNEL); + ctx_size =3D crypto_ctxsize(alg, type, mask); + tfm =3D kzalloc(sizeof(*tfm) + ctx_size, GFP_KERNEL); if (tfm =3D=3D NULL) goto out_err; =20 tfm->__crt_alg =3D alg; + crypto_track_tfm(tfm, ctx_size); =20 if (!tfm->exit && alg->cra_init && (err =3D alg->cra_init(tfm))) goto cra_init_failed; @@ -428,7 +486,8 @@ struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg= *alg, u32 type, crypto_exit_ops(tfm); if (err =3D=3D -EAGAIN) crypto_shoot_alg(alg); - kfree(tfm); + crypto_untrack_tfm(tfm); + kfree_sensitive(tfm); out_err: tfm =3D ERR_PTR(err); out: @@ -497,12 +556,12 @@ void *crypto_create_tfm_node(struct crypto_alg *alg, int node) { struct crypto_tfm *tfm; - size_t size; char *mem; int err; + size_t ctx_size =3D frontend->extsize(alg); =20 - size =3D frontend->tfmsize + sizeof(*tfm) + frontend->extsize(alg); - mem =3D kzalloc_node(size, GFP_KERNEL, node); + mem =3D kzalloc_node(frontend->tfmsize + sizeof(*tfm) + ctx_size, + GFP_KERNEL, node); if (!mem) return ERR_PTR(-ENOMEM); =20 @@ -510,6 +569,7 @@ void *crypto_create_tfm_node(struct crypto_alg *alg, tfm->__crt_alg =3D alg; tfm->node =3D node; tfm->fb =3D tfm; + crypto_track_tfm(tfm, ctx_size); =20 err =3D frontend->init_tfm(tfm); if (err) @@ -525,7 +585,8 @@ void *crypto_create_tfm_node(struct crypto_alg *alg, out_free_tfm: if (err =3D=3D -EAGAIN) crypto_shoot_alg(alg); - kfree(mem); + crypto_untrack_tfm(tfm); + kfree_sensitive(mem); mem =3D ERR_PTR(err); out: return mem; @@ -627,6 +688,7 @@ void crypto_destroy_tfm(void *mem, struct crypto_tfm *t= fm) alg->cra_exit(tfm); crypto_exit_ops(tfm); crypto_mod_put(alg); + crypto_untrack_tfm(tfm); kfree_sensitive(mem); } EXPORT_SYMBOL_GPL(crypto_destroy_tfm); diff --git a/include/linux/crypto.h b/include/linux/crypto.h index b7c97f1c47c9..59d6d62180fd 100644 --- a/include/linux/crypto.h +++ b/include/linux/crypto.h @@ -14,6 +14,7 @@ =20 #include #include +#include #include #include #include @@ -420,6 +421,16 @@ struct crypto_tfm { =20 struct crypto_alg *__crt_alg; =20 +#ifdef CONFIG_CRASH_WIPE_SECRETS + /* + * Link on crypto_tfm_list, used to wipe the expanded key schedule in + * __crt_ctx before kdump. wipe_size covers __crt_ctx only, excluding + * this struct and any frontend preceding it. + */ + struct hlist_node wipe_list; + size_t wipe_size; +#endif + void *__crt_ctx[] CRYPTO_MINALIGN_ATTR; }; =20 --=20 2.53.0 From nobody Tue Sep 29 06:11:02 2026 Received: from flow-b7-smtp.messagingengine.com (flow-b7-smtp.messagingengine.com [202.12.124.142]) (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 E59A4352022; Tue, 11 Aug 2026 17:54:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.142 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786470900; cv=none; b=SOWOQ/2psOIvwjLURNoGE5tuDNHyiO6LrrvjJBjYCqAVVkifypFUzINbyf58TpywG7tO6HUI0DOqEQLoJ7E0Ea1xiCbmPqKv4jjYXjdtU2+bHvN75Gn7t7uWbhABHcl35nwslbXBo00J/Myjk+AQmAlqf7z/GS3OIF77xypMrtQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786470900; c=relaxed/simple; bh=T47lbZ/5Ik9XFF2I7gSkXtBswUfH4MhklVGOicIW3mg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=T8F7mpdJ7X1uuAPzu8fNjUZX09aqofBaxgnXTfUPCTJ8zASYksYcDHxo2WlUf+eW0+MaZ0BOOU6UE3TOu0+AhtdSqSX04drHaaIwYo4/05nuxylIXz3O0/tGz0ppOLHKA1GaM0nbrhB6oWoaYIJI0EXmCbOvDSrak4tQKmiI2XQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=jaseg.de; spf=pass smtp.mailfrom=jaseg.de; dkim=pass (2048-bit key) header.d=jaseg.de header.i=@jaseg.de header.b=VxLE2qEQ; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=SSkpNzd/; arc=none smtp.client-ip=202.12.124.142 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=jaseg.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=jaseg.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=jaseg.de header.i=@jaseg.de header.b="VxLE2qEQ"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="SSkpNzd/" Received: from phl-compute-05.internal (phl-compute-05.internal [10.202.2.45]) by mailflow.stl.internal (Postfix) with ESMTP id E4B6A13003B7; Tue, 11 Aug 2026 13:54:56 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-05.internal (MEProxy); Tue, 11 Aug 2026 13:54:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jaseg.de; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1786470896; x=1786478096; bh=VywNlkxt81T21aE3I2g5wIsi8+Y5h/Z8ZTT1u80XjqQ=; b= VxLE2qEQb7RhsyFopOdNb1xsSG9C6lDp17xIF/tW5fjKC1h018h/TlWsm/mt1Idn ZSK2E16qh46bW4rFguHdnSDeoawg47gLExP576bp6CIE8pmJO1p3VJR4godaM57E hegomH+Tm6aRDm7eapdKWDIRCOLutTQUOXkcdoqTQUYkPUlYwNK4AiE2GEjntV8D nOZUZE1dsHD7l7B6o6I0E+Z7KOFHSCwfmpbVItkOnDXBlwdg/KI6LFsv1O4fgK8C sNIXlyLHP/J1eRm5b34phMIq8G1I046mN12Eh2YjdyHKUEiWE8gOIdkKynoaeOtc hry+Xrxf5w8noY46zpYPgQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1786470896; x= 1786478096; bh=VywNlkxt81T21aE3I2g5wIsi8+Y5h/Z8ZTT1u80XjqQ=; b=S SkpNzd/1QrAjL9XQuiY+AkLt5lhLMYS3fgQngrswG+ix3NYfCF51zDhtGkf9E3it EQyT+Rd7EOEwWw0vxrrZ4kZgKv2EaomfwB4Q4IfGJXY5OLdoKREMy6SWMXJE2hkQ Gh27Q1huZYbWz0FezXE2ibsfSAkFa8EzFJTwZZvodEhUTI3ayQ1c1LlpFvNjnscD eEMLauBLJnWFJ+YEiJrj4V6aLPml0dvZnT68l8/ygPykF6BpcpZvnPx1T3IY0Hx0 CyS6cPyQrBjHT9LKQGDvcLFnAxB0OmdCrqj6Y7qHTBK/z6ZMRmdQQkdO+AJ8uv2e 59gY7aIp+7XNH/xQlIfhA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTFz4vgNe8oY8QyUL0mlPqEECv57Qi7HCBIaM0H0fEpf1xbY2+8hZG6UpCbiC57xgk VavagF0YgIkokz9w1ZYP1FsIKkSgwmPUkWwZZopzEj1hsTumYxogfZ8LsE2lIsmrvQrzxe DNsAmjkffjDdnK7Hikwb1PBijPzdc+/pLDsJWa/G9io4Zr2WihJBScLGTtc/AAEph99TK7 KMYjrfPBzTMOGahPoGoXnc0LQ7Z6pMXIRNlA+PEZw+HSeBor1z9UME1MTUTi3zab2cdg5l S2ygLFXboS6erW/oqrZ0wC4vZEyPuJEZAHdMIjRfMGBWirnE5Gt0LHQJATpVfpt20aHeqK Vr9NQnZCOXNfk60Be2/UTgwxliwGfCsjAkA0QYgfJNinx6Wwn1xj1scz+ZOK1UcMfrRo3H GCXnRzeaKRJs42Gl0t0l71rV4rTv2MuB04VclqcHrLKbriLjI7PchBKyX9kKyt8FtiadHn kgkLCoKG8Tq29peNW3i083C3qqLlJiA31CXtZwOLh0hzkw0OD7PaCvxdbvZqcmgF/2MQXw ok2S4ZpzbXxDIPa2svuYyCoOyztu/wUpLoiJbWVNlNpLTwmQbxnU0qlYkEMtS1gPXfoUt0 +shDuurgOLjLUdMZz5xGuS9e2Efp7ZYl0UQf/a+Ej/KDT1ub33VVQNiznkQA X-ME-Proxy: Feedback-ID: i60a14417:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 11 Aug 2026 13:54:50 -0400 (EDT) From: =?utf-8?q?Jan_Sebastian_G=C3=B6tte?= Date: Tue, 11 Aug 2026 19:53:02 +0200 Subject: [PATCH v2 13/13] dm crypt: wipe key material before kdump 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260811-crash-zeroize-rework-v2-13-9561d13c2340@jaseg.de> References: <20260811-crash-zeroize-rework-v2-0-9561d13c2340@jaseg.de> In-Reply-To: <20260811-crash-zeroize-rework-v2-0-9561d13c2340@jaseg.de> To: Andrew Morton , Baoquan He , Mike Rapoport , Pasha Tatashin , Pratyush Yadav , Dave Young , Catalin Marinas , Will Deacon , David Howells , Jarkko Sakkinen , Jonathan Corbet , Shuah Khan , Paul Moore , James Morris , "Serge E. Hallyn" , Lukas Wunner , Ignat Korchagin , Herbert Xu , "David S. Miller" , Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , Trond Myklebust , Anna Schumaker , Mimi Zohar , James Bottomley , Marc Dionne , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Eric Biggers , "Theodore Y. Ts'o" , Jaegeuk Kim , Alexander Viro , Christian Brauner , Jan Kara , Alasdair Kergon , Mike Snitzer , Mikulas Patocka , Benjamin Marzinski Cc: kexec@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, keyrings@vger.kernel.org, linux-doc@vger.kernel.org, linux-security-module@vger.kernel.org, linux-crypto@vger.kernel.org, linux-nvme@lists.infradead.org, linux-nfs@vger.kernel.org, linux-integrity@vger.kernel.org, linux-afs@lists.infradead.org, netdev@vger.kernel.org, linux-fscrypt@vger.kernel.org, linux-fsdevel@vger.kernel.org, dm-devel@lists.linux.dev, =?utf-8?q?Jan_Sebastian_G=C3=B6tte?= X-Mailer: b4 0.15.2 Wipe volume key/iv copies kept by dm-crypt with CONFIG_CRASH_WIPE_SECRETS. The backend tfms are already handled separately. Add a list tracking struct crypt_config instances when CONFIG_CRASH_WIPE_SECRETS is set. Structs are tracked here to avoid having to enumerate them through some roundabout way before kdump, when we can't safely take locks anymore. Use custom wipe handlers even for things like ivs that have existing wipe functions elsewhere because we need to use crash_wipe_memzero instead of memzero_explicit. The crash_wipe helper memzero_explicit's the target buffers and flushes data caches. On ARM64, missing that cache flush could lead to the zeros not being written to DRAM before the kdump code turns off the data caches moments later. Signed-off-by: Jan Sebastian G=C3=B6tte --- drivers/md/dm-crypt.c | 151 ++++++++++++++++++++++++++++++++++++++++++++--= ---- 1 file changed, 134 insertions(+), 17 deletions(-) diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c index 608b617fb817..86adb2f9b94c 100644 --- a/drivers/md/dm-crypt.c +++ b/drivers/md/dm-crypt.c @@ -9,12 +9,14 @@ */ =20 #include +#include #include #include #include #include #include #include +#include #include #include #include @@ -234,6 +236,11 @@ struct crypt_config { struct mutex bio_alloc_lock; =20 u8 *authenc_key; /* space for keys in authenc() format (if used) */ + +#ifdef CONFIG_CRASH_WIPE_SECRETS + struct list_head wipe_list; +#endif + u8 key[] __counted_by(key_size); }; =20 @@ -243,6 +250,12 @@ struct crypt_config { =20 static DEFINE_SPINLOCK(dm_crypt_clients_lock); static unsigned int dm_crypt_clients_n; + +#ifdef CONFIG_CRASH_WIPE_SECRETS +static LIST_HEAD(dm_crypt_wipe_list); +static DEFINE_SPINLOCK(dm_crypt_wipe_list_lock); +#endif + static volatile unsigned long dm_crypt_pages_per_client; #define DM_CRYPT_MEMORY_PERCENT 2 #define DM_CRYPT_MIN_PAGES_PER_CLIENT (BIO_MAX_VECS * 16) @@ -460,8 +473,7 @@ static void crypt_iv_lmk_dtr(struct crypt_config *cc) { struct iv_lmk_private *lmk =3D &cc->iv_gen_private.lmk; =20 - kfree_sensitive(lmk->seed); - lmk->seed =3D NULL; + kfree_sensitive(xchg(&lmk->seed, NULL)); } =20 static int crypt_iv_lmk_ctr(struct crypt_config *cc, struct dm_target *ti, @@ -582,10 +594,8 @@ static void crypt_iv_tcw_dtr(struct crypt_config *cc) { struct iv_tcw_private *tcw =3D &cc->iv_gen_private.tcw; =20 - kfree_sensitive(tcw->iv_seed); - tcw->iv_seed =3D NULL; - kfree_sensitive(tcw->whitening); - tcw->whitening =3D NULL; + kfree_sensitive(xchg(&tcw->iv_seed, NULL)); + kfree_sensitive(xchg(&tcw->whitening, NULL)); } =20 static int crypt_iv_tcw_ctr(struct crypt_config *cc, struct dm_target *ti, @@ -761,8 +771,7 @@ static void crypt_iv_elephant_dtr(struct crypt_config *= cc) { struct iv_elephant_private *elephant =3D &cc->iv_gen_private.elephant; =20 - kfree_sensitive(elephant->key); - elephant->key =3D NULL; + kfree_sensitive(xchg(&elephant->key, NULL)); } =20 static int crypt_iv_elephant_ctr(struct crypt_config *cc, struct dm_target= *ti, @@ -2547,8 +2556,7 @@ static int crypt_set_keyring_key(struct crypt_config = *cc, const char *key_string goto free_new_key_string; =20 set_bit(DM_CRYPT_KEY_VALID, &cc->flags); - kfree_sensitive(cc->key_string); - cc->key_string =3D new_key_string; + kfree_sensitive(xchg(&cc->key_string, new_key_string)); return 0; =20 free_new_key_string: @@ -2612,8 +2620,7 @@ static int crypt_set_key(struct crypt_config *cc, cha= r *key) clear_bit(DM_CRYPT_KEY_VALID, &cc->flags); =20 /* wipe references to any kernel keyring key */ - kfree_sensitive(cc->key_string); - cc->key_string =3D NULL; + kfree_sensitive(xchg(&cc->key_string, NULL)); =20 /* Decode key from its hex representation. */ if (cc->key_size && hex2bin(cc->key, key, cc->key_size) < 0) @@ -2641,14 +2648,97 @@ static int crypt_wipe_key(struct crypt_config *cc) if (cc->iv_gen_ops && cc->iv_gen_ops->wipe) cc->iv_gen_ops->wipe(cc); =20 - kfree_sensitive(cc->key_string); - cc->key_string =3D NULL; + kfree_sensitive(xchg(&cc->key_string, NULL)); r =3D crypt_setkey(cc); memset(&cc->key, 0, cc->key_size * sizeof(u8)); =20 return r; } =20 +#ifdef CONFIG_CRASH_WIPE_SECRETS +static void crypt_crash_wipe_iv(struct crypt_config *cc) +{ + if (cc->iv_gen_ops =3D=3D &crypt_iv_lmk_ops) { + struct iv_lmk_private *lmk =3D &cc->iv_gen_private.lmk; + + if (lmk->seed) + crash_wipe_memzero(lmk->seed, LMK_SEED_SIZE); + } else if (cc->iv_gen_ops =3D=3D &crypt_iv_tcw_ops) { + struct iv_tcw_private *tcw =3D &cc->iv_gen_private.tcw; + + if (tcw->iv_seed) + crash_wipe_memzero(tcw->iv_seed, cc->iv_size); + if (tcw->whitening) + crash_wipe_memzero(tcw->whitening, TCW_WHITENING_SIZE); + } else if (cc->iv_gen_ops =3D=3D &crypt_iv_elephant_ops) { + struct iv_elephant_private *elephant =3D + &cc->iv_gen_private.elephant; + + if (elephant->key) + crash_wipe_memzero(elephant->key, + sizeof(*elephant->key)); + } +} + +static int crypt_crash_wipe(struct notifier_block *nb, unsigned long actio= n, + void *data) +{ + struct crypt_config *cc; + + /* No locking: all other CPUs are stopped, and a cc is unlinked before + * it is freed, so the forward walk can't reach freed memory. + */ + list_for_each_entry(cc, &dm_crypt_wipe_list, wipe_list) { + crash_wipe_memzero(cc->key, cc->key_size); + + if (cc->authenc_key) + crash_wipe_memzero(cc->authenc_key, + crypt_authenckey_size(cc)); + + if (cc->key_string) + crash_wipe_memzero(cc->key_string, + strlen(cc->key_string)); + + crypt_crash_wipe_iv(cc); + } + + return NOTIFY_DONE; +} + +static struct notifier_block crypt_crash_wipe_nb =3D { + .notifier_call =3D crypt_crash_wipe +}; + +static void crypt_track_cc(struct crypt_config *cc) +{ + spin_lock(&dm_crypt_wipe_list_lock); + list_add(&cc->wipe_list, &dm_crypt_wipe_list); + spin_unlock(&dm_crypt_wipe_list_lock); +} + +static void crypt_untrack_cc(struct crypt_config *cc) +{ + spin_lock(&dm_crypt_wipe_list_lock); + list_del(&cc->wipe_list); + spin_unlock(&dm_crypt_wipe_list_lock); +} + +static void crypt_crash_wipe_init(void) +{ + crash_wipe_secrets_register(&crypt_crash_wipe_nb); +} + +static void crypt_crash_wipe_exit(void) +{ + crash_wipe_secrets_unregister(&crypt_crash_wipe_nb); +} +#else +static void crypt_track_cc(struct crypt_config *cc) { } +static void crypt_untrack_cc(struct crypt_config *cc) { } +static void crypt_crash_wipe_init(void) { } +static void crypt_crash_wipe_exit(void) { } +#endif /* CONFIG_CRASH_WIPE_SECRETS */ + static void crypt_calculate_pages_per_client(void) { unsigned long pages =3D (totalram_pages() - totalhigh_pages()) * DM_CRYPT= _MEMORY_PERCENT / 100; @@ -2729,12 +2819,15 @@ static void crypt_dtr(struct dm_target *ti) dm_put_device(ti, cc->dev); =20 kfree_sensitive(cc->cipher_string); - kfree_sensitive(cc->key_string); + kfree_sensitive(xchg(&cc->key_string, NULL)); kfree_sensitive(cc->cipher_auth); - kfree_sensitive(cc->authenc_key); + kfree_sensitive(xchg(&cc->authenc_key, NULL)); =20 mutex_destroy(&cc->bio_alloc_lock); =20 + memzero_explicit(cc->key, cc->key_size); + crypt_untrack_cc(cc); + /* Must zero key material before freeing */ kfree_sensitive(cc); =20 @@ -3210,6 +3303,8 @@ static int crypt_ctr(struct dm_target *ti, unsigned i= nt argc, char **argv) =20 ti->private =3D cc; =20 + crypt_track_cc(cc); + spin_lock(&dm_crypt_clients_lock); dm_crypt_clients_n++; crypt_calculate_pages_per_client(); @@ -3716,7 +3811,29 @@ static struct target_type crypt_target =3D { .iterate_devices =3D crypt_iterate_devices, .io_hints =3D crypt_io_hints, }; -module_dm(crypt); + +static int __init dm_crypt_init(void) +{ + int r; + + crypt_crash_wipe_init(); + + r =3D dm_register_target(&crypt_target); + if (r) { + crypt_crash_wipe_exit(); + return r; + } + + return 0; +} +module_init(dm_crypt_init); + +static void __exit dm_crypt_exit(void) +{ + crypt_crash_wipe_exit(); + dm_unregister_target(&crypt_target); +} +module_exit(dm_crypt_exit); =20 MODULE_AUTHOR("Jana Saout "); MODULE_DESCRIPTION(DM_NAME " target for transparent encryption / decryptio= n"); --=20 2.53.0