[PATCH v2 00/13] CRASH_WIPE_SECRETS: Wipe secrets before kdump (was: CRASH_ZEROIZE)

Jan Sebastian Götte posted 13 patches 1 month, 2 weeks ago
Documentation/security/keys/core.rst      |  13 +++
arch/arm64/include/asm/set_memory.h       |   2 +
arch/arm64/kernel/machine_kexec.c         |  20 ++++
arch/arm64/mm/pageattr.c                  |  21 +++++
crypto/api.c                              |  78 +++++++++++++--
crypto/asymmetric_keys/asymmetric_type.c  |  11 +++
crypto/asymmetric_keys/pkcs7_key_type.c   |   1 +
crypto/asymmetric_keys/public_key.c       |  15 +++
drivers/md/dm-crypt.c                     | 151 ++++++++++++++++++++++++++----
drivers/nvme/common/keyring.c             |   1 +
fs/crypto/block.c                         |  10 ++
fs/crypto/fscrypt_private.h               |  15 +++
fs/crypto/keyring.c                       |  68 +++++++++++++-
fs/crypto/keysetup_v1.c                   |  15 +++
fs/nfs/nfs4idmap.c                        |   2 +
fs/super.c                                |  29 ++++++
include/keys/asymmetric-subtype.h         |   5 +
include/keys/user-type.h                  |   1 +
include/linux/crash_core.h                |  37 ++++++++
include/linux/crypto.h                    |  11 +++
include/linux/fs.h                        |   4 +
include/linux/key-type.h                  |   9 ++
include/linux/set_memory.h                |  17 +++-
kernel/Kconfig.kexec                      |  16 ++++
kernel/crash_core.c                       |  52 ++++++++++
mm/secretmem.c                            |  53 +++++++++++
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 +++
security/keys/big_key.c                   |  17 ++++
security/keys/encrypted-keys/encrypted.c  |  13 +++
security/keys/key.c                       |  43 +++++++++
security/keys/trusted-keys/trusted_core.c |  15 +++
security/keys/user_defined.c              |  15 +++
36 files changed, 808 insertions(+), 27 deletions(-)
[PATCH v2 00/13] CRASH_WIPE_SECRETS: Wipe secrets before kdump (was: CRASH_ZEROIZE)
Posted by Jan Sebastian Götte 1 month, 2 weeks ago
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 handlers for the major locations I found where
having this sort of thing makes sense. Notable omissions right now are
the Ceph and CIFS subsystems. I have WIP patches for these, but since I
can't easily test them right now, I omitted them from this patch set for
now. Currently included locations are:

* various key types in security/keys
* rxrpc
* fscrypt
* dm-crypt
* crypto tfm instances
* secretmem (which I'm going to start using in my application)

I've verified this patch series on an ARM64 target using the helper code
at https://codeberg.org/yasec/crash-wipe-test . This code stuffs the
affected kernel subsystems with keys and secret data, then crashes the
system, takes a RAM dump and verifies the dump is clean of secrets. Note
that the helper code is partially LLM-generated, so read with care. It
passes a positive control test with the config option disabled.

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,
ARM64) embedded target.

Signed-off-by: Jan Sebastian Götte <linux@jaseg.de>
---
Changes in v2:
- New keyring key types
- New handlers: rxrpc, fscrypt, dm-crypt and crypto tfm
- Renamed from "zeroize" to "wipe"
- Add ARM64-specific cache flush logic
- Link to v1: https://patch.msgid.link/20260731162739.158320-1-linux@jaseg.de

To: Andrew Morton <akpm@linux-foundation.org>
To: Baoquan He <baoquan.he@linux.dev>
To: Mike Rapoport <rppt@kernel.org>
To: Pasha Tatashin <pasha.tatashin@soleen.com>
To: Pratyush Yadav <pratyush@kernel.org>
To: Dave Young <ruirui.yang@linux.dev>
To: Catalin Marinas <catalin.marinas@arm.com>
To: Will Deacon <will@kernel.org>
To: David Howells <dhowells@redhat.com>
To: Jarkko Sakkinen <jarkko@kernel.org>
To: Jonathan Corbet <corbet@lwn.net>
To: Shuah Khan <skhan@linuxfoundation.org>
To: Paul Moore <paul@paul-moore.com>
To: James Morris <jmorris@namei.org>
To: "Serge E. Hallyn" <serge@hallyn.com>
To: Lukas Wunner <lukas@wunner.de>
To: Ignat Korchagin <ignat@linux.win>
To: Herbert Xu <herbert@gondor.apana.org.au>
To: "David S. Miller" <davem@davemloft.net>
To: Keith Busch <kbusch@kernel.org>
To: Jens Axboe <axboe@kernel.dk>
To: Christoph Hellwig <hch@lst.de>
To: Sagi Grimberg <sagi@grimberg.me>
To: Trond Myklebust <trondmy@kernel.org>
To: Anna Schumaker <anna@kernel.org>
To: Mimi Zohar <zohar@linux.ibm.com>
To: James Bottomley <James.Bottomley@HansenPartnership.com>
To: Marc Dionne <marc.dionne@auristor.com>
To: Eric Dumazet <edumazet@google.com>
To: Jakub Kicinski <kuba@kernel.org>
To: Paolo Abeni <pabeni@redhat.com>
To: Simon Horman <horms@kernel.org>
To: Eric Biggers <ebiggers@kernel.org>
To: "Theodore Y. Ts'o" <tytso@mit.edu>
To: Jaegeuk Kim <jaegeuk@kernel.org>
To: Alexander Viro <viro@zeniv.linux.org.uk>
To: Christian Brauner <brauner@kernel.org>
To: Jan Kara <jack@suse.cz>
To: Alasdair Kergon <agk@redhat.com>
To: Mike Snitzer <snitzer@kernel.org>
To: Mikulas Patocka <mpatocka@redhat.com>
To: Benjamin Marzinski <bmarzins@redhat.com>
Cc: kexec@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-mm@kvack.org
Cc: keyrings@vger.kernel.org
Cc: linux-doc@vger.kernel.org
Cc: linux-security-module@vger.kernel.org
Cc: linux-crypto@vger.kernel.org
Cc: linux-nvme@lists.infradead.org
Cc: linux-nfs@vger.kernel.org
Cc: linux-integrity@vger.kernel.org
Cc: linux-afs@lists.infradead.org
Cc: netdev@vger.kernel.org
Cc: linux-fscrypt@vger.kernel.org
Cc: linux-fsdevel@vger.kernel.org
Cc: dm-devel@lists.linux.dev

---
Jan Sebastian Götte (13):
      kexec: add CRASH_WIPE_SECRETS to wipe secrets before kdump
      crash-core: Flush caches on CRASH_WIPE_SECRETS
      arm64/mm: add set_direct_map_default_nosplit()
      mm/secretmem: wipe secret pages before kdump
      security/keys: wipe key payloads before kdump
      security/keys: implement wipe op for user-type keys
      security/keys: implement wipe op for big_key
      security/keys: implement wipe op for trusted and encrypted keys
      security/keys: implement wipe op for asymmetric keys
      rxrpc: implement wipe op for rxrpc keys
      fscrypt: wipe master keys before kdump
      crypto: api - wipe tfm contexts before kdump
      dm crypt: wipe key material before kdump

 Documentation/security/keys/core.rst      |  13 +++
 arch/arm64/include/asm/set_memory.h       |   2 +
 arch/arm64/kernel/machine_kexec.c         |  20 ++++
 arch/arm64/mm/pageattr.c                  |  21 +++++
 crypto/api.c                              |  78 +++++++++++++--
 crypto/asymmetric_keys/asymmetric_type.c  |  11 +++
 crypto/asymmetric_keys/pkcs7_key_type.c   |   1 +
 crypto/asymmetric_keys/public_key.c       |  15 +++
 drivers/md/dm-crypt.c                     | 151 ++++++++++++++++++++++++++----
 drivers/nvme/common/keyring.c             |   1 +
 fs/crypto/block.c                         |  10 ++
 fs/crypto/fscrypt_private.h               |  15 +++
 fs/crypto/keyring.c                       |  68 +++++++++++++-
 fs/crypto/keysetup_v1.c                   |  15 +++
 fs/nfs/nfs4idmap.c                        |   2 +
 fs/super.c                                |  29 ++++++
 include/keys/asymmetric-subtype.h         |   5 +
 include/keys/user-type.h                  |   1 +
 include/linux/crash_core.h                |  37 ++++++++
 include/linux/crypto.h                    |  11 +++
 include/linux/fs.h                        |   4 +
 include/linux/key-type.h                  |   9 ++
 include/linux/set_memory.h                |  17 +++-
 kernel/Kconfig.kexec                      |  16 ++++
 kernel/crash_core.c                       |  52 ++++++++++
 mm/secretmem.c                            |  53 +++++++++++
 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 +++
 security/keys/big_key.c                   |  17 ++++
 security/keys/encrypted-keys/encrypted.c  |  13 +++
 security/keys/key.c                       |  43 +++++++++
 security/keys/trusted-keys/trusted_core.c |  15 +++
 security/keys/user_defined.c              |  15 +++
 36 files changed, 808 insertions(+), 27 deletions(-)
---
base-commit: a0dbb7d3457bdebe2dbe198bd08bf9690be5f1ec
change-id: 20260811-crash-zeroize-rework-bb1a5d917577

Best regards,
--  
Jan Sebastian Götte <linux@jaseg.de>

Re: [PATCH v2 00/13] CRASH_WIPE_SECRETS: Wipe secrets before kdump (was: CRASH_ZEROIZE)
Posted by Eric Biggers 1 month, 2 weeks ago
On Tue, Aug 11, 2026 at 07:52:49PM +0200, 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.
> 
> 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 handlers for the major locations I found where
> having this sort of thing makes sense. Notable omissions right now are
> the Ceph and CIFS subsystems. I have WIP patches for these, but since I
> can't easily test them right now, I omitted them from this patch set for
> now. Currently included locations are:
> 
> * various key types in security/keys
> * rxrpc
> * fscrypt
> * dm-crypt
> * crypto tfm instances
> * secretmem (which I'm going to start using in my application)
> 
> I've verified this patch series on an ARM64 target using the helper code
> at https://codeberg.org/yasec/crash-wipe-test . This code stuffs the
> affected kernel subsystems with keys and secret data, then crashes the
> system, takes a RAM dump and verifies the dump is clean of secrets. Note
> that the helper code is partially LLM-generated, so read with care. It
> passes a positive control test with the config option disabled.
> 
> 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,
> ARM64) embedded target.

Can we not?  It's already hard enough to zeroize keys and data at the
normal end of their lifetime in the kernel: that's something that is
always a struggle, with fix patches regularly going by for many years
and many subsystems never fixed at all.  If we can barely even do that,
we aren't going to be able to correctly and completely implement and
maintain separate zeroization code for every kernel subsystem that runs
only on kernel panics and has special constraints, like not being able
to take locks.

This is never going to be done either, with the scope always wanting to
grow to include other keys and data.  You may think this series covers
"almost everything" but it's actually not even close.

Could you perhaps narrow the scope to one or two things that actually
are useful and can reasonably be supported for the application?  For
example, secretmem seems to be the only thing you mentioned that you're
actually planning to use.

- Eric
Re: [PATCH v2 00/13] CRASH_WIPE_SECRETS: Wipe secrets before kdump (was: CRASH_ZEROIZE)
Posted by Jan Sebastian Götte 1 month, 2 weeks ago
On 8/11/26 20:20, Eric Biggers wrote:
> On Tue, Aug 11, 2026 at 07:52:49PM +0200, 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.
>>
>> 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 handlers for the major locations I found where
>> having this sort of thing makes sense. Notable omissions right now are
>> the Ceph and CIFS subsystems. I have WIP patches for these, but since I
>> can't easily test them right now, I omitted them from this patch set for
>> now. Currently included locations are:
>>
>> * various key types in security/keys
>> * rxrpc
>> * fscrypt
>> * dm-crypt
>> * crypto tfm instances
>> * secretmem (which I'm going to start using in my application)
>>
>> I've verified this patch series on an ARM64 target using the helper code
>> at https://codeberg.org/yasec/crash-wipe-test . This code stuffs the
>> affected kernel subsystems with keys and secret data, then crashes the
>> system, takes a RAM dump and verifies the dump is clean of secrets. Note
>> that the helper code is partially LLM-generated, so read with care. It
>> passes a positive control test with the config option disabled.
>>
>> 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,
>> ARM64) embedded target.
> 
> Can we not?  It's already hard enough to zeroize keys and data at the
> normal end of their lifetime in the kernel: that's something that is
> always a struggle, with fix patches regularly going by for many years
> and many subsystems never fixed at all.  If we can barely even do that,
> we aren't going to be able to correctly and completely implement and
> maintain separate zeroization code for every kernel subsystem that runs
> only on kernel panics and has special constraints, like not being able
> to take locks.

These crash wipe code paths are less critical than places where you'd 
use memzero_explicit or kfree_sensitive. They are "only" a defense in 
depth / hardening measure. For most of these, if the crash happens at 
the exact time when data structures are being modified or when things 
are being intialized/deinitialized, they can skip things so they can 
never be 100% reliable anyway.

It's not realistic to clean *all* sensitive data in the first place, 
since that would include plaintext as well, which would mean cleaning 
the entire page cache which would be too complex, take too long, and 
destroy forensic evidence that people might want to keep intact for 
regular kdump uses.

> This is never going to be done either, with the scope always wanting to
> grow to include other keys and data.  You may think this series covers
> "almost everything" but it's actually not even close.

I'm sure there's always more. In my particular application, I'm using 
this not for complete coverage (for that I have another full memory wipe 
afterwards), but for speed - I want the obviously sensitive stuff like 
keys gone as fast as possible, with the full wipe cleaning up whatever 
the fast wipe here missed.

> Could you perhaps narrow the scope to one or two things that actually
> are useful and can reasonably be supported for the application?  For
> example, secretmem seems to be the only thing you mentioned that you're
> actually planning to use.

I'm open to whittling down the scope of this series. In my use case I 
need at least secretmem as well as dm-crypt, which then pulls in the 
crypto tfm stuff. Personally, I could live without the other bits, I 
just thought they'd be easy enough to include.

- Jan
Re: [PATCH v2 00/13] CRASH_WIPE_SECRETS: Wipe secrets before kdump (was: CRASH_ZEROIZE)
Posted by Eric Biggers 1 month, 2 weeks ago
On Tue, Aug 11, 2026 at 09:38:20PM +0200, Jan Sebastian Götte wrote:
> > Could you perhaps narrow the scope to one or two things that actually
> > are useful and can reasonably be supported for the application?  For
> > example, secretmem seems to be the only thing you mentioned that you're
> > actually planning to use.
> 
> I'm open to whittling down the scope of this series. In my use case I need
> at least secretmem as well as dm-crypt, which then pulls in the crypto tfm
> stuff. Personally, I could live without the other bits, I just thought
> they'd be easy enough to include.

Please do reduce the scope.

Note that even if dm-crypt is in scope, "crypto: api - wipe tfm contexts
before kdump" is neither required nor sufficient.  For one, dm-crypt has
its own copy of the key.  The wiping should be done by the kernel
feature(s) that need it, as they know what actually needs to be wiped,
and they can do so without the bottleneck of a new global list.

- Eric