* [PATCH 0/4] CRASH_ZEROIZE: Wipe secrets before kdump
@ 2026-07-31 15:46 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
` (4 more replies)
0 siblings, 5 replies; 14+ messages in thread
From: Jan Sebastian Götte @ 2026-07-31 15:46 UTC (permalink / raw)
To: Andrew Morton, Baoquan He, Mike Rapoport, Pasha Tatashin,
Pratyush Yadav, Dave Young, David Howells, Jarkko Sakkinen,
Paul Moore, James Morris, Serge E. Hallyn, Mimi Zohar,
James Bottomley, Jan Sebastian Götte
Cc: Rob Herring, Saravana Kannan, Coiby Xu, "devicetree,
"linux-kernel, "kexec, "keyrings, "linux-mm,
"linux-security-module, "linux-integrity
I'm using linux on an embedded target in a Hardware Security Module-like
application. One requirement is that I want the system to be able to
quickly erase its memory when it detects physical tampering. I'm
approaching that by using kdump to load into a small payload that
instead of dumping RAM, erases RAM from start to end. However, writing
all of RAM, especially on an embedded target, is rather slow. For this
reason, I propose the mechanism in this patch series:
Add CONFIG_CRASH_ZEROIZE (default off), which when enabled makes various
subsystems handling secret data do a quick, targeted wipe of these
secrets before kdump. This behavior might also be interesting in cases
where you run a normal kdump kernel but you still want to keep things
like fde crypto keys out of these dumps.
CONFIG_CRASH_ZEROIZE is a best effort, defense in depth solution. There
are circumstances, such as when a panic is triggered after memory
corruption, or when a panic interrupts some operation that mutates data
structures under locks, when the kernel cannot safely wipe some memory
areas. The handlers proposed in this series will just print a warning
and skip the affected areas in this case.
This series introduces two handlers as a starting point: One for kernel
keyrings, and one for secretmem. Future places where such handlers could
be added would be for example drivers for crypto accelerators.
The patch series applies on top of linux-next but should work on 7.0.0,
too. I've tested the patches on a Arduino uno Q (Qualcomm QRB2210)
embedded target.
Jan Sebastian Götte (4):
of/kexec: fix typo in comment (usable-memory-range)
kexec: add CRASH_ZEROIZE to wipe secrets before kdump
mm/secretmem: zeroize secret pages before kdump
security/keys: zeroize key payloads before kdump
drivers/of/kexec.c | 2 +-
include/linux/crash_core.h | 5 +++
include/linux/key-type.h | 9 ++++
kernel/Kconfig.kexec | 8 ++++
kernel/crash_core.c | 18 ++++++++
mm/secretmem.c | 50 +++++++++++++++++++++++
security/keys/big_key.c | 15 +++++++
security/keys/encrypted-keys/encrypted.c | 12 ++++++
security/keys/key.c | 44 ++++++++++++++++++++
security/keys/trusted-keys/trusted_core.c | 14 +++++++
security/keys/user_defined.c | 11 +++++
11 files changed, 187 insertions(+), 1 deletion(-)
--
2.53.0
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 1/4] of/kexec: fix typo in comment (usable-memory-range)
2026-07-31 15:46 [PATCH 0/4] CRASH_ZEROIZE: Wipe secrets before kdump Jan Sebastian Götte
@ 2026-07-31 15:46 ` Jan Sebastian Götte
2026-07-31 15:46 ` [PATCH 2/4] kexec: add CRASH_ZEROIZE to wipe secrets before kdump Jan Sebastian Götte
` (3 subsequent siblings)
4 siblings, 0 replies; 14+ messages in thread
From: Jan Sebastian Götte @ 2026-07-31 15:46 UTC (permalink / raw)
To: Andrew Morton, Baoquan He, Mike Rapoport, Pasha Tatashin,
Pratyush Yadav, Dave Young, David Howells, Jarkko Sakkinen,
Paul Moore, James Morris, Serge E. Hallyn, Mimi Zohar,
James Bottomley, Jan Sebastian Götte
Cc: Rob Herring, Saravana Kannan, Coiby Xu, "devicetree,
"linux-kernel, "kexec, "keyrings, "linux-mm,
"linux-security-module, "linux-integrity
Signed-off-by: Jan Sebastian Götte <linux@jaseg.de>
---
drivers/of/kexec.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/of/kexec.c b/drivers/of/kexec.c
index 029903b986cb..36635f6cb900 100644
--- a/drivers/of/kexec.c
+++ b/drivers/of/kexec.c
@@ -24,7 +24,7 @@
/*
* Additional space needed for the FDT buffer so that we can add initrd,
- * bootargs, kaslr-seed, rng-seed, useable-memory-range and elfcorehdr.
+ * bootargs, kaslr-seed, rng-seed, usable-memory-range and elfcorehdr.
*/
#define FDT_EXTRA_SPACE 0x1000
--
2.53.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 2/4] kexec: add CRASH_ZEROIZE to wipe secrets before kdump
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
2026-07-31 15:46 ` [PATCH 3/4] mm/secretmem: zeroize secret pages " Jan Sebastian Götte
` (2 subsequent siblings)
4 siblings, 0 replies; 14+ messages in thread
From: Jan Sebastian Götte @ 2026-07-31 15:46 UTC (permalink / raw)
To: Andrew Morton, Baoquan He, Mike Rapoport, Pasha Tatashin,
Pratyush Yadav, Dave Young, David Howells, Jarkko Sakkinen,
Paul Moore, James Morris, Serge E. Hallyn, Mimi Zohar,
James Bottomley, Jan Sebastian Götte
Cc: Rob Herring, Saravana Kannan, Coiby Xu, "devicetree,
"linux-kernel, "kexec, "keyrings, "linux-mm,
"linux-security-module, "linux-integrity
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
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 3/4] mm/secretmem: zeroize secret pages before kdump
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 ` [PATCH 2/4] kexec: add CRASH_ZEROIZE to wipe secrets before kdump Jan Sebastian Götte
@ 2026-07-31 15:46 ` Jan Sebastian Götte
2026-07-31 15:46 ` [PATCH 4/4] security/keys: zeroize key payloads " Jan Sebastian Götte
2026-08-01 14:03 ` [PATCH 0/4] CRASH_ZEROIZE: Wipe secrets " Baoquan He
4 siblings, 0 replies; 14+ messages in thread
From: Jan Sebastian Götte @ 2026-07-31 15:46 UTC (permalink / raw)
To: Andrew Morton, Baoquan He, Mike Rapoport, Pasha Tatashin,
Pratyush Yadav, Dave Young, David Howells, Jarkko Sakkinen,
Paul Moore, James Morris, Serge E. Hallyn, Mimi Zohar,
James Bottomley, Jan Sebastian Götte
Cc: Rob Herring, Saravana Kannan, Coiby Xu, "devicetree,
"linux-kernel, "kexec, "keyrings, "linux-mm,
"linux-security-module, "linux-integrity
Register a CRASH_ZEROIZE notifier that wipes secretmem folios. As a
result, when CONFIG_CRASH_ZEROIZE is set, secretmem areas will be
cleared before the kdump kernel is kexec'ed.
Zeroization 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ötte <linux@jaseg.de>
---
mm/secretmem.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 50 insertions(+)
diff --git a/mm/secretmem.c b/mm/secretmem.c
index d29865075b6e..53f629d6633c 100644
--- a/mm/secretmem.c
+++ b/mm/secretmem.c
@@ -13,9 +13,11 @@
#include <linux/bitops.h>
#include <linux/printk.h>
#include <linux/pagemap.h>
+#include <linux/notifier.h>
#include <linux/syscalls.h>
#include <linux/pseudo_fs.h>
#include <linux/secretmem.h>
+#include <linux/crash_core.h>
#include <linux/set_memory.h>
#include <linux/sched/signal.h>
@@ -187,6 +189,50 @@ static const struct inode_operations secretmem_iops = {
static struct vfsmount *secretmem_mnt;
+#ifdef CONFIG_CRASH_ZEROIZE
+/* Called far into vpanic from crash_core.c with other CPUs stopped and
+ * preemption disabled
+ */
+static int secretmem_crash_zeroize(struct notifier_block *nb, unsigned long
+ action, void *data)
+{
+ struct super_block *sb;
+ struct inode *inode;
+
+ if (!secretmem_mnt)
+ return NOTIFY_DONE;
+ sb = 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_zeroize: can't acquire secretmem superblock lock.\n"
+ "crash_zeroize: 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;
+ inode->i_mapping->a_ops->free_folio(folio);
+ }
+ }
+ /* off to kexec()! */
+ return NOTIFY_DONE;
+}
+
+static struct notifier_block secretmem_zeroize_nb = {
+ .notifier_call = secretmem_crash_zeroize
+};
+#endif /* CONFIG_CRASH_ZEROIZE */
+
static struct file *secretmem_file_create(unsigned long flags)
{
struct file *file;
@@ -263,6 +309,10 @@ static int __init secretmem_init(void)
if (IS_ERR(secretmem_mnt))
return PTR_ERR(secretmem_mnt);
+#ifdef CONFIG_CRASH_ZEROIZE
+ atomic_notifier_chain_register(&crash_zeroize_notifier_list, &secretmem_zeroize_nb);
+#endif
+
return 0;
}
fs_initcall(secretmem_init);
--
2.53.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 4/4] security/keys: zeroize key payloads before kdump
2026-07-31 15:46 [PATCH 0/4] CRASH_ZEROIZE: Wipe secrets before kdump Jan Sebastian Götte
` (2 preceding siblings ...)
2026-07-31 15:46 ` [PATCH 3/4] mm/secretmem: zeroize secret pages " Jan Sebastian Götte
@ 2026-07-31 15:46 ` Jan Sebastian Götte
2026-08-01 14:03 ` [PATCH 0/4] CRASH_ZEROIZE: Wipe secrets " Baoquan He
4 siblings, 0 replies; 14+ messages in thread
From: Jan Sebastian Götte @ 2026-07-31 15:46 UTC (permalink / raw)
To: Andrew Morton, Baoquan He, Mike Rapoport, Pasha Tatashin,
Pratyush Yadav, Dave Young, David Howells, Jarkko Sakkinen,
Paul Moore, James Morris, Serge E. Hallyn, Mimi Zohar,
James Bottomley, Jan Sebastian Götte
Cc: Rob Herring, Saravana Kannan, Coiby Xu, "devicetree,
"linux-kernel, "kexec, "keyrings, "linux-mm,
"linux-security-module, "linux-integrity
When CONFIG_CRASH_ZEROIZE is set, try to erase key payloads on panic
before jumping to the kdump kernel.
CRASH_ZEROIZE 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 zeroize key op.
Implement the zeroize op for the user/logon, encrypted, trusted, and
big_key types.
Signed-off-by: Jan Sebastian Götte <linux@jaseg.de>
---
include/linux/key-type.h | 9 +++++
security/keys/big_key.c | 15 ++++++++
security/keys/encrypted-keys/encrypted.c | 12 +++++++
security/keys/key.c | 44 +++++++++++++++++++++++
security/keys/trusted-keys/trusted_core.c | 14 ++++++++
security/keys/user_defined.c | 11 ++++++
6 files changed, 105 insertions(+)
diff --git a/include/linux/key-type.h b/include/linux/key-type.h
index bb97bd3e5af4..ff0944ce368f 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);
+ /* scrub the key material without free'ing (optional)
+ * - used from CONFIG_CRASH_ZEROIZE 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 (*zeroize)(struct key *key);
+
/* describe a key */
void (*describe)(const struct key *key, struct seq_file *p);
diff --git a/security/keys/big_key.c b/security/keys/big_key.c
index 268f702df380..ad8537dda70f 100644
--- a/security/keys/big_key.c
+++ b/security/keys/big_key.c
@@ -35,6 +35,8 @@ struct big_key_payload {
*/
#define BIG_KEY_FILE_THRESHOLD (sizeof(struct inode) + sizeof(struct dentry))
+static void big_key_zeroize(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 +48,7 @@ struct key_type key_type_big_key = {
.instantiate = generic_key_instantiate,
.revoke = big_key_revoke,
.destroy = big_key_destroy,
+ .zeroize = big_key_zeroize,
.describe = big_key_describe,
.read = big_key_read,
.update = big_key_update,
@@ -279,6 +282,18 @@ long big_key_read(const struct key *key, char *buffer, size_t buflen)
return ret;
}
+static void big_key_zeroize(struct key *key)
+{
+ struct big_key_payload *payload = to_big_key_payload(key->payload);
+
+ if (payload->data) {
+ if (payload->length > BIG_KEY_FILE_THRESHOLD)
+ memzero_explicit(payload->data, CHACHA20POLY1305_KEY_SIZE);
+ else
+ memzero_explicit(payload->data, payload->length);
+ }
+}
+
/*
* Register key type
*/
diff --git a/security/keys/encrypted-keys/encrypted.c b/security/keys/encrypted-keys/encrypted.c
index 59cb77b237b3..9f56fa9b4aaf 100644
--- a/security/keys/encrypted-keys/encrypted.c
+++ b/security/keys/encrypted-keys/encrypted.c
@@ -970,11 +970,23 @@ static void encrypted_destroy(struct key *key)
kfree_sensitive(key->payload.data[0]);
}
+static void encrypted_zeroize(struct key *key)
+{
+ struct encrypted_key_payload *epayload = key->payload.data[0];
+
+ if (!epayload)
+ return;
+
+ memzero_explicit(epayload->payload_data,
+ epayload->payload_datalen + epayload->datablob_len);
+}
+
struct key_type key_type_encrypted = {
.name = "encrypted",
.instantiate = encrypted_instantiate,
.update = encrypted_update,
.destroy = encrypted_destroy,
+ .zeroize = encrypted_zeroize,
.describe = user_describe,
.read = encrypted_read,
};
diff --git a/security/keys/key.c b/security/keys/key.c
index b34a64d81d47..5673dcc8c5d2 100644
--- a/security/keys/key.c
+++ b/security/keys/key.c
@@ -12,6 +12,7 @@
#include <linux/slab.h>
#include <linux/security.h>
#include <linux/workqueue.h>
+#include <linux/crash_core.h>
#include <linux/random.h>
#include <linux/err.h>
#include "internal.h"
@@ -1268,6 +1269,44 @@ void unregister_key_type(struct key_type *ktype)
}
EXPORT_SYMBOL(unregister_key_type);
+#ifdef CONFIG_CRASH_ZEROIZE
+/* Called far into vpanic from crash_core.c with other CPUs stopped and
+ * preemption disabled
+ */
+static int key_crash_zeroize(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_zeroize: can't acquire key_serial_lock. skipping keyrings.\n");
+ return NOTIFY_DONE;
+ }
+
+ for (node = rb_first(&key_serial_tree); node; node = rb_next(node)) {
+ struct key *key = rb_entry(node, struct key, serial_node);
+
+ if (key->type == &key_type_keyring ||
+ key->state == KEY_IS_UNINSTANTIATED)
+ continue;
+
+ /* custom zeroize since free'ing isn't safe at this point */
+ if (key->type->zeroize)
+ key->type->zeroize(key);
+ }
+ /* off to kexec()! */
+ return NOTIFY_DONE;
+}
+
+static struct notifier_block key_crash_zeroize_nb = {
+ .notifier_call = key_crash_zeroize
+};
+#endif /* CONFIG_CRASH_ZEROIZE */
+
/*
* Initialise the key management state.
*/
@@ -1290,4 +1329,9 @@ void __init key_init(void)
rb_insert_color(&root_key_user.node,
&key_user_tree);
+
+#ifdef CONFIG_CRASH_ZEROIZE
+ atomic_notifier_chain_register(&crash_zeroize_notifier_list,
+ &key_crash_zeroize_nb);
+#endif
}
diff --git a/security/keys/trusted-keys/trusted_core.c b/security/keys/trusted-keys/trusted_core.c
index 0509d9955f2a..f159faeafe23 100644
--- a/security/keys/trusted-keys/trusted_core.c
+++ b/security/keys/trusted-keys/trusted_core.c
@@ -325,11 +325,25 @@ static void trusted_destroy(struct key *key)
kfree_sensitive(key->payload.data[0]);
}
+static void trusted_zeroize(struct key *key)
+{
+ struct trusted_key_payload *p = key->payload.data[0];
+
+ if (!p)
+ return;
+
+ memzero_explicit(p->key, sizeof(p->key));
+ memzero_explicit(p->blob, sizeof(p->blob));
+ p->key_len = 0;
+ p->blob_len = 0;
+}
+
struct key_type key_type_trusted = {
.name = "trusted",
.instantiate = trusted_instantiate,
.update = trusted_update,
.destroy = trusted_destroy,
+ .zeroize = trusted_zeroize,
.describe = user_describe,
.read = trusted_read,
};
diff --git a/security/keys/user_defined.c b/security/keys/user_defined.c
index 6f88b507f927..ade95dc2481d 100644
--- a/security/keys/user_defined.c
+++ b/security/keys/user_defined.c
@@ -15,6 +15,7 @@
#include "internal.h"
static int logon_vet_description(const char *desc);
+static void user_zeroize(struct key *key);
/*
* user defined keys take an arbitrary string as the description and an
@@ -28,6 +29,7 @@ struct key_type key_type_user = {
.update = user_update,
.revoke = user_revoke,
.destroy = user_destroy,
+ .zeroize = user_zeroize,
.describe = user_describe,
.read = user_read,
};
@@ -48,6 +50,7 @@ struct key_type key_type_logon = {
.update = user_update,
.revoke = user_revoke,
.destroy = user_destroy,
+ .zeroize = user_zeroize,
.describe = user_describe,
.vet_description = logon_vet_description,
};
@@ -152,6 +155,14 @@ void user_destroy(struct key *key)
EXPORT_SYMBOL_GPL(user_destroy);
+static void user_zeroize(struct key *key)
+{
+ struct user_key_payload *upayload = key->payload.data[0];
+
+ if (upayload)
+ memzero_explicit(upayload->data, upayload->datalen);
+}
+
/*
* describe the user key
*/
--
2.53.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 3/4] mm/secretmem: zeroize secret pages before kdump
2026-07-31 16:27 Jan Sebastian Götte
@ 2026-07-31 16:27 ` Jan Sebastian Götte
0 siblings, 0 replies; 14+ messages in thread
From: Jan Sebastian Götte @ 2026-07-31 16:27 UTC (permalink / raw)
To: Jan Sebastian Götte
Cc: devicetree, linux-kernel, kexec, keyrings, linux-mm,
linux-security-module, linux-integrity
Register a CRASH_ZEROIZE notifier that wipes secretmem folios. As a
result, when CONFIG_CRASH_ZEROIZE is set, secretmem areas will be
cleared before the kdump kernel is kexec'ed.
Zeroization 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ötte <linux@jaseg.de>
---
mm/secretmem.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 50 insertions(+)
diff --git a/mm/secretmem.c b/mm/secretmem.c
index d29865075b6e..53f629d6633c 100644
--- a/mm/secretmem.c
+++ b/mm/secretmem.c
@@ -13,9 +13,11 @@
#include <linux/bitops.h>
#include <linux/printk.h>
#include <linux/pagemap.h>
+#include <linux/notifier.h>
#include <linux/syscalls.h>
#include <linux/pseudo_fs.h>
#include <linux/secretmem.h>
+#include <linux/crash_core.h>
#include <linux/set_memory.h>
#include <linux/sched/signal.h>
@@ -187,6 +189,50 @@ static const struct inode_operations secretmem_iops = {
static struct vfsmount *secretmem_mnt;
+#ifdef CONFIG_CRASH_ZEROIZE
+/* Called far into vpanic from crash_core.c with other CPUs stopped and
+ * preemption disabled
+ */
+static int secretmem_crash_zeroize(struct notifier_block *nb, unsigned long
+ action, void *data)
+{
+ struct super_block *sb;
+ struct inode *inode;
+
+ if (!secretmem_mnt)
+ return NOTIFY_DONE;
+ sb = 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_zeroize: can't acquire secretmem superblock lock.\n"
+ "crash_zeroize: 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;
+ inode->i_mapping->a_ops->free_folio(folio);
+ }
+ }
+ /* off to kexec()! */
+ return NOTIFY_DONE;
+}
+
+static struct notifier_block secretmem_zeroize_nb = {
+ .notifier_call = secretmem_crash_zeroize
+};
+#endif /* CONFIG_CRASH_ZEROIZE */
+
static struct file *secretmem_file_create(unsigned long flags)
{
struct file *file;
@@ -263,6 +309,10 @@ static int __init secretmem_init(void)
if (IS_ERR(secretmem_mnt))
return PTR_ERR(secretmem_mnt);
+#ifdef CONFIG_CRASH_ZEROIZE
+ atomic_notifier_chain_register(&crash_zeroize_notifier_list, &secretmem_zeroize_nb);
+#endif
+
return 0;
}
fs_initcall(secretmem_init);
--
2.53.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH 0/4] CRASH_ZEROIZE: Wipe secrets before kdump
2026-07-31 15:46 [PATCH 0/4] CRASH_ZEROIZE: Wipe secrets before kdump Jan Sebastian Götte
` (3 preceding siblings ...)
2026-07-31 15:46 ` [PATCH 4/4] security/keys: zeroize key payloads " Jan Sebastian Götte
@ 2026-08-01 14:03 ` Baoquan He
2026-08-01 16:31 ` Jan Sebastian Götte
4 siblings, 1 reply; 14+ messages in thread
From: Baoquan He @ 2026-08-01 14:03 UTC (permalink / raw)
To: Jan Sebastian Götte
Cc: Andrew Morton, Mike Rapoport, Pasha Tatashin, Pratyush Yadav,
Dave Young, David Howells, Jarkko Sakkinen, Paul Moore,
James Morris, Serge E. Hallyn, Mimi Zohar, James Bottomley,
Rob Herring, Saravana Kannan, Coiby Xu, devicetree, linux-kernel,
kexec, keyrings, linux-mm, linux-security-module, linux-integrity
On 07/31/26 at 05:46pm, Jan Sebastian Götte wrote:
> I'm using linux on an embedded target in a Hardware Security Module-like
> application. One requirement is that I want the system to be able to
> quickly erase its memory when it detects physical tampering. I'm
> approaching that by using kdump to load into a small payload that
> instead of dumping RAM, erases RAM from start to end. However, writing
> all of RAM, especially on an embedded target, is rather slow. For this
> reason, I propose the mechanism in this patch series:
>
> Add CONFIG_CRASH_ZEROIZE (default off), which when enabled makes various
> subsystems handling secret data do a quick, targeted wipe of these
> secrets before kdump. This behavior might also be interesting in cases
> where you run a normal kdump kernel but you still want to keep things
> like fde crypto keys out of these dumps.
Please check below patchset, you both seem to have the similar
requirement. Please go there to discuss.
[RFC PATCH 0/4] panic: a pre kdump notifier list for hypervisor upcalls
Note that we usually dont' want to run a lot of work after panic and
before jumping into kdump kernel.
>
> CONFIG_CRASH_ZEROIZE is a best effort, defense in depth solution. There
> are circumstances, such as when a panic is triggered after memory
> corruption, or when a panic interrupts some operation that mutates data
> structures under locks, when the kernel cannot safely wipe some memory
> areas. The handlers proposed in this series will just print a warning
> and skip the affected areas in this case.
>
> This series introduces two handlers as a starting point: One for kernel
> keyrings, and one for secretmem. Future places where such handlers could
> be added would be for example drivers for crypto accelerators.
>
> The patch series applies on top of linux-next but should work on 7.0.0,
> too. I've tested the patches on a Arduino uno Q (Qualcomm QRB2210)
> embedded target.
>
> Jan Sebastian Götte (4):
> of/kexec: fix typo in comment (usable-memory-range)
> kexec: add CRASH_ZEROIZE to wipe secrets before kdump
> mm/secretmem: zeroize secret pages before kdump
> security/keys: zeroize key payloads before kdump
>
> drivers/of/kexec.c | 2 +-
> include/linux/crash_core.h | 5 +++
> include/linux/key-type.h | 9 ++++
> kernel/Kconfig.kexec | 8 ++++
> kernel/crash_core.c | 18 ++++++++
> mm/secretmem.c | 50 +++++++++++++++++++++++
> security/keys/big_key.c | 15 +++++++
> security/keys/encrypted-keys/encrypted.c | 12 ++++++
> security/keys/key.c | 44 ++++++++++++++++++++
> security/keys/trusted-keys/trusted_core.c | 14 +++++++
> security/keys/user_defined.c | 11 +++++
> 11 files changed, 187 insertions(+), 1 deletion(-)
>
> --
> 2.53.0
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 0/4] CRASH_ZEROIZE: Wipe secrets before kdump
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
0 siblings, 1 reply; 14+ messages in thread
From: Jan Sebastian Götte @ 2026-08-01 16:31 UTC (permalink / raw)
To: Baoquan He
Cc: Andrew Morton, Mike Rapoport, Pasha Tatashin, Pratyush Yadav,
Dave Young, David Howells, Jarkko Sakkinen, Paul Moore,
James Morris, Serge E. Hallyn, Mimi Zohar, James Bottomley,
Rob Herring, Saravana Kannan, Coiby Xu, devicetree, linux-kernel,
kexec, keyrings, linux-mm, linux-security-module, linux-integrity
Hi there,
On 8/1/26 16:03, Baoquan He wrote:
> On 07/31/26 at 05:46pm, Jan Sebastian Götte wrote:
>> Add CONFIG_CRASH_ZEROIZE (default off), which when enabled makes various
>> subsystems handling secret data do a quick, targeted wipe of these
>> secrets before kdump. This behavior might also be interesting in cases
>> where you run a normal kdump kernel but you still want to keep things
>> like fde crypto keys out of these dumps.
>
> Please check below patchset, you both seem to have the similar
> requirement. Please go there to discuss.
>
> [RFC PATCH 0/4] panic: a pre kdump notifier list for hypervisor upcalls
Thank you for the pointer. That's indeed similar, but I think this
patchset here makes sense as an independent patchset.
* The two notifier chains run at different points, and theirs runs
inside panic independent of kdump. This one here has to be run after
machine_crash_shutdown(), and so makes most sense inside
__crash_kexec(). The wipe code in this patchset must be one of the last
things to run before the kexec since the wiped data structures could
easily lead to problems if something tried using them later.
* I think this patch series here is a bit cleaner. I don't think this
needs a custom notifier implementation.
* Since there's lots of places that may need wiping after crash, I think
it makes sense to have an explicit notifier list for that purpose, and
to not mix these with other things like hypercalls. I think ordering is
important here: The wiping should be the last thing before the kexec
jump. Having it on a generic notifier chain risks that later, other
callbacks get added that when interleaved could cause problems.
* Since a good fraction of users may not care about wiping secrets, I
think it should be gated behind an explicit enable setting.
> Note that we usually dont' want to run a lot of work after panic and
> before jumping into kdump kernel.
I understand. For this reason, I think it's best to keep this
default-off. As-is, the notifier list call is timed and on the (slow)
ARM64 target I'm using, it takes about 3-5 ms to run. I took the "try
lock, skip if locked" approach to keep the risk of this code crashing
during panic minimal. In my application, the kdump payload is code that
then does a full wipe, taking a couple hundred milliseconds.
Let me know what you think.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 0/4] CRASH_ZEROIZE: Wipe secrets before kdump
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 9:59 ` David Howells
0 siblings, 2 replies; 14+ messages in thread
From: Dave Young @ 2026-08-02 5:08 UTC (permalink / raw)
To: Jan Sebastian Götte, Baoquan He
Cc: Andrew Morton, Mike Rapoport, Pasha Tatashin, Pratyush Yadav,
David Howells, Jarkko Sakkinen, Paul Moore, James Morris,
Serge E. Hallyn, Mimi Zohar, James Bottomley, Rob Herring,
Saravana Kannan, Coiby Xu, devicetree, linux-kernel, kexec,
keyrings, linux-mm, linux-security-module, linux-integrity,
Tao Liu
On 8/2/26 12:31 AM, Jan Sebastian Götte wrote:
> Hi there,
>
> On 8/1/26 16:03, Baoquan He wrote:
>> On 07/31/26 at 05:46pm, Jan Sebastian Götte wrote:
>>> Add CONFIG_CRASH_ZEROIZE (default off), which when enabled makes various
>>> subsystems handling secret data do a quick, targeted wipe of these
>>> secrets before kdump. This behavior might also be interesting in cases
>>> where you run a normal kdump kernel but you still want to keep things
>>> like fde crypto keys out of these dumps.
>>
>> Please check below patchset, you both seem to have the similar
>> requirement. Please go there to discuss.
>>
>> [RFC PATCH 0/4] panic: a pre kdump notifier list for hypervisor upcalls
>
> Thank you for the pointer. That's indeed similar, but I think this patchset here makes sense as an independent patchset.
>
> * The two notifier chains run at different points, and theirs runs inside panic independent of kdump. This one here has to be run after machine_crash_shutdown(), and so makes most sense inside __crash_kexec(). The wipe code in this patchset must be one of the last things to run before the kexec since the wiped data structures could easily lead to problems if something tried using them later.
>
> * I think this patch series here is a bit cleaner. I don't think this needs a custom notifier implementation.
>
> * Since there's lots of places that may need wiping after crash, I think it makes sense to have an explicit notifier list for that purpose, and to not mix these with other things like hypercalls. I think ordering is important here: The wiping should be the last thing before the kexec jump. Having it on a generic notifier chain risks that later, other callbacks get added that when interleaved could cause problems.
>
> * Since a good fraction of users may not care about wiping secrets, I think it should be gated behind an explicit enable setting.
>
>> Note that we usually dont' want to run a lot of work after panic and
>> before jumping into kdump kernel.
>
> I understand. For this reason, I think it's best to keep this default-off. As-is, the notifier list call is timed and on the (slow) ARM64 target I'm using, it takes about 3-5 ms to run. I took the "try lock, skip if locked" approach to keep the risk of this code crashing during panic minimal. In my application, the kdump payload is code that then does a full wipe, taking a couple hundred milliseconds.
Not only about the time used, the panicked kernel is not reliable, any more extra logic can make it even not reliable, any pre-kdump extra logic is not a good idea unless it is a must to ensure kdump working.
Cleaning up secret data can be done with makedumpfile + eppic scripts (see the manual of makedumpfile), or it is even possible to do so in kdump kernel with Tao Liu's improvments for makedumpfile previously (I don't know the status, probably dropped for the time being, but it is possible, cced him).
Thanks
Dave
>
> Let me know what you think.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 0/4] CRASH_ZEROIZE: Wipe secrets before kdump
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 9:59 ` David Howells
1 sibling, 1 reply; 14+ messages in thread
From: Jan Sebastian Götte @ 2026-08-02 10:20 UTC (permalink / raw)
To: Dave Young, Baoquan He
Cc: Andrew Morton, Mike Rapoport, Pasha Tatashin, Pratyush Yadav,
David Howells, Jarkko Sakkinen, Paul Moore, James Morris,
Serge E. Hallyn, Mimi Zohar, James Bottomley, Rob Herring,
Saravana Kannan, Coiby Xu, devicetree, linux-kernel, kexec,
keyrings, linux-mm, linux-security-module, linux-integrity,
Tao Liu
On 8/2/26 07:08, Dave Young wrote:
> On 8/2/26 12:31 AM, Jan Sebastian Götte wrote:
>> On 8/1/26 16:03, Baoquan He wrote:
>>> Note that we usually dont' want to run a lot of work after panic and
>>> before jumping into kdump kernel.
>>
>> I understand. For this reason, I think it's best to keep this default-off. As-is, the notifier list call is timed and on the (slow) ARM64 target I'm using, it takes about 3-5 ms to run. I took the "try lock, skip if locked" approach to keep the risk of this code crashing during panic minimal. In my application, the kdump payload is code that then does a full wipe, taking a couple hundred milliseconds.
>
> Not only about the time used, the panicked kernel is not reliable, any more extra logic can make it even not reliable, any pre-kdump extra logic is not a good idea unless it is a must to ensure kdump working.
>
> Cleaning up secret data can be done with makedumpfile + eppic scripts (see the manual of makedumpfile), or it is even possible to do so in kdump kernel with Tao Liu's improvments for makedumpfile previously (I don't know the status, probably dropped for the time being, but it is possible, cced him).
Thank you for the pointer!
There's two scenarios worth considering. First, in the standard scenario
where you enable this option, then drop into a standard kdump kernel, I
don't think it makes a big difference *when* you do this cleanup since
someone is going to have to dereference these pointers. IMHO a good
reason to do it in the old kernel is that there, the code knows about
the layout of all the data structures. To retroactively do this in the
kdump kernel is much more complicated, since there you have to
reconstruct the structure layouts from symbols or hardcoded struct
layouts, and you have to keep this symbol/layout information perfectly
in sync with the running kernel.
The second scenario is what I'm working on here: I'm not using a normal
kdump kernel, but instead a custom payload that wipes all RAM from start
to end. This payload will wipe all these keys too, but my critical
concern is speed: On the embedded SoCs I'm targeting, the full memory
wipe takes too long (hundreds of ms) for an HSM application, so I want
to do a targeted wipe of just the keys first. The old kernel I think is
the natural place to do this. Adding to that, in my scenario the most
likely trigger of a panic is not something like memory corruption, but a
trigger of the system's tamper alarms, which would leave the old kernel
relatively stable during panic.
I can imagine several possible mitigations for the stability concerns
beyond the default off config option:
* Since the wipe handlers are all really simple, it would be possible to
manually guard every memory access there to ensure they can't fail and
that they don't write to sensitive areas like the dump kernel or the
remaining panic'ing stack. Doing that would only rely on information
(more or less intact stack pointer, kdump kernel area boundaries) that
would be necessary for kdump to succeed anyway.
* And/Or I could extend the patchset to include a mechanism similar to
that in Bradley Morgan's patchset that catches segfaults during wipe,
and then skips the handler causing the fault.
* A last option would be to have the alive kernel prepare some kind of
"wipe this first" structure in its memory during normal operation that
the dump kernel then can pick up to do the actual dirty work. I disfavor
that since it adds double bookkeeping to a lot of places, some of which
could be performance critical.
I've also picked up that I should remove the timing logic since that
could cause instability.
Thanks,
Jan Sebastian
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 0/4] CRASH_ZEROIZE: Wipe secrets before kdump
2026-08-02 5:08 ` Dave Young
2026-08-02 10:20 ` Jan Sebastian Götte
@ 2026-08-03 9:59 ` David Howells
2026-08-03 12:00 ` Dave Young
1 sibling, 1 reply; 14+ messages in thread
From: David Howells @ 2026-08-03 9:59 UTC (permalink / raw)
To: Dave Young
Cc: dhowells, Jan Sebastian Götte, Baoquan He, Andrew Morton,
Mike Rapoport, Pasha Tatashin, Pratyush Yadav, Jarkko Sakkinen,
Paul Moore, James Morris, Serge E. Hallyn, Mimi Zohar,
James Bottomley, Rob Herring, Saravana Kannan, Coiby Xu,
devicetree, linux-kernel, kexec, keyrings, linux-mm,
linux-security-module, linux-integrity, Tao Liu
Dave Young <ruirui.yang@linux.dev> wrote:
> Cleaning up secret data can be done with makedumpfile + eppic scripts (see
> the manual of makedumpfile), or it is even possible to do so in kdump kernel
> with Tao Liu's improvments for makedumpfile previously (I don't know the
> status, probably dropped for the time being, but it is possible, cced him).
Does this represent a leak of the secrets? Also do governmental
standardisation bodies have opinions on what constitutes a leak?
David
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 0/4] CRASH_ZEROIZE: Wipe secrets before kdump
2026-08-03 9:59 ` David Howells
@ 2026-08-03 12:00 ` Dave Young
0 siblings, 0 replies; 14+ messages in thread
From: Dave Young @ 2026-08-03 12:00 UTC (permalink / raw)
To: David Howells
Cc: Jan Sebastian Götte, Baoquan He, Andrew Morton,
Mike Rapoport, Pasha Tatashin, Pratyush Yadav, Jarkko Sakkinen,
Paul Moore, James Morris, Serge E. Hallyn, Mimi Zohar,
James Bottomley, Rob Herring, Saravana Kannan, Coiby Xu,
devicetree, linux-kernel, kexec, keyrings, linux-mm,
linux-security-module, linux-integrity, Tao Liu
On 8/3/26 5:59 PM, David Howells wrote:
> Dave Young <ruirui.yang@linux.dev> wrote:
>
>> Cleaning up secret data can be done with makedumpfile + eppic scripts (see
>> the manual of makedumpfile), or it is even possible to do so in kdump kernel
>> with Tao Liu's improvments for makedumpfile previously (I don't know the
>> status, probably dropped for the time being, but it is possible, cced him).
>
> Does this represent a leak of the secrets? Also do governmental
> standardisation bodies have opinions on what constitutes a leak?
It depends, for the crash case I'm not against to clear sensitive data, the
concern is to avoid extra complexity of logic pre-kdump. Which
government? Sorry I can not answer here.
>
> David
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 0/4] CRASH_ZEROIZE: Wipe secrets before kdump
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
0 siblings, 1 reply; 14+ messages in thread
From: Dave Young @ 2026-08-03 12:12 UTC (permalink / raw)
To: Jan Sebastian Götte, Baoquan He
Cc: Andrew Morton, Mike Rapoport, Pasha Tatashin, Pratyush Yadav,
David Howells, Jarkko Sakkinen, Paul Moore, James Morris,
Serge E. Hallyn, Mimi Zohar, James Bottomley, Rob Herring,
Saravana Kannan, Coiby Xu, devicetree, linux-kernel, kexec,
keyrings, linux-mm, linux-security-module, linux-integrity,
Tao Liu
On 8/2/26 6:20 PM, Jan Sebastian Götte wrote:
> On 8/2/26 07:08, Dave Young wrote:
>> On 8/2/26 12:31 AM, Jan Sebastian Götte wrote:
>>> On 8/1/26 16:03, Baoquan He wrote:
>>>> Note that we usually dont' want to run a lot of work after panic and
>>>> before jumping into kdump kernel.
>>>
>>> I understand. For this reason, I think it's best to keep this default-off. As-is, the notifier list call is timed and on the (slow) ARM64 target I'm using, it takes about 3-5 ms to run. I took the "try lock, skip if locked" approach to keep the risk of this code crashing during panic minimal. In my application, the kdump payload is code that then does a full wipe, taking a couple hundred milliseconds.
>>
>> Not only about the time used, the panicked kernel is not reliable, any more extra logic can make it even not reliable, any pre-kdump extra logic is not a good idea unless it is a must to ensure kdump working.
>>
>> Cleaning up secret data can be done with makedumpfile + eppic scripts (see the manual of makedumpfile), or it is even possible to do so in kdump kernel with Tao Liu's improvments for makedumpfile previously (I don't know the status, probably dropped for the time being, but it is possible, cced him).
>
> Thank you for the pointer!
>
> There's two scenarios worth considering. First, in the standard scenario where you enable this option, then drop into a standard kdump kernel, I don't think it makes a big difference *when* you do this cleanup since someone is going to have to dereference these pointers. IMHO a good reason to do it in the old kernel is that there, the code knows about the layout of all the data structures. To retroactively do this in the kdump kernel is much more complicated, since there you have to reconstruct the structure layouts from symbols or hardcoded struct layouts, and you have to keep this symbol/layout information perfectly in sync with the running kernel.
I know that this is the usual reason people want to do things in 1st
kernel :) Like the crash_kexec_post_notifiers which was introduced for
people to use at their own risk. Is it doable for your case to use
crash_kexec_post_notifiers?
>
> The second scenario is what I'm working on here: I'm not using a normal kdump kernel, but instead a custom payload that wipes all RAM from start to end. This payload will wipe all these keys too, but my critical concern is speed: On the embedded SoCs I'm targeting, the full memory wipe takes too long (hundreds of ms) for an HSM application, so I want to do a targeted wipe of just the keys first. The old kernel I think is the natural place to do this. Adding to that, in my scenario the most likely trigger of a panic is not something like memory corruption, but a trigger of the system's tamper alarms, which would leave the old kernel relatively stable during panic.
>
> I can imagine several possible mitigations for the stability concerns beyond the default off config option:
>
> * Since the wipe handlers are all really simple, it would be possible to manually guard every memory access there to ensure they can't fail and that they don't write to sensitive areas like the dump kernel or the remaining panic'ing stack. Doing that would only rely on information (more or less intact stack pointer, kdump kernel area boundaries) that would be necessary for kdump to succeed anyway.
>
> * And/Or I could extend the patchset to include a mechanism similar to that in Bradley Morgan's patchset that catches segfaults during wipe, and then skips the handler causing the fault.
>
> * A last option would be to have the alive kernel prepare some kind of "wipe this first" structure in its memory during normal operation that the dump kernel then can pick up to do the actual dirty work. I disfavor that since it adds double bookkeeping to a lot of places, some of which could be performance critical.
>
> I've also picked up that I should remove the timing logic since that could cause instability.
>
> Thanks,
> Jan Sebastian
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 0/4] CRASH_ZEROIZE: Wipe secrets before kdump
2026-08-03 12:12 ` Dave Young
@ 2026-08-03 12:54 ` Jan Sebastian Götte
0 siblings, 0 replies; 14+ messages in thread
From: Jan Sebastian Götte @ 2026-08-03 12:54 UTC (permalink / raw)
To: Dave Young, Baoquan He
Cc: Andrew Morton, Mike Rapoport, Pasha Tatashin, Pratyush Yadav,
David Howells, Jarkko Sakkinen, Paul Moore, James Morris,
Serge E. Hallyn, Mimi Zohar, James Bottomley, Rob Herring,
Saravana Kannan, Coiby Xu, devicetree, linux-kernel, kexec,
keyrings, linux-mm, linux-security-module, linux-integrity,
Tao Liu
On 8/3/26 14:12, Dave Young wrote:
> On 8/2/26 6:20 PM, Jan Sebastian Götte wrote:
>> On 8/2/26 07:08, Dave Young wrote:
>>> On 8/2/26 12:31 AM, Jan Sebastian Götte wrote:
>>>> On 8/1/26 16:03, Baoquan He wrote:
>>>>> Note that we usually dont' want to run a lot of work after panic and
>>>>> before jumping into kdump kernel.
>>>>
>>>> I understand. For this reason, I think it's best to keep this default-off. As-is, the notifier list call is timed and on the (slow) ARM64 target I'm using, it takes about 3-5 ms to run. I took the "try lock, skip if locked" approach to keep the risk of this code crashing during panic minimal. In my application, the kdump payload is code that then does a full wipe, taking a couple hundred milliseconds.
>>>
>>> Not only about the time used, the panicked kernel is not reliable, any more extra logic can make it even not reliable, any pre-kdump extra logic is not a good idea unless it is a must to ensure kdump working.
>>>
>>> Cleaning up secret data can be done with makedumpfile + eppic scripts (see the manual of makedumpfile), or it is even possible to do so in kdump kernel with Tao Liu's improvments for makedumpfile previously (I don't know the status, probably dropped for the time being, but it is possible, cced him).
>>
>> Thank you for the pointer!
>>
>> There's two scenarios worth considering. First, in the standard scenario where you enable this option, then drop into a standard kdump kernel, I don't think it makes a big difference *when* you do this cleanup since someone is going to have to dereference these pointers. IMHO a good reason to do it in the old kernel is that there, the code knows about the layout of all the data structures. To retroactively do this in the kdump kernel is much more complicated, since there you have to reconstruct the structure layouts from symbols or hardcoded struct layouts, and you have to keep this symbol/layout information perfectly in sync with the running kernel.
>
> I know that this is the usual reason people want to do things in 1st
> kernel :) Like the crash_kexec_post_notifiers which was introduced for
> people to use at their own risk. Is it doable for your case to use
> crash_kexec_post_notifiers?
I think there's a few reasons why crash_kexec_post_notifiers isn't what
we want here:
1. Enabling/disabling just the key wipe notifiers scattered around the
kernel becomes a bit ugly when they're mixed into the same notifier list.
2. The key wipe should run after other notifiers because by definition
it will corrupt data structures so future operations like any crypto
operations will fail in interesting ways. Having two separate notifier
chains is an easy way to separate them.
3. For my use case, the stability argument is exactly why I want to run
only the wipe, but not crash_kexec_post_notifiers. There are many things
in crash_kexec_post_notifiers. They take precious time, and they
themselves can cause instability. For example, the remoteproc panic
notifier can (intentionally) wait up to several hundred milliseconds,
which is too long in my use case.
Thanks,
Jan Sebastian
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2026-08-03 13:37 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 2/4] kexec: add CRASH_ZEROIZE to wipe secrets before kdump Jan Sebastian Götte
2026-07-31 15:46 ` [PATCH 3/4] mm/secretmem: zeroize secret pages " Jan Sebastian Götte
2026-07-31 15:46 ` [PATCH 4/4] security/keys: zeroize key payloads " Jan Sebastian Götte
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 3/4] mm/secretmem: zeroize secret pages " Jan Sebastian Götte
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox