From: Coiby Xu <coiby.xu@gmail.com>
To: sashiko-reviews@lists.linux.dev
Cc: Jinjie Ruan <ruanjinjie@huawei.com>,
Andrew Morton <akpm@linux-foundation.org>,
Sourabh Jain <sourabhjain@linux.ibm.com>,
kexec@lists.infradead.org, Pratyush Yadav <pratyush@kernel.org>,
Dave Young <ruirui.yang@linux.dev>,
Will Deacon <will@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Mike Rapoport <rppt@kernel.org>,
Catalin Marinas <catalin.marinas@arm.com>,
Pasha Tatashin <pasha.tatashin@soleen.com>,
Baoquan He <baoquan.he@linux.dev>,
linux-arm-kernel@lists.infradead.org,
open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v5 1/9] crash_dump: Fix potential double free and UAF of keys_header
Date: Wed, 9 Sep 2026 21:27:47 +0800 [thread overview]
Message-ID: <aqFeOaIxKNMKVOTM@Rk> (raw)
In-Reply-To: <20260909005311.B1E471F00A3A@smtp.kernel.org>
On Wed, Sep 09, 2026 at 12:53:11AM +0000, sashiko-bot@kernel.org wrote:
>Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
>
>New issues:
>- [High] Prematurely clearing `is_dm_key_reused` breaks the ARM64 kexec_file_load retry loop and defeats hotplug dm-crypt key reuse.
Thanks for catching this issue! I'll send a new version to address this
issue.
>
>Pre-existing issues:
>- [High] Mapping crash-reserved memory with `kmap_local_page()` causes out-of-bounds reads if dm-crypt keys exceed a single page.
x86 is not supported so I think this concern can be dismissed.
>--
>
>commit 9cf0538566bf6406e97a7f29629856abff44a5b0
>Author: Coiby Xu <coiby.xu@gmail.com>
>
>crash_dump: Fix potential double free and UAF of keys_header
>
>This commit addresses a potential double free and UAF of keys_header when
>loading dm-crypt keys for kdump. It establishes an invariant to free
>keys_header at the end of kexec_file_load unless reuse=true.
>
>> diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c
>> index b70f4df15a1ae..1a0ca54adc9a4 100644
>> --- a/arch/arm64/kernel/kexec_image.c
>> +++ b/arch/arm64/kernel/kexec_image.c
>> @@ -110,6 +110,7 @@ static void *image_load(struct kimage *image,
>> image->nr_segments -= 1;
>> kbuf.buf_min = kernel_segment->mem + kernel_segment->memsz;
>> kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
>> + crash_dm_crypt_cleanup(image);
>
>[Severity: High]
>Does this call to crash_dm_crypt_cleanup() during a retry loop unintentionally
>free the keys_header buffer?
>
>Since crash_load_dm_crypt_keys() unconditionally clears the is_dm_key_reused
>flag before returning, any mid-retry cleanup performed here when segment
>placement fails will see the flag as false and wrongfully free the valid
>keys_header buffer.
>
>> }
>>
>> if (ret) {
>
>[ ... ]
>
>> diff --git a/kernel/crash_dump_dm_crypt.c b/kernel/crash_dump_dm_crypt.c
>> index c685497cd470e..f638fb4b8554c 100644
>> --- a/kernel/crash_dump_dm_crypt.c
>> +++ b/kernel/crash_dump_dm_crypt.c
>> @@ -84,18 +84,25 @@ static int add_key_to_keyring(struct dm_crypt_key *dm_key,
>
>[ ... ]
>
>> -static void get_keys_from_kdump_reserved_memory(void)
>> +static int get_keys_from_kdump_reserved_memory(void)
>> {
>> struct keys_header *keys_header_loaded;
>> + size_t keys_header_size;
>>
>> - arch_kexec_unprotect_crashkres();
>> + keys_header_size = get_keys_header_size(key_count);
>> + keys_header = kzalloc(keys_header_size, GFP_KERNEL);
>> + if (!keys_header)
>> + return -ENOMEM;
>>
>> + arch_kexec_unprotect_crashkres();
>> keys_header_loaded = kmap_local_page(pfn_to_page(
>> kexec_crash_image->dm_crypt_keys_addr >> PAGE_SHIFT));
>>
>> - memcpy(keys_header, keys_header_loaded, get_keys_header_size(key_count));
>> + memcpy(keys_header, keys_header_loaded, keys_header_size);
>
>[Severity: High]
>This is a pre-existing issue, but does this copy read out of bounds?
>
>kmap_local_page() guarantees mapping exactly one physical page frame. If user
>configuration has enough dm-crypt keys (e.g., > 10 keys, where each struct is
>388 bytes), keys_header_size easily exceeds the 4KB page size.
>
>Copying beyond the single-page mapping will cause out-of-bounds reads and
>could trigger a kernel panic on systems with HIGHMEM or when
>CONFIG_DEBUG_KMAP_LOCAL is enabled. Could memremap() be used instead?
>
>> kunmap_local(keys_header_loaded);
>> arch_kexec_protect_crashkres();
>> +
>> + return 0;
>> }
>
>[ ... ]
>
>> @@ -441,18 +458,33 @@ int crash_load_dm_crypt_keys(struct kimage *image)
>> 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;
>> + goto out;
>> }
>> +
>> image->dm_crypt_keys_addr = kbuf.mem;
>> image->dm_crypt_keys_sz = kbuf.bufsz;
>> kexec_dprintk(
>> "Loaded dm crypt keys to kexec_buffer bufsz=0x%lx memsz=0x%lx\n",
>> kbuf.bufsz, kbuf.memsz);
>>
>> +out:
>> + is_dm_key_reused = false;
>
>[Severity: High]
>Does prematurely clearing is_dm_key_reused here destroy the state needed for
>the segment placement retry loop?
>
>On ARM64, if the first attempt at segment placement fails, the kexec load
>code retries the loop. Since the flag is unconditionally cleared here, the
>first iteration will clear it. When the retry cleanup executes in
>image_load(), it will see is_dm_key_reused == false, freeing the keys_header
>buffer and leaving subsequent retries without the required keys.
>
>> return r;
>> }
>
>--
>Sashiko AI review · https://sashiko.dev/#/patchset/20260909003657.1570544-1-coiby.xu@gmail.com?part=1
--
Best regards,
Coiby
next prev parent reply other threads:[~2026-09-09 13:30 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260909003657.1570544-1-coiby.xu@gmail.com>
2026-09-09 0:36 ` Coiby Xu
2026-09-09 0:53 ` sashiko-bot
2026-09-09 13:27 ` Coiby Xu [this message]
2026-09-09 0:36 ` [PATCH v5 2/9] crash_dump: Read the number of dm-crypt keys from reserved memory Coiby Xu
2026-09-09 0:52 ` sashiko-bot
2026-09-09 0:36 ` [PATCH v5 3/9] crash_dump: Disallow writing to dm-crypt configfs during kexec_file_load syscall Coiby Xu
2026-09-09 0:47 ` sashiko-bot
2026-09-09 13:29 ` Coiby Xu
2026-09-09 0:36 ` [PATCH v5 4/9] crash_dump: Free temporary dm-crypt keys_header buffer in kdump kernel Coiby Xu
2026-09-09 0:46 ` sashiko-bot
2026-09-09 0:36 ` [PATCH v5 5/9] crash_dump: Only use kexec_dprintk during the kexec_file_load syscall Coiby Xu
2026-09-09 0:47 ` sashiko-bot
2026-09-09 0:36 ` [PATCH v5 6/9] crash_dump: Improve readability of config_keys_restore_store Coiby Xu
2026-09-09 0:45 ` sashiko-bot
2026-09-09 0:36 ` [PATCH v5 7/9] crash_dump: Check the function return codes in restore_dm_crypt_keys_to_thread_keyring Coiby Xu
2026-09-09 0:49 ` sashiko-bot
2026-09-09 0:36 ` [PATCH v5 8/9] crash_dump: Disallow configfs/crash_dm_crypt_key/reuse if crash hotplug supported Coiby Xu
2026-09-09 0:53 ` sashiko-bot
2026-09-09 5:46 ` Randy Dunlap
2026-09-09 13:33 ` Coiby Xu
2026-09-09 0:36 ` [PATCH v5 9/9] Documentation: kdump: Add arm64 and ppc64le to encrypted dump target support list Coiby Xu
2026-09-09 0:38 ` sashiko-bot
2026-09-09 5:48 ` Randy Dunlap
2026-09-09 13:34 ` Coiby Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aqFeOaIxKNMKVOTM@Rk \
--to=coiby.xu@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=baoquan.he@linux.dev \
--cc=catalin.marinas@arm.com \
--cc=kexec@lists.infradead.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=pasha.tatashin@soleen.com \
--cc=pratyush@kernel.org \
--cc=rppt@kernel.org \
--cc=ruanjinjie@huawei.com \
--cc=ruirui.yang@linux.dev \
--cc=sashiko-reviews@lists.linux.dev \
--cc=sourabhjain@linux.ibm.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®