Re: [PATCH v6 3/7] crash_dump: store dm crypt keys in kdump reserved memory

Coiby Xu
2024-12-23T01:15:20Z

On Wed, Dec 11, 2024 at 08:58:27PM +0800, Baoquan He wrote:
>On 10/29/24 at 01:52pm, Coiby Xu wrote:
>......
>> +int crash_load_dm_crypt_keys(struct kimage *image)
>> +{
>> + struct kexec_buf kbuf = {
>> + .image = image,
>> + .buf_min = 0,
>> + .buf_max = ULONG_MAX,
>> + .top_down = false,
>> + .random = true,
>> + };
>> + int r;
>> +
>> +
>> + if (key_count <= 0) {
>> + kexec_dprintk("No dm-crypt keys\n");
>> + return -EINVAL;
>> + }
>> +
>> + image->dm_crypt_keys_addr = 0;
>> + r = build_keys_header();
>> + if (r)
>> + return r;
>> +
>> + kbuf.buffer = keys_header;
>> + kbuf.bufsz = get_keys_header_size(key_count);
>> +
>> + kbuf.memsz = kbuf.bufsz;
>> + kbuf.buf_align = ELF_CORE_HEADER_ALIGN;
>> + kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
>> + r = kexec_add_buffer(&kbuf);
>> + if (r) {
>> + kvfree((void *)kbuf.buffer);
>> + return r;
>> + }
>> + image->dm_crypt_keys_addr = kbuf.mem;
>> + image->dm_crypt_keys_sz = kbuf.bufsz;
>
>Wondering why not assigning kbuf.memsz, but bufsz.

Thanks for the question! I think there is no need to use kbuf.memsz
after reading the code on setting image->elf_headers_sz. Currently all
arches except for x86 CONFIG_CRASH_HOTPLUG assigns kbuf.bufsz to
image->elf_headers_sz. For x86 CONFIG_CRASH_HOTPLUG, if I understand it
correctly, it assigns kbuf.memsz to kbuf.memsz because elfcorehdr
changes when there is memory/CPU hot-plugging. For dm crypt keys, there
is no so such concern, so assigning kbuf.bufsz shall be OK.

--
Best regards,
Coiby