powerpc/kdump: pass dm-crypt keys to kdump kernel
Subsystems (5)
PATCH 1/1 powerpc/kdump: pass dm-crypt keys to kdump kernel
Based on the CONFIG_CRASH_DM_CRYPT feature, this patch adds LUKS-encrypted device dump target support to PowerPC 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.
1st kernel will build up the kernel command parameter dmcryptkeys 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]/
--- arch/powerpc/include/asm/kexec.h | 3 ++- arch/powerpc/kexec/elf_64.c | 26 +++++++++++++++++++++++++- arch/powerpc/kexec/file_load.c | 19 +++++++++++-------- 3 files changed, 38 insertions(+), 10 deletions(-)
arch/powerpc/include/asm/kexec.h +2 -1
@@ -80,7 +80,8 @@ struct kimage_arch { };char *setup_kdump_cmdline (struct kimage *image,char *cmdline, -unsigned long cmdline_len); +unsigned long cmdline_len, +char *name,unsigned long addr);int setup_purgatory (struct kimage *image,const void *slave_code,const void *fdt,unsigned long kernel_load_addr,unsigned long fdt_load_addr);
arch/powerpc/kexec/elf_64.c +25 -1
@@ -81,13 +81,37 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,/* Setup cmdline for kdump kernel case */ modified_cmdline =setup_kdump_cmdline (image, cmdline, - cmdline_len); + cmdline_len, +"elfcorehdr" , + image->elf_load_addr);if (!modified_cmdline) {pr_err ("Setting up cmdline for kdump kernel failed\n" ); ret = -EINVAL ; goto out; } cmdline = modified_cmdline; + cmdline_len =strlen (cmdline) +1 ; + + 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" ); +return ERR_PTR (ret); + } + +if (image->dm_crypt_keys_addr !=0 ) { + modified_cmdline =setup_kdump_cmdline (image, cmdline, + cmdline_len, +"dmcryptkeys" , + image->dm_crypt_keys_addr); +if (!modified_cmdline) { +pr_err ("Setting up cmdline for kdump kernel failed\n" ); + ret = -EINVAL ; + goto out; + } + cmdline = modified_cmdline; + } }if (initrd !=NULL ) {
arch/powerpc/kexec/file_load.c +11 -8
@@ -23,38 +23,41 @@#define SLAVE_CODE_SIZE 256/* First 0x100 bytes */ /** -* setup_kdump_cmdline - Prepend "elfcorehdr=<addr> " to command line +* setup_kdump_cmdline - Prepend "<name>=<addr> " to command line * of kdump kernel for exporting the core. * @image: Kexec image * @cmdline: Command line parameters to update. * @cmdline_len: Length of the cmdline parameters. +* @name: Name e.g elfcorehdr. +* @addr: Memory address. * * kdump segment must be setup before calling this function. * * Returns new cmdline buffer for kdump kernel on success, NULL otherwise. */ char *setup_kdump_cmdline (struct kimage *image,char *cmdline, -unsigned long cmdline_len) +unsigned long cmdline_len, +char *name,unsigned long addr) { -int elfcorehdr_strlen; +unsigned long parameter_len;char *cmdline_ptr; cmdline_ptr =kzalloc (COMMAND_LINE_SIZE ,GFP_KERNEL );if (!cmdline_ptr)return NULL ; - elfcorehdr_strlen =sprintf (cmdline_ptr,"elfcorehdr=0x%lx " , - image->elf_load_addr); + parameter_len =sprintf (cmdline_ptr,"%s=0x%lx " , name, addr); -if (elfcorehdr_strlen + cmdline_len >COMMAND_LINE_SIZE ) { -pr_err ("Appending elfcorehdr=<addr> exceeds cmdline size\n" ); +if (parameter_len + cmdline_len >COMMAND_LINE_SIZE ) { +pr_err ("Appending %s=<addr> exceeds cmdline size\n" , name);kfree (cmdline_ptr);return NULL ; } -memcpy (cmdline_ptr + elfcorehdr_strlen, cmdline, cmdline_len); +memcpy (cmdline_ptr + parameter_len, cmdline, cmdline_len);// Ensure it's nul terminated cmdline_ptr[COMMAND_LINE_SIZE -1 ] ='\0' ; +kfree (cmdline);return cmdline_ptr; }
base-commit: ccd1cdca5cd433c8a5dff78b69a79b31d9b77ee1
Signature · 1 line
2.52.0
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Coiby,
kernel test robot noticed the following build errors:
[auto build test ERROR on ccd1cdca5cd433c8a5dff78b69a79b31d9b77ee1]
url: https://github.com/intel-lab-lkp/linux/commits/Coiby-Xu/powerpc-kdump-pass-dm-crypt-keys-to-kdump-kernel/20251226-220726 base: ccd1cdca5cd433c8a5dff78b69a79b31d9b77ee1 patch link: https://lore.kernel.org/r/20251226140636.1378505-1-coxu%40redhat.com patch subject: [PATCH] powerpc/kdump: pass dm-crypt keys to kdump kernel config: powerpc64-randconfig-001-20251227 (https://download.01.org/0day-ci/archive/20251227/[email protected]/config) compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project 4ef602d446057dabf5f61fb221669ecbeda49279) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251227/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> arch/powerpc/kexec/elf_64.c:95:9: error: call to undeclared function 'crash_load_dm_crypt_keys'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
95 | ret = crash_load_dm_crypt_keys(image);
| ^1 error generated.
vim +/crash_load_dm_crypt_keys +95 arch/powerpc/kexec/elf_64.c
27
28 static void *elf64_load(struct kimage *image, char *kernel_buf,
29 unsigned long kernel_len, char *initrd,
30 unsigned long initrd_len, char *cmdline,
31 unsigned long cmdline_len)
32 {
33 int ret;
34 unsigned long kernel_load_addr;
35 unsigned long initrd_load_addr = 0, fdt_load_addr;
36 void *fdt;
37 const void *slave_code;
38 struct elfhdr ehdr;
39 char *modified_cmdline = NULL;
40 struct crash_mem *rmem = NULL;
41 struct kexec_elf_info elf_info;
42 struct kexec_buf kbuf = { .image = image, .buf_min = 0,
43 .buf_max = ppc64_rma_size };
44 struct kexec_buf pbuf = { .image = image, .buf_min = 0,
45 .buf_max = ppc64_rma_size, .top_down = true,
46 .mem = KEXEC_BUF_MEM_UNKNOWN };
47
48 ret = kexec_build_elf_info(kernel_buf, kernel_len, &ehdr, &elf_info);
49 if (ret)
50 return ERR_PTR(ret);
51
52 if (IS_ENABLED(CONFIG_CRASH_DUMP) && image->type == KEXEC_TYPE_CRASH) {
53 /* min & max buffer values for kdump case */
54 kbuf.buf_min = pbuf.buf_min = crashk_res.start;
55 kbuf.buf_max = pbuf.buf_max =
56 ((crashk_res.end < ppc64_rma_size) ?
57 crashk_res.end : (ppc64_rma_size - 1));
58 }
59
60 ret = kexec_elf_load(image, &ehdr, &elf_info, &kbuf, &kernel_load_addr);
61 if (ret)
62 goto out;
63
64 kexec_dprintk("Loaded the kernel at 0x%lx\n", kernel_load_addr);
65
66 ret = kexec_load_purgatory(image, &pbuf);
67 if (ret) {
68 pr_err("Loading purgatory failed.\n");
69 goto out;
70 }
71
72 kexec_dprintk("Loaded purgatory at 0x%lx\n", pbuf.mem);
73
74 /* Load additional segments needed for panic kernel */
75 if (IS_ENABLED(CONFIG_CRASH_DUMP) && image->type == KEXEC_TYPE_CRASH) {
76 ret = load_crashdump_segments_ppc64(image, &kbuf);
77 if (ret) {
78 pr_err("Failed to load kdump kernel segments\n");
79 goto out;
80 }
81
82 /* Setup cmdline for kdump kernel case */
83 modified_cmdline = setup_kdump_cmdline(image, cmdline,
84 cmdline_len,
85 "elfcorehdr",
86 image->elf_load_addr);
87 if (!modified_cmdline) {
88 pr_err("Setting up cmdline for kdump kernel failed\n");
89 ret = -EINVAL;
90 goto out;
91 }
92 cmdline = modified_cmdline;
93 cmdline_len = strlen(cmdline) + 1;
94
> 95 ret = crash_load_dm_crypt_keys(image);
96 if (ret == -ENOENT) {
97 kexec_dprintk("No dm crypt key to load\n");
98 } else if (ret) {
99 pr_err("Failed to load dm crypt keys\n");
100 return ERR_PTR(ret);
101 }
102
103 if (image->dm_crypt_keys_addr != 0) {
104 modified_cmdline = setup_kdump_cmdline(image, cmdline,
105 cmdline_len,
106 "dmcryptkeys",
107 image->dm_crypt_keys_addr); 108 if (!modified_cmdline) {
109 pr_err("Setting up cmdline for kdump kernel failed\n");
110 ret = -EINVAL;
111 goto out;
112 }
113 cmdline = modified_cmdline;
114 }
115 }
116
117 if (initrd != NULL) {
118 kbuf.buffer = initrd;
119 kbuf.bufsz = kbuf.memsz = initrd_len;
120 kbuf.buf_align = PAGE_SIZE;
121 kbuf.top_down = false;
122 kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
123 ret = kexec_add_buffer(&kbuf);
124 if (ret)
125 goto out;
126 initrd_load_addr = kbuf.mem;
127
128 kexec_dprintk("Loaded initrd at 0x%lx\n", initrd_load_addr);
129 }
130
131 ret = get_reserved_memory_ranges(&rmem);
132 if (ret)
133 goto out;
134
135 fdt = of_kexec_alloc_and_setup_fdt(image, initrd_load_addr,
136 initrd_len, cmdline,
137 kexec_extra_fdt_size_ppc64(image, rmem));
138 if (!fdt) {
139 pr_err("Error setting up the new device tree.\n");
140 ret = -EINVAL;
141 goto out;
142 }
143
144 ret = setup_new_fdt_ppc64(image, fdt, rmem);
145 if (ret)
146 goto out_free_fdt;
147
148 if (!IS_ENABLED(CONFIG_CRASH_HOTPLUG) || image->type != KEXEC_TYPE_CRASH)
149 fdt_pack(fdt);
150
151 kbuf.buffer = fdt;
152 kbuf.bufsz = kbuf.memsz = fdt_totalsize(fdt);
153 kbuf.buf_align = PAGE_SIZE;
154 kbuf.top_down = true;
155 kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
156 ret = kexec_add_buffer(&kbuf);
157 if (ret)
158 goto out_free_fdt;
159
160 /* FDT will be freed in arch_kimage_file_post_load_cleanup */
161 image->arch.fdt = fdt;
162
163 fdt_load_addr = kbuf.mem;
164
165 kexec_dprintk("Loaded device tree at 0x%lx\n", fdt_load_addr);
166
167 slave_code = elf_info.buffer + elf_info.proghdrs[0].p_offset;
168 ret = setup_purgatory_ppc64(image, slave_code, fdt, kernel_load_addr,
169 fdt_load_addr);
170 if (ret)
171 pr_err("Error setting up the purgatory.\n");
172
173 goto out;
174
175 out_free_fdt:
176 kvfree(fdt);
177 out:
178 kfree(rmem);
179 kfree(modified_cmdline);
180 kexec_free_elf_info(&elf_info);
181
182 return ret ? ERR_PTR(ret) : NULL;
183 }
184
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Quoted 19 lines · kernel test robot
Hi Coiby,
kernel test robot noticed the following build errors:
[auto build test ERROR on
ccd1cdca5cd433c8a5dff78b69a79b31d9b77ee1]url: https://github.com/intel-lab-lkp/linux/commits/Coiby-Xu/powerpc-kdump-pass-dm-crypt-keys-to-kdump-kernel/20251226-220726 base: ccd1cdca5cd433c8a5dff78b69a79b31d9b77ee1 patch link: https://lore.kernel.org/r/20251226140636.1378505-1-coxu%40redhat.com patch subject: [PATCH] powerpc/kdump: pass dm-crypt keys to kdump kernel config: powerpc64-randconfig-001-20251227 (https://download.01.org/0day-ci/archive/20251227/[email protected]/config) compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project 4ef602d446057dabf5f61fb221669ecbeda49279) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251227/[email protected]/reproduce)If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
Quoted 6 lines
All errors (new ones prefixed by >>):
Quoted 1 line
Quoted 1 line
arch/powerpc/kexec/elf_64.c:95:9: error: call to undeclared function 'crash_load_dm_crypt_keys'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]95 | ret = crash_load_dm_crypt_keys(image); | ^1 error generated.
This issue has been addressed in v2
https://lore.kernel.org/all/[email protected]/
Thanks!
Signature · 2 lines
Best regards, Coiby
Quoted 130 lines · Coiby Xu
Based on the
CONFIG_CRASH_DM_CRYPTfeature, this patch adds LUKS-encrypted device dump target support to PowerPC 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.
1st kernel will build up the kernel command parameter dmcryptkeys 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]/
Cc Thomas Staudt <[email protected]>Cc 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]>Signed-off-by Coiby Xu <[email protected]>--- arch/powerpc/include/asm/kexec.h | 3 ++- arch/powerpc/kexec/elf_64.c | 26 +++++++++++++++++++++++++- arch/powerpc/kexec/file_load.c | 19 +++++++++++-------- 3 files changed, 38 insertions(+), 10 deletions(-)arch/powerpc/include/asm/kexec.h +2
-1@@ -80,7 +80,8 @@ struct kimage_arch { };char *setup_kdump_cmdline (struct kimage *image,char *cmdline, -unsigned long cmdline_len); +unsigned long cmdline_len, +char *name,unsigned long addr);int setup_purgatory (struct kimage *image,const void *slave_code,const void *fdt,unsigned long kernel_load_addr,unsigned long fdt_load_addr);arch/powerpc/kexec/elf_64.c +25
-1@@ -81,13 +81,37 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,/* Setup cmdline for kdump kernel case */ modified_cmdline =setup_kdump_cmdline (image, cmdline, - cmdline_len); + cmdline_len, +"elfcorehdr" , + image->elf_load_addr);if (!modified_cmdline) {pr_err ("Setting up cmdline for kdump kernel failed\n" ); ret = -EINVAL ; goto out; } cmdline = modified_cmdline; + cmdline_len =strlen (cmdline) +1 ; + + 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" ); +return ERR_PTR (ret); + } + +if (image->dm_crypt_keys_addr !=0 ) { + modified_cmdline =setup_kdump_cmdline (image, cmdline, + cmdline_len, +"dmcryptkeys" , + image->dm_crypt_keys_addr); +if (!modified_cmdline) { +pr_err ("Setting up cmdline for kdump kernel failed\n" ); + ret = -EINVAL ; + goto out; + } + cmdline = modified_cmdline; + } }if (initrd !=NULL ) {arch/powerpc/kexec/file_load.c +8
-7@@ -23,38 +23,41 @@#define SLAVE_CODE_SIZE 256/* First 0x100 bytes */ /** -* setup_kdump_cmdline - Prepend "elfcorehdr=<addr> " to command line +* setup_kdump_cmdline - Prepend "<name>=<addr> " to command line * of kdump kernel for exporting the core. * @image: Kexec image * @cmdline: Command line parameters to update. * @cmdline_len: Length of the cmdline parameters. +* @name: Name e.g elfcorehdr. +* @addr: Memory address. * * kdump segment must be setup before calling this function. * * Returns new cmdline buffer for kdump kernel on success, NULL otherwise. */ char *setup_kdump_cmdline (struct kimage *image,char *cmdline, -unsigned long cmdline_len) +unsigned long cmdline_len, +char *name,unsigned long addr) { -int elfcorehdr_strlen; +unsigned long parameter_len;char *cmdline_ptr; cmdline_ptr =kzalloc (COMMAND_LINE_SIZE ,GFP_KERNEL );if (!cmdline_ptr)return NULL ; - elfcorehdr_strlen =sprintf (cmdline_ptr,"elfcorehdr=0x%lx " , - image->elf_load_addr); + parameter_len =sprintf (cmdline_ptr,"%s=0x%lx " , name, addr); -if (elfcorehdr_strlen + cmdline_len >COMMAND_LINE_SIZE ) { -pr_err ("Appending elfcorehdr=<addr> exceeds cmdline size\n" ); +if (parameter_len + cmdline_len >COMMAND_LINE_SIZE ) {
arch/powerpc/kexec/file_load.c line 60
Quoted 10 lines
arch/powerpc/kexec/file_load.c +3
-1+pr_err ("Appending %s=<addr> exceeds cmdline size\n" , name);kfree (cmdline_ptr);return NULL ; } -memcpy (cmdline_ptr + elfcorehdr_strlen, cmdline, cmdline_len); +memcpy (cmdline_ptr + parameter_len, cmdline, cmdline_len);// Ensure it's nul terminated cmdline_ptr[COMMAND_LINE_SIZE -1 ] ='\0' ; +kfree (cmdline);
When setup_kdump_cmdline() is called for elfcorehdr, cmdline holds the same pointer as image->cmdline_buf. Freeing it here may therefore cause issues, right?
Currently, image->cmdline_buf is not used after calling the architecture-specific load function (elf64_load on powerpc). However, kimage_file_post_load_cleanup() later calls kfree() on the same address.
Quoted 5 lines
arch/powerpc/kexec/file_load.c +0
-0return cmdline_ptr; }base-commit:
ccd1cdca5cd433c8a5dff78b69a79b31d9b77ee1
Quoted 131 lines · Sourabh Jain
Quoted 128 lines · Coiby Xu
Based on the
CONFIG_CRASH_DM_CRYPTfeature, this patch adds LUKS-encrypted device dump target support to PowerPC 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.
1st kernel will build up the kernel command parameter dmcryptkeys 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]/
Cc Thomas Staudt <[email protected]>Cc 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]>Signed-off-by Coiby Xu <[email protected]>--- arch/powerpc/include/asm/kexec.h | 3 ++- arch/powerpc/kexec/elf_64.c | 26 +++++++++++++++++++++++++- arch/powerpc/kexec/file_load.c | 19 +++++++++++-------- 3 files changed, 38 insertions(+), 10 deletions(-)arch/powerpc/include/asm/kexec.h +2
-1@@ -80,7 +80,8 @@ struct kimage_arch { };char *setup_kdump_cmdline (struct kimage *image,char *cmdline, -unsigned long cmdline_len); +unsigned long cmdline_len, +char *name,unsigned long addr);int setup_purgatory (struct kimage *image,const void *slave_code,const void *fdt,unsigned long kernel_load_addr,unsigned long fdt_load_addr);arch/powerpc/kexec/elf_64.c +25
-1@@ -81,13 +81,37 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,/* Setup cmdline for kdump kernel case */ modified_cmdline =setup_kdump_cmdline (image, cmdline, - cmdline_len); + cmdline_len, +"elfcorehdr" , + image->elf_load_addr);if (!modified_cmdline) {pr_err ("Setting up cmdline for kdump kernel failed\n" ); ret = -EINVAL ; goto out; } cmdline = modified_cmdline; + cmdline_len =strlen (cmdline) +1 ; + + 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" ); +return ERR_PTR (ret); + } + +if (image->dm_crypt_keys_addr !=0 ) { + modified_cmdline =setup_kdump_cmdline (image, cmdline, + cmdline_len, +"dmcryptkeys" , + image->dm_crypt_keys_addr); +if (!modified_cmdline) { +pr_err ("Setting up cmdline for kdump kernel failed\n" ); + ret = -EINVAL ; + goto out; + } + cmdline = modified_cmdline; + } }if (initrd !=NULL ) {arch/powerpc/kexec/file_load.c +9
-8@@ -23,38 +23,41 @@#define SLAVE_CODE_SIZE 256/* First 0x100 bytes */ /** -* setup_kdump_cmdline - Prepend "elfcorehdr=<addr> " to command line +* setup_kdump_cmdline - Prepend "<name>=<addr> " to command line * of kdump kernel for exporting the core. * @image: Kexec image * @cmdline: Command line parameters to update. * @cmdline_len: Length of the cmdline parameters. +* @name: Name e.g elfcorehdr. +* @addr: Memory address. * * kdump segment must be setup before calling this function. * * Returns new cmdline buffer for kdump kernel on success, NULL otherwise. */ char *setup_kdump_cmdline (struct kimage *image,char *cmdline, -unsigned long cmdline_len) +unsigned long cmdline_len, +char *name,unsigned long addr) { -int elfcorehdr_strlen; +unsigned long parameter_len;char *cmdline_ptr; cmdline_ptr =kzalloc (COMMAND_LINE_SIZE ,GFP_KERNEL );if (!cmdline_ptr)return NULL ; - elfcorehdr_strlen =sprintf (cmdline_ptr,"elfcorehdr=0x%lx " , - image->elf_load_addr); + parameter_len =sprintf (cmdline_ptr,"%s=0x%lx " , name, addr); -if (elfcorehdr_strlen + cmdline_len >COMMAND_LINE_SIZE ) { -pr_err ("Appending elfcorehdr=<addr> exceeds cmdline size\n" ); +if (parameter_len + cmdline_len >COMMAND_LINE_SIZE ) { +pr_err ("Appending %s=<addr> exceeds cmdline size\n" , name);kfree (cmdline_ptr);return NULL ; } -memcpy (cmdline_ptr + elfcorehdr_strlen, cmdline, cmdline_len);
Quoted 8 lines
arch/powerpc/kexec/file_load.c line 60
Quoted 4 lines
arch/powerpc/kexec/file_load.c +2
-0+memcpy (cmdline_ptr + parameter_len, cmdline, cmdline_len);// Ensure it's nul terminated cmdline_ptr[COMMAND_LINE_SIZE -1 ] ='\0' ; +kfree (cmdline);When
setup_kdump_cmdline()is called for elfcorehdr, cmdline holds the same pointer asimage->cmdline_buf. Freeing it here may therefore cause issues, right?
Yes, you are right, I'll drop the above kfree in next version.
Quoted 5 lines
Currently,
image->cmdline_bufis not used after calling the architecture-specific load function (elf64_loadon powerpc). However,kimage_file_post_load_cleanup()later callskfree()on the same address.
I missed kimage_file_post_load_cleanup. Thanks for pointing it out!
Signature · 2 lines
Best regards, Coiby
PATCH v2 1/1 powerpc/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 PowerPC, we only need to let 1st kernel build up the kernel command parameter dmcryptkeys as similar to elfcorehdr to pass the memory address of the stored info of dm-crypt keys to the kdump kernel.
Note to avoid a building failure [2] caused by undeclared function crash_load_dm_crypt_keys when CONFIG_CRASH_DUMP is not enabled, realign the function declaration with CONFIG_CRASH_DM_CRYPT.
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/oe-kbuild-all/[email protected]/
---
v2:
- fix double kfree issue [Sourabh]
- corretly kfree old modified_cmdline
- use imperative mood for commit message
- fix a compiling error caught by kernel test robot
arch/powerpc/include/asm/kexec.h | 3 ++- arch/powerpc/kexec/elf_64.c | 27 ++++++++++++++++++++++++++- arch/powerpc/kexec/file_load.c | 18 ++++++++++-------- include/linux/crash_core.h | 14 +++++++------- 4 files changed, 45 insertions(+), 17 deletions(-)
arch/powerpc/include/asm/kexec.h +2 -1
@@ -80,7 +80,8 @@ struct kimage_arch { };char *setup_kdump_cmdline (struct kimage *image,char *cmdline, -unsigned long cmdline_len); +unsigned long cmdline_len, +char *name,unsigned long addr);int setup_purgatory (struct kimage *image,const void *slave_code,const void *fdt,unsigned long kernel_load_addr,unsigned long fdt_load_addr);
arch/powerpc/kexec/elf_64.c +26 -1
@@ -81,13 +81,38 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,/* Setup cmdline for kdump kernel case */ modified_cmdline =setup_kdump_cmdline (image, cmdline, - cmdline_len); + cmdline_len, +"elfcorehdr" , + image->elf_load_addr);if (!modified_cmdline) {pr_err ("Setting up cmdline for kdump kernel failed\n" ); ret = -EINVAL ; goto out; } cmdline = modified_cmdline; + cmdline_len =strlen (cmdline) +1 ; + + 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" ); +return ERR_PTR (ret); + } + +if (image->dm_crypt_keys_addr !=0 ) { + modified_cmdline =setup_kdump_cmdline (image, cmdline, + cmdline_len, +"dmcryptkeys" , + image->dm_crypt_keys_addr); +kfree (cmdline); +if (!modified_cmdline) { +pr_err ("Setting up cmdline for kdump kernel failed\n" ); + ret = -EINVAL ; + goto out; + } + cmdline = modified_cmdline; + } }if (initrd !=NULL ) {
arch/powerpc/kexec/file_load.c +10 -8
@@ -23,36 +23,38 @@#define SLAVE_CODE_SIZE 256/* First 0x100 bytes */ /** -* setup_kdump_cmdline - Prepend "elfcorehdr=<addr> " to command line +* setup_kdump_cmdline - Prepend "<name>=<addr> " to command line * of kdump kernel for exporting the core. * @image: Kexec image * @cmdline: Command line parameters to update. * @cmdline_len: Length of the cmdline parameters. +* @name: Name e.g elfcorehdr. +* @addr: Memory address. * * kdump segment must be setup before calling this function. * * Returns new cmdline buffer for kdump kernel on success, NULL otherwise. */ char *setup_kdump_cmdline (struct kimage *image,char *cmdline, -unsigned long cmdline_len) +unsigned long cmdline_len, +char *name,unsigned long addr) { -int elfcorehdr_strlen; +unsigned long parameter_len;char *cmdline_ptr; cmdline_ptr =kzalloc (COMMAND_LINE_SIZE ,GFP_KERNEL );if (!cmdline_ptr)return NULL ; - elfcorehdr_strlen =sprintf (cmdline_ptr,"elfcorehdr=0x%lx " , - image->elf_load_addr); + parameter_len =sprintf (cmdline_ptr,"%s=0x%lx " , name, addr); -if (elfcorehdr_strlen + cmdline_len >COMMAND_LINE_SIZE ) { -pr_err ("Appending elfcorehdr=<addr> exceeds cmdline size\n" ); +if (parameter_len + cmdline_len >COMMAND_LINE_SIZE ) { +pr_err ("Appending %s=<addr> exceeds cmdline size\n" , name);kfree (cmdline_ptr);return NULL ; } -memcpy (cmdline_ptr + elfcorehdr_strlen, cmdline, cmdline_len); +memcpy (cmdline_ptr + parameter_len, cmdline, cmdline_len);// Ensure it's nul terminated cmdline_ptr[COMMAND_LINE_SIZE -1 ] ='\0' ;return cmdline_ptr;
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 */
base-commit: 7f98ab9da046865d57c102fd3ca9669a29845f67
Signature · 1 line
2.52.0
Quoted 68 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 PowerPC, we only need to let 1st kernel build up the kernel command parameter dmcryptkeys as similar to elfcorehdr to pass the memory address of the stored info of dm-crypt keys to the kdump kernel.
Note to avoid a building failure [2] caused by undeclared function
crash_load_dm_crypt_keyswhenCONFIG_CRASH_DUMPis not enabled, realign the function declaration withCONFIG_CRASH_DM_CRYPT.[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/oe-kbuild-all/[email protected]/Cc Thomas Staudt <[email protected]>Cc 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 Sourabh Jain <[email protected]>Signed-off-by Coiby Xu <[email protected]>---
v2:
- fix double kfree issue [Sourabh]
- corretly kfree oldmodified_cmdline
- use imperative mood for commit message
- fix a compiling error caught by kernel test robotarch/powerpc/include/asm/kexec.h | 3 ++- arch/powerpc/kexec/elf_64.c | 27 ++++++++++++++++++++++++++- arch/powerpc/kexec/file_load.c | 18 ++++++++++-------- include/linux/crash_core.h | 14 +++++++------- 4 files changed, 45 insertions(+), 17 deletions(-)arch/powerpc/include/asm/kexec.h +2
-1@@ -80,7 +80,8 @@ struct kimage_arch { };char *setup_kdump_cmdline (struct kimage *image,char *cmdline, -unsigned long cmdline_len); +unsigned long cmdline_len, +char *name,unsigned long addr);int setup_purgatory (struct kimage *image,const void *slave_code,const void *fdt,unsigned long kernel_load_addr,unsigned long fdt_load_addr);arch/powerpc/kexec/elf_64.c +0
-1@@ -81,13 +81,38 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,/* Setup cmdline for kdump kernel case */ modified_cmdline = setup_kdump_cmdline(image, cmdline, - cmdline_len);
arch/powerpc/kexec/elf_64.c static void *elf64_load(struct kimage *image, char *kernel_buf, · line 93
Quoted 10 lines
arch/powerpc/kexec/elf_64.c +4
-0+ cmdline_len, +"elfcorehdr" , + image->elf_load_addr);if (!modified_cmdline) {pr_err ("Setting up cmdline for kdump kernel failed\n" ); ret = -EINVAL ; goto out; } cmdline = modified_cmdline; + cmdline_len =strlen (cmdline) +1 ;
I have a limited understanding of the new dm-crypt keys, but the way they are loaded and the additional command-line options added for the kdump kernel look good to me.
Feel free to add:
Quoted 108 lines
arch/powerpc/kexec/elf_64.c +22
-0+ + 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" ); +return ERR_PTR (ret); + } + +if (image->dm_crypt_keys_addr !=0 ) { + modified_cmdline =setup_kdump_cmdline (image, cmdline, + cmdline_len, +"dmcryptkeys" , + image->dm_crypt_keys_addr); +kfree (cmdline); +if (!modified_cmdline) { +pr_err ("Setting up cmdline for kdump kernel failed\n" ); + ret = -EINVAL ; + goto out; + } + cmdline = modified_cmdline; + } }if (initrd !=NULL ) {arch/powerpc/kexec/file_load.c +10
-8@@ -23,36 +23,38 @@#define SLAVE_CODE_SIZE 256/* First 0x100 bytes */ /** -* setup_kdump_cmdline - Prepend "elfcorehdr=<addr> " to command line +* setup_kdump_cmdline - Prepend "<name>=<addr> " to command line * of kdump kernel for exporting the core. * @image: Kexec image * @cmdline: Command line parameters to update. * @cmdline_len: Length of the cmdline parameters. +* @name: Name e.g elfcorehdr. +* @addr: Memory address. * * kdump segment must be setup before calling this function. * * Returns new cmdline buffer for kdump kernel on success, NULL otherwise. */ char *setup_kdump_cmdline (struct kimage *image,char *cmdline, -unsigned long cmdline_len) +unsigned long cmdline_len, +char *name,unsigned long addr) { -int elfcorehdr_strlen; +unsigned long parameter_len;char *cmdline_ptr; cmdline_ptr =kzalloc (COMMAND_LINE_SIZE ,GFP_KERNEL );if (!cmdline_ptr)return NULL ; - elfcorehdr_strlen =sprintf (cmdline_ptr,"elfcorehdr=0x%lx " , - image->elf_load_addr); + parameter_len =sprintf (cmdline_ptr,"%s=0x%lx " , name, addr); -if (elfcorehdr_strlen + cmdline_len >COMMAND_LINE_SIZE ) { -pr_err ("Appending elfcorehdr=<addr> exceeds cmdline size\n" ); +if (parameter_len + cmdline_len >COMMAND_LINE_SIZE ) { +pr_err ("Appending %s=<addr> exceeds cmdline size\n" , name);kfree (cmdline_ptr);return NULL ; } -memcpy (cmdline_ptr + elfcorehdr_strlen, cmdline, cmdline_len); +memcpy (cmdline_ptr + parameter_len, cmdline, cmdline_len);// Ensure it's nul terminated cmdline_ptr[COMMAND_LINE_SIZE -1 ] ='\0' ;return cmdline_ptr;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 */ base-commit:
7f98ab9da046865d57c102fd3ca9669a29845f67
Quoted 84 lines · Sourabh Jain
Quoted 66 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 PowerPC, we only need to let 1st kernel build up the kernel command parameter dmcryptkeys as similar to elfcorehdr to pass the memory address of the stored info of dm-crypt keys to the kdump kernel.
Note to avoid a building failure [2] caused by undeclared function
crash_load_dm_crypt_keyswhenCONFIG_CRASH_DUMPis not enabled, realign the function declaration withCONFIG_CRASH_DM_CRYPT.[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/oe-kbuild-all/[email protected]/Cc Thomas Staudt <[email protected]>Cc 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 Sourabh Jain <[email protected]>Signed-off-by Coiby Xu <[email protected]>---
v2:
- fix double kfree issue [Sourabh]
- corretly kfree oldmodified_cmdline
- use imperative mood for commit message
- fix a compiling error caught by kernel test robotarch/powerpc/include/asm/kexec.h | 3 ++- arch/powerpc/kexec/elf_64.c | 27 ++++++++++++++++++++++++++- arch/powerpc/kexec/file_load.c | 18 ++++++++++-------- include/linux/crash_core.h | 14 +++++++------- 4 files changed, 45 insertions(+), 17 deletions(-)arch/powerpc/include/asm/kexec.h +2
-1@@ -80,7 +80,8 @@ struct kimage_arch { };char *setup_kdump_cmdline (struct kimage *image,char *cmdline, -unsigned long cmdline_len); +unsigned long cmdline_len, +char *name,unsigned long addr);int setup_purgatory (struct kimage *image,const void *slave_code,const void *fdt,unsigned long kernel_load_addr,unsigned long fdt_load_addr);arch/powerpc/kexec/elf_64.c +0
-1@@ -81,13 +81,38 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,/* Setup cmdline for kdump kernel case */ modified_cmdline = setup_kdump_cmdline(image, cmdline, - cmdline_len);arch/powerpc/kexec/elf_64.c static void *elf64_load(struct kimage *image, char *kernel_buf, · line 92
Quoted 10 lines
arch/powerpc/kexec/elf_64.c +4
-0+ cmdline_len, +"elfcorehdr" , + image->elf_load_addr);if (!modified_cmdline) {pr_err ("Setting up cmdline for kdump kernel failed\n" ); ret = -EINVAL ; goto out; } cmdline = modified_cmdline; + cmdline_len =strlen (cmdline) +1 ;I have a limited understanding of the new dm-crypt keys, but the way they are loaded and the additional command-line options added for the kdump kernel look good to me.
Quoted 2 lines
Feel free to add:
Acked-by Sourabh Jain <[email protected]>
Thanks for reviewing and acknowledging the patch!
Signature · 2 lines
Best regards, Coiby