From: Youling Tang <youling.tang@linux.dev>
To: Huacai Chen <chenhuacai@kernel.org>
Cc: kexec@lists.infradead.org, Breno Leitao <leitao@debian.org>,
Youling Tang <tangyouling@kylinos.cn>,
loongarch@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] LoongArch: kexec: Initialize kexec_buf struct
Date: Fri, 24 Oct 2025 15:06:56 +0800 [thread overview]
Message-ID: <d327af2b-8089-4d1b-8f7f-9f18c0d9faba@linux.dev> (raw)
In-Reply-To: <20251024063653.35492-1-youling.tang@linux.dev>
cc to loongarch@lists.linux.dev and linux-kernel@vger.kernel.org
On 10/24/25 14:36, Youling Tang wrote:
> From: Youling Tang <tangyouling@kylinos.cn>
>
> The kexec_buf structure was previously declared without initialization.
> commit bf454ec31add ("kexec_file: allow to place kexec_buf randomly")
> added a field that is always read but not consistently populated by all
> architectures. This un-initialized field will contain garbage.
>
> This is also triggering a UBSAN warning when the uninitialized data was
> accessed:
>
> ------------[ cut here ]------------
> UBSAN: invalid-load in ./include/linux/kexec.h:210:10
> load of value 252 is not a valid value for type '_Bool'
>
> Zero-initializing kexec_buf at declaration ensures all fields are
> cleanly set, preventing future instances of uninitialized memory being
> used.
>
> Fixes: bf454ec31add ("kexec_file: allow to place kexec_buf randomly")
> Link: https://lore.kernel.org/r/20250827-kbuf_all-v1-2-1df9882bb01a@debian.org
> Signed-off-by: Youling Tang <tangyouling@kylinos.cn>
> ---
> arch/loongarch/kernel/kexec_efi.c | 2 +-
> arch/loongarch/kernel/kexec_elf.c | 2 +-
> arch/loongarch/kernel/machine_kexec_file.c | 2 +-
> 3 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/arch/loongarch/kernel/kexec_efi.c b/arch/loongarch/kernel/kexec_efi.c
> index 45121b914f8f..5ee78ebb1546 100644
> --- a/arch/loongarch/kernel/kexec_efi.c
> +++ b/arch/loongarch/kernel/kexec_efi.c
> @@ -42,7 +42,7 @@ static void *efi_kexec_load(struct kimage *image,
> {
> int ret;
> unsigned long text_offset, kernel_segment_number;
> - struct kexec_buf kbuf;
> + struct kexec_buf kbuf = {};
> struct kexec_segment *kernel_segment;
> struct loongarch_image_header *h;
>
> diff --git a/arch/loongarch/kernel/kexec_elf.c b/arch/loongarch/kernel/kexec_elf.c
> index 97b2f049801a..1b6b64744c7f 100644
> --- a/arch/loongarch/kernel/kexec_elf.c
> +++ b/arch/loongarch/kernel/kexec_elf.c
> @@ -59,7 +59,7 @@ static void *elf_kexec_load(struct kimage *image,
> int ret;
> unsigned long text_offset, kernel_segment_number;
> struct elfhdr ehdr;
> - struct kexec_buf kbuf;
> + struct kexec_buf kbuf = {};
> struct kexec_elf_info elf_info;
> struct kexec_segment *kernel_segment;
>
> diff --git a/arch/loongarch/kernel/machine_kexec_file.c b/arch/loongarch/kernel/machine_kexec_file.c
> index dda236b51a88..fb57026f5f25 100644
> --- a/arch/loongarch/kernel/machine_kexec_file.c
> +++ b/arch/loongarch/kernel/machine_kexec_file.c
> @@ -143,7 +143,7 @@ int load_other_segments(struct kimage *image,
> unsigned long initrd_load_addr = 0;
> unsigned long orig_segments = image->nr_segments;
> char *modified_cmdline = NULL;
> - struct kexec_buf kbuf;
> + struct kexec_buf kbuf = {};
>
> kbuf.image = image;
> /* Don't allocate anything below the kernel */
parent reply other threads:[~2025-10-24 7:07 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <20251024063653.35492-1-youling.tang@linux.dev>]
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=d327af2b-8089-4d1b-8f7f-9f18c0d9faba@linux.dev \
--to=youling.tang@linux.dev \
--cc=chenhuacai@kernel.org \
--cc=kexec@lists.infradead.org \
--cc=leitao@debian.org \
--cc=linux-kernel@vger.kernel.org \
--cc=loongarch@lists.linux.dev \
--cc=tangyouling@kylinos.cn \
/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