mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3 00/12] CRASH_MEMACTION: describe pages to a kdump kernel (was: CRASH_WIPE_SECRETS)
@ 2026-09-28 17:17 Jan Sebastian Götte
  2026-09-28 17:17 ` [PATCH v3 01/12] kexec: Add a crash memaction registry Jan Sebastian Götte
                   ` (13 more replies)
  0 siblings, 14 replies; 29+ messages in thread
From: Jan Sebastian Götte @ 2026-09-28 17:17 UTC (permalink / raw)
  To: Jonathan Corbet, Shuah Khan, Randy Dunlap, Rob Herring,
	Saravana Kannan, Andrew Morton, Baoquan He, Mike Rapoport,
	Pasha Tatashin, Pratyush Yadav, Dave Young, Greg Kroah-Hartman,
	Rafael J. Wysocki, Danilo Krummrich, Muchun Song, Oscar Salvador,
	David Hildenbrand, Vlastimil Babka, Suren Baghdasaryan,
	Michal Hocko, Brendan Jackman, Johannes Weiner, Zi Yan,
	Catalin Marinas, Will Deacon, Mark Rutland, Alasdair Kergon,
	Mike Snitzer, Mikulas Patocka, Benjamin Marzinski, Herbert Xu,
	David S. Miller, Mimi Zohar, David Howells, Jarkko Sakkinen,
	Paul Moore, James Morris, Serge E. Hallyn, James Bottomley,
	Liam R. Howlett, Lorenzo Stoakes, Jann Horn, Pedro Falcato,
	Rik van Riel, Harry Yoo, Lance Yang, Baolin Wang, Nico Pache,
	Ryan Roberts, Dev Jain, Barry Song, Usama Arif, Kiryl Shutsemau,
	Matthew Brost, Joshua Hahn, Byungchul Park, Gregory Price,
	Ying Huang, Alistair Popple, Peter Xu, Arnd Bergmann
  Cc: Eric Biggers, linux-doc, linux-kernel, devicetree, kexec,
	driver-core, linux-mm, linux-arm-kernel, dm-devel, linux-crypto,
	linux-integrity, keyrings, linux-security-module, linux-fsdevel,
	linux-arch, Jan Sebastian Götte

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 frmo start to end. However, writing
all of RAM, especially on an embedded target, is rather slow. For this
reason, I propose a new crash_memaction mechanism that lets the old
kernel indicate marked memory areas to the kdump kernel at page
granularity.

I will be using this mechanism to indicate "secret" memory ranges for
early wiping by my kdump payload. After discussion with Baoquan He early
August, the patchset includes a second flag that can be used to indicate
"cache" memory that the kdump kernel may want to skip when creating the
dumpfile.

The record is a bitmap with one bit per page, allocated at boot. It
reaches the kdump kernel as a PT_NOTE named MEMACTION. Marking is a
lock-free atomic bitmap update with no allocation, so it is safe in any
context.

The feature is gated by a static key that is patched in only when the
kernel is booted with a crash_memaction= parameter indicating which
flags to pass to the kdump kernel. The parameter sets the meaning of the
bitmap bits to both kernels.

Marking Memory
==============

Theres both a kernel and a userspace interface to mark memory.

In-kernel, crash_memaction_mark() takes a virtual address range and a
type. Marking has page granularity. To support smaller objects,
patch 2 adds a "secret pool" kmem_buckets instance whose backing pages
are marked SECRET. Patches 5 to 7 move dm-crypt volume keys and IV
seeds, crypto tfm contexts, and the payloads of the user, trusted, and
encrypted key types into this pool. Keeping keys in dedicated slab
caches also provides some defence in depth against use-after-free and
out-of-bounds reads, independently of what I'm doing here with kdump.

For userspace mappings, madvise() with MADV_CRASH_SECRET or
MADV_CRASH_CACHE sets a new VMA flag, VM_CRASH_MARK. Folios mapped into
a marked VMA are registered as they arrive in rmap.

A mark lasts until the page frame is allocated again, so it is cleared
in post_alloc_hook() rather than when freed to account for leftover
data. Hugetlb folios reused from the pool bypass post_alloc_hook(), so
their marks are cleared on dequeue instead.

Overhead
========

Measured on arm64 (QRB2210, 4x Cortex-A53, 3.6G) at next-20260922, three
boots of the same tree:

    k0  CONFIG_CRASH_MEMACTION=n
    k1  CONFIG_CRASH_MEMACTION=y, no crash_memaction=
    k2  CONFIG_CRASH_MEMACTION=y, crash_memaction=secret

k1 and k2 are the same kernel image. The workload rebuilds mm/ of a
kernel tree a few times with make -j4.

    k0  157.05 s median (n=8, range 156.51-157.77)
    k1  158.23 s median (n=8, range 157.96-159.69)
    k2  157.42 s median (n=8, range 156.97-163.24)

Against k0 that is +0.75% for k1 and +0.24% for k2, both within
measurement noise.

Out of scope here
=================

This series only records the page types in the note. The secret type is
wired up with some kernel users related to disk encryption. The cache
type is not wired up with any kernel users (but can be used from
userspace).

The bitmap is sized from the memblock memory map at boot and is never
resized. Memory added by hotplug is therefore not covered by a bitmap
and cannot be marked. I'm focused on embedded targets that don't support
hotplug anyway.

Signed-off-by: Jan Sebastian Götte <linux@jaseg.de>
---
Changes in v3:
- Use page bitmap instead of range-based registry
- Move smaller allocations into secret_pool buckets
- Link to v3: https://patch.msgid.link/20260811-crash-zeroize-rework-v2-0-9561d13c2340@jaseg.de

To: Jonathan Corbet <corbet@lwn.net>
To: Shuah Khan <skhan@linuxfoundation.org>
To: Randy Dunlap <rdunlap@infradead.org>
To: Rob Herring <robh@kernel.org>
To: Saravana Kannan <saravanak@kernel.org>
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: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: "Rafael J. Wysocki" <rafael@kernel.org>
To: Danilo Krummrich <dakr@kernel.org>
To: Muchun Song <muchun.song@linux.dev>
To: Oscar Salvador <osalvador@suse.de>
To: David Hildenbrand <david@kernel.org>
To: Vlastimil Babka <vbabka@kernel.org>
To: Suren Baghdasaryan <surenb@google.com>
To: Michal Hocko <mhocko@suse.com>
To: Brendan Jackman <brendan.jackman@linux.dev>
To: Johannes Weiner <hannes@cmpxchg.org>
To: Zi Yan <ziy@nvidia.com>
To: Catalin Marinas <catalin.marinas@arm.com>
To: Will Deacon <will@kernel.org>
To: Mark Rutland <mark.rutland@arm.com>
To: Alasdair Kergon <agk@redhat.com>
To: Mike Snitzer <snitzer@kernel.org>
To: Mikulas Patocka <mpatocka@redhat.com>
To: Benjamin Marzinski <bmarzins@redhat.com>
To: Herbert Xu <herbert@gondor.apana.org.au>
To: "David S. Miller" <davem@davemloft.net>
To: Mimi Zohar <zohar@linux.ibm.com>
To: David Howells <dhowells@redhat.com>
To: Jarkko Sakkinen <jarkko@kernel.org>
To: Paul Moore <paul@paul-moore.com>
To: James Morris <jmorris@namei.org>
To: "Serge E. Hallyn" <serge@hallyn.com>
To: James Bottomley <James.Bottomley@HansenPartnership.com>
To: "Liam R. Howlett" <liam@infradead.org>
To: Lorenzo Stoakes <ljs@kernel.org>
To: Jann Horn <jannh@google.com>
To: Pedro Falcato <pfalcato@suse.de>
To: Rik van Riel <riel@surriel.com>
To: Harry Yoo <harry@kernel.org>
To: Lance Yang <lance.yang@linux.dev>
To: Baolin Wang <baolin.wang@linux.alibaba.com>
To: Nico Pache <nico.pache@linux.dev>
To: Ryan Roberts <ryan.roberts@arm.com>
To: Dev Jain <dev.jain@arm.com>
To: Barry Song <baohua@kernel.org>
To: Usama Arif <usama.arif@linux.dev>
To: Kiryl Shutsemau <kas@kernel.org>
To: Matthew Brost <matthew.brost@intel.com>
To: Joshua Hahn <joshua.hahnjy@gmail.com>
To: Byungchul Park <byungchul@sk.com>
To: Gregory Price <gourry@gourry.net>
To: Ying Huang <ying.huang@linux.alibaba.com>
To: Alistair Popple <apopple@nvidia.com>
To: Peter Xu <peterx@redhat.com>
To: Arnd Bergmann <arnd@arndb.de>
Cc: linux-doc@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: devicetree@vger.kernel.org
Cc: kexec@lists.infradead.org
Cc: driver-core@lists.linux.dev
Cc: linux-mm@kvack.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: dm-devel@lists.linux.dev
Cc: linux-crypto@vger.kernel.org
Cc: linux-integrity@vger.kernel.org
Cc: keyrings@vger.kernel.org
Cc: linux-security-module@vger.kernel.org
Cc: linux-fsdevel@vger.kernel.org
Cc: linux-arch@vger.kernel.org

---
Jan Sebastian Götte (12):
      kexec: Add a crash memaction registry
      lib, kexec: Add a secret pool for key material
      mm: Wire up the crash memaction registry
      arm64: Enable the crash memaction registry
      dm crypt: Allocate key material from the secret pool
      crypto: api - Allocate tfms from the secret pool
      security/keys: Allocate key payloads from the secret pool
      mm: Add VM_CRASH_MARK
      mm/rmap: Mark folios mapped into crash_memaction-marked VMAs
      mm/madvise: Add MADV_CRASH_SECRET, MADV_CRASH_CACHE and MADV_CRASH_RESET
      Documentation/mm: Document the crash memaction registry
      kexec: Expose the crash memaction bitmap in debugfs

 Documentation/admin-guide/kernel-parameters.txt |   9 +
 Documentation/mm/crash_memaction.rst            |  68 ++++
 Documentation/mm/index.rst                      |   1 +
 MAINTAINERS                                     |   4 +
 arch/arm64/Kconfig                              |   3 +
 crypto/api.c                                    |   9 +-
 drivers/md/dm-crypt.c                           |  19 +-
 drivers/of/kexec.c                              |   7 +
 fs/proc/task_mmu.c                              |   3 +
 include/linux/crash_memaction.h                 |  86 +++++
 include/linux/kexec.h                           |   6 +
 include/linux/mm.h                              |   9 +
 include/linux/rmap.h                            |   5 +-
 include/linux/secret_pool.h                     |  47 +++
 include/uapi/asm-generic/mman-common.h          |   4 +
 kernel/Kconfig.kexec                            |  39 ++
 kernel/crash_core.c                             | 475 ++++++++++++++++++++++++
 kernel/kexec_core.c                             |   4 +
 kernel/kexec_file.c                             |  10 +
 kernel/ksysfs.c                                 |  15 +
 lib/Makefile                                    |   1 +
 lib/secret_pool.c                               |  27 ++
 mm/huge_memory.c                                |   2 +
 mm/hugetlb.c                                    |  10 +-
 mm/madvise.c                                    | 132 +++++++
 mm/migrate.c                                    |   2 +-
 mm/mm_init.c                                    |   3 +
 mm/page_alloc.c                                 |   6 +
 mm/rmap.c                                       |   8 +
 mm/userfaultfd.c                                |   1 +
 security/keys/encrypted-keys/encrypted.c        |   5 +-
 security/keys/trusted-keys/trusted_core.c       |   3 +-
 security/keys/user_defined.c                    |   3 +-
 33 files changed, 1006 insertions(+), 20 deletions(-)
---
base-commit: a8c591ed6b672915e0be57843f943a2a723aff40
change-id: 20260925-crash-memaction-upstream-20260921-6e3cfac5a389

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


^ permalink raw reply	[flat|nested] 29+ messages in thread

end of thread, other threads:[~2026-09-28 19:20 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-28 17:17 [PATCH v3 00/12] CRASH_MEMACTION: describe pages to a kdump kernel (was: CRASH_WIPE_SECRETS) Jan Sebastian Götte
2026-09-28 17:17 ` [PATCH v3 01/12] kexec: Add a crash memaction registry Jan Sebastian Götte
2026-09-28 17:36   ` sashiko-bot
2026-09-28 17:17 ` [PATCH v3 02/12] lib, kexec: Add a secret pool for key material Jan Sebastian Götte
2026-09-28 17:36   ` sashiko-bot
2026-09-28 17:17 ` [PATCH v3 03/12] mm: Wire up the crash memaction registry Jan Sebastian Götte
2026-09-28 17:38   ` sashiko-bot
2026-09-28 17:17 ` [PATCH v3 04/12] arm64: Enable " Jan Sebastian Götte
2026-09-28 17:35   ` sashiko-bot
2026-09-28 17:17 ` [PATCH v3 05/12] dm crypt: Allocate key material from the secret pool Jan Sebastian Götte
2026-09-28 17:33   ` sashiko-bot
2026-09-28 17:17 ` [PATCH v3 06/12] crypto: api - Allocate tfms " Jan Sebastian Götte
2026-09-28 17:32   ` sashiko-bot
2026-09-28 17:17 ` [PATCH v3 07/12] security/keys: Allocate key payloads " Jan Sebastian Götte
2026-09-28 17:32   ` sashiko-bot
2026-09-28 17:17 ` [PATCH v3 08/12] mm: Add VM_CRASH_MARK Jan Sebastian Götte
2026-09-28 17:34   ` sashiko-bot
2026-09-28 17:17 ` [PATCH v3 09/12] mm/rmap: Mark folios mapped into crash_memaction-marked VMAs Jan Sebastian Götte
2026-09-28 17:41   ` sashiko-bot
2026-09-28 17:17 ` [PATCH v3 10/12] mm/madvise: Add MADV_CRASH_SECRET, MADV_CRASH_CACHE and MADV_CRASH_RESET Jan Sebastian Götte
2026-09-28 17:35   ` sashiko-bot
2026-09-28 17:17 ` [PATCH v3 11/12] Documentation/mm: Document the crash memaction registry Jan Sebastian Götte
2026-09-28 17:31   ` sashiko-bot
2026-09-28 17:18 ` [PATCH v3 12/12] kexec: Expose the crash memaction bitmap in debugfs Jan Sebastian Götte
2026-09-28 17:38   ` sashiko-bot
2026-09-28 19:19   ` Randy Dunlap
2026-09-28 17:49 ` [PATCH v3 00/12] CRASH_MEMACTION: describe pages to a kdump kernel (was: CRASH_WIPE_SECRETS) Lorenzo Stoakes (ARM)
2026-09-28 18:58   ` David Hildenbrand (Arm)
2026-09-28 19:02 ` David Hildenbrand (Arm)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®