From: "Jan Sebastian Götte" <linux@jaseg.de>
To: "Andrew Morton" <akpm@linux-foundation.org>,
"Baoquan He" <baoquan.he@linux.dev>,
"Mike Rapoport" <rppt@kernel.org>,
"Pasha Tatashin" <pasha.tatashin@soleen.com>,
"Pratyush Yadav" <pratyush@kernel.org>,
"Dave Young" <ruirui.yang@linux.dev>,
"David Howells" <dhowells@redhat.com>,
"Jarkko Sakkinen" <jarkko@kernel.org>,
"Paul Moore" <paul@paul-moore.com>,
"James Morris" <jmorris@namei.org>,
"Serge E. Hallyn" <serge@hallyn.com>,
"Mimi Zohar" <zohar@linux.ibm.com>,
"James Bottomley" <James.Bottomley@HansenPartnership.com>,
"Jan Sebastian Götte" <linux@jaseg.de>
Cc: Rob Herring <robh@kernel.org>,
Saravana Kannan <saravanak@kernel.org>,
Coiby Xu <coxu@redhat.com>,
"devicetree@vger.kernel.org"@kvack.org,
"linux-kernel@vger.kernel.org"@kvack.org,
"kexec@lists.infradead.org"@kvack.org,
"keyrings@vger.kernel.org"@kvack.org,
"linux-mm@kvack.org"@kvack.org,
"linux-security-module@vger.kernel.org"@kvack.org,
"linux-integrity@vger.kernel.org"@kvack.org
Subject: [PATCH 2/4] kexec: add CRASH_ZEROIZE to wipe secrets before kdump
Date: Fri, 31 Jul 2026 17:46:06 +0200 [thread overview]
Message-ID: <20260731154608.153258-3-linux@jaseg.de> (raw)
In-Reply-To: <20260731154608.153258-1-linux@jaseg.de>
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_zeroize_notifier_list, invoked late into __crash_kexec().
Subsystems holding secrets can register a callback to scrub 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ötte <linux@jaseg.de>
---
include/linux/crash_core.h | 5 +++++
kernel/Kconfig.kexec | 8 ++++++++
kernel/crash_core.c | 18 ++++++++++++++++++
3 files changed, 31 insertions(+)
diff --git a/include/linux/crash_core.h b/include/linux/crash_core.h
index bc087124cd78..5c7207c0bba1 100644
--- a/include/linux/crash_core.h
+++ b/include/linux/crash_core.h
@@ -5,6 +5,7 @@
#include <linux/linkage.h>
#include <linux/elfcore.h>
#include <linux/elf.h>
+#include <linux/notifier.h>
struct kimage;
@@ -34,6 +35,10 @@ static inline void arch_kexec_protect_crashkres(void) { }
static inline void arch_kexec_unprotect_crashkres(void) { }
#endif
+#ifdef CONFIG_CRASH_ZEROIZE
+extern struct atomic_notifier_head crash_zeroize_notifier_list;
+#endif
+
#ifndef arch_crash_handle_hotplug_event
static inline void arch_crash_handle_hotplug_event(struct kimage *image, void *arg) { }
#endif
diff --git a/kernel/Kconfig.kexec b/kernel/Kconfig.kexec
index 15632358bcf7..92ab0a69c8ec 100644
--- a/kernel/Kconfig.kexec
+++ b/kernel/Kconfig.kexec
@@ -179,4 +179,12 @@ config CRASH_MAX_MEMORY_RANGES
the computation behind the value provided through the
/sys/kernel/crash_elfcorehdr_size attribute.
+config CRASH_ZEROIZE
+ bool "Zeroize secrets on panic"
+ depends on CRASH_DUMP
+ help
+ Wipe secrets (e.g. kernel keyring and memfd_secret pages) on crash or panic.
+
+ If unsure, say N.
+
endmenu
diff --git a/kernel/crash_core.c b/kernel/crash_core.c
index 2b36aa9fade0..d3a7763e2759 100644
--- a/kernel/crash_core.c
+++ b/kernel/crash_core.c
@@ -23,6 +23,7 @@
#include <linux/objtool.h>
#include <linux/delay.h>
#include <linux/panic.h>
+#include <linux/timekeeping.h>
#include <asm/page.h>
#include <asm/sections.h>
@@ -33,6 +34,22 @@
/* Per cpu memory for storing cpu states in case of system crash. */
note_buf_t __percpu *crash_notes;
+#ifdef CONFIG_CRASH_ZEROIZE
+ATOMIC_NOTIFIER_HEAD(crash_zeroize_notifier_list);
+EXPORT_SYMBOL_GPL(crash_zeroize_notifier_list);
+
+static void crash_zeroize(void)
+{
+ ktime_t zeroize_start = ktime_get();
+
+ pr_info("Wiping sensitive secrets...\n");
+ atomic_notifier_call_chain(&crash_zeroize_notifier_list, 0, NULL);
+ pr_info("Done in %lld us\n", ktime_us_delta(ktime_get(), zeroize_start));
+}
+#else
+static inline void crash_zeroize(void) { }
+#endif /* CONFIG_CRASH_ZEROIZE */
+
/* time to wait for possible DMA to finish before starting the kdump kernel
* when a CMA reservation is used
*/
@@ -142,6 +159,7 @@ void __noclone __crash_kexec(struct pt_regs *regs)
crash_save_vmcoreinfo();
machine_crash_shutdown(&fixed_regs);
crash_cma_clear_pending_dma();
+ crash_zeroize();
machine_kexec(kexec_crash_image);
}
kexec_unlock();
--
2.53.0
next prev parent reply other threads:[~2026-07-31 15:46 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-31 15:46 [PATCH 0/4] CRASH_ZEROIZE: Wipe secrets before kdump Jan Sebastian Götte
2026-07-31 15:46 ` [PATCH 1/4] of/kexec: fix typo in comment (usable-memory-range) Jan Sebastian Götte
2026-07-31 15:46 ` Jan Sebastian Götte [this message]
2026-08-05 4:19 ` [PATCH 2/4] kexec: add CRASH_ZEROIZE to wipe secrets before kdump sashiko-bot
2026-07-31 15:46 ` [PATCH 3/4] mm/secretmem: zeroize secret pages " Jan Sebastian Götte
2026-08-05 4:26 ` sashiko-bot
2026-07-31 15:46 ` [PATCH 4/4] security/keys: zeroize key payloads " Jan Sebastian Götte
2026-07-31 22:50 ` David Howells
2026-08-05 4:29 ` sashiko-bot
2026-08-01 14:03 ` [PATCH 0/4] CRASH_ZEROIZE: Wipe secrets " Baoquan He
2026-08-01 16:31 ` Jan Sebastian Götte
2026-08-02 5:08 ` Dave Young
2026-08-02 10:20 ` Jan Sebastian Götte
2026-08-03 12:12 ` Dave Young
2026-08-03 12:54 ` Jan Sebastian Götte
2026-08-03 9:59 ` David Howells
2026-08-03 12:00 ` Dave Young
-- strict thread matches above, loose matches on Subject: below --
2026-07-31 16:27 Jan Sebastian Götte
2026-07-31 16:27 ` [PATCH 2/4] kexec: add CRASH_ZEROIZE to wipe " Jan Sebastian Götte
2026-07-31 16:35 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260731154608.153258-3-linux@jaseg.de \
--to=linux@jaseg.de \
--cc="devicetree@vger.kernel.org"@kvack.org \
--cc="kexec@lists.infradead.org"@kvack.org \
--cc="keyrings@vger.kernel.org"@kvack.org \
--cc="linux-integrity@vger.kernel.org"@kvack.org \
--cc="linux-kernel@vger.kernel.org"@kvack.org \
--cc="linux-mm@kvack.org"@kvack.org \
--cc="linux-security-module@vger.kernel.org"@kvack.org \
--cc=James.Bottomley@HansenPartnership.com \
--cc=akpm@linux-foundation.org \
--cc=baoquan.he@linux.dev \
--cc=coxu@redhat.com \
--cc=dhowells@redhat.com \
--cc=jarkko@kernel.org \
--cc=jmorris@namei.org \
--cc=pasha.tatashin@soleen.com \
--cc=paul@paul-moore.com \
--cc=pratyush@kernel.org \
--cc=robh@kernel.org \
--cc=rppt@kernel.org \
--cc=ruirui.yang@linux.dev \
--cc=saravanak@kernel.org \
--cc=serge@hallyn.com \
--cc=zohar@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.