Skip to content

Commit 81bbcff

Browse files
liutgnuPaul Walmsley
authored andcommitted
riscv: Prevent NULL pointer dereference in machine_kexec_prepare()
A NULL pointer dereference issue is noticed in riscv's machine_kexec_prepare(), where image->segment[i].buf might be NULL and copied unchecked. The NULL buf comes from ima_add_kexec_buffer(), where kbuf is added by kexec_add_buffer(), but kbuf.buffer is NULL, then it is copied without a check in machine_kexec_prepare(): kexec_file_load -> kimage_file_alloc_init() -> kimage_file_prepare_segments() -> ima_add_kexec_buffer() -> kexec_add_buffer() -> machine_kexec_prepare() -> memcpy() Address this by adding a check before the data copy attempt. Fixes: b7fb4d7 ("RISC-V: use memcpy for kexec_file mode") Cc: stable@vger.kernel.org Closes: https://lore.kernel.org/kexec/CAO7dBbVftLUhd2qrh7hmijTB3PEPfZAhykCGqEfrPoOcSrrj-w@mail.gmail.com/ Acked-by: Baoquan He <bhe@redhat.com> Acked-by: Pratyush Yadav <pratyush@kernel.org> Reviewed-by: Nutty Liu <nutty.liu@hotmail.com> Signed-off-by: Tao Liu <ltao@redhat.com> Link: https://patch.msgid.link/20260705232706.30265-2-ltao@redhat.com Signed-off-by: Paul Walmsley <pjw@kernel.org>
1 parent 8cdeaa5 commit 81bbcff

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

arch/riscv/kernel/machine_kexec.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ machine_kexec_prepare(struct kimage *image)
4141
if (image->segment[i].memsz <= sizeof(fdt))
4242
continue;
4343

44+
if (!image->segment[i].buf)
45+
continue;
46+
4447
if (image->file_mode)
4548
memcpy(&fdt, image->segment[i].buf, sizeof(fdt));
4649
else if (copy_from_user(&fdt, image->segment[i].buf, sizeof(fdt)))

0 commit comments

Comments
 (0)