Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

riscv: kexec: initialize kexec_buf struct

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.

Link: https://lkml.kernel.org/r/20250827-kbuf_all-v1-2-1df9882bb01a@debian.org
Fixes: bf454ec31add ("kexec_file: allow to place kexec_buf randomly")
Signed-off-by: Breno Leitao <leitao@debian.org>
Cc: Albert Ou <aou@eecs.berkeley.edu>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Alexandre Ghiti <alex@ghiti.fr>
Cc: Baoquan He <bhe@redhat.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: Coiby Xu <coxu@redhat.com>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Paul Walmsley <paul.walmsley@sifive.com>
Cc: Sven Schnelle <svens@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Will Deacon <will@kernel.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Breno Leitao and committed by
Andrew Morton
8afbd004 04d3cd43

+4 -4
+2 -2
arch/riscv/kernel/kexec_elf.c
··· 28 28 int i; 29 29 int ret = 0; 30 30 size_t size; 31 - struct kexec_buf kbuf; 31 + struct kexec_buf kbuf = {}; 32 32 const struct elf_phdr *phdr; 33 33 34 34 kbuf.image = image; ··· 66 66 { 67 67 int i; 68 68 int ret; 69 - struct kexec_buf kbuf; 69 + struct kexec_buf kbuf = {}; 70 70 const struct elf_phdr *phdr; 71 71 unsigned long lowest_paddr = ULONG_MAX; 72 72 unsigned long lowest_vaddr = ULONG_MAX;
+1 -1
arch/riscv/kernel/kexec_image.c
··· 41 41 struct riscv_image_header *h; 42 42 u64 flags; 43 43 bool be_image, be_kernel; 44 - struct kexec_buf kbuf; 44 + struct kexec_buf kbuf = {}; 45 45 int ret; 46 46 47 47 /* Check Image header */
+1 -1
arch/riscv/kernel/machine_kexec_file.c
··· 261 261 int ret; 262 262 void *fdt; 263 263 unsigned long initrd_pbase = 0UL; 264 - struct kexec_buf kbuf; 264 + struct kexec_buf kbuf = {}; 265 265 char *modified_cmdline = NULL; 266 266 267 267 kbuf.image = image;