LoongArch: kexec: Initialize kexec_buf struct
Subsystems (3)
PATCH 1/1 LoongArch: kexec: Initialize kexec_buf struct
From: Youling Tang <[email protected]>
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.
--- 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(-)
arch/loongarch/kernel/kexec_efi.c +1 -1
@@ -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;
arch/loongarch/kernel/kexec_elf.c +1 -1
@@ -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;
arch/loongarch/kernel/machine_kexec_file.c +1 -1
@@ -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 */
Signature · 1 line
2.43.0
cc to [email protected] and [email protected]
Quoted 66 lines · Youling Tang
From: Youling Tang <[email protected]>
The
kexec_bufstructure was previously declared without initialization. commitbf454ec31add("kexec_file: allow to placekexec_bufrandomly") 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_bufat 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")Signed-off-by Youling Tang <[email protected]>--- 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(-)arch/loongarch/kernel/kexec_efi.c +1
-1@@ -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;arch/loongarch/kernel/kexec_elf.c +1
-1@@ -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;arch/loongarch/kernel/machine_kexec_file.c +1
-1@@ -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 */
Applied, thanks.
Huacai
Quoted 70 lines · Youling Tang
From: Youling Tang <[email protected]>
The
kexec_bufstructure was previously declared without initialization. commitbf454ec31add("kexec_file: allow to placekexec_bufrandomly") 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_bufat 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")Signed-off-by Youling Tang <[email protected]>--- 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(-)arch/loongarch/kernel/kexec_efi.c +1
-1@@ -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;arch/loongarch/kernel/kexec_elf.c +1
-1@@ -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;arch/loongarch/kernel/machine_kexec_file.c +1
-2@@ -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 */ --2.43.0