]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
LoongArch: kexec: Initialize the kexec_buf structure
authorYouling Tang <tangyouling@kylinos.cn>
Sun, 9 Nov 2025 08:02:01 +0000 (16:02 +0800)
committerHuacai Chen <chenhuacai@loongson.cn>
Mon, 10 Nov 2025 00:37:07 +0000 (08:37 +0800)
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 is
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>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
arch/loongarch/kernel/kexec_efi.c
arch/loongarch/kernel/kexec_elf.c
arch/loongarch/kernel/machine_kexec_file.c

index 45121b914f8f7987dc93f62bfb2b537804257336..5ee78ebb1546e21e6aea23bee4f3f5991d246f0d 100644 (file)
@@ -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;
 
index 97b2f049801a8fd9ba3e70cc9fd80f681ddf6f35..1b6b64744c7fdea119b5ef15cb2a5cf6f29f922d 100644 (file)
@@ -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;
 
index dda236b51a881f1f61ad84c64ac31da8e6cc62de..fb57026f5f25e5b3b1875a6908b18d337023c30e 100644 (file)
@@ -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 */