[PATCH 0/2] crash_dump: fix dm-crypt key description lifetime
From: Yingjie Wang
Date: Thu Dec 03 2026 - 03:24:27 EST
The description attribute of /sys/kernel/config/crash_dm_crypt_keys/<key>
has no locking of its own, and configfs only serializes attribute I/O per
open file. Patch 1 adds a per-key mutex covering the store, the show and
the copy made by build_keys_header() during kexec_file_load(). Patch 2
frees the description when a key directory is removed.
Relation to Coiby's "Bug fixes and enhancements for kdump LUKS support"
v5 [1]:
- That series does not touch the description attribute. Its patch 3/9
holds config_keys_subsys.su_mutex across crash_load_dm_crypt_keys(),
but configfs takes su_mutex only for directory operations, not for
attribute reads and writes, so these races remain with it applied.
- This series does not fix kexec_file_load() racing with mkdir/rmdir of
a key directory. build_keys_header() walks cg_children without
su_mutex, so removing a key during the walk is already a
use-after-free of the config_key itself. v5 3/9 fixes that: with it,
a key that build_keys_header() sees stays linked, so it cannot be
released (which frees its lock and description) until su_mutex is
dropped. The lock order is then su_mutex -> config_key->lock; the
store and show paths never take su_mutex.
The two series apply on top of each other in either order, with the
same result. This one is based on mainline; kernel/crash_dump_dm_crypt.c
is the same in mm-nonmm-unstable and linux-next.
Testing (x86_64 QEMU guest, KASAN, PROVE_LOCKING, KMEMLEAK,
crashkernel=256M, booted with oops=panic panic_on_warn=1):
unpatched patched
3 writers + 3 readers, separate fds double-free clean, 120 s
1 writer + 7 readers UAF in show clean, 120 s
1 writer vs. kexec_file_load(crash) UAF in clean, 300 s
build_keys_header
create, describe, remove 50 keys 47 kmemleak reports 0 reports
In the kexec_file_load() test no logon key matches the description, so
each of the 23050 load attempts copied the description and then failed
with ENOKEY. A functional check (store/read back, 128- and 129-character
and empty descriptions, count, and loading a crash image with a matching
logon key using KEXEC_FILE_DEBUG to confirm "Loaded dm crypt keys")
passes on both kernels.
With the v5 series (1-8/9) applied alone, the first three tests still
hit the double-free, the UAF in show and the UAF in build_keys_header().
With both series applied, all four tests are clean, and so is a 120 s
run that removes and recreates a key directory in a loop (678439 times)
during kexec_file_load() (4147 load attempts), with no lockdep reports.
The reproducers are available on request.
Not tested: arm64 and powerpc, which call crash_load_dm_crypt_keys() from
their own kexec_file loaders.
[1] https://lore.kernel.org/r/20260909003657.1570544-1-coiby.xu@xxxxxxxxx
Yingjie Wang (2):
crash_dump: serialize access to dm-crypt key descriptions
crash_dump: free dm-crypt key description on release
kernel/crash_dump_dm_crypt.c | 33 +++++++++++++++++++++++++++------
1 file changed, 27 insertions(+), 6 deletions(-)
base-commit: 5a29cfaf51105039d156dd8a61d2783e8b653667
--
2.43.0