Commit 95c54cd9 authored by Breno Leitao's avatar Breno Leitao Committed by Paul Walmsley
Browse files

riscv: kexec: Initialize kexec_buf struct



The kexec_buf structure was previously declared without initialization.
commit bf454ec3 ("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: bf454ec3 ("kexec_file: allow to place kexec_buf randomly")
Signed-off-by: default avatarBreno Leitao <leitao@debian.org>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20250827-kbuf_all-v1-2-1df9882bb01a@debian.org


Signed-off-by: default avatarPaul Walmsley <pjw@kernel.org>
parent f4ea67a7
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ static int riscv_kexec_elf_load(struct kimage *image, struct elfhdr *ehdr,
	int i;
	int ret = 0;
	size_t size;
	struct kexec_buf kbuf;
	struct kexec_buf kbuf = {};
	const struct elf_phdr *phdr;

	kbuf.image = image;
@@ -66,7 +66,7 @@ static int elf_find_pbase(struct kimage *image, unsigned long kernel_len,
{
	int i;
	int ret;
	struct kexec_buf kbuf;
	struct kexec_buf kbuf = {};
	const struct elf_phdr *phdr;
	unsigned long lowest_paddr = ULONG_MAX;
	unsigned long lowest_vaddr = ULONG_MAX;
+1 −1
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ static void *image_load(struct kimage *image,
	struct riscv_image_header *h;
	u64 flags;
	bool be_image, be_kernel;
	struct kexec_buf kbuf;
	struct kexec_buf kbuf = {};
	int ret;

	/* Check Image header */
+1 −1
Original line number Diff line number Diff line
@@ -261,7 +261,7 @@ int load_extra_segments(struct kimage *image, unsigned long kernel_start,
	int ret;
	void *fdt;
	unsigned long initrd_pbase = 0UL;
	struct kexec_buf kbuf;
	struct kexec_buf kbuf = {};
	char *modified_cmdline = NULL;

	kbuf.image = image;