Skip to content

Commit 95c54cd

Browse files
leitaoPaul Walmsley
authored andcommitted
riscv: kexec: Initialize kexec_buf struct
The kexec_buf structure was previously declared without initialization. commit bf454ec ("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. Fixes: bf454ec ("kexec_file: allow to place kexec_buf randomly") Signed-off-by: Breno Leitao <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Paul Walmsley <[email protected]>
1 parent f4ea67a commit 95c54cd

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

arch/riscv/kernel/kexec_elf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ static int riscv_kexec_elf_load(struct kimage *image, struct elfhdr *ehdr,
2828
int i;
2929
int ret = 0;
3030
size_t size;
31-
struct kexec_buf kbuf;
31+
struct kexec_buf kbuf = {};
3232
const struct elf_phdr *phdr;
3333

3434
kbuf.image = image;
@@ -66,7 +66,7 @@ static int elf_find_pbase(struct kimage *image, unsigned long kernel_len,
6666
{
6767
int i;
6868
int ret;
69-
struct kexec_buf kbuf;
69+
struct kexec_buf kbuf = {};
7070
const struct elf_phdr *phdr;
7171
unsigned long lowest_paddr = ULONG_MAX;
7272
unsigned long lowest_vaddr = ULONG_MAX;

arch/riscv/kernel/kexec_image.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static void *image_load(struct kimage *image,
4141
struct riscv_image_header *h;
4242
u64 flags;
4343
bool be_image, be_kernel;
44-
struct kexec_buf kbuf;
44+
struct kexec_buf kbuf = {};
4545
int ret;
4646

4747
/* Check Image header */

arch/riscv/kernel/machine_kexec_file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ int load_extra_segments(struct kimage *image, unsigned long kernel_start,
261261
int ret;
262262
void *fdt;
263263
unsigned long initrd_pbase = 0UL;
264-
struct kexec_buf kbuf;
264+
struct kexec_buf kbuf = {};
265265
char *modified_cmdline = NULL;
266266

267267
kbuf.image = image;

0 commit comments

Comments
 (0)