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

s390: 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-3-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
e67f0bd0 8afbd004

+5 -5
+1 -1
arch/s390/kernel/kexec_elf.c
··· 16 16 static int kexec_file_add_kernel_elf(struct kimage *image, 17 17 struct s390_load_data *data) 18 18 { 19 - struct kexec_buf buf; 19 + struct kexec_buf buf = {}; 20 20 const Elf_Ehdr *ehdr; 21 21 const Elf_Phdr *phdr; 22 22 Elf_Addr entry;
+1 -1
arch/s390/kernel/kexec_image.c
··· 16 16 static int kexec_file_add_kernel_image(struct kimage *image, 17 17 struct s390_load_data *data) 18 18 { 19 - struct kexec_buf buf; 19 + struct kexec_buf buf = {}; 20 20 21 21 buf.image = image; 22 22
+3 -3
arch/s390/kernel/machine_kexec_file.c
··· 129 129 static int kexec_file_add_purgatory(struct kimage *image, 130 130 struct s390_load_data *data) 131 131 { 132 - struct kexec_buf buf; 132 + struct kexec_buf buf = {}; 133 133 int ret; 134 134 135 135 buf.image = image; ··· 152 152 static int kexec_file_add_initrd(struct kimage *image, 153 153 struct s390_load_data *data) 154 154 { 155 - struct kexec_buf buf; 155 + struct kexec_buf buf = {}; 156 156 int ret; 157 157 158 158 buf.image = image; ··· 184 184 { 185 185 __u32 *lc_ipl_parmblock_ptr; 186 186 unsigned int len, ncerts; 187 - struct kexec_buf buf; 187 + struct kexec_buf buf = {}; 188 188 unsigned long addr; 189 189 void *ptr, *end; 190 190 int ret;