kdump: Enable LUKS-encrypted dump target support in ARM64 and PowerPC
Subsystems (7)
v5 cover kdump: Enable LUKS-encrypted dump target support in ARM64 and PowerPC
CONFIG_CRASH_DM_CRYPT has been introduced to support LUKS-encrypted device dump target by addressing two challenges [1],
- Kdump kernel may not be able to decrypt the LUKS partition. For some machines, a system administrator may not have a chance to enter the password to decrypt the device in kdump initramfs after the 1st kernel crashes
- LUKS2 by default use the memory-hard Argon2 key derivation function which is quite memory-consuming compared to the limited memory reserved for kdump.
To also enable this feature for ARM64 and PowerPC, we need to add a device tree property dmcryptkeys [2] as similar to elfcorehdr to pass the memory address of the stored info of dm-crypt keys to the kdump kernel.
[1] https://lore.kernel.org/all/[email protected]/
[2] https://github.com/devicetree-org/dt-schema/pull/181
v5
- Improve commit msg [Christophe]
- Fix a compiling error found by kernel test robot
v4
- Make arch-specific code more succinct by printing more logs in arch-independent code [Will Deacon]
- Also use device tree for PowerPC to pass memory address of dm-crypt keys info
- powerpc v2 patch that passes the dmcryptkeys kernel cmdline
parameter:
https://lore.kernel.org/all/[email protected]/v3
- Delete the property after reading it [Rob Herring]
v2
- Krzysztof
- Use imperative mood for commit message
- Add dt-schema ABI Documentation
https://github.com/devicetree-org/dt-schema/pull/181
- Don't print dm-crypt keys address via pr_debug
Coiby Xu (3):
crash_dump/dm-crypt: Don't print in arch-specific code
crash: Align the declaration of crash_load_dm_crypt_keys with
CONFIG_CRASH_DM_CRYPT
arm64,ppc64le/kdump: pass dm-crypt keys to kdump kernel
arch/arm64/kernel/machine_kexec_file.c | 4 ++++ arch/powerpc/kexec/elf_64.c | 4 ++++ arch/x86/kernel/kexec-bzimage64.c | 6 +----- drivers/of/fdt.c | 21 +++++++++++++++++++++ drivers/of/kexec.c | 19 +++++++++++++++++++ include/linux/crash_core.h | 14 +++++++------- kernel/crash_dump_dm_crypt.c | 7 +++++-- 7 files changed, 61 insertions(+), 14 deletions(-)
base-commit: 7dff99b354601dd01829e1511711846e04340a69
Signature · 1 line
2.53.0
PATCH v5 1/3 crash_dump/dm-crypt: Don't print in arch-specific code
When the vmcore dumping target is not a LUKS-encrypted target, it's expected that there is no dm-crypt key thus no need to return -ENOENT. Also print more logs in crash_load_dm_crypt_keys. The benefit is arch-specific code can be more succinct.
--- arch/x86/kernel/kexec-bzimage64.c | 6 +----- kernel/crash_dump_dm_crypt.c | 7 +++++-- 2 files changed, 6 insertions(+), 7 deletions(-)
arch/x86/kernel/kexec-bzimage64.c +1 -5
@@ -525,12 +525,8 @@ static void *bzImage64_load(struct kimage *image, char *kernel,if (ret)return ERR_PTR (ret); ret =crash_load_dm_crypt_keys (image); -if (ret == -ENOENT ) { -kexec_dprintk ("No dm crypt key to load\n" ); - }else if (ret) { -pr_err ("Failed to load dm crypt keys\n" ); +if (ret)return ERR_PTR (ret); - }if (image->dm_crypt_keys_addr && cmdline_len +MAX_ELFCOREHDR_STR_LEN +MAX_DMCRYPTKEYS_STR_LEN > header->cmdline_size) {
kernel/crash_dump_dm_crypt.c +5 -2
@@ -414,14 +414,16 @@ int crash_load_dm_crypt_keys(struct kimage *image)if (key_count <=0 ) {kexec_dprintk ("No dm-crypt keys\n" ); -return -ENOENT ; +return 0 ; }if (!is_dm_key_reused) { image->dm_crypt_keys_addr =0 ; r =build_keys_header (); -if (r) +if (r) { +pr_err ("Failed to build dm-crypt keys header, ret=%d\n" , r);return r; + } } kbuf.buffer = keys_header;
@@ -432,6 +434,7 @@ int crash_load_dm_crypt_keys(struct kimage *image) kbuf.mem =KEXEC_BUF_MEM_UNKNOWN ; r =kexec_add_buffer (&kbuf);if (r) { +pr_err ("Failed to call kexec_add_buffer, ret=%d\n" , r);kvfree ((void *)kbuf.buffer);return r; }
Signature · 1 line
2.53.0
Re: [PATCH v5 1/3] crash_dump/dm-crypt: Don't print in arch-specific code
Quoted 11 lines · Coiby Xu
When the vmcore dumping target is not a LUKS-encrypted target, it's expected that there is no dm-crypt key thus no need to return
-ENOENT. Also print more logs incrash_load_dm_crypt_keys. The benefit is arch-specific code can be more succinct.Suggested-by Will Deacon <[email protected]>Signed-off-by Coiby Xu <[email protected]>--- arch/x86/kernel/kexec-bzimage64.c | 6 +----- kernel/crash_dump_dm_crypt.c | 7 +++++-- 2 files changed, 6 insertions(+), 7 deletions(-)
Quoted 53 lines
arch/x86/kernel/kexec-bzimage64.c +1
-5@@ -525,12 +525,8 @@ static void *bzImage64_load(struct kimage *image, char *kernel,if (ret)return ERR_PTR (ret); ret =crash_load_dm_crypt_keys (image); -if (ret == -ENOENT ) { -kexec_dprintk ("No dm crypt key to load\n" ); - }else if (ret) { -pr_err ("Failed to load dm crypt keys\n" ); +if (ret)return ERR_PTR (ret); - }if (image->dm_crypt_keys_addr && cmdline_len +MAX_ELFCOREHDR_STR_LEN +MAX_DMCRYPTKEYS_STR_LEN > header->cmdline_size) {kernel/crash_dump_dm_crypt.c +5
-2@@ -414,14 +414,16 @@ int crash_load_dm_crypt_keys(struct kimage *image)if (key_count <=0 ) {kexec_dprintk ("No dm-crypt keys\n" ); -return -ENOENT ; +return 0 ; }if (!is_dm_key_reused) { image->dm_crypt_keys_addr =0 ; r =build_keys_header (); -if (r) +if (r) { +pr_err ("Failed to build dm-crypt keys header, ret=%d\n" , r);return r; + } } kbuf.buffer = keys_header;@@ -432,6 +434,7 @@ int crash_load_dm_crypt_keys(struct kimage *image) kbuf.mem =KEXEC_BUF_MEM_UNKNOWN ; r =kexec_add_buffer (&kbuf);if (r) { +pr_err ("Failed to call kexec_add_buffer, ret=%d\n" , r);kvfree ((void *)kbuf.buffer);return r; }Signature · 1 line
2.53.0
Re: [PATCH v5 1/3] crash_dump/dm-crypt: Don't print in arch-specific code
Quoted 6 lines · Baoquan He
Quoted 5 lines · Coiby Xu
When the vmcore dumping target is not a LUKS-encrypted target, it's expected that there is no dm-crypt key thus no need to return
-ENOENT. Also print more logs incrash_load_dm_crypt_keys. The benefit is arch-specific code can be more succinct.
Quoted 8 lines
Quoted 6 lines
Suggested-by Will Deacon <[email protected]>Signed-off-by Coiby Xu <[email protected]>--- arch/x86/kernel/kexec-bzimage64.c | 6 +----- kernel/crash_dump_dm_crypt.c | 7 +++++-- 2 files changed, 6 insertions(+), 7 deletions(-)Acked-by Baoquan He <[email protected]>
Thank Baoquan for ack'ing the kexec/kdump part of this patch set!
Signature · 2 lines
Best regards, Coiby
PATCH v5 2/3 crash: Align the declaration of crash_load_dm_crypt_keys with CONFIG_CRASH_DM_CRYPT
In reply to Coiby XuThis will prevent a compiling failure when CONFIG_CRASH_DUMP is enabled but CONFIG_CRASH_DM_CRYPT is disabled,
arch/powerpc/kexec/elf_64.c: In function 'elf64_load':
>> arch/powerpc/kexec/elf_64.c:82:23: error: implicit declaration of function 'crash_load_dm_crypt_keys' [-Werror=implicit-function-declaration]
82 | ret = crash_load_dm_crypt_keys(image);
| ^~~~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors--- include/linux/crash_core.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
include/linux/crash_core.h +7 -7
@@ -34,13 +34,6 @@ static inline void arch_kexec_protect_crashkres(void) { }static inline void arch_kexec_unprotect_crashkres (void ) { }#endif -#ifdef CONFIG_CRASH_DM_CRYPT -int crash_load_dm_crypt_keys (struct kimage *image); -ssize_t dm_crypt_keys_read (char *buf,size_t count,u64 *ppos); -#else -static inline int crash_load_dm_crypt_keys (struct kimage *image) {return 0 ; } -#endif -#ifndef arch_crash_handle_hotplug_eventstatic inline void arch_crash_handle_hotplug_event (struct kimage *image,void *arg) { }#endif
@@ -96,4 +89,11 @@ static inline void crash_save_cpu(struct pt_regs *regs, int cpu) {};static inline int kimage_crash_copy_vmcoreinfo (struct kimage *image) {return 0 ; };#endif /* CONFIG_CRASH_DUMP*/ +#ifdef CONFIG_CRASH_DM_CRYPT +int crash_load_dm_crypt_keys (struct kimage *image); +ssize_t dm_crypt_keys_read (char *buf,size_t count,u64 *ppos); +#else +static inline int crash_load_dm_crypt_keys (struct kimage *image) {return 0 ; } +#endif +#endif /* LINUX_CRASH_CORE_H */
Signature · 1 line
2.53.0
Re: [PATCH v5 2/3] crash: Align the declaration of crash_load_dm_crypt_keys with CONFIG_CRASH_DM_CRYPT
Quoted 9 lines · Coiby Xu
This will prevent a compiling failure when
CONFIG_CRASH_DUMPis enabled butCONFIG_CRASH_DM_CRYPTis disabled,arch/powerpc/kexec/elf_64.c: In function 'elf64_load': >> arch/powerpc/kexec/elf_64.c:82:23: error: implicit declaration of function 'crash_load_dm_crypt_keys' [-Werror=implicit-function-declaration] 82 | ret = crash_load_dm_crypt_keys(image); | ^~~~~~~~~~~~~~~~~~~~~~~~ cc1: some warnings being treated as errors
Quoted 6 lines
Reported-by kernel test robot <[email protected]>Signed-off-by Coiby Xu <[email protected]>--- include/linux/crash_core.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
Quoted 34 lines
include/linux/crash_core.h +7
-7@@ -34,13 +34,6 @@ static inline void arch_kexec_protect_crashkres(void) { }static inline void arch_kexec_unprotect_crashkres (void ) { }#endif -#ifdef CONFIG_CRASH_DM_CRYPT -int crash_load_dm_crypt_keys (struct kimage *image); -ssize_t dm_crypt_keys_read (char *buf,size_t count,u64 *ppos); -#else -static inline int crash_load_dm_crypt_keys (struct kimage *image) {return 0 ; } -#endif -#ifndef arch_crash_handle_hotplug_eventstatic inline void arch_crash_handle_hotplug_event (struct kimage *image,void *arg) { }#endif @@ -96,4 +89,11 @@ static inline void crash_save_cpu(struct pt_regs *regs, int cpu) {};static inline int kimage_crash_copy_vmcoreinfo (struct kimage *image) {return 0 ; };#endif /* CONFIG_CRASH_DUMP*/ +#ifdef CONFIG_CRASH_DM_CRYPT +int crash_load_dm_crypt_keys (struct kimage *image); +ssize_t dm_crypt_keys_read (char *buf,size_t count,u64 *ppos); +#else +static inline int crash_load_dm_crypt_keys (struct kimage *image) {return 0 ; } +#endif +#endif /* LINUX_CRASH_CORE_H */ Signature · 1 line
2.53.0
PATCH v5 3/3 arm64,ppc64le/kdump: pass dm-crypt keys to kdump kernel
In reply to Coiby XuCONFIG_CRASH_DM_CRYPT has been introduced to support LUKS-encrypted device dump target by addressing two challenges [1],
- Kdump kernel may not be able to decrypt the LUKS partition. For some machines, a system administrator may not have a chance to enter the password to decrypt the device in kdump initramfs after the 1st kernel crashes
- LUKS2 by default use the memory-hard Argon2 key derivation function which is quite memory-consuming compared to the limited memory reserved for kdump.
To also enable this feature for ARM64 and PowerPC, the missing piece is to let the kdump kernel know where to find the dm-crypt keys which are randomly stored in memory reserved for kdump. Introduce a new device tree property dmcryptkeys [2] as similar to elfcorehdr to pass the memory address of the stored info of dm-crypt keys to the kdump kernel. Since this property is only needed by the kdump kernel, it won't be exposed to user space.
[1] https://lore.kernel.org/all/[email protected]/
[2] https://github.com/devicetree-org/dt-schema/pull/181
--- arch/arm64/kernel/machine_kexec_file.c | 4 ++++ arch/powerpc/kexec/elf_64.c | 4 ++++ drivers/of/fdt.c | 21 +++++++++++++++++++++ drivers/of/kexec.c | 19 +++++++++++++++++++ 4 files changed, 48 insertions(+)
arch/arm64/kernel/machine_kexec_file.c +4 -0
@@ -134,6 +134,10 @@ int load_other_segments(struct kimage *image,kexec_dprintk ("Loaded elf core header at 0x%lx bufsz=0x%lx memsz=0x%lx\n" , image->elf_load_addr, kbuf.bufsz, kbuf.memsz); + + ret =crash_load_dm_crypt_keys (image); +if (ret) + goto out_err; }#endif
arch/powerpc/kexec/elf_64.c +4 -0
@@ -79,6 +79,10 @@ static void *elf64_load(struct kimage *image, char *kernel_buf, goto out; } + ret =crash_load_dm_crypt_keys (image); +if (ret) + goto out; +/* Setup cmdline for kdump kernel case */ modified_cmdline =setup_kdump_cmdline (image, cmdline, cmdline_len);
drivers/of/fdt.c +21 -0
@@ -866,6 +866,26 @@ static void __init early_init_dt_check_for_elfcorehdr(unsigned long node) elfcorehdr_addr, elfcorehdr_size); } +static void __init early_init_dt_check_for_dmcryptkeys (unsigned long node) +{ +const char *prop_name ="linux,dmcryptkeys" ; +const __be32 *prop; + +if (!IS_ENABLED (CONFIG_CRASH_DM_CRYPT )) +return ; + +pr_debug ("Looking for dmcryptkeys property... " ); + + prop =of_get_flat_dt_prop (node, prop_name,NULL ); +if (!prop) +return ; + + dm_crypt_keys_addr =dt_mem_next_cell (dt_root_addr_cells, &prop); + +/* Property only accessible to crash dump kernel */ +fdt_delprop (initial_boot_params, node, prop_name); +} +static unsigned long chosen_node_offset = -FDT_ERR_NOTFOUND ;/*
@@ -1097,6 +1117,7 @@ int __init early_init_dt_scan_chosen(char *cmdline)early_init_dt_check_for_initrd (node);early_init_dt_check_for_elfcorehdr (node); +early_init_dt_check_for_dmcryptkeys (node); rng_seed =of_get_flat_dt_prop (node,"rng-seed" , &l);if (rng_seed && l >0 ) {
drivers/of/kexec.c +19 -0
@@ -423,6 +423,25 @@ void *of_kexec_alloc_and_setup_fdt(const struct kimage *image,if (ret) goto out; +if (image->dm_crypt_keys_addr !=0 ) { + ret =fdt_appendprop_addrrange (fdt,0 , chosen_node, +"linux,dmcryptkeys" , + image->dm_crypt_keys_addr, + image->dm_crypt_keys_sz); + +if (ret) + goto out; + +/* +* Avoid dmcryptkeys from being stomped on in kdump kernel by +* setting up memory reserve map. +*/ + ret =fdt_add_mem_rsv (fdt, image->dm_crypt_keys_addr, + image->dm_crypt_keys_sz); +if (ret) + goto out; + } +#ifdef CONFIG_CRASH_DUMP /* add linux,usable-memory-range */ ret = fdt_appendprop_addrrange(fdt, 0, chosen_node,
Signature · 1 line
2.53.0
Re: [PATCH v5 3/3] arm64,ppc64le/kdump: pass dm-crypt keys to kdump kernel
Quoted 36 lines · Coiby Xu
CONFIG_CRASH_DM_CRYPThas been introduced to support LUKS-encrypted device dump target by addressing two challenges [1],
- Kdump kernel may not be able to decrypt the LUKS partition. For some machines, a system administrator may not have a chance to enter the password to decrypt the device in kdump initramfs after the 1st kernel crashes- LUKS2 by default use the memory-hard Argon2 key derivation function which is quite memory-consuming compared to the limited memory reserved for kdump.
To also enable this feature for ARM64 and PowerPC, the missing piece is to let the kdump kernel know where to find the dm-crypt keys which are randomly stored in memory reserved for kdump. Introduce a new device tree property dmcryptkeys [2] as similar to elfcorehdr to pass the memory address of the stored info of dm-crypt keys to the kdump kernel. Since this property is only needed by the kdump kernel, it won't be exposed to user space.
[1] https://lore.kernel.org/all/[email protected]/
[2] https://github.com/devicetree-org/dt-schema/pull/181Cc Arnaud Lefebvre <[email protected]>Cc Baoquan he <[email protected]>Cc Dave Young <[email protected]>Cc Kairui Song <[email protected]>Cc Pingfan Liu <[email protected]>Cc Andrew Morton <[email protected]>Cc Krzysztof Kozlowski <[email protected]>Cc Rob Herring <[email protected]>Cc Thomas Staudt <[email protected]>Cc Sourabh Jain <[email protected]>Cc Will Deacon <[email protected]>Cc Christophe Leroy (CS GROUP) <[email protected]>Signed-off-by Coiby Xu <[email protected]>
Quoted 6 lines
--- arch/arm64/kernel/machine_kexec_file.c | 4 ++++ arch/powerpc/kexec/elf_64.c | 4 ++++ drivers/of/fdt.c | 21 +++++++++++++++++++++ drivers/of/kexec.c | 19 +++++++++++++++++++ 4 files changed, 48 insertions(+)
Re: [PATCH v5 3/3] arm64,ppc64le/kdump: pass dm-crypt keys to kdump kernel
Quoted 44 lines · Rob Herring
Quoted 36 lines · Coiby Xu
CONFIG_CRASH_DM_CRYPThas been introduced to support LUKS-encrypted device dump target by addressing two challenges [1],
- Kdump kernel may not be able to decrypt the LUKS partition. For some machines, a system administrator may not have a chance to enter the password to decrypt the device in kdump initramfs after the 1st kernel crashes- LUKS2 by default use the memory-hard Argon2 key derivation function which is quite memory-consuming compared to the limited memory reserved for kdump.
To also enable this feature for ARM64 and PowerPC, the missing piece is to let the kdump kernel know where to find the dm-crypt keys which are randomly stored in memory reserved for kdump. Introduce a new device tree property dmcryptkeys [2] as similar to elfcorehdr to pass the memory address of the stored info of dm-crypt keys to the kdump kernel. Since this property is only needed by the kdump kernel, it won't be exposed to user space.
[1] https://lore.kernel.org/all/[email protected]/
[2] https://github.com/devicetree-org/dt-schema/pull/181Cc Arnaud Lefebvre <[email protected]>Cc Baoquan he <[email protected]>Cc Dave Young <[email protected]>Cc Kairui Song <[email protected]>Cc Pingfan Liu <[email protected]>Cc Andrew Morton <[email protected]>Cc Krzysztof Kozlowski <[email protected]>Cc Rob Herring <[email protected]>Cc Thomas Staudt <[email protected]>Cc Sourabh Jain <[email protected]>Cc Will Deacon <[email protected]>Cc Christophe Leroy (CS GROUP) <[email protected]>Signed-off-by Coiby Xu <[email protected]>Quoted 6 lines
--- arch/arm64/kernel/machine_kexec_file.c | 4 ++++ arch/powerpc/kexec/elf_64.c | 4 ++++ drivers/of/fdt.c | 21 +++++++++++++++++++++ drivers/of/kexec.c | 19 +++++++++++++++++++ 4 files changed, 48 insertions(+)
Quoted 1 line
Hi Rob,
Thanks for acknowledging this device tree patch and also merging the dt-schema PR!
Signature · 2 lines
Best regards, Coiby
Re: [PATCH v5 3/3] arm64,ppc64le/kdump: pass dm-crypt keys to kdump kernel
In reply to Coiby XuQuoted 131 lines · Coiby Xu
CONFIG_CRASH_DM_CRYPThas been introduced to support LUKS-encrypted device dump target by addressing two challenges [1],
- Kdump kernel may not be able to decrypt the LUKS partition. For some machines, a system administrator may not have a chance to enter the password to decrypt the device in kdump initramfs after the 1st kernel crashes- LUKS2 by default use the memory-hard Argon2 key derivation function which is quite memory-consuming compared to the limited memory reserved for kdump.
To also enable this feature for ARM64 and PowerPC, the missing piece is to let the kdump kernel know where to find the dm-crypt keys which are randomly stored in memory reserved for kdump. Introduce a new device tree property dmcryptkeys [2] as similar to elfcorehdr to pass the memory address of the stored info of dm-crypt keys to the kdump kernel. Since this property is only needed by the kdump kernel, it won't be exposed to user space.
[1] https://lore.kernel.org/all/[email protected]/
[2] https://github.com/devicetree-org/dt-schema/pull/181Cc Arnaud Lefebvre <[email protected]>Cc Baoquan he <[email protected]>Cc Dave Young <[email protected]>Cc Kairui Song <[email protected]>Cc Pingfan Liu <[email protected]>Cc Andrew Morton <[email protected]>Cc Krzysztof Kozlowski <[email protected]>Cc Rob Herring <[email protected]>Cc Thomas Staudt <[email protected]>Cc Sourabh Jain <[email protected]>Cc Will Deacon <[email protected]>Cc Christophe Leroy (CS GROUP) <[email protected]>Signed-off-by Coiby Xu <[email protected]>--- arch/arm64/kernel/machine_kexec_file.c | 4 ++++ arch/powerpc/kexec/elf_64.c | 4 ++++ drivers/of/fdt.c | 21 +++++++++++++++++++++ drivers/of/kexec.c | 19 +++++++++++++++++++ 4 files changed, 48 insertions(+)arch/arm64/kernel/machine_kexec_file.c +4
-0@@ -134,6 +134,10 @@ int load_other_segments(struct kimage *image,kexec_dprintk ("Loaded elf core header at 0x%lx bufsz=0x%lx memsz=0x%lx\n" , image->elf_load_addr, kbuf.bufsz, kbuf.memsz); + + ret =crash_load_dm_crypt_keys (image); +if (ret) + goto out_err; }#endif arch/powerpc/kexec/elf_64.c +4
-0@@ -79,6 +79,10 @@ static void *elf64_load(struct kimage *image, char *kernel_buf, goto out; } + ret =crash_load_dm_crypt_keys (image); +if (ret) + goto out; +/* Setup cmdline for kdump kernel case */ modified_cmdline =setup_kdump_cmdline (image, cmdline, cmdline_len);drivers/of/fdt.c +21
-0@@ -866,6 +866,26 @@ static void __init early_init_dt_check_for_elfcorehdr(unsigned long node) elfcorehdr_addr, elfcorehdr_size); } +static void __init early_init_dt_check_for_dmcryptkeys (unsigned long node) +{ +const char *prop_name ="linux,dmcryptkeys" ; +const __be32 *prop; + +if (!IS_ENABLED (CONFIG_CRASH_DM_CRYPT )) +return ; + +pr_debug ("Looking for dmcryptkeys property... " ); + + prop =of_get_flat_dt_prop (node, prop_name,NULL ); +if (!prop) +return ; + + dm_crypt_keys_addr =dt_mem_next_cell (dt_root_addr_cells, &prop); + +/* Property only accessible to crash dump kernel */ +fdt_delprop (initial_boot_params, node, prop_name); +} +static unsigned long chosen_node_offset = -FDT_ERR_NOTFOUND ;/* @@ -1097,6 +1117,7 @@ int __init early_init_dt_scan_chosen(char *cmdline)early_init_dt_check_for_initrd (node);early_init_dt_check_for_elfcorehdr (node); +early_init_dt_check_for_dmcryptkeys (node); rng_seed =of_get_flat_dt_prop (node,"rng-seed" , &l);if (rng_seed && l >0 ) {drivers/of/kexec.c +12
-0@@ -423,6 +423,25 @@ void *of_kexec_alloc_and_setup_fdt(const struct kimage *image,if (ret) goto out; +if (image->dm_crypt_keys_addr !=0 ) { + ret =fdt_appendprop_addrrange (fdt,0 , chosen_node, +"linux,dmcryptkeys" , + image->dm_crypt_keys_addr, + image->dm_crypt_keys_sz); + +if (ret) + goto out; + +/* +* Avoid dmcryptkeys from being stomped on in kdump kernel by +* setting up memory reserve map.
drivers/of/kexec.c void *of_kexec_alloc_and_setup_fdt(const struct kimage *image, · line 447
Quoted 10 lines
drivers/of/kexec.c +7
-0+*/ + ret =fdt_add_mem_rsv (fdt, image->dm_crypt_keys_addr, + image->dm_crypt_keys_sz); +if (ret) + goto out; + } +#ifdef CONFIG_CRASH_DUMP /* add linux,usable-memory-range */ ret = fdt_appendprop_addrrange(fdt, 0, chosen_node,
The above changes look good to me.
Feel free to add:
But while reading crash_load_dm_crypt_keys() I noticed a possibility of a double free at the address pointed by keys_header:
In crash_load_dm_crypt_keys()/crash_dump_dm_crypt.c snip...
kbuf.buffer = keys_header;
snip....
r = kexec_add_buffer(&kbuf);
if (r) {
pr_err("Failed to call kexec_add_buffer, ret=%d\n", r); kvfree((void *)kbuf.buffer); <--- First Free return r;
}
Since keys_header is not reset, the next call to build_keys_header() will cause a double free at keys_header.
static int build_keys_header(void)
{
snip...
if (keys_header != NULL)
kvfree(keys_header);
snip...
}
What do you think?
- Sourabh Jain
Andrew Morton
maintainerRe: [PATCH v5 3/3] arm64,ppc64le/kdump: pass dm-crypt keys to kdump kernel
Quoted 26 lines · On Thu, 2 Apr 2026 16:24:14 +0530 Sourabh Jain <[email protected]>…
But while reading
crash_load_dm_crypt_keys()I noticed a possibility of a double free at the address pointed bykeys_header:In crash_load_dm_crypt_keys()/crash_dump_dm_crypt.c
snip...kbuf.buffer =
keys_header;snip....
r =
kexec_add_buffer(&kbuf);
if (r) {
pr_err("Failed to call kexec_add_buffer, ret=%d\n", r);kvfree((void *)kbuf.buffer); <---
First Free
return r;
}Since
keys_headeris not reset, the next call to build_keys_header() will cause a double free atkeys_header.static int
build_keys_header(void)
{snip...
Quoted 7 lines
if (
keys_header!= NULL)
kvfree(keys_header);snip...
}What do you think?
It looks that way to me.
Re: [PATCH v5 3/3] arm64,ppc64le/kdump: pass dm-crypt keys to kdump kernel
Quoted 31 lines · Andrew Morton
Quoted 29 lines · On Thu, 2 Apr 2026 16:24:14 +0530 Sourabh Jain <[email protected]>…
But while reading
crash_load_dm_crypt_keys()I noticed a possibility of a double free at the address pointed bykeys_header:In crash_load_dm_crypt_keys()/crash_dump_dm_crypt.c
snip...kbuf.buffer =
keys_header;snip....
r =
kexec_add_buffer(&kbuf);
if (r) {
pr_err("Failed to call kexec_add_buffer, ret=%d\n", r);kvfree((void *)kbuf.buffer); <---
First Free
return r;
}Since
keys_headeris not reset, the next call to build_keys_header() will cause a double free atkeys_header.static int
build_keys_header(void)
{snip...
if (
keys_header!= NULL)
kvfree(keys_header);
Quoted 6 lines
Quoted 4 lines
snip...
}What do you think?
It looks that way to me.
Thanks for confirming it! I'll send a patch after finishing the testing.
Signature · 2 lines
Best regards, Coiby
Re: [PATCH v5 3/3] arm64,ppc64le/kdump: pass dm-crypt keys to kdump kernel
In reply to Sourabh JainQuoted 139 lines · Sourabh Jain
Quoted 123 lines · Coiby Xu
CONFIG_CRASH_DM_CRYPThas been introduced to support LUKS-encrypted device dump target by addressing two challenges [1],
- Kdump kernel may not be able to decrypt the LUKS partition. For some machines, a system administrator may not have a chance to enter the password to decrypt the device in kdump initramfs after the 1st kernel crashes- LUKS2 by default use the memory-hard Argon2 key derivation function which is quite memory-consuming compared to the limited memory reserved for kdump.
To also enable this feature for ARM64 and PowerPC, the missing piece is to let the kdump kernel know where to find the dm-crypt keys which are randomly stored in memory reserved for kdump. Introduce a new device tree property dmcryptkeys [2] as similar to elfcorehdr to pass the memory address of the stored info of dm-crypt keys to the kdump kernel. Since this property is only needed by the kdump kernel, it won't be exposed to user space.
[1] https://lore.kernel.org/all/[email protected]/
[2] https://github.com/devicetree-org/dt-schema/pull/181Cc Arnaud Lefebvre <[email protected]>Cc Baoquan he <[email protected]>Cc Dave Young <[email protected]>Cc Kairui Song <[email protected]>Cc Pingfan Liu <[email protected]>Cc Andrew Morton <[email protected]>Cc Krzysztof Kozlowski <[email protected]>Cc Rob Herring <[email protected]>Cc Thomas Staudt <[email protected]>Cc Sourabh Jain <[email protected]>Cc Will Deacon <[email protected]>Cc Christophe Leroy (CS GROUP) <[email protected]>Signed-off-by Coiby Xu <[email protected]>--- arch/arm64/kernel/machine_kexec_file.c | 4 ++++ arch/powerpc/kexec/elf_64.c | 4 ++++ drivers/of/fdt.c | 21 +++++++++++++++++++++ drivers/of/kexec.c | 19 +++++++++++++++++++ 4 files changed, 48 insertions(+)arch/arm64/kernel/machine_kexec_file.c +4
-0@@ -134,6 +134,10 @@ int load_other_segments(struct kimage *image,kexec_dprintk ("Loaded elf core header at 0x%lx bufsz=0x%lx memsz=0x%lx\n" , image->elf_load_addr, kbuf.bufsz, kbuf.memsz); + + ret =crash_load_dm_crypt_keys (image); +if (ret) + goto out_err; }#endif arch/powerpc/kexec/elf_64.c +4
-0@@ -79,6 +79,10 @@ static void *elf64_load(struct kimage *image, char *kernel_buf, goto out; } + ret =crash_load_dm_crypt_keys (image); +if (ret) + goto out; +/* Setup cmdline for kdump kernel case */ modified_cmdline =setup_kdump_cmdline (image, cmdline, cmdline_len);drivers/of/fdt.c +21
-0@@ -866,6 +866,26 @@ static void __init early_init_dt_check_for_elfcorehdr(unsigned long node) elfcorehdr_addr, elfcorehdr_size); } +static void __init early_init_dt_check_for_dmcryptkeys (unsigned long node) +{ +const char *prop_name ="linux,dmcryptkeys" ; +const __be32 *prop; + +if (!IS_ENABLED (CONFIG_CRASH_DM_CRYPT )) +return ; + +pr_debug ("Looking for dmcryptkeys property... " ); + + prop =of_get_flat_dt_prop (node, prop_name,NULL ); +if (!prop) +return ; + + dm_crypt_keys_addr =dt_mem_next_cell (dt_root_addr_cells, &prop); + +/* Property only accessible to crash dump kernel */ +fdt_delprop (initial_boot_params, node, prop_name); +} +static unsigned long chosen_node_offset = -FDT_ERR_NOTFOUND ;/* @@ -1097,6 +1117,7 @@ int __init early_init_dt_scan_chosen(char *cmdline)early_init_dt_check_for_initrd (node);early_init_dt_check_for_elfcorehdr (node); +early_init_dt_check_for_dmcryptkeys (node); rng_seed =of_get_flat_dt_prop (node,"rng-seed" , &l);if (rng_seed && l >0 ) {drivers/of/kexec.c +12
-0@@ -423,6 +423,25 @@ void *of_kexec_alloc_and_setup_fdt(const struct kimage *image,if (ret) goto out; +if (image->dm_crypt_keys_addr !=0 ) { + ret =fdt_appendprop_addrrange (fdt,0 , chosen_node, +"linux,dmcryptkeys" , + image->dm_crypt_keys_addr, + image->dm_crypt_keys_sz); + +if (ret) + goto out; + +/* +* Avoid dmcryptkeys from being stomped on in kdump kernel by +* setting up memory reserve map. drivers/of/kexec.c void *of_kexec_alloc_and_setup_fdt(const struct kimage *image, · line 446
Quoted 10 lines
drivers/of/kexec.c +7
-0+*/ + ret =fdt_add_mem_rsv (fdt, image->dm_crypt_keys_addr, + image->dm_crypt_keys_sz); +if (ret) + goto out; + } +#ifdef CONFIG_CRASH_DUMP /* add linux,usable-memory-range */ ret = fdt_appendprop_addrrange(fdt, 0, chosen_node,The above changes look good to me.
Quoted 2 lines
Feel free to add:
Reviewed-by Sourabh Jain <[email protected]>
Thanks for reviewing the patch!
Quoted 29 lines
But while reading
crash_load_dm_crypt_keys()I noticed a possibility of a double free at the address pointed bykeys_header:In crash_load_dm_crypt_keys()/crash_dump_dm_crypt.c snip...
kbuf.buffer =
keys_header;snip....
r =
kexec_add_buffer(&kbuf);
if (r) {
pr_err("Failed to call kexec_add_buffer, ret=%d\n", r);kvfree((void *)kbuf.buffer); <--- First Free return r;
}Since
keys_headeris not reset, the next call to build_keys_header() will cause a double free atkeys_header.static int
build_keys_header(void)
{snip...
if (
keys_header!= NULL)
kvfree(keys_header);
Quoted 6 lines
snip...
}What do you think?
- Sourabh Jain
Good catch! I'll send a patch to address this issue. Thanks!
Signature · 2 lines
Best regards, Coiby
Andrew Morton
maintainerQuoted 7 lines · On Wed, 25 Feb 2026 14:03:43 +0800 Coiby Xu <[email protected]> wrote:
CONFIG_CRASH_DM_CRYPThas been introduced to support LUKS-encrypted device dump target by addressing two challenges [1],
- Kdump kernel may not be able to decrypt the LUKS partition. For some machines, a system administrator may not have a chance to enter the password to decrypt the device in kdump initramfs after the 1st kernel crashes
Quoted 8 lines
- LUKS2 by default use the memory-hard Argon2 key derivation function which is quite memory-consuming compared to the limited memory reserved for kdump.
To also enable this feature for ARM64 and PowerPC, we need to add a device tree property dmcryptkeys [2] as similar to elfcorehdr to pass the memory address of the stored info of dm-crypt keys to the kdump kernel.
We don't have any ack/review tags for this series. Could someone please help out?