s390: kexec: initialize kexec_buf struct
authorBreno Leitao <leitao@debian.org>
Wed, 27 Aug 2025 10:42:23 +0000 (03:42 -0700)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 4 Sep 2025 00:10:37 +0000 (17:10 -0700)
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>
arch/s390/kernel/kexec_elf.c
arch/s390/kernel/kexec_image.c
arch/s390/kernel/machine_kexec_file.c

index 4d364de4379921c852de6d98fcea95e82ed53743..143e34a4eca57c5c467413627cc7e6822f7490f6 100644 (file)
@@ -16,7 +16,7 @@
 static int kexec_file_add_kernel_elf(struct kimage *image,
                                     struct s390_load_data *data)
 {
-       struct kexec_buf buf;
+       struct kexec_buf buf = {};
        const Elf_Ehdr *ehdr;
        const Elf_Phdr *phdr;
        Elf_Addr entry;
index a32ce8bea745cfde0a4eea3ff57ac0572714f504..9a439175723cadaebccf677b73826e7daba57ac0 100644 (file)
@@ -16,7 +16,7 @@
 static int kexec_file_add_kernel_image(struct kimage *image,
                                       struct s390_load_data *data)
 {
-       struct kexec_buf buf;
+       struct kexec_buf buf = {};
 
        buf.image = image;
 
index c2bac14dd668ae39d7fd9f2aa6092618464f3fd4..a36d7311c6683b15d76f8db84fb44f300574d922 100644 (file)
@@ -129,7 +129,7 @@ static int kexec_file_update_purgatory(struct kimage *image,
 static int kexec_file_add_purgatory(struct kimage *image,
                                    struct s390_load_data *data)
 {
-       struct kexec_buf buf;
+       struct kexec_buf buf = {};
        int ret;
 
        buf.image = image;
@@ -152,7 +152,7 @@ static int kexec_file_add_purgatory(struct kimage *image,
 static int kexec_file_add_initrd(struct kimage *image,
                                 struct s390_load_data *data)
 {
-       struct kexec_buf buf;
+       struct kexec_buf buf = {};
        int ret;
 
        buf.image = image;
@@ -184,7 +184,7 @@ static int kexec_file_add_ipl_report(struct kimage *image,
 {
        __u32 *lc_ipl_parmblock_ptr;
        unsigned int len, ncerts;
-       struct kexec_buf buf;
+       struct kexec_buf buf = {};
        unsigned long addr;
        void *ptr, *end;
        int ret;