The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] riscv: Fix a NULL pointer reference in machine_kexec_prepare
@ 2026-05-29  3:27 Tao Liu
  2026-06-25 23:17 ` Tao Liu
  0 siblings, 1 reply; 6+ messages in thread
From: Tao Liu @ 2026-05-29  3:27 UTC (permalink / raw)
  To: pjw, palmer, aou, alex; +Cc: linux-riscv, linux-kernel, Tao Liu

A NULL pointer reference 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 security/integrity/ima/ima_kexec.c:
ima_add_kexec_buffer(), where kbuf is added by kexec_add_buffer(),
but kbuf.buffer is NULL.

Fix this by simply adding a check before copy.

Signed-off-by: Tao Liu <ltao@redhat.com>
---
 arch/riscv/kernel/machine_kexec.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/riscv/kernel/machine_kexec.c b/arch/riscv/kernel/machine_kexec.c
index 2306ce3e5f22..d81d576f9cb5 100644
--- a/arch/riscv/kernel/machine_kexec.c
+++ b/arch/riscv/kernel/machine_kexec.c
@@ -41,6 +41,9 @@ machine_kexec_prepare(struct kimage *image)
 		if (image->segment[i].memsz <= sizeof(fdt))
 			continue;
 
+		if (image->segment[i].buf == NULL)
+			continue;
+
 		if (image->file_mode)
 			memcpy(&fdt, image->segment[i].buf, sizeof(fdt));
 		else if (copy_from_user(&fdt, image->segment[i].buf, sizeof(fdt)))
-- 
2.47.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-06-29  2:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-29  3:27 [PATCH] riscv: Fix a NULL pointer reference in machine_kexec_prepare Tao Liu
2026-06-25 23:17 ` Tao Liu
2026-06-26  8:04   ` Baoquan He
2026-06-26  8:38     ` Tao Liu
2026-06-27 22:38       ` Tao Liu
2026-06-29  2:44         ` Baoquan He

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox